Fix update of the pool member backup state

Change-Id: I405bc36559998f16bf67eb6b807e1fd95c2358e1
This commit is contained in:
asarfaty 2020-11-02 11:22:29 +02:00
parent f4a16ac6d0
commit 620c918579
3 changed files with 10 additions and 6 deletions

View File

@ -14,6 +14,7 @@
# under the License. # under the License.
# #
import copy
from unittest import mock from unittest import mock
from vmware_nsxlib.tests.unit.v3 import nsxlib_testcase from vmware_nsxlib.tests.unit.v3 import nsxlib_testcase
@ -1727,7 +1728,8 @@ class TestPolicyLBPoolApi(test_resources.NsxPolicyLibTestCase):
ip_address = '1.1.1.1' ip_address = '1.1.1.1'
port = '80' port = '80'
new_name = 'mem1' new_name = 'mem1'
member = {'ip_address': ip_address, 'port': port} member = {'ip_address': ip_address, 'port': port,
'backup_member': True}
with mock.patch.object(self.policy_api, "get", with mock.patch.object(self.policy_api, "get",
return_value={'id': obj_id, return_value={'id': obj_id,
'members': [member]}), \ 'members': [member]}), \
@ -1735,11 +1737,13 @@ class TestPolicyLBPoolApi(test_resources.NsxPolicyLibTestCase):
"create_or_update") as update_call: "create_or_update") as update_call:
self.resourceApi.update_pool_member( self.resourceApi.update_pool_member(
obj_id, ip_address, port=port, display_name=new_name, obj_id, ip_address, port=port, display_name=new_name,
tenant=TEST_TENANT) backup_member=False, tenant=TEST_TENANT)
member['display_name'] = new_name new_member = copy.copy(member)
new_member['display_name'] = new_name
new_member['backup_member'] = False
expected_def = lb_defs.LBPoolDef( expected_def = lb_defs.LBPoolDef(
lb_pool_id=obj_id, lb_pool_id=obj_id,
members=[member], members=[new_member],
tenant=TEST_TENANT) tenant=TEST_TENANT)
self.assert_called_with_def(update_call, expected_def) self.assert_called_with_def(update_call, expected_def)

View File

@ -79,7 +79,7 @@ class LBPoolMemberDef(object):
body['weight'] = self.weight body['weight'] = self.weight
if self.admin_state: if self.admin_state:
body['admin_state'] = self.admin_state body['admin_state'] = self.admin_state
if self.backup_member: if self.backup_member is not None:
body['backup_member'] = self.backup_member body['backup_member'] = self.backup_member
return body return body

View File

@ -585,7 +585,7 @@ class NsxPolicyLoadBalancerPoolApi(NsxPolicyResourceBase):
member_to_update[0]['weight'] = weight member_to_update[0]['weight'] = weight
if admin_state: if admin_state:
member_to_update[0]['admin_state'] = admin_state member_to_update[0]['admin_state'] = admin_state
if backup_member: if backup_member is not None:
member_to_update[0]['backup_member'] = backup_member member_to_update[0]['backup_member'] = backup_member
self._update(lb_pool_id=lb_pool_id, members=lb_pool_members, self._update(lb_pool_id=lb_pool_id, members=lb_pool_members,
tenant=tenant) tenant=tenant)