Don't try to get aodh endpoint if auth_url didn't provided
This change includes: * Allow users of ceilometerclient specifying aodh_endpoint explicitly * If aodh_endpoint didn't provided and users just provide ceilometer endpoint and token, no auth_url, we assume aodh is unavailable and avoid trying to get aodh endpoint. Change-Id: Idd0ce60058d23507a99b89926e461d19db267ca2 Closes-Bug: #1488290
This commit is contained in:
@@ -371,6 +371,15 @@ class ClientAuthTest(utils.BaseTestCase):
|
||||
session_instance_mock.get_endpoint.assert_called_with(
|
||||
region_name=None, interface='publicURL', service_type='alarming')
|
||||
|
||||
def test_get_aodh_endpoint_without_auth_url(self):
|
||||
env = FAKE_ENV.copy()
|
||||
env.pop('auth_plugin', None)
|
||||
env.pop('endpoint', None)
|
||||
env.pop('auth_url', None)
|
||||
client = self.create_client(env, endpoint='fake_endpoint')
|
||||
self.assertEqual(client.alarm_auth_plugin.opts,
|
||||
client.auth_plugin.opts)
|
||||
|
||||
@mock.patch('ceilometerclient.client._get_keystone_session')
|
||||
@mock.patch('ceilometerclient.client._get_token_auth_ks_session')
|
||||
def test_get_different_endpoint_type(self, token_session, session):
|
||||
|
||||
@@ -87,14 +87,25 @@ class Client(object):
|
||||
|
||||
def _get_alarm_client(self, **kwargs):
|
||||
"""Get client for alarm manager that redirect to aodh."""
|
||||
|
||||
self.alarm_auth_plugin = copy.deepcopy(self.auth_plugin)
|
||||
try:
|
||||
# NOTE(liusheng): Getting the aodh's endpoint to rewrite
|
||||
# the endpoint of alarm auth_plugin.
|
||||
self.alarm_auth_plugin.redirect_to_aodh_endpoint(
|
||||
kwargs.get('timeout'))
|
||||
except exceptions.EndpointNotFound:
|
||||
aodh_endpoint = kwargs.get('aodh_endpoint')
|
||||
if aodh_endpoint:
|
||||
self.alarm_auth_plugin.opts['endpoint'] = aodh_endpoint
|
||||
elif not kwargs.get('auth_url'):
|
||||
# Users may just provided ceilometer endpoint and token, and no
|
||||
# auth_url, in this case, we need 'aodh_endpoint' also provided,
|
||||
# otherwise we cannot get aodh endpoint from keystone, and assume
|
||||
# aodh is unavailable.
|
||||
return self.http_client, False
|
||||
else:
|
||||
try:
|
||||
# NOTE(liusheng): Getting the aodh's endpoint to rewrite
|
||||
# the endpoint of alarm auth_plugin.
|
||||
self.alarm_auth_plugin.redirect_to_aodh_endpoint(
|
||||
kwargs.get('timeout'))
|
||||
except exceptions.EndpointNotFound:
|
||||
return self.http_client, False
|
||||
alarm_client = client.HTTPClient(
|
||||
auth_plugin=self.alarm_auth_plugin,
|
||||
region_name=kwargs.get('region_name'),
|
||||
|
||||
Reference in New Issue
Block a user