Support Tier0 BGP Config in NSX Policy
Change-Id: I1bcd0533e7d5f531280c151b7fef78327b6fd2ab
This commit is contained in:
parent
54308ced90
commit
60de62f64c
|
@ -3607,6 +3607,136 @@ class TestPolicyTier1NoPassthrough(TestPolicyTier1):
|
|||
self.assertEqual(None, realized_id)
|
||||
|
||||
|
||||
class TestPolicyTier0Bgp(NsxPolicyLibTestCase):
|
||||
|
||||
def setUp(self, *args, **kwargs):
|
||||
super(TestPolicyTier0Bgp, self).setUp()
|
||||
self.resourceApi = self.policy_lib.tier0_bgp
|
||||
|
||||
def test_create(self):
|
||||
name = 'test'
|
||||
description = 'bgp'
|
||||
tier0_id = 't0'
|
||||
service_id = "default",
|
||||
ecmp = True,
|
||||
enabled = True,
|
||||
graceful_restart_config = {
|
||||
"mode": "DISABLE",
|
||||
"timer": {
|
||||
"restart_timer": 180,
|
||||
"stale_route_timer": 600
|
||||
}
|
||||
}
|
||||
inter_sr_ibgp = False,
|
||||
local_as_num = "65546",
|
||||
multipath_relax = False,
|
||||
route_aggregations = [{
|
||||
"prefix": "10.1.1.0/24"}, {
|
||||
"prefix": "11.1.0.0/16", "summary_only": "false"}]
|
||||
tags = [{"tag": "tag", "scope": "scope"}]
|
||||
tenant = TEST_TENANT
|
||||
with mock.patch.object(self.policy_api,
|
||||
"create_or_update") as api_call:
|
||||
result = self.resourceApi.create_or_overwrite(
|
||||
tier0_id, service_id,
|
||||
name=name,
|
||||
description=description,
|
||||
ecmp=ecmp,
|
||||
enabled=enabled,
|
||||
graceful_restart_config=graceful_restart_config,
|
||||
inter_sr_ibgp=inter_sr_ibgp,
|
||||
local_as_num=local_as_num,
|
||||
multipath_relax=multipath_relax,
|
||||
route_aggregations=route_aggregations,
|
||||
tags=tags,
|
||||
tenant=tenant)
|
||||
expected_def = core_defs.BgpRoutingConfigDef(
|
||||
tier0_id=tier0_id,
|
||||
service_id=service_id,
|
||||
name=name,
|
||||
description=description,
|
||||
ecmp=ecmp,
|
||||
enabled=enabled,
|
||||
graceful_restart_config=graceful_restart_config,
|
||||
inter_sr_ibgp=inter_sr_ibgp,
|
||||
local_as_num=local_as_num,
|
||||
multipath_relax=multipath_relax,
|
||||
route_aggregations=route_aggregations,
|
||||
tags=tags,
|
||||
tenant=tenant
|
||||
)
|
||||
self.assert_called_with_def(api_call, expected_def)
|
||||
self.assertIsNone(result)
|
||||
|
||||
def test_update(self):
|
||||
name = 'test'
|
||||
description = 'bgp'
|
||||
tier0_id = 't0'
|
||||
service_id = "default",
|
||||
ecmp = True,
|
||||
enabled = True,
|
||||
graceful_restart_config = {
|
||||
"mode": "DISABLE",
|
||||
"timer": {
|
||||
"restart_timer": 180,
|
||||
"stale_route_timer": 600
|
||||
}
|
||||
}
|
||||
inter_sr_ibgp = False,
|
||||
local_as_num = "65546",
|
||||
multipath_relax = False,
|
||||
route_aggregations = [{
|
||||
"prefix": "10.1.1.0/24"}, {
|
||||
"prefix": "11.1.0.0/16", "summary_only": "false"}]
|
||||
tags = [{"tag": "tag", "scope": "scope"}]
|
||||
tenant = TEST_TENANT
|
||||
with mock.patch.object(self.policy_api,
|
||||
"create_or_update") as api_call:
|
||||
result = self.resourceApi.update(
|
||||
tier0_id, service_id,
|
||||
name=name,
|
||||
description=description,
|
||||
ecmp=ecmp,
|
||||
enabled=enabled,
|
||||
graceful_restart_config=graceful_restart_config,
|
||||
inter_sr_ibgp=inter_sr_ibgp,
|
||||
local_as_num=local_as_num,
|
||||
multipath_relax=multipath_relax,
|
||||
route_aggregations=route_aggregations,
|
||||
tags=tags,
|
||||
tenant=tenant)
|
||||
expected_def = core_defs.BgpRoutingConfigDef(
|
||||
tier0_id=tier0_id,
|
||||
service_id=service_id,
|
||||
name=name,
|
||||
description=description,
|
||||
ecmp=ecmp,
|
||||
enabled=enabled,
|
||||
graceful_restart_config=graceful_restart_config,
|
||||
inter_sr_ibgp=inter_sr_ibgp,
|
||||
local_as_num=local_as_num,
|
||||
multipath_relax=multipath_relax,
|
||||
route_aggregations=route_aggregations,
|
||||
tags=tags,
|
||||
tenant=tenant
|
||||
)
|
||||
self.assert_called_with_def(api_call, expected_def)
|
||||
self.assertIsNone(result)
|
||||
|
||||
def test_get(self):
|
||||
tier0_id = 't0'
|
||||
service_id = 'default'
|
||||
tenant = TEST_TENANT
|
||||
with mock.patch.object(self.policy_api, "get") as api_call:
|
||||
mock_tier0_bgp = mock.Mock()
|
||||
api_call.return_value = mock_tier0_bgp
|
||||
result = self.resourceApi.get(tier0_id, service_id, tenant=tenant)
|
||||
expected_def = core_defs.BgpRoutingConfigDef(
|
||||
tier0_id=tier0_id, service_id=service_id, tenant=tenant)
|
||||
self.assert_called_with_def(api_call, expected_def)
|
||||
self.assertEqual(result, mock_tier0_bgp)
|
||||
|
||||
|
||||
class TestPolicyTier0NatRule(NsxPolicyLibTestCase):
|
||||
|
||||
def setUp(self, *args, **kwargs):
|
||||
|
|
|
@ -79,6 +79,7 @@ class NsxPolicyLib(lib.NsxLibBase):
|
|||
self.tier0_route_map = core_resources.NsxPolicyTier0RouteMapApi(*args)
|
||||
self.tier0_prefix_list = core_resources.NsxPolicyTier0PrefixListApi(
|
||||
*args)
|
||||
self.tier0_bgp = core_resources.NsxPolicyTier0BgpApi(*args)
|
||||
self.tier1 = core_resources.NsxPolicyTier1Api(*args)
|
||||
self.tier1_segment = core_resources.NsxPolicyTier1SegmentApi(*args)
|
||||
self.tier1_nat_rule = core_resources.NsxPolicyTier1NatRuleApi(
|
||||
|
|
|
@ -2716,6 +2716,17 @@ class BgpRoutingConfigDef(ResourceDef):
|
|||
# This resource has no keys, since it is a single object
|
||||
return ('tenant', 'tier0_id', 'service_id', 'dummy')
|
||||
|
||||
def get_obj_dict(self):
|
||||
body = super(BgpRoutingConfigDef, self).get_obj_dict()
|
||||
self._set_attrs_if_specified(body, ['ecmp',
|
||||
'enabled',
|
||||
'graceful_restart_config',
|
||||
'inter_sr_ibgp',
|
||||
'local_as_num',
|
||||
'multipath_relax',
|
||||
'route_aggregations'])
|
||||
return body
|
||||
|
||||
|
||||
class Tier0RouteRedistributionConfig(object):
|
||||
|
||||
|
|
|
@ -1703,6 +1703,83 @@ class NsxPolicyTier0Api(NsxPolicyResourceBase):
|
|||
self.policy_api.create_or_update(service_def)
|
||||
|
||||
|
||||
class NsxPolicyTier0BgpApi(NsxPolicyResourceBase):
|
||||
|
||||
@property
|
||||
def entry_def(self):
|
||||
return core_defs.BgpRoutingConfigDef
|
||||
|
||||
def delete(self, tier0_id, service_id,
|
||||
tenant=constants.POLICY_INFRA_TENANT):
|
||||
err_msg = _("This action is currently not supported")
|
||||
raise exceptions.ManagerError(details=err_msg)
|
||||
|
||||
def create_or_overwrite(self, tier0_id, service_id,
|
||||
name=IGNORE,
|
||||
description=IGNORE,
|
||||
ecmp=IGNORE,
|
||||
enabled=IGNORE,
|
||||
graceful_restart_config=IGNORE,
|
||||
inter_sr_ibgp=IGNORE,
|
||||
local_as_num=IGNORE,
|
||||
multipath_relax=IGNORE,
|
||||
route_aggregations=IGNORE,
|
||||
tags=IGNORE,
|
||||
tenant=constants.POLICY_INFRA_TENANT):
|
||||
bgp_config_def = self._init_def(
|
||||
name=name,
|
||||
description=description,
|
||||
tier0_id=tier0_id,
|
||||
service_id=service_id,
|
||||
ecmp=ecmp,
|
||||
enabled=enabled,
|
||||
graceful_restart_config=graceful_restart_config,
|
||||
inter_sr_ibgp=inter_sr_ibgp,
|
||||
local_as_num=local_as_num,
|
||||
multipath_relax=multipath_relax,
|
||||
route_aggregations=route_aggregations,
|
||||
tags=tags,
|
||||
tenant=tenant)
|
||||
self._create_or_store(bgp_config_def)
|
||||
|
||||
def get(self, tier0_id, service_id,
|
||||
tenant=constants.POLICY_INFRA_TENANT, silent=False):
|
||||
bgp_config_def = self.entry_def(
|
||||
tier0_id=tier0_id, service_id=service_id, tenant=tenant)
|
||||
return self.policy_api.get(bgp_config_def, silent=silent)
|
||||
|
||||
def list(self, tier0_id, service_id,
|
||||
tenant=constants.POLICY_INFRA_TENANT):
|
||||
err_msg = _("This action is currently not supported")
|
||||
raise exceptions.ManagerError(details=err_msg)
|
||||
|
||||
def update(self, tier0_id, service_id,
|
||||
name=IGNORE,
|
||||
description=IGNORE,
|
||||
ecmp=IGNORE,
|
||||
enabled=IGNORE,
|
||||
graceful_restart_config=IGNORE,
|
||||
inter_sr_ibgp=IGNORE,
|
||||
local_as_num=IGNORE,
|
||||
multipath_relax=IGNORE,
|
||||
route_aggregations=IGNORE,
|
||||
tags=IGNORE,
|
||||
tenant=constants.POLICY_INFRA_TENANT):
|
||||
self._update(name=name,
|
||||
description=description,
|
||||
tier0_id=tier0_id,
|
||||
service_id=service_id,
|
||||
ecmp=ecmp,
|
||||
enabled=enabled,
|
||||
graceful_restart_config=graceful_restart_config,
|
||||
inter_sr_ibgp=inter_sr_ibgp,
|
||||
local_as_num=local_as_num,
|
||||
multipath_relax=multipath_relax,
|
||||
route_aggregations=route_aggregations,
|
||||
tags=tags,
|
||||
tenant=tenant)
|
||||
|
||||
|
||||
class NsxPolicyTier0NatRuleApi(NsxPolicyResourceBase):
|
||||
DEFAULT_NAT_ID = 'USER'
|
||||
|
||||
|
|
Loading…
Reference in New Issue