Support deletion of all tags

Add support for removal of all tags by PUTing empty tags array.

Also moved assignment after initial session query for the
object in the listener update path.

Task: #41009
Story: #2008220

Change-Id: I7488f2fae61917f6d4a56cedd05bace7c5e2bc70
Signed-off-by: Andrew Karpow <andrew.karpow@sap.com>
(cherry picked from commit 7ad022379f)
This commit is contained in:
Andrew Karpow 2020-10-02 17:32:52 +02:00 committed by Gregory Thiemonge
parent b5c6c884a4
commit adb4e78e44
2 changed files with 20 additions and 5 deletions

View File

@ -106,7 +106,7 @@ class BaseRepository(object):
"""
with session.begin(subtransactions=True):
tags = model_kwargs.pop('tags', None)
if tags:
if tags is not None:
resource = session.query(self.model_class).get(id)
resource.tags = tags
session.query(self.model_class).filter_by(
@ -1142,15 +1142,15 @@ class ListenerRepository(BaseRepository):
def update(self, session, id, **model_kwargs):
with session.begin(subtransactions=True):
tags = model_kwargs.pop('tags', None)
if tags:
resource = session.query(self.model_class).get(id)
resource.tags = tags
listener_db = session.query(self.model_class).filter_by(
id=id).first()
if not listener_db:
raise exceptions.NotFound(
resource=data_models.Listener._name(), id=id)
tags = model_kwargs.pop('tags', None)
if tags is not None:
resource = session.query(self.model_class).get(id)
resource.tags = tags
# Verify any newly specified default_pool_id exists
default_pool_id = model_kwargs.get('default_pool_id')
if default_pool_id:

View File

@ -1842,6 +1842,21 @@ class TestLoadBalancer(base.BaseAPITest):
self.assert_correct_lb_status(api_lb.get('id'), constants.ONLINE,
constants.PENDING_UPDATE)
def test_update_delete_tag(self):
project_id = uuidutils.generate_uuid()
lb = self.create_load_balancer(uuidutils.generate_uuid(),
name='lb1',
project_id=project_id,
admin_state_up=False,
tags=['test_tag1'],)
lb_dict = lb.get(self.root_tag)
lb_json = self._build_body({'tags': []})
self.set_lb_status(lb_dict.get('id'))
response = self.put(self.LB_PATH.format(lb_id=lb_dict.get('id')),
lb_json)
api_lb = response.json.get(self.root_tag)
self.assertEqual([], api_lb.get('tags'))
def test_update_with_vip(self):
project_id = uuidutils.generate_uuid()
lb = self.create_load_balancer(uuidutils.generate_uuid(),