Support customized update of Policy LB service

Change-Id: Ice8119d9a6740f573921d5e147dbc15c8a83887a
This commit is contained in:
asarfaty 2020-05-06 08:36:18 +02:00 committed by Adit Sarfaty
parent c27628b868
commit ecd9c849c2
2 changed files with 43 additions and 0 deletions

View File

@ -754,6 +754,25 @@ class TestPolicyLBService(test_resources.NsxPolicyLibTestCase):
relax_scale_validation=relax_scale_validation)
self.assert_called_with_def(update_call, expected_def)
def test_update_customized(self):
obj_id = '111'
name = 'name'
tags = [{'tag': '1', 'scope': '2'}]
def update_callback(body):
body['tags'] = tags
with self.mock_get(obj_id, name), \
mock.patch.object(self.policy_api.client, "update") as update_call:
self.resourceApi.update_customized(
obj_id, update_callback)
update_call.assert_called_once_with(
'infra/lb-services/%s' % obj_id,
{'id': obj_id, 'display_name': name,
'resource_type': 'LBService',
'tags': tags})
def test_get_status(self):
obj_id = '111'
with mock.patch.object(self.policy_api, "get") as api_call:

View File

@ -635,6 +635,30 @@ class NsxPolicyLoadBalancerServiceApi(NsxPolicyResourceBase):
relax_scale_validation=relax_scale_validation,
tenant=tenant)
def update_customized(self, lb_service_id, update_payload_cbk,
tenant=constants.POLICY_INFRA_TENANT):
"""Update the LB service using GET & PUT
Changing the body with a customized callback
"""
lb_service_def = self.entry_def(
lb_service_id=lb_service_id, tenant=tenant)
lb_service_path = lb_service_def.get_resource_path()
@utils.retry_upon_exception(
nsxlib_exc.StaleRevision,
max_attempts=self.policy_api.client.max_attempts)
def _update():
# Get the current data of service
lb_service_body = self.policy_api.get(lb_service_def)
# Update the body with the supplied callback
update_payload_cbk(lb_service_body)
# Update the backend using PUT
self.policy_api.client.update(lb_service_path, lb_service_body)
_update()
def get_statistics(self, lb_service_id,
tenant=constants.POLICY_INFRA_TENANT):
lb_service_stats_def = (