[IPSet]: Allow updating IPSet with empty list

In order to remove IP addresses from the IPSet and empty the list,
the request to update IPSets should allow empty list. Currently an
empty list is replaced with previous values which ends up not
updating the ip address list with the desired values.

Change-Id: I7261cffd39ad983d4c225b6ab352632c95e2a950
This commit is contained in:
Abhishek Raut 2017-01-22 07:21:41 -08:00
parent f8bf9d0443
commit 9418bdbd5d
2 changed files with 18 additions and 1 deletions

View File

@ -139,6 +139,23 @@ class TestNsxLibIPSet(nsxlib_testcase.NsxClientTestCase):
resource = 'ip-sets/%s' % fake_ip_set['id']
update.assert_called_with(resource, data)
def test_update_ip_set_empty_ip_addresses(self):
fake_ip_set = test_constants.FAKE_IP_SET.copy()
new_ip_addresses = []
data = {
'id': fake_ip_set['id'],
'display_name': fake_ip_set['display_name'],
'ip_addresses': new_ip_addresses,
'resource_type': 'IPSet'
}
with mock.patch.object(self.nsxlib.client, 'get',
return_value=fake_ip_set):
with mock.patch.object(self.nsxlib.client, 'update') as update:
self.nsxlib.ip_set.update(
fake_ip_set['id'], ip_addresses=new_ip_addresses)
resource = 'ip-sets/%s' % fake_ip_set['id']
update.assert_called_with(resource, data)
class TestNsxLibNSGroup(nsxlib_testcase.NsxClientTestCase):
"""Tests for vmware_nsxlib.v3.security.NsxLibNSGroup"""

View File

@ -588,7 +588,7 @@ class NsxLibIPSet(utils.NsxLibApiBase):
ip_set['display_name'] = display_name
if description is not None:
ip_set['description'] = description
if ip_addresses:
if ip_addresses is not None:
ip_set['ip_addresses'] = ip_addresses
return self.client.update(resource, ip_set)