def test_get_endpoint_retry(self, value, mock_method, mock_init): endpoint_dict = utils.create_endpoint_dict(value) mock_init.return_value = None cache = endpoint_cache.EndpointCache() mock_method.return_value = { 'another_region': { endpoint_dict['service_id']: 'another_fake_url' } } self.assertEqual( cache.get_endpoint('another_region', endpoint_dict['service_id']), 'another_fake_url')
def test_get_endpoint(self, value, mock_method, mock_init): endpoint_dict = utils.create_endpoint_dict(value) mock_method.return_value = { endpoint_dict['region_id']: { endpoint_dict['service_id']: endpoint_dict['url'] } } mock_init.return_value = None cache = endpoint_cache.EndpointCache() self.assertEqual( cache.get_endpoint(endpoint_dict['region_id'], endpoint_dict['service_id']), endpoint_dict['url'])
def __init__(self, *args, **kwargs): LOG.debug(_('QuotaManager initialization...')) super(QuotaManager, self).__init__(service_name="quota_manager", *args, **kwargs) self.context = context.get_admin_context() self.endpoints = endpoint_cache.EndpointCache() # This lock is used to ensure we only have one quota sync audit at # a time. For better efficiency we could use per-project locks # and/or the ReaderWriterLock from the "fastener" package. self.quota_audit_lock = threading.Lock()
def get_all_regions_for_project(self, project_id): try: # Retrieve regions based on endpoint filter for the project. region_lists = self._get_filtered_regions(project_id) if not region_lists: # If endpoint filter is not used for the project, then # return all regions region_lists = endpoint_cache.EndpointCache().get_all_regions() # nova, cinder, and neutron have no endpoints in consts.CLOUD_0 if consts.CLOUD_0 in region_lists: region_lists.remove(consts.CLOUD_0) return region_lists except Exception as exception: LOG.error('Error Occurred: %s', exception.message) raise
def test_get_all_regions(self, mock_method, mock_init): mock_method.return_value = { FAKE_REGION: { FAKE_NOVA_SERVICE: FAKE_NOVA_URL_1, FAKE_NEUTRON_SERVICE: FAKE_NEUTRON_URL_1 }, FAKE_REGION_2: { FAKE_NOVA_SERVICE: FAKE_NOVA_URL_2, FAKE_CINDER_SERVICE: FAKE_CINDER_URL_2 } } mock_init.return_value = None cache = endpoint_cache.EndpointCache() region_list = cache.get_all_regions() self.assertIn(FAKE_REGION, region_list) self.assertIn(FAKE_REGION_2, region_list)