Added Tier 0 static routes

Adds Tier 0 static routes API to support dev
on NCP side on multi VRF and multi T0 topology

Issue: #
Jira: #
Signed-off-by: Rongrong_Miao <rmiao@vmware.com>
Change-Id: I73756350b23dbd8f23c8e22ad84abe93b49831a4
(cherry picked from commit 4dcc68b807)
This commit is contained in:
Rongrong_Miao 2021-04-05 09:23:00 -07:00 committed by Salvatore Orlando
parent 17437c2cf0
commit 3d5cbe2f3a
3 changed files with 114 additions and 1 deletions

View File

@ -7013,5 +7013,54 @@ class TestNsxPolicyObjectRolePermissionGroup(NsxPolicyLibTestCase):
path_prefix=path_prefix,
role_name=role_name,
tenant=TEST_TENANT)
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)

View File

@ -80,6 +80,8 @@ class NsxPolicyLib(lib.NsxLibBase):
self.tier0_prefix_list = core_resources.NsxPolicyTier0PrefixListApi(
*args)
self.tier0_bgp = core_resources.NsxPolicyTier0BgpApi(*args)
self.tier0_static_route = (
core_resources.NSXPolicyTier0StaticRouteApi(*args))
self.tier1 = core_resources.NsxPolicyTier1Api(*args)
self.tier1_segment = core_resources.NsxPolicyTier1SegmentApi(*args)
self.tier1_nat_rule = core_resources.NsxPolicyTier1NatRuleApi(

View File

@ -2000,6 +2000,68 @@ class NsxPolicyTier1NatRuleApi(NsxPolicyResourceBase):
enabled=enabled)
class NSXPolicyTier0StaticRouteApi(NsxPolicyResourceBase):
@property
def entry_def(self):
return core_defs.Tier0StaticRoute
def create_or_overwrite(self, name, tier0_id,
static_route_id=None,
description=IGNORE,
network=IGNORE,
next_hop=IGNORE,
tags=IGNORE,
tenant=constants.POLICY_INFRA_TENANT):
static_route_id = self._init_obj_uuid(static_route_id)
static_route_def = self._init_def(tier0_id=tier0_id,
static_route_id=static_route_id,
name=name,
description=description,
network=network,
next_hop=next_hop,
tags=tags,
tenant=tenant)
self._create_or_store(static_route_def)
return static_route_id
def delete(self, tier0_id, static_route_id,
tenant=constants.POLICY_INFRA_TENANT):
static_route_def = self.entry_def(tier0_id=tier0_id,
static_route_id=static_route_id,
tenant=tenant)
self._delete_with_retry(static_route_def)
def get(self, tier0_id, static_route_id,
tenant=constants.POLICY_INFRA_TENANT, silent=False):
static_route_def = self.entry_def(tier0_id=tier0_id,
static_route_id=static_route_id,
tenant=tenant)
return self.policy_api.get(static_route_def, silent=silent)
def list(self, tier0_id,
tenant=constants.POLICY_INFRA_TENANT):
static_route_def = self.entry_def(tier0_id=tier0_id,
tenant=tenant)
return self._list(static_route_def)
def update(self, tier0_id, static_route_id,
name=IGNORE,
description=IGNORE,
network=IGNORE,
next_hop=IGNORE,
tags=IGNORE,
tenant=constants.POLICY_INFRA_TENANT):
self._update(tier0_id=tier0_id,
static_route_id=static_route_id,
name=name,
description=description,
network=network,
next_hop=next_hop,
tags=tags,
tenant=tenant)
class NsxPolicyTier1StaticRouteApi(NsxPolicyResourceBase):
@property