Browse Source

Support customized update of Policy LB service

Change-Id: Ice8119d9a6740f573921d5e147dbc15c8a83887a
changes/46/728646/1
asarfaty 2 months ago
committed by Adit Sarfaty
parent
commit
85a6980fa1
2 changed files with 43 additions and 0 deletions
  1. +19
    -0
      vmware_nsxlib/tests/unit/v3/policy/test_lb_resources.py
  2. +24
    -0
      vmware_nsxlib/v3/policy/lb_resources.py

+ 19
- 0
vmware_nsxlib/tests/unit/v3/policy/test_lb_resources.py View File

@@ -731,6 +731,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:


+ 24
- 0
vmware_nsxlib/v3/policy/lb_resources.py View File

@@ -615,6 +615,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 = (


Loading…
Cancel
Save