Add enforcement_point_path param for LBServiceUsage

This change adds LBS usage, statistics and status API with param
'enforcement_point_path' to support querying in a multi enforcement
point setup.

Change-Id: I08cbc05bbad6e70dbd3a1c96fba72931a94f0b7f
Signed-off-by: Shawn Wang <wshaoquan@vmware.com>
This commit is contained in:
Shawn Wang 2023-08-20 11:18:30 -07:00
parent 77688b9934
commit 9341330fdb
No known key found for this signature in database
GPG Key ID: C98A86CC967E89A7
3 changed files with 107 additions and 3 deletions

View File

@ -951,6 +951,21 @@ class TestPolicyLBService(test_resources.NsxPolicyLibTestCase):
tenant=TEST_TENANT)
self.assert_called_with_def(api_call, expected_def)
def test_get_status_with_ep(self):
obj_id = '111'
ep_path = '/infra/sites/default/enforcement-points/default'
with mock.patch.object(self.policy_api, "get") as api_call:
self.resourceApi.get_status(
obj_id, enforcement_point_path=ep_path, tenant=TEST_TENANT)
expected_def = lb_defs.LBServiceStatusDef(
lb_service_id=obj_id,
enforcement_point_path=ep_path,
tenant=TEST_TENANT)
self.assert_called_with_def(api_call, expected_def)
self.assertEqual(
'%s/lb-services/%s/detailed-status?enforcement_point_path=' +
ep_path, expected_def.path_pattern)
def test_get_statistics(self):
obj_id = '111'
with mock.patch.object(self.policy_api, "get") as api_call:
@ -976,6 +991,24 @@ class TestPolicyLBService(test_resources.NsxPolicyLibTestCase):
self.assertEqual('%s/lb-services/%s/statistics?source=realtime',
expected_def.path_pattern)
def test_get_statistics_realtime_with_ep(self):
obj_id = '111'
ep_path = '/infra/sites/default/enforcement-points/default'
with mock.patch.object(self.policy_api, "get") as api_call:
self.resourceApi.get_statistics(
obj_id, realtime=True, enforcement_point_path=ep_path,
tenant=TEST_TENANT)
expected_def = lb_defs.LBServiceStatisticsDef(
lb_service_id=obj_id,
realtime=True,
enforcement_point_path=ep_path,
tenant=TEST_TENANT)
self.assert_called_with_def(api_call, expected_def)
self.assertEqual(
'%s/lb-services/%s/statistics?source=realtime&' +
'enforcement_point_path=' + ep_path,
expected_def.path_pattern)
def test_get_virtual_server_status(self):
obj_id = '111'
vs_id = '222'
@ -995,11 +1028,48 @@ class TestPolicyLBService(test_resources.NsxPolicyLibTestCase):
expected_def = lb_defs.LBServiceUsageDef(
lb_service_id=lbs_id,
realtime=True,
enforcement_point_path=None,
tenant=TEST_TENANT)
expected_path = '%s/lb-services/%s/service-usage?source=realtime'
self.assert_called_with_def(api_call, expected_def)
self.assertEqual(expected_def.path_pattern, expected_path)
def test_get_usage_with_ep(self):
lbs_id = 'test_vs'
ep_path = '/infra/sites/default/enforcement-points/default'
with mock.patch.object(self.policy_api, "get") as api_call:
self.resourceApi.get_usage(
lbs_id, realtime=False, enforcement_point_path=ep_path,
tenant=TEST_TENANT)
expected_def = lb_defs.LBServiceUsageDef(
lb_service_id=lbs_id,
realtime=False,
enforcement_point_path=ep_path,
tenant=TEST_TENANT)
expected_path = (
'%s/lb-services/%s/service-usage?' +
'enforcement_point_path=' + ep_path)
self.assert_called_with_def(api_call, expected_def)
self.assertEqual(expected_def.path_pattern, expected_path)
def test_get_usage_realtime_with_ep(self):
lbs_id = 'test_vs'
ep_path = '/infra/sites/default/enforcement-points/default'
with mock.patch.object(self.policy_api, "get") as api_call:
self.resourceApi.get_usage(
lbs_id, realtime=True, enforcement_point_path=ep_path,
tenant=TEST_TENANT)
expected_def = lb_defs.LBServiceUsageDef(
lb_service_id=lbs_id,
realtime=True,
enforcement_point_path=ep_path,
tenant=TEST_TENANT)
expected_path = (
'%s/lb-services/%s/service-usage?source=realtime&' +
'enforcement_point_path=' + ep_path)
self.assert_called_with_def(api_call, expected_def)
self.assertEqual(expected_def.path_pattern, expected_path)
def test_wait_until_realized_fail(self):
lbs_id = 'test_lbs'
info = {'state': constants.STATE_UNREALIZED,

View File

@ -451,13 +451,21 @@ class LBServiceStatisticsDef(ResourceDef):
def __init__(self, **kwargs):
self.realtime = kwargs.pop('realtime')
self.enforcement_point_path = kwargs.pop(
'enforcement_point_path', None)
super(LBServiceStatisticsDef, self).__init__(**kwargs)
@property
def path_pattern(self):
params = []
if self.realtime:
params.append('source=realtime')
if self.enforcement_point_path:
params.append('enforcement_point_path=%s' %
self.enforcement_point_path)
if params:
return (LB_SERVICES_PATH_PATTERN +
'%s/statistics?source=realtime')
'%s/statistics?' + '&'.join(params))
return LB_SERVICES_PATH_PATTERN + '%s/statistics/'
@property
@ -467,8 +475,20 @@ class LBServiceStatisticsDef(ResourceDef):
class LBServiceStatusDef(ResourceDef):
def __init__(self, **kwargs):
self.enforcement_point_path = kwargs.pop(
'enforcement_point_path', None)
super(LBServiceStatusDef, self).__init__(**kwargs)
@property
def path_pattern(self):
params = []
if self.enforcement_point_path:
params.append('enforcement_point_path=%s' %
self.enforcement_point_path)
if params:
return (LB_SERVICES_PATH_PATTERN +
'%s/detailed-status?' + '&'.join(params))
return LB_SERVICES_PATH_PATTERN + '%s/detailed-status/'
@property
@ -480,13 +500,21 @@ class LBServiceUsageDef(ResourceDef):
def __init__(self, **kwargs):
self.realtime = kwargs.pop('realtime')
self.enforcement_point_path = kwargs.pop(
'enforcement_point_path', None)
super(LBServiceUsageDef, self).__init__(**kwargs)
@property
def path_pattern(self):
params = []
if self.realtime:
params.append('source=realtime')
if self.enforcement_point_path:
params.append('enforcement_point_path=%s' %
self.enforcement_point_path)
if params:
return (LB_SERVICES_PATH_PATTERN +
'%s/service-usage?source=realtime')
'%s/service-usage?' + '&'.join(params))
return LB_SERVICES_PATH_PATTERN + '%s/service-usage/'
@property

