Merge "Add parameter for segment port delete api"

This commit is contained in:
Zuul 2024-10-24 09:01:12 +00:00 committed by Gerrit Code Review
commit 9086057bd6
3 changed files with 40 additions and 0 deletions

View File

@ -5418,6 +5418,22 @@ class TestPolicySegmentPort(NsxPolicyLibTestCase):
super(TestPolicySegmentPort, self).setUp()
self.resourceApi = self.policy_lib.segment_port
def testSegmentPortDef(self):
port_def = core_defs.SegmentPortDef(
segment_id="mock_seg", port_id="mock_port",
tenant=constants.POLICY_INFRA_TENANT)
path = port_def.get_resource_path()
self.assertEqual(path,
"infra/segments/mock_seg/ports/mock_port")
port_def = core_defs.SegmentPortDef(
segment_id="mock_seg", port_id="mock_port",
tenant=constants.POLICY_INFRA_TENANT,
skip_host_detach=True)
path = port_def.get_resource_path()
self.assertEqual(path,
"infra/segments/mock_seg/ports/mock_port?"
"skip_host_detach=true")
def test_feature_supported(self):
with mock.patch.object(self.policy_lib, "get_version",
return_value='2.5.0'):
@ -5708,6 +5724,17 @@ class TestPolicySegmentPort(NsxPolicyLibTestCase):
"%s/segments/%s/ports/%s" % (TEST_TENANT, segment_id, port_id),
{'attachment': None, 'tags': tags})
def test_delete_skip_host_detach(self):
segment_id = "segment"
port_id = "port"
with mock.patch.object(self.policy_api.client,
"delete", return_value={}) as api_delete:
self.resourceApi.delete_skip_host_detach(segment_id=segment_id,
port_id=port_id)
api_delete.assert_called_once_with(
"%s/segments/%s/ports/%s?skip_host_detach=true" % (
"infra", segment_id, port_id), headers=None)
def test_detach_with_vif(self):
segment_id = "segment"
port_id = "port"

View File

@ -1299,6 +1299,12 @@ class SegmentPortDef(ResourceDef):
def path_ids(self):
return ('tenant', 'segment_id', 'port_id')
def get_resource_path(self):
if self.has_attr("skip_host_detach"):
base_path = super().get_resource_path()
return base_path + "?skip_host_detach=true"
return super().get_resource_path()
@staticmethod
def resource_type():
return 'SegmentPort'

View File

@ -2594,6 +2594,13 @@ class NsxPolicySegmentPortApi(NsxPolicyResourceBase):
tenant=tenant)
self._delete_with_retry(port_def)
def delete_skip_host_detach(self, segment_id, port_id):
port_def = self.entry_def(segment_id=segment_id,
port_id=port_id,
tenant=constants.POLICY_INFRA_TENANT,
skip_host_detach=True)
self._delete_with_retry(port_def)
def get(self, segment_id, port_id,
tenant=constants.POLICY_INFRA_TENANT,
silent=False):