Get BGP config from T0 locale service

Change-Id: I7f14d96dfb79f1a41ebbd4f41129709927bb9ac7
This commit is contained in:
Danting Liu 2019-11-15 01:53:48 -08:00
parent 7ece72cd83
commit a5c23064e0
3 changed files with 41 additions and 0 deletions

View File

@ -3560,6 +3560,18 @@ class TestPolicyTier0(NsxPolicyLibTestCase):
pt_mock.assert_called_once_with(logical_router_id)
self.assertIsNotNone(result)
def test_get_bgp_config(self):
tier0_id = '111'
services = {'results': [{'id': 'service1'}]}
bgp_config = {"id": "bgp", "enabled": True}
with mock.patch.object(self.resourceApi.policy_api, "get",
return_value=bgp_config), \
mock.patch.object(self.resourceApi.policy_api, "list",
return_value=services):
result = self.resourceApi.get_bgp_config(
tier0_id, tenant=TEST_TENANT)
self.assertEqual(result, bgp_config)
class TestPolicyTier1Segment(NsxPolicyLibTestCase):

View File

@ -2270,3 +2270,20 @@ class Tier0PrefixListDef(ResourceDef):
prefixes = [prefix.get_obj_dict() for prefix in prefixes]
body['prefixes'] = prefixes
return body
class BgpRoutingConfigDef(ResourceDef):
@staticmethod
def resource_type():
return 'BgpRoutingConfig'
@property
def path_pattern(self):
return TIER0_LOCALE_SERVICES_PATH_PATTERN + "%s/bgp"
@property
def path_ids(self):
# Adding dummy key to satisfy get_section_path
# This resource has no keys, since it is a single object
return ('tenant', 'tier0_id', 'service_id', 'dummy')

View File

@ -1525,6 +1525,18 @@ class NsxPolicyTier0Api(NsxPolicyResourceBase):
subnet.get('prefix_len')))
return cidrs
def get_bgp_config(self, tier0_id, tenant=constants.POLICY_INFRA_TENANT):
services = self.get_locale_services(tier0_id, tenant=tenant)
for srv in services:
bgpconfig_def = core_defs.BgpRoutingConfigDef(
tier0_id=tier0_id,
service_id=srv['id'],
tenant=constants.POLICY_INFRA_TENANT)
try:
return self.policy_api.get(bgpconfig_def)
except exceptions.ResourceNotFound:
continue
class NsxPolicyTier0NatRuleApi(NsxPolicyResourceBase):
DEFAULT_NAT_ID = 'USER'