From 21047202b1363e02e306ff91b3c93ab83159f3ed Mon Sep 17 00:00:00 2001 From: ranp Date: Mon, 18 Nov 2024 15:53:57 +0800 Subject: [PATCH] Remove MP search API in policy resources From NSX 9.0, MP api is removed, so in policy resources, it should not use MP resource apis or MP resource search interface. following apis are removed: /api/v1/search/query?query=resource_type:LogicalRouter /api/v1/search/query?query=resource_type:LogicalSwitch Change-Id: Ie79c95a491b7fa6364c440522d127f100d44c7c0 --- .../tests/unit/v3/policy/test_resources.py | 25 ++++--------------- vmware_nsxlib/v3/policy/core_resources.py | 13 ---------- 2 files changed, 5 insertions(+), 33 deletions(-) diff --git a/vmware_nsxlib/tests/unit/v3/policy/test_resources.py b/vmware_nsxlib/tests/unit/v3/policy/test_resources.py index 44c3ed98..273f5d32 100644 --- a/vmware_nsxlib/tests/unit/v3/policy/test_resources.py +++ b/vmware_nsxlib/tests/unit/v3/policy/test_resources.py @@ -3257,10 +3257,7 @@ class TestPolicyTier1(NsxPolicyLibTestCase): 'realization_specific_identifier': logical_router_id} passthrough_mock = self.resourceApi.nsx_api.logical_router.update with mock.patch.object(self.resourceApi, "_get_realization_info", - return_value=info) as realization,\ - mock.patch.object(self.resourceApi, - "_get_realized_id_using_search", - return_value=logical_router_id): + return_value=info) as realization: self.resourceApi.update_transport_zone(tier1_id, tz_uuid, tenant=TEST_TENANT) realization.assert_called_once() @@ -3283,26 +3280,14 @@ class TestPolicyTier1(NsxPolicyLibTestCase): # Get realized ID using search tier1_id = '111' logical_router_id = 'realized_111' - info = {'results': [{'status': {'state': 'success'}, - 'id': logical_router_id}]} - with mock.patch.object(self.resourceApi.nsx_api, "search_by_tags", + info = {'state': constants.STATE_REALIZED, + 'realization_specific_identifier': logical_router_id, + 'entity_type': 'RealizedLogicalRouter'} + with mock.patch.object(self.resourceApi, "_get_realization_info", return_value=info): realized_id = self.resourceApi.get_realized_id(tier1_id) self.assertEqual(logical_router_id, realized_id) - def test_get_realized_id_failed(self): - # Get realized ID using search - tier1_id = '111' - logical_router_id = 'realized_111' - info = {'results': [{'status': {'state': 'in_progress'}, - 'id': logical_router_id}]} - with mock.patch.object(self.resourceApi.nsx_api, "search_by_tags", - return_value=info),\ - mock.patch.object(self.resourceApi.policy_api, - "get_realized_entities"): - self.assertRaises(nsxlib_exc.RealizationTimeoutError, - self.resourceApi.get_realized_id, tier1_id) - def test_get_realized_downlink_port(self): tier1_id = '111' segment_id = '222' diff --git a/vmware_nsxlib/v3/policy/core_resources.py b/vmware_nsxlib/v3/policy/core_resources.py index 33f9e963..4921f449 100644 --- a/vmware_nsxlib/v3/policy/core_resources.py +++ b/vmware_nsxlib/v3/policy/core_resources.py @@ -1431,12 +1431,6 @@ class NsxPolicyTier1Api(NsxPolicyResourceBase): tenant=constants.POLICY_INFRA_TENANT, realization_info=None): tier1_def = self.entry_def(tier1_id=tier1_id, tenant=tenant) - if self.nsx_api: - # Use MP search api to find the LR ID as it is faster - return self._get_realized_id_using_search( - self.get_path(tier1_id, tenant=tenant), - self.nsx_api.logical_router.resource_type, - resource_def=tier1_def, entity_type=entity_type) return self._get_realized_id(tier1_def, entity_type=entity_type, realization_info=realization_info) @@ -2443,13 +2437,6 @@ class NsxPolicySegmentApi(NsxPolicyResourceBase): tenant=constants.POLICY_INFRA_TENANT): segment_def = self.entry_def(segment_id=segment_id, tenant=tenant) entity_type = 'RealizedLogicalSwitch' - if self.nsx_api: - # Use MP search api to find the LS ID as it is faster - return self._get_realized_id_using_search( - self.get_path(segment_id, tenant=tenant), - self.nsx_api.logical_switch.resource_type, - resource_def=segment_def, entity_type=entity_type) - realization_info = self._wait_until_realized( segment_def, entity_type=entity_type) return self._get_realized_id(segment_def,