def get_api_servers(context): """Shuffle a list of service endpoints and return an iterator that will cycle through the list, looping around to the beginning if necessary. """ # NOTE(efried): utils.get_ksa_adapter().get_endpoint() is the preferred # mechanism for endpoint discovery. Only use `api_servers` if you really # need to shuffle multiple endpoints. if CONF.glance.api_servers: api_servers = CONF.glance.api_servers random.shuffle(api_servers) else: sess, auth = _session_and_auth(context) ksa_adap = utils.get_ksa_adapter( nova.conf.glance.DEFAULT_SERVICE_TYPE, ksa_auth=auth, ksa_session=sess, min_version='2.0', max_version='2.latest') endpoint = utils.get_endpoint(ksa_adap) if endpoint: # NOTE(mriedem): Due to python-glanceclient bug 1707995 we have # to massage the endpoint URL otherwise it won't work properly. # We can't use glanceclient.common.utils.strip_version because # of bug 1748009. endpoint = re.sub(r'/v\d+(\.\d+)?/?$', '/', endpoint) api_servers = [endpoint] return itertools.cycle(api_servers)
def get_api_servers(context): """Shuffle a list of service endpoints and return an iterator that will cycle through the list, looping around to the beginning if necessary. """ # NOTE(efried): utils.get_ksa_adapter().get_endpoint() is the preferred # mechanism for endpoint discovery. Only use `api_servers` if you really # need to shuffle multiple endpoints. if CONF.glance.api_servers: api_servers = CONF.glance.api_servers random.shuffle(api_servers) else: sess, auth = _session_and_auth(context) ksa_adap = utils.get_ksa_adapter(nova.conf.glance.DEFAULT_SERVICE_TYPE, ksa_auth=auth, ksa_session=sess, min_version='2.0', max_version='2.latest') endpoint = utils.get_endpoint(ksa_adap) if endpoint: # NOTE(mriedem): Due to python-glanceclient bug 1707995 we have # to massage the endpoint URL otherwise it won't work properly. # We can't use glanceclient.common.utils.strip_version because # of bug 1748009. endpoint = re.sub(r'/v\d+(\.\d+)?/?$', '/', endpoint) api_servers = [endpoint] return itertools.cycle(api_servers)
def test_image_bad(self): self.adap.service_type = 'image' self.adap.get_endpoint_data.side_effect = AttributeError self.adap.get_endpoint.return_value = 'url' self.assertEqual('url', utils.get_endpoint(self.adap)) self.adap.get_endpoint_data.assert_called_once_with() self.adap.get_endpoint.assert_called_once_with()
def get_api_servers(context): """Shuffle a list of service endpoints and return an iterator that will cycle through the list, looping around to the beginning if necessary. """ # NOTE(efried): utils.get_ksa_adapter().get_endpoint() is the preferred # mechanism for endpoint discovery. Only use `api_servers` if you really # need to shuffle multiple endpoints. if CONF.glance.api_servers: api_servers = CONF.glance.api_servers random.shuffle(api_servers) else: sess, auth = _session_and_auth(context) ksa_adap = utils.get_ksa_adapter( nova.conf.glance.DEFAULT_SERVICE_TYPE, ksa_auth=auth, ksa_session=sess, min_version='2.0', max_version='2.latest') api_servers = [utils.get_endpoint(ksa_adap)] return itertools.cycle(api_servers)
def test_nonimage_good(self): self.adap.get_endpoint.return_value = 'url' self.assertEqual('url', utils.get_endpoint(self.adap)) self.adap.get_endpoint_data.assert_not_called() self.adap.get_endpoint.assert_called_once_with()
def test_image_good(self): self.adap.service_type = 'image' self.adap.get_endpoint_data.return_value.catalog_url = 'url' self.assertEqual('url', utils.get_endpoint(self.adap)) self.adap.get_endpoint_data.assert_called_once_with() self.adap.get_endpoint.assert_not_called()
def test_endpoint_override(self): self.adap.endpoint_override = 'foo' self.assertEqual('foo', utils.get_endpoint(self.adap)) self.adap.get_endpoint_data.assert_not_called() self.adap.get_endpoint.assert_not_called()