Use search-by-tags to get segment/tier1 realization Id
This should be faster than using the realization api Change-Id: Ifcc3d76f06f79a1e850503693fbee323ab35a756
This commit is contained in:
parent
bbdadef620
commit
b69d615ac3
|
@ -2670,7 +2670,10 @@ 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:
|
||||
return_value=info) as realization,\
|
||||
mock.patch.object(self.resourceApi,
|
||||
"_get_realized_id_using_search",
|
||||
return_value=logical_router_id):
|
||||
self.resourceApi.update_transport_zone(tier1_id, tz_uuid,
|
||||
tenant=TEST_TENANT)
|
||||
realization.assert_called_once()
|
||||
|
|
|
@ -270,6 +270,39 @@ class NsxPolicyResourceBase(object):
|
|||
attempts=max_attempts,
|
||||
sleep=sleep)
|
||||
|
||||
@check_allowed_passthrough
|
||||
def _get_realized_id_using_search(self, policy_resource_path,
|
||||
mp_resource_type,
|
||||
sleep=None, max_attempts=None):
|
||||
"""Wait until the policy path will be found using search api
|
||||
|
||||
And return the NSX ID of the MP resource that was found
|
||||
"""
|
||||
if sleep is None:
|
||||
sleep = self.nsxlib_config.realization_wait_sec
|
||||
if max_attempts is None:
|
||||
max_attempts = self.nsxlib_config.realization_max_attempts
|
||||
|
||||
tag = [{'scope': 'policyPath',
|
||||
'tag': utils.escape_tag_data(policy_resource_path)}]
|
||||
|
||||
@utils.retry_upon_none_result(max_attempts, delay=sleep, random=True)
|
||||
def get_info():
|
||||
resources = self.nsx_api.search_by_tags(
|
||||
tags=tag, resource_type=mp_resource_type)['results']
|
||||
if resources:
|
||||
return resources[0]['id']
|
||||
|
||||
try:
|
||||
return get_info()
|
||||
except Exception:
|
||||
# max retries reached
|
||||
raise exceptions.RealizationTimeoutError(
|
||||
resource_type=mp_resource_type,
|
||||
resource_id=policy_resource_path,
|
||||
attempts=max_attempts,
|
||||
sleep=sleep)
|
||||
|
||||
def _get_extended_attr_from_realized_info(self, realization_info,
|
||||
requested_attr):
|
||||
# Returns a list. In case a single value is expected,
|
||||
|
@ -1132,6 +1165,11 @@ class NsxPolicyTier1Api(NsxPolicyResourceBase):
|
|||
def get_realized_id(self, tier1_id, entity_type=None,
|
||||
tenant=constants.POLICY_INFRA_TENANT,
|
||||
realization_info=None):
|
||||
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)
|
||||
tier1_def = self.entry_def(tier1_id=tier1_id, tenant=tenant)
|
||||
return self._get_realized_id(tier1_def, entity_type=entity_type,
|
||||
realization_info=realization_info)
|
||||
|
@ -1847,10 +1885,17 @@ class NsxPolicySegmentApi(NsxPolicyResourceBase):
|
|||
return self._get_realized_id(segment_def, entity_type=entity_type,
|
||||
realization_info=realization_info)
|
||||
|
||||
def get_realized_logical_switch_id(
|
||||
self,
|
||||
segment_id,
|
||||
tenant=constants.POLICY_INFRA_TENANT):
|
||||
def get_path(self, segment_id, tenant=constants.POLICY_INFRA_TENANT):
|
||||
segment_def = self.entry_def(segment_id=segment_id, tenant=tenant)
|
||||
return segment_def.get_resource_full_path()
|
||||
|
||||
def get_realized_logical_switch_id(self, segment_id,
|
||||
tenant=constants.POLICY_INFRA_TENANT):
|
||||
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)
|
||||
|
||||
segment_def = self.entry_def(segment_id=segment_id, tenant=tenant)
|
||||
realization_info = self._wait_until_realized(
|
||||
|
|
Loading…
Reference in New Issue