diff options
author | Jenkins <jenkins@review.openstack.org> | 2015-02-23 21:04:24 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2015-02-23 21:04:24 +0000 |
commit | 008662b82dbf16e1d9179095a2809f90370393b7 (patch) | |
tree | b7f3752704f1d830d9a499d2a77c86565ceaeaf4 | |
parent | a370982b8254ef827a752778aab1e3606923c885 (diff) | |
parent | a880c8e762e94b70c1e5d5692a3defcde734a601 (diff) | |
download | glance-008662b82dbf16e1d9179095a2809f90370393b7.tar.gz |
Merge "Initiate deletion of image files if the import was interrupted" into stable/juno
-rw-r--r-- | glance/common/scripts/image_import/main.py | 40 |
1 files changed, 25 insertions, 15 deletions
diff --git a/glance/common/scripts/image_import/main.py b/glance/common/scripts/image_import/main.py index 72c992eea..ced93c934 100644 --- a/glance/common/scripts/image_import/main.py +++ b/glance/common/scripts/image_import/main.py @@ -22,6 +22,7 @@ import six from glance.api.v2 import images as v2_api from glance.common import exception from glance.common.scripts import utils as script_utils +from glance.common import store_utils from glance.common import utils as common_utils from glance import i18n from glance.openstack.common import excutils @@ -92,21 +93,30 @@ def import_image(image_repo, image_factory, task_input, task_id, uri): new_image = image_repo.get(image_id) set_image_data(new_image, uri, None) - # NOTE: Check if the Image is not deleted after setting the data - # before saving the active image. Here if image status is - # saving, then new_image is saved as it contains updated location, - # size, virtual_size and checksum information and the status of - # new_image is already set to active in set_image_data() call. - image = image_repo.get(image_id) - if image.status == 'saving': - image_repo.save(new_image) - return image_id - else: - msg = _LE("The Image %(image_id)s object being created by this task " - "%(task_id)s, is no longer in valid status for further " - "processing." % {"image_id": new_image.image_id, - "task_id": task_id}) - raise exception.Conflict(msg) + try: + # NOTE: Check if the Image is not deleted after setting the data + # before saving the active image. Here if image status is + # saving, then new_image is saved as it contains updated location, + # size, virtual_size and checksum information and the status of + # new_image is already set to active in set_image_data() call. + image = image_repo.get(image_id) + if image.status == 'saving': + image_repo.save(new_image) + return image_id + else: + msg = _("The Image %(image_id)s object being created by this task " + "%(task_id)s, is no longer in valid status for further " + "processing.") % {"image_id": image_id, + "task_id": task_id} + raise exception.Conflict(msg) + except (exception.Conflict, exception.NotFound): + with excutils.save_and_reraise_exception(): + if new_image.locations: + for location in new_image.locations: + store_utils.delete_image_location_from_backend( + new_image.context, + image_id, + location) def create_image(image_repo, image_factory, image_properties, task_id): |