diff --git a/vmware_nsxlib/tests/unit/v3/policy/test_resources.py b/vmware_nsxlib/tests/unit/v3/policy/test_resources.py index bcd836a6..646e5e50 100644 --- a/vmware_nsxlib/tests/unit/v3/policy/test_resources.py +++ b/vmware_nsxlib/tests/unit/v3/policy/test_resources.py @@ -5452,81 +5452,85 @@ class TestPolicySegmentPort(NsxPolicyLibTestCase): admin_state = True init_state = 'RESTORE_VIF' - 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) + for version in [nsx_constants.NSX_VERSION_3_2_3, + nsx_constants.NSX_VERSION_4_1_0]: + with mock.patch.object( + self.policy_api.client, "url_post") as api_post, \ + mock.patch.object(self.resourceApi, 'version', version): + 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) + expected_def = core_defs.SegmentPortDef( + nsx_version=version, + 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) + 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( - 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) + for version in [nsx_constants.NSX_VERSION_3_2_1, + nsx_constants.NSX_VERSION_4_0_0]: + with mock.patch.object( + self.policy_api, "create_or_update") as api_call, \ + mock.patch.object(self.resourceApi, 'version', version): + 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=nsxlib_testcase.LATEST_VERSION, - 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) - self.assert_called_with_def(api_call, expected_def) - self.assertIsNotNone(result) + expected_def = core_defs.SegmentPortDef( + nsx_version=version, + 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) + self.assert_called_with_def(api_call, expected_def) + self.assertIsNotNone(result) def test_create_with_unsupported_attribute(self): name = 'test' diff --git a/vmware_nsxlib/v3/nsx_constants.py b/vmware_nsxlib/v3/nsx_constants.py index df4857fa..69a3ad2d 100644 --- a/vmware_nsxlib/v3/nsx_constants.py +++ b/vmware_nsxlib/v3/nsx_constants.py @@ -164,6 +164,7 @@ NSX_VERSION_3_0_2 = '3.0.2' NSX_VERSION_3_1_0 = '3.1.0' NSX_VERSION_3_2_0 = '3.2.0' NSX_VERSION_3_2_1 = '3.2.1' +NSX_VERSION_3_2_3 = '3.2.3' NSX_VERSION_4_0_0 = '4.0.0' NSX_VERSION_4_1_0 = '4.1.0' NSX_VERSION_4_1_1 = '4.1.1' diff --git a/vmware_nsxlib/v3/policy/core_resources.py b/vmware_nsxlib/v3/policy/core_resources.py index ae607fc5..9a7f8196 100644 --- a/vmware_nsxlib/v3/policy/core_resources.py +++ b/vmware_nsxlib/v3/policy/core_resources.py @@ -2548,6 +2548,10 @@ class NsxPolicySegmentPortApi(NsxPolicyResourceBase): tenant=tenant) if init_state == nsx_constants.INIT_STATE_RESTORE_VIF: if (version.LooseVersion(self.version) >= + version.LooseVersion(nsx_constants.NSX_VERSION_3_2_3) and + version.LooseVersion(self.version) < + version.LooseVersion(nsx_constants.NSX_VERSION_4_0_0) or + 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()