Update version check to use POST API when restore vif

According to NSX side fix merged in NSX versions 3.2.3
(and later impactor releases if any) and 4.1.*, update
the version check.

Change-Id: I8e5b29da1d10b076bef159d45ba436d135718ca8
This commit is contained in:
lxiaopei 2023-03-28 12:06:51 +08:00
parent acb8f2d53f
commit 3a627ed498
3 changed files with 80 additions and 71 deletions

View File

@ -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'

View File

@ -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'

View File

@ -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()