summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorliu-sheng <liusheng@huawei.com>2015-08-24 19:14:51 +0800
committerliusheng <liusheng2048@gmail.com>2015-08-25 01:32:56 +0000
commit2429daec98998767924d1287711b309aacfb03dc (patch)
tree5b76afe8d7be79e568c085b5b80c749ed049b895
parent1fc68877ff8c6f31867a39dbb647688db6b069c3 (diff)
downloadpython-ceilometerclient-2429daec98998767924d1287711b309aacfb03dc.tar.gz
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
-rw-r--r--ceilometerclient/tests/unit/test_client.py9
-rw-r--r--ceilometerclient/v2/client.py23
2 files changed, 26 insertions, 6 deletions
diff --git a/ceilometerclient/tests/unit/test_client.py b/ceilometerclient/tests/unit/test_client.py
index b4e1f65..085e259 100644
--- a/ceilometerclient/tests/unit/test_client.py
+++ b/ceilometerclient/tests/unit/test_client.py
@@ -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):
diff --git a/ceilometerclient/v2/client.py b/ceilometerclient/v2/client.py
index 8813860..0ba76e5 100644
--- a/ceilometerclient/v2/client.py
+++ b/ceilometerclient/v2/client.py
@@ -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'),