Support customized update of Policy LB service
Change-Id: Ice8119d9a6740f573921d5e147dbc15c8a83887a
This commit is contained in:
parent
067bb9ee40
commit
85a6980fa1
|
@ -731,6 +731,25 @@ class TestPolicyLBService(test_resources.NsxPolicyLibTestCase):
|
||||||
relax_scale_validation=relax_scale_validation)
|
relax_scale_validation=relax_scale_validation)
|
||||||
self.assert_called_with_def(update_call, expected_def)
|
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):
|
def test_get_status(self):
|
||||||
obj_id = '111'
|
obj_id = '111'
|
||||||
with mock.patch.object(self.policy_api, "get") as api_call:
|
with mock.patch.object(self.policy_api, "get") as api_call:
|
||||||
|
|
|
@ -615,6 +615,30 @@ class NsxPolicyLoadBalancerServiceApi(NsxPolicyResourceBase):
|
||||||
relax_scale_validation=relax_scale_validation,
|
relax_scale_validation=relax_scale_validation,
|
||||||
tenant=tenant)
|
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,
|
def get_statistics(self, lb_service_id,
|
||||||
tenant=constants.POLICY_INFRA_TENANT):
|
tenant=constants.POLICY_INFRA_TENANT):
|
||||||
lb_service_stats_def = (
|
lb_service_stats_def = (
|
||||||
|
|
Loading…
Reference in New Issue