Don't fail on trying to delete non-existant images

This currently throws an attribute exception, which is definitely not
the right choice.

Change-Id: I2e08ce9f46f4fa8ec1d42508efb16a014d485850
This commit is contained in:
Monty Taylor 2016-10-19 07:53:49 -05:00
parent e545865f8f
commit 6996f2329e
No known key found for this signature in database
GPG Key ID: 7BAE94BC7141A594
2 changed files with 10 additions and 1 deletions

View File

@ -0,0 +1,6 @@
---
fixes:
- delete_image used to fail with an AttributeError if an invalid image
name or id was passed, rather than returning False which was the
intent. This is worthy of note because it's a behavior change, but the
previous behavior was a bug.

View File

@ -2820,6 +2820,8 @@ class OpenStackCloud(_normalize.Normalizer):
self, name_or_id, wait=False, timeout=3600,
delete_objects=True):
image = self.get_image(name_or_id)
if not image:
return False
with _utils.shade_exceptions("Error in deleting image"):
# Note that in v1, the param name is image, but in v2,
# it's image_id
@ -2843,7 +2845,8 @@ class OpenStackCloud(_normalize.Normalizer):
"Timeout waiting for the image to be deleted."):
self._get_cache(None).invalidate()
if self.get_image(image.id) is None:
return
break
return True
def _get_name_and_filename(self, name):
# See if name points to an existing file