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.

Conflicts:
	octavia/db/repositories.py

Task: #41009
Story: #2008220

Change-Id: I7488f2fae61917f6d4a56cedd05bace7c5e2bc70
Signed-off-by: Andrew Karpow <andrew.karpow@sap.com>
(cherry picked from commit 7ad022379f)
(cherry picked from commit adb4e78e44)
(cherry picked from commit 95a97cf1eb)
This commit is contained in:
Andrew Karpow 2020-10-02 17:32:52 +02:00 committed by Gregory Thiemonge
parent fd622009e6
commit a94e5af899
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(
@ -1061,12 +1061,12 @@ 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()
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

@ -1780,6 +1780,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(),