diff options
author | Jenkins <jenkins@review.openstack.org> | 2014-10-09 16:54:48 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2014-10-09 16:54:48 +0000 |
commit | 064c24afa3c3c5e9aef15699abe5363fd58ae39c (patch) | |
tree | ead39a8466a5cb48bcd318474ed0cd72cdef86cc | |
parent | 6833ca9e4235cb99e550ef272dbeed1227754655 (diff) | |
parent | fdcc5c4519bd71b9912ad6c0c7562ef51e774523 (diff) | |
download | glance-064c24afa3c3c5e9aef15699abe5363fd58ae39c.tar.gz |
Merge "Remove stale chunks when failed to update image to registry" into proposed/juno
-rw-r--r-- | glance/api/v1/images.py | 31 |
1 files changed, 27 insertions, 4 deletions
diff --git a/glance/api/v1/images.py b/glance/api/v1/images.py index ea511fd4b..15ec91201 100644 --- a/glance/api/v1/images.py +++ b/glance/api/v1/images.py @@ -52,6 +52,7 @@ import glance.registry.client.v1.api as registry LOG = logging.getLogger(__name__) _LI = gettextutils._LI +_LW = gettextutils._LW SUPPORTED_PARAMS = glance.api.v1.SUPPORTED_PARAMS SUPPORTED_FILTERS = glance.api.v1.SUPPORTED_FILTERS ACTIVE_IMMUTABLE = glance.api.v1.ACTIVE_IMMUTABLE @@ -685,10 +686,32 @@ class Controller(controller.BaseController): :retval Mapping of updated image data """ location_data = self._upload(req, image_meta) - return self._activate(req, - image_meta['id'], - location_data, - from_state='saving') if location_data else None + image_id = image_meta['id'] + LOG.info(_LI("Uploaded data of image %s from request " + "payload successfully.") % image_id) + + if location_data: + try: + image_meta = self._activate(req, + image_id, + location_data, + from_state='saving') + except Exception as e: + with excutils.save_and_reraise_exception(): + if not isinstance(e, exception.Duplicate): + # NOTE(zhiyan): Delete image data since it has already + # been added to store by above _upload() call. + LOG.warn(_LW("Failed to activate image %s in " + "registry. About to delete image " + "bits from store and update status " + "to 'killed'.") % image_id) + upload_utils.initiate_deletion(req, location_data, + image_id) + upload_utils.safe_kill(req, image_id, 'saving') + else: + image_meta = None + + return image_meta def _get_size(self, context, image_meta, location): # retrieve the image size from remote store (if not provided) |