Ignore notfound error when delete image tags

This change will ignore notfound when delete image tags to make
sure update the image resource successful.

Change-Id: I7031d6ab92e6765ed1d23bfbbe6c8761cf91670b
Closes-Bug: #1589795
This commit is contained in:
huangtianhua 2016-06-07 17:57:38 +08:00
parent e57a2936d7
commit 94d6f34c02
2 changed files with 25 additions and 10 deletions

View File

@ -148,10 +148,11 @@ class GlanceImage(resource.Resource):
removed_tags = set(existing_tags) - set(prop_diff[self.TAGS])
for tag in removed_tags:
self.client(
version=self.client_plugin().V2).image_tags.delete(
self.resource_id,
tag)
with self.client_plugin().ignore_not_found:
self.client(
version=self.client_plugin().V2).image_tags.delete(
self.resource_id,
tag)
def _show_resource(self):
if self.glance().version == 1.0:

View File

@ -14,6 +14,7 @@
import mock
import six
from glanceclient import exc
from heat.common import exception
from heat.common import template_format
from heat.engine import stack as parser
@ -237,12 +238,7 @@ class GlanceImageTest(common.HeatTestCase):
self.my_image.resource_id,
'tag1')
def test_image_handle_update(self):
self.my_image.resource_id = '477e8273-60a7-4c41-b683-fdb0bc7cd151'
self.my_image.t['Properties']['tags'] = ['tag1']
prop_diff = {'tags': ['tag2']}
def _handle_update_tags(self, prop_diff):
self.my_image.handle_update(json_snippet=None,
tmpl_diff=None,
prop_diff=prop_diff)
@ -256,6 +252,24 @@ class GlanceImageTest(common.HeatTestCase):
'tag1'
)
def test_image_handle_update(self):
self.my_image.resource_id = '477e8273-60a7-4c41-b683-fdb0bc7cd151'
self.my_image.t['Properties']['tags'] = ['tag1']
prop_diff = {'tags': ['tag2']}
self._handle_update_tags(prop_diff)
def test_image_handle_update_tags_delete_not_found(self):
self.my_image.resource_id = '477e8273-60a7-4c41-b683-fdb0bc7cd151'
self.my_image.t['Properties']['tags'] = ['tag1']
prop_diff = {'tags': ['tag2']}
self.image_tags.delete.side_effect = exc.HTTPNotFound()
self._handle_update_tags(prop_diff)
def test_image_show_resource_v1(self):
self.glanceclient.version = 1.0
self.my_image.resource_id = 'test_image_id'