~glance-coresec/glance/cactus-trunk

« back to all changes in this revision

Viewing changes to glance/server.py

  • Committer: Tarmac
  • Author(s): jaypipes at gmail
  • Date: 2011-04-13 22:07:59 UTC
  • mfrom: (108.1.6 functional-tests)
  • Revision ID: tarmac-20110413220759-2sgwtflz7ma3oqqk
Tags: 2011.2rc1
Removes capture of exception from eventlet in _upload_and_activate(), which catches the exceptions that come from the _safe_kill() method properly.

Also fixes an incorrect call to _safe_kill() with mapping instead of image ID in the block of code that kills an image if a bad checksum is given.

Fixes bug #759018.

Show diffs side-by-side

added added

removed removed

Lines of Context:
227
227
        :raises HTTPConflict if image already exists
228
228
        :retval The location where the image was stored
229
229
        """
 
230
        image_id = image_meta['id']
230
231
        content_type = req.headers.get('content-type', 'notset')
231
232
        if content_type != 'application/octet-stream':
232
 
            raise HTTPBadRequest(
233
 
                "Content-Type must be application/octet-stream")
 
233
            self._safe_kill(req, image_id)
 
234
            msg = ("Content-Type must be application/octet-stream")
 
235
            logger.error(msg)
 
236
            raise HTTPBadRequest(msg, content_type="text/plain",
 
237
                                 request=req)
234
238
 
235
239
        store_name = req.headers.get(
236
240
            'x-image-meta-store', self.options['default_store'])
237
241
 
238
242
        store = self.get_store_or_400(req, store_name)
239
243
 
240
 
        image_id = image_meta['id']
241
244
        logger.debug("Setting image %s to status 'saving'"
242
245
                     % image_id)
243
246
        registry.update_image_metadata(self.options, image_id,
257
260
                       "checksum generated from uploaded image "
258
261
                       "(%(checksum)s) did not match. Setting image "
259
262
                       "status to 'killed'.") % locals()
260
 
                self._safe_kill(req, image_meta)
 
263
                logger.error(msg)
 
264
                self._safe_kill(req, image_id)
261
265
                raise HTTPBadRequest(msg, content_type="text/plain",
262
266
                                     request=req)
263
267
 
272
276
 
273
277
            return location
274
278
        except exception.Duplicate, e:
275
 
            logger.error("Error adding image to store: %s", str(e))
276
 
            raise HTTPConflict(str(e), request=req)
 
279
            msg = ("Attempt to upload duplicate image: %s") % str(e)
 
280
            logger.error(msg)
 
281
            self._safe_kill(req, image_id)
 
282
            raise HTTPConflict(msg, request=req)
 
283
        except Exception, e:
 
284
            msg = ("Error uploading image: %s") % str(e)
 
285
            logger.error(msg)
 
286
            self._safe_kill(req, image_id)
 
287
            raise HTTPBadRequest(msg, request=req)
277
288
 
278
289
    def _activate(self, req, image_id, location):
279
290
        """
329
340
 
330
341
        :retval Mapping of updated image data
331
342
        """
332
 
        try:
333
 
            image_id = image_meta['id']
334
 
            location = self._upload(req, image_meta)
335
 
            return self._activate(req, image_id, location)
336
 
        except:  # unqualified b/c we're re-raising it
337
 
            exc_type, exc_value, exc_traceback = sys.exc_info()
338
 
            self._safe_kill(req, image_id)
339
 
            # NOTE(sirp): _safe_kill uses httplib which, in turn, uses
340
 
            # Eventlet's GreenSocket. Eventlet subsequently clears exceptions
341
 
            # by calling `sys.exc_clear()`.
342
 
            #
343
 
            # This is why we can't use a raise with no arguments here: our
344
 
            # exception context was destroyed by Eventlet. To work around
345
 
            # this, we need to 'memorize' the exception context, and then
346
 
            # re-raise here.
347
 
            raise exc_type(exc_value)
 
343
        image_id = image_meta['id']
 
344
        location = self._upload(req, image_meta)
 
345
        return self._activate(req, image_id, location)
348
346
 
349
347
    def create(self, req):
350
348
        """