diff --git a/vmware_nsxlib/tests/unit/v3/policy/test_resources.py b/vmware_nsxlib/tests/unit/v3/policy/test_resources.py index 3b9430eb..66337378 100644 --- a/vmware_nsxlib/tests/unit/v3/policy/test_resources.py +++ b/vmware_nsxlib/tests/unit/v3/policy/test_resources.py @@ -5423,6 +5423,46 @@ class TestPolicySegmentPort(NsxPolicyLibTestCase): with mock.patch.object( self.policy_api.client, "url_post") as api_post, \ + mock.patch.object(self.resourceApi, 'version', + nsx_constants.NSX_VERSION_4_1_0): + result = self.resourceApi.create_or_overwrite( + name, segment_id, port_id=port_id, description=description, + address_bindings=address_bindings, + attachment_type=attachment_type, vif_id=vif_id, app_id=app_id, + context_id=context_id, traffic_tag=traffic_tag, + allocate_addresses=allocate_addresses, + hyperbus_mode=hyperbus_mode, admin_state=admin_state, + tags=tags, + tenant=TEST_TENANT, + init_state=init_state) + + expected_def = core_defs.SegmentPortDef( + nsx_version=nsx_constants.NSX_VERSION_4_1_0, + segment_id=segment_id, + port_id=port_id, + name=name, + description=description, + address_bindings=address_bindings, + attachment_type=attachment_type, + vif_id=vif_id, + app_id=app_id, + context_id=context_id, + traffic_tag=traffic_tag, + allocate_addresses=allocate_addresses, + admin_state=admin_state, + tags=tags, + tenant=TEST_TENANT, + hyperbus_mode=hyperbus_mode, + init_state=init_state) + + api_post.assert_called_once_with( + expected_def.get_resource_path(), + expected_def.get_obj_dict(), headers=None, + expected_results=None, retry_confirm=False) + self.assertIsNotNone(result) + + with mock.patch.object( + self.policy_api, "create_or_update") as api_call, \ mock.patch.object(self.resourceApi, 'version', nsxlib_testcase.LATEST_VERSION): result = self.resourceApi.create_or_overwrite( @@ -5454,11 +5494,7 @@ class TestPolicySegmentPort(NsxPolicyLibTestCase): tenant=TEST_TENANT, hyperbus_mode=hyperbus_mode, init_state=init_state) - - api_post.assert_called_once_with( - expected_def.get_resource_path(), - expected_def.get_obj_dict(), headers=None, - expected_results=None, retry_confirm=False) + self.assert_called_with_def(api_call, expected_def) self.assertIsNotNone(result) def test_create_with_unsupported_attribute(self): diff --git a/vmware_nsxlib/v3/policy/core_resources.py b/vmware_nsxlib/v3/policy/core_resources.py index 351a806a..3a83c583 100644 --- a/vmware_nsxlib/v3/policy/core_resources.py +++ b/vmware_nsxlib/v3/policy/core_resources.py @@ -2547,9 +2547,13 @@ class NsxPolicySegmentPortApi(NsxPolicyResourceBase): tags=tags, tenant=tenant) if init_state == nsx_constants.INIT_STATE_RESTORE_VIF: - path = port_def.get_resource_path() - body = port_def.get_obj_dict() - self.policy_api.client.create(path, body=body) + if (version.LooseVersion(self.version) >= + version.LooseVersion(nsx_constants.NSX_VERSION_4_1_0)): + path = port_def.get_resource_path() + body = port_def.get_obj_dict() + self.policy_api.client.create(path, body=body) + else: + self._create_or_store(port_def) else: self._create_or_store(port_def) return port_id