Use PUT instead of PATCH for segment port detach

Change-Id: Ib411f1898778362030c91ddc707bdd8dc1e07760
This commit is contained in:
asarfaty 2020-03-11 11:15:34 +02:00
parent cddf191084
commit 6c71cfb145
2 changed files with 23 additions and 18 deletions

View File

@ -4567,21 +4567,18 @@ class TestPolicySegmentPort(NsxPolicyLibTestCase):
segment_id = "segment"
port_id = "port"
tags = [{'scope': 'a', 'tag': 'b'}]
with mock.patch.object(self.policy_api,
"create_or_update") as api_call:
with mock.patch.object(self.policy_api.client,
"get", return_value={}) as api_get,\
mock.patch.object(self.policy_api.client,
"update") as api_put:
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)
api_get.assert_called_once()
api_put.assert_called_once_with(
"%s/segments/%s/ports/%s" % (TEST_TENANT, segment_id, port_id),
{'attachment': None})
class TestPolicySegmentProfileBase(NsxPolicyLibTestCase):

View File

@ -2183,14 +2183,22 @@ class NsxPolicySegmentPortApi(NsxPolicyResourceBase):
def detach(self, segment_id, port_id, tags=IGNORE,
tenant=constants.POLICY_INFRA_TENANT):
# Due to platform limitation, PUT should be used here and not PATCH
port_def = self.entry_def(
segment_id=segment_id,
port_id=port_id,
tenant=tenant)
path = port_def.get_resource_path()
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)
@utils.retry_upon_exception(
exceptions.StaleRevision,
max_attempts=self.policy_api.client.max_attempts)
def _detach():
port = self.policy_api.get(port_def)
port['attachment'] = None
self.policy_api.client.update(path, port)
_detach()
def attach(self, segment_id, port_id,
attachment_type,