Merge "Add ability to set Tier-0 to an Infra Segment"
This commit is contained in:
commit
dda224e488
|
@ -3302,34 +3302,43 @@ class TestPolicySegment(NsxPolicyLibTestCase):
|
|||
super(TestPolicySegment, self).setUp()
|
||||
self.resourceApi = self.policy_lib.segment
|
||||
|
||||
def test_create(self):
|
||||
def _test_create(self, tier1_id=None, tier0_id=None):
|
||||
name = 'test'
|
||||
description = 'desc'
|
||||
tier1_id = '111'
|
||||
ip_pool_id = 'external-ip-pool'
|
||||
subnets = [core_defs.Subnet(gateway_address="2.2.2.0/24")]
|
||||
kwargs = {'description': description,
|
||||
'subnets': subnets,
|
||||
'ip_pool_id': 'external-ip-pool',
|
||||
'tenant': TEST_TENANT}
|
||||
if tier1_id:
|
||||
kwargs['tier1_id'] = tier1_id
|
||||
|
||||
if tier0_id:
|
||||
kwargs['tier0_id'] = tier0_id
|
||||
|
||||
with mock.patch.object(self.policy_api,
|
||||
"create_or_update") as api_call:
|
||||
result = self.resourceApi.create_or_overwrite(
|
||||
name, description=description,
|
||||
tier1_id=tier1_id,
|
||||
ip_pool_id=ip_pool_id,
|
||||
subnets=subnets,
|
||||
tenant=TEST_TENANT)
|
||||
result = self.resourceApi.create_or_overwrite(name, **kwargs)
|
||||
|
||||
expected_def = core_defs.SegmentDef(
|
||||
segment_id=mock.ANY,
|
||||
name=name,
|
||||
description=description,
|
||||
tier1_id=tier1_id,
|
||||
ip_pool_id=ip_pool_id,
|
||||
subnets=subnets,
|
||||
tenant=TEST_TENANT)
|
||||
**kwargs)
|
||||
|
||||
self.assert_called_with_def(api_call, expected_def)
|
||||
self.assertIsNotNone(result)
|
||||
|
||||
def test_create_with_t1(self):
|
||||
self._test_create(tier1_id='111')
|
||||
|
||||
def test_create_with_t0(self):
|
||||
self._test_create(tier0_id='000')
|
||||
|
||||
def test_create_with_t0_t1_fail(self):
|
||||
self.assertRaises(nsxlib_exc.InvalidInput,
|
||||
self.resourceApi.create_or_overwrite,
|
||||
'seg-name', tier1_id='111', tier0_id='000')
|
||||
|
||||
def test_delete(self):
|
||||
segment_id = '111'
|
||||
with mock.patch.object(self.policy_api, "delete") as api_call:
|
||||
|
|
|
@ -711,6 +711,16 @@ class SegmentDef(BaseSegmentDef):
|
|||
body_attr='connectivity_path',
|
||||
value=path)
|
||||
|
||||
if self.has_attr('tier0_id'):
|
||||
path = ""
|
||||
if self.get_attr('tier0_id'):
|
||||
tier0 = Tier0Def(tier0_id=self.get_attr('tier0_id'),
|
||||
tenant=self.get_tenant())
|
||||
path = tier0.get_resource_full_path()
|
||||
self._set_attr_if_specified(body, 'tier0_id',
|
||||
body_attr='connectivity_path',
|
||||
value=path)
|
||||
|
||||
if self.has_attr('transport_zone_id'):
|
||||
path = ""
|
||||
if self.get_attr('transport_zone_id'):
|
||||
|
@ -723,7 +733,6 @@ class SegmentDef(BaseSegmentDef):
|
|||
body_attr='transport_zone_path',
|
||||
value=path)
|
||||
|
||||
# TODO(annak): support also tier0
|
||||
return body
|
||||
|
||||
|
||||
|
|
|
@ -1668,6 +1668,7 @@ class NsxPolicySegmentApi(NsxPolicyResourceBase):
|
|||
def create_or_overwrite(self, name,
|
||||
segment_id=None,
|
||||
tier1_id=IGNORE,
|
||||
tier0_id=IGNORE,
|
||||
description=IGNORE,
|
||||
subnets=IGNORE,
|
||||
dns_domain_name=IGNORE,
|
||||
|
@ -1677,11 +1678,17 @@ class NsxPolicySegmentApi(NsxPolicyResourceBase):
|
|||
tags=IGNORE,
|
||||
tenant=constants.POLICY_INFRA_TENANT):
|
||||
|
||||
if tier0_id != IGNORE and tier1_id != IGNORE:
|
||||
err_msg = (_("Cannot connect Segment to a Tier-0 and Tier-1 "
|
||||
"Gateway simultaneously"))
|
||||
raise exceptions.InvalidInput(details=err_msg)
|
||||
|
||||
segment_id = self._init_obj_uuid(segment_id)
|
||||
segment_def = self._init_def(segment_id=segment_id,
|
||||
name=name,
|
||||
description=description,
|
||||
tier1_id=tier1_id,
|
||||
tier0_id=tier0_id,
|
||||
subnets=subnets,
|
||||
dns_domain_name=dns_domain_name,
|
||||
vlan_ids=vlan_ids,
|
||||
|
@ -1707,7 +1714,7 @@ class NsxPolicySegmentApi(NsxPolicyResourceBase):
|
|||
return self._list(segment_def)
|
||||
|
||||
def update(self, segment_id, name=IGNORE, description=IGNORE,
|
||||
tier1_id=IGNORE, subnets=IGNORE,
|
||||
tier1_id=IGNORE, tier0_id=IGNORE, subnets=IGNORE,
|
||||
dns_domain_name=IGNORE,
|
||||
vlan_ids=IGNORE, tags=IGNORE,
|
||||
tenant=constants.POLICY_INFRA_TENANT):
|
||||
|
@ -1715,6 +1722,7 @@ class NsxPolicySegmentApi(NsxPolicyResourceBase):
|
|||
name=name,
|
||||
description=description,
|
||||
tier1_id=tier1_id,
|
||||
tier0_id=tier0_id,
|
||||
subnets=subnets,
|
||||
dns_domain_name=dns_domain_name,
|
||||
vlan_ids=vlan_ids,
|
||||
|
|
Loading…
Reference in New Issue