On update_tags, clean up tags from the requested resource only
There was a bug in I0179a3616689f39d93c337c730283e21a01677cf that made the service plugin to clean up removed tags from all resources, not just the one requested. Change-Id: Ifbe13102ebd903e01eb28a00d97e7e94d1a0e0b1 Closes-Bug: #1673086
This commit is contained in:
parent
1414ea9538
commit
0cb8fd6374
|
@ -90,11 +90,16 @@ class TagPlugin(common_db_mixin.CommonDbMixin, tag_ext.TagPluginBase):
|
||||||
old_tags = {tag_db.tag for tag_db in res.standard_attr.tags}
|
old_tags = {tag_db.tag for tag_db in res.standard_attr.tags}
|
||||||
tags_added = new_tags - old_tags
|
tags_added = new_tags - old_tags
|
||||||
tags_removed = old_tags - new_tags
|
tags_removed = old_tags - new_tags
|
||||||
tag_obj.Tag.delete_objects(context, tag=[
|
if tags_removed:
|
||||||
tag_db.tag
|
tag_obj.Tag.delete_objects(
|
||||||
for tag_db in res.standard_attr.tags
|
context,
|
||||||
if tag_db.tag in tags_removed
|
standard_attr_id=res.standard_attr_id,
|
||||||
])
|
tag=[
|
||||||
|
tag_db.tag
|
||||||
|
for tag_db in res.standard_attr.tags
|
||||||
|
if tag_db.tag in tags_removed
|
||||||
|
]
|
||||||
|
)
|
||||||
for tag in tags_added:
|
for tag in tags_added:
|
||||||
tag_obj.Tag(context, standard_attr_id=res.standard_attr_id,
|
tag_obj.Tag(context, standard_attr_id=res.standard_attr_id,
|
||||||
tag=tag).create()
|
tag=tag).create()
|
||||||
|
|
|
@ -315,3 +315,35 @@ class TagFilterRouterTestJSON(TagFilterTestJSON):
|
||||||
@test.requires_ext(extension="tag-ext", service="network")
|
@test.requires_ext(extension="tag-ext", service="network")
|
||||||
def test_filter_router_tags(self):
|
def test_filter_router_tags(self):
|
||||||
self._test_filter_tags()
|
self._test_filter_tags()
|
||||||
|
|
||||||
|
|
||||||
|
class UpdateTagsTest(base.BaseAdminNetworkTest):
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
@test.requires_ext(extension="tag", service="network")
|
||||||
|
def resource_setup(cls):
|
||||||
|
super(UpdateTagsTest, cls).resource_setup()
|
||||||
|
|
||||||
|
def _get_and_compare_tags(self, tags, res_id):
|
||||||
|
# nothing specific about networks here, just a resource that is
|
||||||
|
# available in all setups
|
||||||
|
res_body = self.client.get_tags('networks', res_id)
|
||||||
|
self.assertItemsEqual(tags, res_body['tags'])
|
||||||
|
|
||||||
|
@test.attr(type='smoke')
|
||||||
|
@decorators.idempotent_id('74c56fb1-a3b1-4a62-a8d2-d04dca6bd4cd')
|
||||||
|
def test_update_tags_affects_only_updated_resource(self):
|
||||||
|
res1 = self.create_network()
|
||||||
|
res2 = self.create_network()
|
||||||
|
|
||||||
|
self.client.update_tags('networks', res1['id'], ['red', 'blue'])
|
||||||
|
self._get_and_compare_tags(['red', 'blue'], res1['id'])
|
||||||
|
|
||||||
|
self.client.update_tags('networks', res2['id'], ['red'])
|
||||||
|
self._get_and_compare_tags(['red'], res2['id'])
|
||||||
|
|
||||||
|
self.client.update_tags('networks', res2['id'], [])
|
||||||
|
self._get_and_compare_tags([], res2['id'])
|
||||||
|
|
||||||
|
# check that updates on res2 hasn't dropped tags from res1
|
||||||
|
self._get_and_compare_tags(['red', 'blue'], res1['id'])
|
||||||
|
|
Loading…
Reference in New Issue