Add version check to use POST API when restore vif
Since the new POST API to restore vif only exists on NSX version >=4.1.0, add version check before invoking the new POST API. Otherwise, still use the old patch API. Change-Id: Ic0047cba6ccaf275830b3c24a73f59ca28883de6
This commit is contained in:
parent
7d64ecb265
commit
417f4085a5
|
@ -5451,6 +5451,46 @@ class TestPolicySegmentPort(NsxPolicyLibTestCase):
|
||||||
|
|
||||||
with mock.patch.object(
|
with mock.patch.object(
|
||||||
self.policy_api.client, "url_post") as api_post, \
|
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',
|
mock.patch.object(self.resourceApi, 'version',
|
||||||
nsxlib_testcase.LATEST_VERSION):
|
nsxlib_testcase.LATEST_VERSION):
|
||||||
result = self.resourceApi.create_or_overwrite(
|
result = self.resourceApi.create_or_overwrite(
|
||||||
|
@ -5482,11 +5522,7 @@ class TestPolicySegmentPort(NsxPolicyLibTestCase):
|
||||||
tenant=TEST_TENANT,
|
tenant=TEST_TENANT,
|
||||||
hyperbus_mode=hyperbus_mode,
|
hyperbus_mode=hyperbus_mode,
|
||||||
init_state=init_state)
|
init_state=init_state)
|
||||||
|
self.assert_called_with_def(api_call, expected_def)
|
||||||
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)
|
self.assertIsNotNone(result)
|
||||||
|
|
||||||
def test_create_with_unsupported_attribute(self):
|
def test_create_with_unsupported_attribute(self):
|
||||||
|
|
|
@ -2547,9 +2547,13 @@ class NsxPolicySegmentPortApi(NsxPolicyResourceBase):
|
||||||
tags=tags,
|
tags=tags,
|
||||||
tenant=tenant)
|
tenant=tenant)
|
||||||
if init_state == nsx_constants.INIT_STATE_RESTORE_VIF:
|
if init_state == nsx_constants.INIT_STATE_RESTORE_VIF:
|
||||||
path = port_def.get_resource_path()
|
if (version.LooseVersion(self.version) >=
|
||||||
body = port_def.get_obj_dict()
|
version.LooseVersion(nsx_constants.NSX_VERSION_4_1_0)):
|
||||||
self.policy_api.client.create(path, body=body)
|
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:
|
else:
|
||||||
self._create_or_store(port_def)
|
self._create_or_store(port_def)
|
||||||
return port_id
|
return port_id
|
||||||
|
|
Loading…
Reference in New Issue