diff --git a/vmware_nsxlib/tests/unit/v3/policy/test_resources.py b/vmware_nsxlib/tests/unit/v3/policy/test_resources.py index aa108c1b..44d4a92d 100644 --- a/vmware_nsxlib/tests/unit/v3/policy/test_resources.py +++ b/vmware_nsxlib/tests/unit/v3/policy/test_resources.py @@ -3959,6 +3959,59 @@ class TestPolicySegmentPort(NsxPolicyLibTestCase): self.assert_called_with_def(api_call, expected_def) self.assertIsNotNone(result) + def test_attach(self): + segment_id = "segment" + port_id = "port" + attachment_type = "CHILD" + vif_id = "vif" + app_id = "app" + context_id = "context" + traffic_tag = 10 + allocate_addresses = "BOTH" + tags = [{'scope': 'a', 'tag': 'b'}] + with mock.patch.object(self.policy_api, + "create_or_update") as api_call: + self.resourceApi.attach( + segment_id, port_id, + attachment_type=attachment_type, vif_id=vif_id, app_id=app_id, + context_id=context_id, traffic_tag=traffic_tag, + allocate_addresses=allocate_addresses, tags=tags, + tenant=TEST_TENANT) + + expected_def = core_defs.SegmentPortDef( + segment_id=segment_id, + port_id=port_id, + attachment_type=attachment_type, + vif_id=vif_id, + app_id=app_id, + context_id=context_id, + traffic_tag=traffic_tag, + allocate_addresses=allocate_addresses, + tags=tags, + tenant=TEST_TENANT) + + self.assert_called_with_def(api_call, expected_def) + + def test_detach(self): + segment_id = "segment" + port_id = "port" + tags = [{'scope': 'a', 'tag': 'b'}] + with mock.patch.object(self.policy_api, + "create_or_update") as api_call: + self.resourceApi.detach( + segment_id, port_id, tags=tags, + tenant=TEST_TENANT) + + expected_def = core_defs.SegmentPortDef( + segment_id=segment_id, + port_id=port_id, + attachment_type=None, + vif_id=None, + tags=tags, + tenant=TEST_TENANT) + + self.assert_called_with_def(api_call, expected_def) + class TestPolicySegmentProfileBase(NsxPolicyLibTestCase): diff --git a/vmware_nsxlib/v3/policy/core_resources.py b/vmware_nsxlib/v3/policy/core_resources.py index 0850bdba..60f62e5e 100644 --- a/vmware_nsxlib/v3/policy/core_resources.py +++ b/vmware_nsxlib/v3/policy/core_resources.py @@ -1962,21 +1962,25 @@ class NsxPolicySegmentPortApi(NsxPolicyResourceBase): tags=tags, tenant=tenant) - def detach(self, segment_id, port_id, + def detach(self, segment_id, port_id, tags=IGNORE, tenant=constants.POLICY_INFRA_TENANT): port_def = self.entry_def(segment_id=segment_id, port_id=port_id, + vif_id=None, attachment_type=None, + tags=tags, tenant=tenant) self.policy_api.create_or_update(port_def) def attach(self, segment_id, port_id, attachment_type, vif_id, - allocate_addresses, + allocate_addresses=None, app_id=None, context_id=None, + traffic_tag=None, + tags=IGNORE, tenant=constants.POLICY_INFRA_TENANT): port_def = self.entry_def(segment_id=segment_id, @@ -1986,6 +1990,8 @@ class NsxPolicySegmentPortApi(NsxPolicyResourceBase): vif_id=vif_id, app_id=app_id, context_id=context_id, + traffic_tag=traffic_tag, + tags=tags, tenant=tenant) self.policy_api.create_or_update(port_def)