[T0API] Added SCOPE parameter in static route
In setting T0 static route, a scope parameter is needed.
This patch fixes the problem with previous implementation by
adding the scope field in static route definition
Issue: #
Jira: #
Signed-off-by: Rongrong_Miao <rmiao@vmware.com>
Change-Id: I9b6e579e8e57e13cb1ba9e797c7348e23e3aaa8f
(cherry picked from commit d8596e784e
)
This commit is contained in:
parent
aa5b7deac3
commit
b442394c98
|
@ -6931,6 +6931,61 @@ class TestPolicyGlobalConfig(NsxPolicyLibTestCase):
|
||||||
api_put.assert_not_called()
|
api_put.assert_not_called()
|
||||||
|
|
||||||
|
|
||||||
|
class TestPolicyTier0StaticRoute(NsxPolicyLibTestCase):
|
||||||
|
|
||||||
|
def setUp(self, *args, **kwargs):
|
||||||
|
super(TestPolicyTier0StaticRoute, self).setUp()
|
||||||
|
self.resourceApi = self.policy_lib.tier0_static_route
|
||||||
|
|
||||||
|
def test_create(self):
|
||||||
|
name = 'test'
|
||||||
|
description = 'desc'
|
||||||
|
tier0_id = '111'
|
||||||
|
static_route_id = '222'
|
||||||
|
network = '1.1.1.1/24'
|
||||||
|
nexthop = '2.2.2.2'
|
||||||
|
scope = 'ContainerT0'
|
||||||
|
|
||||||
|
with mock.patch.object(self.policy_api,
|
||||||
|
"create_or_update") as api_call:
|
||||||
|
result = self.resourceApi.create_or_overwrite(
|
||||||
|
name, tier0_id,
|
||||||
|
static_route_id=static_route_id,
|
||||||
|
description=description,
|
||||||
|
network=network,
|
||||||
|
next_hop=nexthop,
|
||||||
|
tenant=TEST_TENANT,
|
||||||
|
scope=scope
|
||||||
|
)
|
||||||
|
|
||||||
|
expected_def = core_defs.Tier0StaticRoute(
|
||||||
|
tier0_id=tier0_id,
|
||||||
|
static_route_id=static_route_id,
|
||||||
|
name=name,
|
||||||
|
description=description,
|
||||||
|
network=network,
|
||||||
|
next_hop=nexthop,
|
||||||
|
tenant=TEST_TENANT,
|
||||||
|
scope=scope
|
||||||
|
)
|
||||||
|
self.assert_called_with_def(api_call, expected_def)
|
||||||
|
self.assertIsNotNone(result)
|
||||||
|
|
||||||
|
def test_delete(self):
|
||||||
|
tier0_id = '111'
|
||||||
|
static_route_id = '222'
|
||||||
|
with mock.patch.object(self.policy_api, "delete") as api_call:
|
||||||
|
self.resourceApi.delete(
|
||||||
|
tier0_id,
|
||||||
|
static_route_id,
|
||||||
|
tenant=TEST_TENANT)
|
||||||
|
expected_def = core_defs.Tier0StaticRoute(
|
||||||
|
tier0_id=tier0_id,
|
||||||
|
static_route_id=static_route_id,
|
||||||
|
tenant=TEST_TENANT)
|
||||||
|
self.assert_called_with_def(api_call, expected_def)
|
||||||
|
|
||||||
|
|
||||||
class TestNsxPolicyObjectRolePermissionGroup(NsxPolicyLibTestCase):
|
class TestNsxPolicyObjectRolePermissionGroup(NsxPolicyLibTestCase):
|
||||||
|
|
||||||
def setUp(self, *args, **kwargs):
|
def setUp(self, *args, **kwargs):
|
||||||
|
@ -7014,53 +7069,3 @@ class TestNsxPolicyObjectRolePermissionGroup(NsxPolicyLibTestCase):
|
||||||
role_name=role_name,
|
role_name=role_name,
|
||||||
tenant=TEST_TENANT)
|
tenant=TEST_TENANT)
|
||||||
self.assert_called_with_def(api_call, expected_def)
|
self.assert_called_with_def(api_call, expected_def)
|
||||||
|
|
||||||
|
|
||||||
class TestPolicyTier0StaticRoute(NsxPolicyLibTestCase):
|
|
||||||
|
|
||||||
def setUp(self, *args, **kwargs):
|
|
||||||
super(TestPolicyTier0StaticRoute, self).setUp()
|
|
||||||
self.resourceApi = self.policy_lib.tier0_static_route
|
|
||||||
|
|
||||||
def test_create(self):
|
|
||||||
name = 'test'
|
|
||||||
description = 'desc'
|
|
||||||
tier0_id = '111'
|
|
||||||
static_route_id = '222'
|
|
||||||
network = '1.1.1.1/24'
|
|
||||||
nexthop = '2.2.2.2'
|
|
||||||
|
|
||||||
with mock.patch.object(self.policy_api,
|
|
||||||
"create_or_update") as api_call:
|
|
||||||
result = self.resourceApi.create_or_overwrite(
|
|
||||||
name, tier0_id,
|
|
||||||
static_route_id=static_route_id,
|
|
||||||
description=description,
|
|
||||||
network=network,
|
|
||||||
next_hop=nexthop,
|
|
||||||
tenant=TEST_TENANT)
|
|
||||||
|
|
||||||
expected_def = core_defs.Tier0StaticRoute(
|
|
||||||
tier0_id=tier0_id,
|
|
||||||
static_route_id=static_route_id,
|
|
||||||
name=name,
|
|
||||||
description=description,
|
|
||||||
network=network,
|
|
||||||
next_hop=nexthop,
|
|
||||||
tenant=TEST_TENANT)
|
|
||||||
self.assert_called_with_def(api_call, expected_def)
|
|
||||||
self.assertIsNotNone(result)
|
|
||||||
|
|
||||||
def test_delete(self):
|
|
||||||
tier0_id = '111'
|
|
||||||
static_route_id = '222'
|
|
||||||
with mock.patch.object(self.policy_api, "delete") as api_call:
|
|
||||||
self.resourceApi.delete(
|
|
||||||
tier0_id,
|
|
||||||
static_route_id,
|
|
||||||
tenant=TEST_TENANT)
|
|
||||||
expected_def = core_defs.Tier0StaticRoute(
|
|
||||||
tier0_id=tier0_id,
|
|
||||||
static_route_id=static_route_id,
|
|
||||||
tenant=TEST_TENANT)
|
|
||||||
self.assert_called_with_def(api_call, expected_def)
|
|
||||||
|
|
|
@ -740,8 +740,17 @@ class RouterStaticRoute(ResourceDef):
|
||||||
|
|
||||||
# next hops
|
# next hops
|
||||||
if self.has_attr('next_hop'):
|
if self.has_attr('next_hop'):
|
||||||
|
next_hops = []
|
||||||
|
param_dict = dict()
|
||||||
next_hop = self.get_attr('next_hop')
|
next_hop = self.get_attr('next_hop')
|
||||||
next_hops = [{'ip_address': next_hop}]
|
param_dict['ip_address'] = next_hop
|
||||||
|
|
||||||
|
# scope parameter
|
||||||
|
if self.has_attr('scope'):
|
||||||
|
scope_path = self.get_attr('scope')
|
||||||
|
param_dict['scope'] = [scope_path]
|
||||||
|
|
||||||
|
next_hops.append(param_dict)
|
||||||
self._set_attr_if_specified(body, 'next_hop',
|
self._set_attr_if_specified(body, 'next_hop',
|
||||||
body_attr='next_hops',
|
body_attr='next_hops',
|
||||||
value=next_hops)
|
value=next_hops)
|
||||||
|
|
|
@ -2012,7 +2012,8 @@ class NSXPolicyTier0StaticRouteApi(NsxPolicyResourceBase):
|
||||||
network=IGNORE,
|
network=IGNORE,
|
||||||
next_hop=IGNORE,
|
next_hop=IGNORE,
|
||||||
tags=IGNORE,
|
tags=IGNORE,
|
||||||
tenant=constants.POLICY_INFRA_TENANT):
|
tenant=constants.POLICY_INFRA_TENANT,
|
||||||
|
scope=IGNORE):
|
||||||
static_route_id = self._init_obj_uuid(static_route_id)
|
static_route_id = self._init_obj_uuid(static_route_id)
|
||||||
static_route_def = self._init_def(tier0_id=tier0_id,
|
static_route_def = self._init_def(tier0_id=tier0_id,
|
||||||
static_route_id=static_route_id,
|
static_route_id=static_route_id,
|
||||||
|
@ -2021,7 +2022,8 @@ class NSXPolicyTier0StaticRouteApi(NsxPolicyResourceBase):
|
||||||
network=network,
|
network=network,
|
||||||
next_hop=next_hop,
|
next_hop=next_hop,
|
||||||
tags=tags,
|
tags=tags,
|
||||||
tenant=tenant)
|
tenant=tenant,
|
||||||
|
scope=scope)
|
||||||
self._create_or_store(static_route_def)
|
self._create_or_store(static_route_def)
|
||||||
return static_route_id
|
return static_route_id
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue