From 6996f2329e9e0d1b3b8c090b64df8737b1495ba4 Mon Sep 17 00:00:00 2001 From: Monty Taylor Date: Wed, 19 Oct 2016 07:53:49 -0500 Subject: [PATCH] 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 --- .../notes/false-not-attribute-error-49484d0fdc61f75d.yaml | 6 ++++++ shade/openstackcloud.py | 5 ++++- 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 releasenotes/notes/false-not-attribute-error-49484d0fdc61f75d.yaml diff --git a/releasenotes/notes/false-not-attribute-error-49484d0fdc61f75d.yaml b/releasenotes/notes/false-not-attribute-error-49484d0fdc61f75d.yaml new file mode 100644 index 000000000..e474e0266 --- /dev/null +++ b/releasenotes/notes/false-not-attribute-error-49484d0fdc61f75d.yaml @@ -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. diff --git a/shade/openstackcloud.py b/shade/openstackcloud.py index 581e93b82..8d3dc4cb5 100644 --- a/shade/openstackcloud.py +++ b/shade/openstackcloud.py @@ -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