Add feature to update NSGroup and FirewallSection tags

update NsxLibNsGroup.update and NsxLibFirewallSection.update
to support tag update

Change-Id: I85acdd297d2c9295091890e8ef17c878ce0c7807
This commit is contained in:
lyliu 2017-09-12 07:47:04 +00:00
parent 199bf788e4
commit 597c4b8321
2 changed files with 26 additions and 2 deletions

View File

@ -92,6 +92,17 @@ class TestNsxLibFirewallSection(nsxlib_testcase.NsxLibTestCase):
self.nsxlib.firewall_section.get_excludelist()
clist.assert_called_with('firewall/excludelist')
def test_update(self):
fws_tags = [{"scope": "name", "tag": "new_name"}]
with mock.patch.object(self.nsxlib.client, 'update') as update:
with mock.patch.object(self.nsxlib.client, 'get') as get:
get.return_value = {}
self.nsxlib.firewall_section.update('fw_section_id',
tags_update=fws_tags)
resource = 'firewall/sections/%s' % 'fw_section_id'
data = {'tags': fws_tags}
update.assert_called_with(resource, data, headers=None)
class TestNsxLibIPSet(nsxlib_testcase.NsxClientTestCase):
"""Tests for vmware_nsxlib.v3.security.NsxLibIPSet"""
@ -174,3 +185,13 @@ class TestNsxLibNSGroup(nsxlib_testcase.NsxClientTestCase):
expected_exp = {'resource_type': const.NSGROUP_COMPLEX_EXP,
'expressions': port_exp}
self.assertEqual(expected_exp, complex_exp)
def test_update(self):
nsg_tags = [{"scope": "name", "tag": "new_name"}]
with mock.patch.object(self.nsxlib.client, 'update') as update:
with mock.patch.object(self.nsxlib.client, 'get') as get:
get.return_value = {}
self.nsxlib.ns_group.update('nsgroupid', tags_update=nsg_tags)
resource = 'ns-groups/nsgroupid'
data = {'tags': nsg_tags}
update.assert_called_with(resource, data)

View File

@ -137,7 +137,7 @@ class NsxLibNsGroup(utils.NsxLibApiBase):
'ns-groups?populate_references=false').get('results', [])
def update(self, nsgroup_id, display_name=None, description=None,
membership_criteria=None, members=None):
membership_criteria=None, members=None, tags_update=None):
# Using internal method so we can access max_attempts in the decorator
@utils.retry_upon_exception(
exceptions.StaleRevision,
@ -152,6 +152,9 @@ class NsxLibNsGroup(utils.NsxLibApiBase):
nsgroup['members'] = members
if membership_criteria is not None:
nsgroup['membership_criteria'] = [membership_criteria]
if tags_update is not None:
nsgroup['tags'] = utils.update_v3_tags(nsgroup.get('tags', []),
tags_update)
return self.client.update(
'ns-groups/%s' % nsgroup_id, nsgroup)
@ -400,7 +403,7 @@ class NsxLibFirewallSection(utils.NsxLibApiBase):
return self.client.create(resource, section, headers=headers)
elif any(p is not None for p in (display_name, description,
applied_tos)):
applied_tos, tags_update)):
return self.client.update(resource, section, headers=headers)
return _do_update()