Merge "Added Tier 0 static routes"
This commit is contained in:
commit
287757d4cd
@ -6919,3 +6919,53 @@ class TestPolicyGlobalConfig(NsxPolicyLibTestCase):
|
||||
self.resourceApi.disable_ipv6(tenant=TEST_TENANT)
|
||||
api_get.assert_called_once()
|
||||
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'
|
||||
|
||||
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)
|
||||
|
@ -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(
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user