Update Lb App Profile attributes
Current resource def for Lb App Profiles (HTTP, TCP, UDP) and their counterparts in MP are incomplete and messy. Refactored related logic to better separate different attributes for each profile type. Change-Id: I11d0752484700cb55168a2fca5bf1a88926c8b81
This commit is contained in:
parent
3aca031d96
commit
7488940eed
@ -640,6 +640,35 @@ class TestPolicyLBApplicationProfile(test_resources.NsxPolicyLibTestCase):
|
||||
self.assert_called_with_def(api_call, expected_def)
|
||||
self.assertEqual(obj_id, result)
|
||||
|
||||
def test_fast_tcp_profile_def(self):
|
||||
obj_dict = {'close_timeout': 8,
|
||||
'ha_flow_mirroring_enabled': False,
|
||||
'idle_timeout': 100}
|
||||
fast_tcp_profile_def = lb_defs.LBFastTcpProfile(**obj_dict)
|
||||
self.assertDictContainsSubset(obj_dict,
|
||||
fast_tcp_profile_def.get_obj_dict())
|
||||
|
||||
def test_fast_udp_profile_def(self):
|
||||
obj_dict = {'flow_mirroring_enabled': False,
|
||||
'idle_timeout': 100}
|
||||
fast_udp_profile_def = lb_defs.LBFastUdpProfile(**obj_dict)
|
||||
self.assertDictContainsSubset(obj_dict,
|
||||
fast_udp_profile_def.get_obj_dict())
|
||||
|
||||
def test_http_profile_def(self):
|
||||
obj_dict = {'http_redirect_to_https': False,
|
||||
'http_redirect_to': "sample-url",
|
||||
'idle_timeout': 100,
|
||||
'ntlm': False,
|
||||
'request_body_size': 1025,
|
||||
'request_header_size': 10,
|
||||
'response_header_size': 10,
|
||||
'response_timeout': 10,
|
||||
'x_forwarded_for': 'INSERT'}
|
||||
http_profile_def = lb_defs.LBHttpProfileDef(**obj_dict)
|
||||
self.assertDictContainsSubset(obj_dict,
|
||||
http_profile_def.get_obj_dict())
|
||||
|
||||
def test_create_without_id(self):
|
||||
name = 'd1'
|
||||
description = 'desc'
|
||||
|
@ -236,7 +236,11 @@ FAKE_APPLICATION_PROFILE = {
|
||||
"id": FAKE_APPLICATION_PROFILE_UUID,
|
||||
"display_name": "httpprofile1",
|
||||
"ntlm": False,
|
||||
"request_body_size": 65536,
|
||||
"request_header_size": 1024,
|
||||
"response_header_size": 4096,
|
||||
"response_timeout": 60,
|
||||
"http_redirect_to": "redirect_url",
|
||||
"http_redirect_to_https": False,
|
||||
"idle_timeout": 1800,
|
||||
"x_forwarded_for": "INSERT",
|
||||
|
@ -53,6 +53,85 @@ class TestApplicationProfile(nsxlib_testcase.NsxClientTestCase):
|
||||
create.assert_called_with('loadbalancer/application-profiles',
|
||||
body)
|
||||
|
||||
def test_create_fast_tcp_profiles(self):
|
||||
fake_profile = consts.FAKE_APPLICATION_PROFILE.copy()
|
||||
body = {
|
||||
'display_name': fake_profile['display_name'],
|
||||
'description': fake_profile['description'],
|
||||
'resource_type': app_profile_types.FAST_TCP,
|
||||
'close_timeout': 8,
|
||||
'ha_flow_mirroring_enabled': True,
|
||||
'idle_timeout': 1800,
|
||||
'tags': consts.FAKE_TAGS
|
||||
}
|
||||
with mock.patch.object(self.nsxlib.client, 'create') as create:
|
||||
self.nsxlib.load_balancer.application_profile.create(
|
||||
display_name=body['display_name'],
|
||||
description=body['description'],
|
||||
resource_type=body['resource_type'],
|
||||
close_timeout=body['close_timeout'],
|
||||
ha_flow_mirroring_enabled=body['ha_flow_mirroring_enabled'],
|
||||
idle_timeout=body['idle_timeout'],
|
||||
tags=consts.FAKE_TAGS)
|
||||
create.assert_called_with('loadbalancer/application-profiles',
|
||||
body)
|
||||
|
||||
def test_create_fast_udp_profiles(self):
|
||||
fake_profile = consts.FAKE_APPLICATION_PROFILE.copy()
|
||||
body = {
|
||||
'display_name': fake_profile['display_name'],
|
||||
'description': fake_profile['description'],
|
||||
'resource_type': app_profile_types.FAST_UDP,
|
||||
'flow_mirroring_enabled': True,
|
||||
'idle_timeout': 1800,
|
||||
'tags': consts.FAKE_TAGS
|
||||
}
|
||||
with mock.patch.object(self.nsxlib.client, 'create') as create:
|
||||
self.nsxlib.load_balancer.application_profile.create(
|
||||
display_name=body['display_name'],
|
||||
description=body['description'],
|
||||
resource_type=body['resource_type'],
|
||||
flow_mirroring_enabled=body['flow_mirroring_enabled'],
|
||||
idle_timeout=body['idle_timeout'],
|
||||
tags=consts.FAKE_TAGS)
|
||||
create.assert_called_with('loadbalancer/application-profiles',
|
||||
body)
|
||||
|
||||
def test_create_http_profiles(self):
|
||||
fake_profile = consts.FAKE_APPLICATION_PROFILE.copy()
|
||||
body = {
|
||||
'display_name': fake_profile['display_name'],
|
||||
'description': fake_profile['description'],
|
||||
'resource_type': app_profile_types.HTTP,
|
||||
'http_redirect_to': fake_profile['http_redirect_to'],
|
||||
'http_redirect_to_https': fake_profile['http_redirect_to_https'],
|
||||
'ntlm': fake_profile['ntlm'],
|
||||
'request_body_size': fake_profile['request_body_size'],
|
||||
'request_header_size': fake_profile['request_header_size'],
|
||||
'response_header_size': fake_profile['response_header_size'],
|
||||
'response_timeout': fake_profile['response_timeout'],
|
||||
'x_forwarded_for': fake_profile['x_forwarded_for'],
|
||||
'idle_timeout': fake_profile['idle_timeout'],
|
||||
'tags': consts.FAKE_TAGS
|
||||
}
|
||||
with mock.patch.object(self.nsxlib.client, 'create') as create:
|
||||
self.nsxlib.load_balancer.application_profile.create(
|
||||
display_name=body['display_name'],
|
||||
description=body['description'],
|
||||
resource_type=body['resource_type'],
|
||||
http_redirect_to=body['http_redirect_to'],
|
||||
http_redirect_to_https=body['http_redirect_to_https'],
|
||||
ntlm=body['ntlm'],
|
||||
request_body_size=body['request_body_size'],
|
||||
request_header_size=body['request_header_size'],
|
||||
response_header_size=body['response_header_size'],
|
||||
response_timeout=body['response_timeout'],
|
||||
x_forwarded_for=body['x_forwarded_for'],
|
||||
idle_timeout=body['idle_timeout'],
|
||||
tags=consts.FAKE_TAGS)
|
||||
create.assert_called_with('loadbalancer/application-profiles',
|
||||
body)
|
||||
|
||||
def test_list_application_profiles(self):
|
||||
with mock.patch.object(self.nsxlib.client, 'list') as list_call:
|
||||
self.nsxlib.load_balancer.application_profile.list()
|
||||
|
@ -170,16 +170,22 @@ class ApplicationProfile(LoadBalancerBase):
|
||||
body['tags'] = tags
|
||||
if resource_type is None:
|
||||
return body
|
||||
if resource_type == ApplicationProfileTypes.HTTP:
|
||||
if resource_type in [ApplicationProfileTypes.HTTP,
|
||||
ApplicationProfileTypes.FAST_TCP,
|
||||
ApplicationProfileTypes.FAST_UDP]:
|
||||
body['resource_type'] = resource_type
|
||||
extra_args = ['http_redirect_to', 'http_redirect_to_https',
|
||||
'ntlm', 'request_header_size', 'x_forwarded_for',
|
||||
'idle_timeout']
|
||||
return utils.build_extra_args(body, extra_args, **kwargs)
|
||||
elif (resource_type == ApplicationProfileTypes.FAST_TCP or
|
||||
resource_type == ApplicationProfileTypes.FAST_UDP):
|
||||
body['resource_type'] = resource_type
|
||||
extra_args = ['ha_flow_mirroring_enabled', 'idle_timeout']
|
||||
extra_args = ['idle_timeout']
|
||||
if resource_type == ApplicationProfileTypes.HTTP:
|
||||
extra_args.extend(
|
||||
['http_redirect_to', 'http_redirect_to_https', 'ntlm',
|
||||
'request_body_size', 'request_header_size',
|
||||
'response_header_size', 'response_timeout',
|
||||
'x_forwarded_for'])
|
||||
elif resource_type == ApplicationProfileTypes.FAST_TCP:
|
||||
extra_args.extend(
|
||||
['close_timeout', 'ha_flow_mirroring_enabled'])
|
||||
elif resource_type == ApplicationProfileTypes.FAST_UDP:
|
||||
extra_args.extend(['flow_mirroring_enabled'])
|
||||
return utils.build_extra_args(body, extra_args, **kwargs)
|
||||
else:
|
||||
raise nsxlib_exc.InvalidInput(
|
||||
|
@ -180,10 +180,7 @@ class LBAppProfileBaseDef(ResourceDef):
|
||||
def get_obj_dict(self):
|
||||
body = super(LBAppProfileBaseDef, self).get_obj_dict()
|
||||
self._set_attrs_if_specified(
|
||||
body, ['idle_timeout', 'http_redirect_to_https',
|
||||
'http_redirect_to', 'idle_timeout', 'ntlm',
|
||||
'request_body_size', 'request_header_size',
|
||||
'response_timeout', 'x_forwarded_for'])
|
||||
body, ['idle_timeout'])
|
||||
return body
|
||||
|
||||
|
||||
@ -193,6 +190,15 @@ class LBHttpProfileDef(LBAppProfileBaseDef):
|
||||
def resource_type():
|
||||
return "LBHttpProfile"
|
||||
|
||||
def get_obj_dict(self):
|
||||
body = super(LBHttpProfileDef, self).get_obj_dict()
|
||||
self._set_attrs_if_specified(
|
||||
body, ['http_redirect_to', 'http_redirect_to_https', 'ntlm',
|
||||
'request_body_size', 'request_header_size',
|
||||
'response_header_size', 'response_timeout',
|
||||
'x_forwarded_for'])
|
||||
return body
|
||||
|
||||
|
||||
class LBFastTcpProfile(LBAppProfileBaseDef):
|
||||
|
||||
@ -200,6 +206,12 @@ class LBFastTcpProfile(LBAppProfileBaseDef):
|
||||
def resource_type():
|
||||
return "LBFastTcpProfile"
|
||||
|
||||
def get_obj_dict(self):
|
||||
body = super(LBFastTcpProfile, self).get_obj_dict()
|
||||
self._set_attrs_if_specified(
|
||||
body, ['close_timeout', 'ha_flow_mirroring_enabled'])
|
||||
return body
|
||||
|
||||
|
||||
class LBFastUdpProfile(LBAppProfileBaseDef):
|
||||
|
||||
@ -207,6 +219,12 @@ class LBFastUdpProfile(LBAppProfileBaseDef):
|
||||
def resource_type():
|
||||
return "LBFastUdpProfile"
|
||||
|
||||
def get_obj_dict(self):
|
||||
body = super(LBFastUdpProfile, self).get_obj_dict()
|
||||
self._set_attrs_if_specified(
|
||||
body, ['flow_mirroring_enabled'])
|
||||
return body
|
||||
|
||||
|
||||
class LBPoolDef(ResourceDef):
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user