diff options
author | Chris Yeoh <cyeoh@au1.ibm.com> | 2013-05-22 20:36:37 +0930 |
---|---|---|
committer | Chris Yeoh <cyeoh@au1.ibm.com> | 2013-05-30 14:18:11 +0930 |
commit | 47daf90e11d75e04442ab50ac3b3ece2ae79423f (patch) | |
tree | b2e8d8dce2212db6df1ee50a1ca3100426071312 | |
parent | 783b0e836d9ba0630d4745a6457144fac6dfa9f0 (diff) | |
download | nova-47daf90e11d75e04442ab50ac3b3ece2ae79423f.tar.gz nova-47daf90e11d75e04442ab50ac3b3ece2ae79423f.tar.xz nova-47daf90e11d75e04442ab50ac3b3ece2ae79423f.zip |
_s3_create handles image being deleted
Change so _s3_create handles the image it is creating
being deleted while it is creating it without logging a stacktrace
and instead just logging a simple message explaining what happened.
Fixes bug 1084703
Change-Id: I9d984dd1cf4f393010493cacd048d20ad5225db8
-rw-r--r-- | nova/image/s3.py | 133 |
1 files changed, 69 insertions, 64 deletions
diff --git a/nova/image/s3.py b/nova/image/s3.py index f08cbcdcb..14ce692b9 100644 --- a/nova/image/s3.py +++ b/nova/image/s3.py @@ -313,74 +313,79 @@ class S3ImageService(object): self.service.update(context, image_uuid, metadata, image_data, purge_props=False) - _update_image_state(context, image_uuid, 'downloading') - - try: - parts = [] - elements = manifest.find('image').getiterator('filename') - for fn_element in elements: - part = self._download_file(bucket, - fn_element.text, - image_path) - parts.append(part) - - # NOTE(vish): this may be suboptimal, should we use cat? - enc_filename = os.path.join(image_path, 'image.encrypted') - with open(enc_filename, 'w') as combined: - for filename in parts: - with open(filename) as part: - shutil.copyfileobj(part, combined) - - except Exception: - LOG.exception(_("Failed to download %(image_location)s " - "to %(image_path)s"), log_vars) - _update_image_state(context, image_uuid, 'failed_download') - return - - _update_image_state(context, image_uuid, 'decrypting') - - try: - hex_key = manifest.find('image/ec2_encrypted_key').text - encrypted_key = binascii.a2b_hex(hex_key) - hex_iv = manifest.find('image/ec2_encrypted_iv').text - encrypted_iv = binascii.a2b_hex(hex_iv) - - dec_filename = os.path.join(image_path, 'image.tar.gz') - self._decrypt_image(context, enc_filename, encrypted_key, - encrypted_iv, dec_filename) - except Exception: - LOG.exception(_("Failed to decrypt %(image_location)s " - "to %(image_path)s"), log_vars) - _update_image_state(context, image_uuid, 'failed_decrypt') - return - - _update_image_state(context, image_uuid, 'untarring') - try: - unz_filename = self._untarzip_image(image_path, dec_filename) - except Exception: - LOG.exception(_("Failed to untar %(image_location)s " - "to %(image_path)s"), log_vars) - _update_image_state(context, image_uuid, 'failed_untar') - return + _update_image_state(context, image_uuid, 'downloading') + + try: + parts = [] + elements = manifest.find('image').getiterator('filename') + for fn_element in elements: + part = self._download_file(bucket, + fn_element.text, + image_path) + parts.append(part) + + # NOTE(vish): this may be suboptimal, should we use cat? + enc_filename = os.path.join(image_path, 'image.encrypted') + with open(enc_filename, 'w') as combined: + for filename in parts: + with open(filename) as part: + shutil.copyfileobj(part, combined) + + except Exception: + LOG.exception(_("Failed to download %(image_location)s " + "to %(image_path)s"), log_vars) + _update_image_state(context, image_uuid, 'failed_download') + return + + _update_image_state(context, image_uuid, 'decrypting') + + try: + hex_key = manifest.find('image/ec2_encrypted_key').text + encrypted_key = binascii.a2b_hex(hex_key) + hex_iv = manifest.find('image/ec2_encrypted_iv').text + encrypted_iv = binascii.a2b_hex(hex_iv) + + dec_filename = os.path.join(image_path, 'image.tar.gz') + self._decrypt_image(context, enc_filename, encrypted_key, + encrypted_iv, dec_filename) + except Exception: + LOG.exception(_("Failed to decrypt %(image_location)s " + "to %(image_path)s"), log_vars) + _update_image_state(context, image_uuid, 'failed_decrypt') + return + + _update_image_state(context, image_uuid, 'untarring') + + try: + unz_filename = self._untarzip_image(image_path, + dec_filename) + except Exception: + LOG.exception(_("Failed to untar %(image_location)s " + "to %(image_path)s"), log_vars) + _update_image_state(context, image_uuid, 'failed_untar') + return + + _update_image_state(context, image_uuid, 'uploading') + try: + with open(unz_filename) as image_file: + _update_image_data(context, image_uuid, image_file) + except Exception: + LOG.exception(_("Failed to upload %(image_location)s " + "to %(image_path)s"), log_vars) + _update_image_state(context, image_uuid, 'failed_upload') + return + + metadata = {'status': 'active', + 'properties': {'image_state': 'available'}} + self.service.update(context, image_uuid, metadata, + purge_props=False) - _update_image_state(context, image_uuid, 'uploading') - try: - with open(unz_filename) as image_file: - _update_image_data(context, image_uuid, image_file) - except Exception: - LOG.exception(_("Failed to upload %(image_location)s " - "to %(image_path)s"), log_vars) - _update_image_state(context, image_uuid, 'failed_upload') + shutil.rmtree(image_path) + except exception.ImageNotFound: + LOG.info(_("Image %s was deleted underneath us"), image_uuid) return - metadata = {'status': 'active', - 'properties': {'image_state': 'available'}} - self.service.update(context, image_uuid, metadata, - purge_props=False) - - shutil.rmtree(image_path) - eventlet.spawn_n(delayed_create) return image |