View File

@ -729,20 +729,24 @@ class NsxPolicyLoadBalancerServiceApi(NsxPolicyResourceBase):
def get_statistics(self, lb_service_id, realtime=False,
tenant=constants.POLICY_INFRA_TENANT,
enforcement_point_path=None,
silent=False):
lb_service_stats_def = (
lb_defs.LBServiceStatisticsDef(
lb_service_id=lb_service_id,
realtime=realtime,
enforcement_point_path=enforcement_point_path,
tenant=tenant))
return self.policy_api.get(lb_service_stats_def, silent=silent)
def get_status(self, lb_service_id,
enforcement_point_path=None,
tenant=constants.POLICY_INFRA_TENANT,
silent=False):
lb_service_status_def = (
lb_defs.LBServiceStatusDef(
lb_service_id=lb_service_id,
enforcement_point_path=enforcement_point_path,
tenant=tenant))
return self.policy_api.get(lb_service_status_def, silent=silent)
@ -756,9 +760,11 @@ class NsxPolicyLoadBalancerServiceApi(NsxPolicyResourceBase):
return self.policy_api.get(lb_vs_status_def)
def get_usage(self, lb_service_id, realtime=False,
enforcement_point_path=None,
tenant=constants.POLICY_INFRA_TENANT):
lb_service_status_def = lb_defs.LBServiceUsageDef(
lb_service_id=lb_service_id, realtime=realtime, tenant=tenant)
lb_service_id=lb_service_id, realtime=realtime,
enforcement_point_path=enforcement_point_path, tenant=tenant)
return self.policy_api.get(lb_service_status_def)
def get_path(self, lb_service_id,