commit ba0994042982c81dede2f7e7800bc479ca23d962 Author: Erica Liu Date: Tue Oct 13 17:07:36 2020 -0700 Adding support for customzing ep value in segement creation In case of none default enforcement point value, the Segment create might fail, because it is hard coded to use default ep for querying transport zone, if specified. This change add support for creating segment with transport zone in none default enforcement point Change-Id: Id122f9591c2bded5edc43fad514e6e1e9e6a9fa3 diff --git a/vmware_nsxlib/tests/unit/v3/policy/test_resources.py b/vmware_nsxlib/tests/unit/v3/policy/test_resources.py index 32d75af..997678e 100644 --- a/vmware_nsxlib/tests/unit/v3/policy/test_resources.py +++ b/vmware_nsxlib/tests/unit/v3/policy/test_resources.py @@ -4186,7 +4186,7 @@ class TestPolicySegment(NsxPolicyLibTestCase): def _test_create(self, tier1_id=None, tier0_id=None, mdproxy=None, dhcp_server=None, admin_state=None, ip_pool_id='external-ip-pool', ls_id=None, - unique_id=None): + unique_id=None, tz_id=None, ep_id=None): name = 'test' description = 'desc' subnets = [core_defs.Subnet(gateway_address="2.2.2.0/24")] @@ -4213,6 +4213,11 @@ class TestPolicySegment(NsxPolicyLibTestCase): if unique_id: kwargs['unique_id'] = unique_id + if tz_id: + kwargs['transport_zone_id'] = tz_id + if ep_id: + kwargs['ep_id'] = ep_id + with mock.patch.object(self.policy_api, "create_or_update") as api_call: result = self.resourceApi.create_or_overwrite(name, **kwargs) @@ -4269,6 +4274,12 @@ class TestPolicySegment(NsxPolicyLibTestCase): def test_create_with_unique_id(self): self._test_create(unique_id='lsid1') + def test_create_with_transport_zone_id(self): + self._test_create(tz_id='tz_id1', ep_id='ep_id1') + + def test_create_with_transport_zone_id_and_default_ep(self): + self._test_create(tz_id='tz_id1') + def test_delete(self): segment_id = '111' with mock.patch.object(self.policy_api, "delete") as api_call: diff --git a/vmware_nsxlib/v3/policy/core_defs.py b/vmware_nsxlib/v3/policy/core_defs.py index 6b03a91..1f691c9 100644 --- a/vmware_nsxlib/v3/policy/core_defs.py +++ b/vmware_nsxlib/v3/policy/core_defs.py @@ -995,7 +995,8 @@ class SegmentDef(BaseSegmentDef): if self.get_attr('transport_zone_id'): tz = TransportZoneDef( tz_id=self.get_attr('transport_zone_id'), - ep_id=constants.DEFAULT_ENFORCEMENT_POINT, + ep_id=self.get_attr( + 'ep_id') or constants.DEFAULT_ENFORCEMENT_POINT, tenant=self.get_tenant()) path = tz.get_resource_full_path() self._set_attr_if_specified(body, 'transport_zone_id', diff --git a/vmware_nsxlib/v3/policy/core_resources.py b/vmware_nsxlib/v3/policy/core_resources.py index d4143d1..5e23310 100644 --- a/vmware_nsxlib/v3/policy/core_resources.py +++ b/vmware_nsxlib/v3/policy/core_resources.py @@ -1982,6 +1982,7 @@ class NsxPolicySegmentApi(NsxPolicyResourceBase): admin_state=IGNORE, ls_id=IGNORE, unique_id=IGNORE, + ep_id=IGNORE, tags=IGNORE, tenant=constants.POLICY_INFRA_TENANT): @@ -2007,6 +2008,7 @@ class NsxPolicySegmentApi(NsxPolicyResourceBase): admin_state=admin_state, ls_id=ls_id, unique_id=unique_id, + ep_id=ep_id, tags=tags, tenant=tenant) self._create_or_store(segment_def)