NSXP LB: Work around backend patch bug for VS

When calling patch method for virtual server objects, the backend
required explicit specification of fields which already have values,
or otherwise they're overwritten.
Patch works around this.

Change-Id: Ia498f974a986c62f084141069dddc205d9bc1401
This commit is contained in:
Kobi Samoray 2019-02-21 14:25:36 +02:00
parent 7ee32b798d
commit 7f2c7afde3
2 changed files with 30 additions and 3 deletions

View File

@ -723,15 +723,20 @@ class TestPolicyLBVirtualServer(test_resources.NsxPolicyLibTestCase):
obj_id = '111'
name = 'new name'
description = 'new desc'
dummy_id = 'xxxx'
dummy_path = '/test/lb-app-profiles/' + dummy_id
with mock.patch.object(self.policy_api,
"create_or_update") as update_call:
"create_or_update") as update_call, \
mock.patch.object(
self.policy_api, "get", return_value={
'application_profile_path': dummy_path}):
self.resourceApi.update(obj_id,
name=name,
description=description,
tenant=TEST_TENANT)
expected_def = lb_defs.LBVirtualServerDef(
virtual_server_id=obj_id, name=name, description=description,
tenant=TEST_TENANT)
tenant=TEST_TENANT, application_profile_id=dummy_id)
self.assert_called_with_def(update_call, expected_def)

View File

@ -24,6 +24,7 @@ from vmware_nsxlib.v3.policy import lb_defs
from vmware_nsxlib.v3.policy.core_resources import IGNORE
from vmware_nsxlib.v3.policy.core_resources import NsxPolicyResourceBase
from vmware_nsxlib.v3.policy import utils as p_utils
LOG = logging.getLogger(__name__)
@ -580,6 +581,27 @@ class NsxPolicyLoadBalancerVirtualServerAPI(NsxPolicyResourceBase):
lbvs_def = self.entry_def(tenant=tenant)
return self.policy_api.list(lbvs_def)['results']
def _update_helper(self, virtual_server_id, tenant, **kwargs):
# TODO(kobis) method should be removed and replaced with a simple
# call to _update(), once the policy backend PATCH method works
# properly
vs_data = self.get(virtual_server_id, tenant)
if kwargs['application_profile_id'] == IGNORE:
kwargs['application_profile_id'] = p_utils.path_to_id(
vs_data['application_profile_path'])
if kwargs['name'] == IGNORE:
kwargs['name'] = vs_data['display_name']
for k in kwargs.keys():
if kwargs.get(k) == IGNORE and vs_data.get(k):
kwargs[k] = vs_data[k]
self._update(
virtual_server_id=virtual_server_id,
tenant=tenant,
**kwargs)
def update(self, virtual_server_id, name=IGNORE, description=IGNORE,
rules=IGNORE, application_profile_id=IGNORE,
ip_address=IGNORE, lb_service_id=IGNORE,
@ -590,7 +612,7 @@ class NsxPolicyLoadBalancerVirtualServerAPI(NsxPolicyResourceBase):
server_ssl_profile_binding=IGNORE,
tags=IGNORE,
tenant=constants.POLICY_INFRA_TENANT):
self._update(
self._update_helper(
virtual_server_id=virtual_server_id,
name=name,
description=description,