summaryrefslogtreecommitdiff
path: root/ceilometerclient
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2017-01-23 10:56:46 +0000
committerGerrit Code Review <review@openstack.org>2017-01-23 10:56:46 +0000
commite60757c258f6c5cb88e7c552aa3afcb557734d2b (patch)
tree497382f22c669d08a272de53f6e0091b8c3e9ee9 /ceilometerclient
parent909032dac3c74e451d2b56c8d9ca161cfd487b4b (diff)
parent72ea5ef82461d12644f0be6b80ac7dd07a4a2cec (diff)
downloadpython-ceilometerclient-e60757c258f6c5cb88e7c552aa3afcb557734d2b.tar.gz
Merge "panko redirect"
Diffstat (limited to 'ceilometerclient')
-rw-r--r--ceilometerclient/client.py3
-rw-r--r--ceilometerclient/tests/unit/test_client.py10
-rw-r--r--ceilometerclient/tests/unit/test_shell.py18
-rw-r--r--ceilometerclient/v2/client.py35
4 files changed, 38 insertions, 28 deletions
diff --git a/ceilometerclient/client.py b/ceilometerclient/client.py
index 9efd818..eb5729c 100644
--- a/ceilometerclient/client.py
+++ b/ceilometerclient/client.py
@@ -411,8 +411,9 @@ def _construct_http_client(**kwargs):
# Drop legacy options
for opt in LEGACY_OPTS:
kwargs.pop(opt, None)
- # Drop aodh_endpoint from kwargs
+ # Drop redirect endpoints from kwargs
kwargs.pop('aodh_endpoint', None)
+ kwargs.pop('panko_endpoint', None)
return SessionClient(
session=kwargs.pop('session'),
diff --git a/ceilometerclient/tests/unit/test_client.py b/ceilometerclient/tests/unit/test_client.py
index 2beaf73..400e997 100644
--- a/ceilometerclient/tests/unit/test_client.py
+++ b/ceilometerclient/tests/unit/test_client.py
@@ -43,8 +43,9 @@ class ClientTest(utils.BaseTestCase):
def create_client(env, api_version=2, endpoint=None, exclude=[]):
env = dict((k, v) for k, v in env.items()
if k not in exclude)
- with mock.patch('ceilometerclient.v2.client.Client._get_alarm_client',
- return_value=None):
+ with mock.patch(
+ 'ceilometerclient.v2.client.Client._get_redirect_client',
+ return_value=None):
return client.get_client(api_version, **env)
def test_client_v2_with_session(self):
@@ -184,8 +185,9 @@ class ClientTest2(ClientTest):
def create_client(env, api_version=2, endpoint=None, exclude=[]):
env = dict((k, v) for k, v in env.items()
if k not in exclude)
- with mock.patch('ceilometerclient.v2.client.Client._get_alarm_client',
- return_value=None):
+ with mock.patch(
+ 'ceilometerclient.v2.client.Client._get_redirect_client',
+ return_value=None):
return client.Client(api_version, endpoint, **env)
diff --git a/ceilometerclient/tests/unit/test_shell.py b/ceilometerclient/tests/unit/test_shell.py
index 41f6f54..d666594 100644
--- a/ceilometerclient/tests/unit/test_shell.py
+++ b/ceilometerclient/tests/unit/test_shell.py
@@ -112,7 +112,7 @@ class ShellBashCompletionTest(ShellTestBase):
class ShellKeystoneV2Test(ShellTestBase):
@mock.patch.object(ks_session, 'Session')
- @mock.patch('ceilometerclient.v2.client.Client._get_alarm_client',
+ @mock.patch('ceilometerclient.v2.client.Client._get_redirect_client',
mock.Mock(return_value=None))
def test_debug_switch_raises_error(self, mock_ksclient):
mock_ksclient.side_effect = exc.HTTPUnauthorized
@@ -121,7 +121,7 @@ class ShellKeystoneV2Test(ShellTestBase):
self.assertRaises(exc.CommandError, ceilometer_shell.main, args)
@mock.patch.object(ks_session, 'Session')
- @mock.patch('ceilometerclient.v2.client.Client._get_alarm_client',
+ @mock.patch('ceilometerclient.v2.client.Client._get_redirect_client',
mock.Mock(return_value=None))
def test_dash_d_switch_raises_error(self, mock_ksclient):
mock_ksclient.side_effect = exc.CommandError("FAIL")
@@ -141,7 +141,7 @@ class ShellKeystoneV2Test(ShellTestBase):
class ShellKeystoneV3Test(ShellTestBase):
@mock.patch.object(ks_session, 'Session')
- @mock.patch('ceilometerclient.v2.client.Client._get_alarm_client',
+ @mock.patch('ceilometerclient.v2.client.Client._get_redirect_client',
mock.Mock(return_value=None))
def test_debug_switch_raises_error(self, mock_ksclient):
mock_ksclient.side_effect = exc.HTTPUnauthorized
@@ -194,7 +194,7 @@ class ShellTimeoutTest(ShellTestBase):
self._test_timeout('0', expected_msg)
@mock.patch.object(ks_session, 'Session')
- @mock.patch('ceilometerclient.v2.client.Client._get_alarm_client',
+ @mock.patch('ceilometerclient.v2.client.Client._get_redirect_client',
mock.Mock(return_value=None))
def test_timeout_keystone_session(self, mocked_session):
mocked_session.side_effect = exc.HTTPUnauthorized("FAIL")
@@ -208,7 +208,7 @@ class ShellTimeoutTest(ShellTestBase):
class ShellInsecureTest(ShellTestBase):
@mock.patch.object(api_client, 'HTTPClient')
- @mock.patch('ceilometerclient.v2.client.Client._get_alarm_client',
+ @mock.patch('ceilometerclient.v2.client.Client._get_redirect_client',
mock.Mock(return_value=None))
def test_insecure_true_ceilometer(self, mocked_client):
self.make_env(FAKE_V2_ENV)
@@ -218,7 +218,7 @@ class ShellInsecureTest(ShellTestBase):
self.assertFalse(kwargs.get('verify'))
@mock.patch.object(ks_session, 'Session')
- @mock.patch('ceilometerclient.v2.client.Client._get_alarm_client',
+ @mock.patch('ceilometerclient.v2.client.Client._get_redirect_client',
mock.Mock(return_value=None))
def test_insecure_true_keystone(self, mocked_session):
mocked_session.side_effect = exc.HTTPUnauthorized("FAIL")
@@ -229,7 +229,7 @@ class ShellInsecureTest(ShellTestBase):
self.assertFalse(kwargs.get('verify'))
@mock.patch.object(api_client, 'HTTPClient')
- @mock.patch('ceilometerclient.v2.client.Client._get_alarm_client',
+ @mock.patch('ceilometerclient.v2.client.Client._get_redirect_client',
mock.Mock(return_value=None))
def test_insecure_false_ceilometer(self, mocked_client):
self.make_env(FAKE_V2_ENV)
@@ -239,7 +239,7 @@ class ShellInsecureTest(ShellTestBase):
self.assertTrue(kwargs.get('verify'))
@mock.patch.object(ks_session, 'Session')
- @mock.patch('ceilometerclient.v2.client.Client._get_alarm_client',
+ @mock.patch('ceilometerclient.v2.client.Client._get_redirect_client',
mock.Mock(return_value=None))
def test_insecure_false_keystone(self, mocked_session):
mocked_session.side_effect = exc.HTTPUnauthorized("FAIL")
@@ -270,7 +270,7 @@ class ShellEndpointTest(ShellTestBase):
class ShellAlarmUpdateRepeatAction(ShellTestBase):
@mock.patch('ceilometerclient.v2.alarms.AlarmManager.update')
- @mock.patch('ceilometerclient.v2.client.Client._get_alarm_client',
+ @mock.patch('ceilometerclient.v2.client.Client._get_redirect_client',
mock.Mock())
def test_repeat_action_not_specified(self, mocked):
self.make_env(FAKE_V2_ENV)
diff --git a/ceilometerclient/v2/client.py b/ceilometerclient/v2/client.py
index dbabe28..8b672dd 100644
--- a/ceilometerclient/v2/client.py
+++ b/ceilometerclient/v2/client.py
@@ -62,21 +62,28 @@ class Client(object):
self.auth_plugin = kwargs.get('auth_plugin')
self.http_client = ceiloclient._construct_http_client(**kwargs)
- self.alarm_client = self._get_alarm_client(**kwargs)
+ self.alarm_client = self._get_redirect_client(
+ 'alarming', 'aodh', **kwargs)
aodh_enabled = self.alarm_client is not None
if not aodh_enabled:
self.alarm_client = self.http_client
+ self.event_client = self._get_redirect_client(
+ 'event', 'panko', **kwargs)
+ panko_enabled = self.event_client is not None
+ if not panko_enabled:
+ self.event_client = self.http_client
+
self.meters = meters.MeterManager(self.http_client)
self.samples = samples.OldSampleManager(self.http_client)
self.new_samples = samples.SampleManager(self.http_client)
self.statistics = statistics.StatisticsManager(self.http_client)
self.resources = resources.ResourceManager(self.http_client)
self.alarms = alarms.AlarmManager(self.alarm_client, aodh_enabled)
- self.events = events.EventManager(self.http_client)
- self.event_types = event_types.EventTypeManager(self.http_client)
- self.traits = traits.TraitManager(self.http_client)
+ self.events = events.EventManager(self.event_client)
+ self.event_types = event_types.EventTypeManager(self.event_client)
+ self.traits = traits.TraitManager(self.event_client)
self.trait_descriptions = trait_descriptions.\
- TraitDescriptionManager(self.http_client)
+ TraitDescriptionManager(self.event_client)
self.query_samples = query.QuerySamplesManager(
self.http_client)
@@ -86,36 +93,36 @@ class Client(object):
self.capabilities = capabilities.CapabilitiesManager(self.http_client)
@staticmethod
- def _get_alarm_client(**ceilo_kwargs):
- """Get client for alarm manager that redirect to aodh."""
+ def _get_redirect_client(new_service_type, new_service, **ceilo_kwargs):
+ """Get client for new service manager to redirect to."""
# NOTE(sileht): the auth_plugin/keystone session cannot be copied
# because they rely on threading module.
auth_plugin = ceilo_kwargs.pop('auth_plugin', None)
session = ceilo_kwargs.pop('session', None)
kwargs = copy.deepcopy(ceilo_kwargs)
- kwargs["service_type"] = "alarming"
- aodh_endpoint = ceilo_kwargs.get('aodh_endpoint')
+ kwargs["service_type"] = new_service_type
+ endpoint = ceilo_kwargs.get('%s_endpoint' % new_service)
if session:
# keystone session can be shared between client
ceilo_kwargs['session'] = kwargs['session'] = session
- if aodh_endpoint:
- kwargs['endpoint_override'] = aodh_endpoint
+ if endpoint:
+ kwargs['endpoint_override'] = endpoint
elif auth_plugin and kwargs.get('auth_url'):
ceilo_kwargs['auth_plugin'] = auth_plugin
kwargs.pop('endpoint', None)
kwargs['auth_plugin'] = ceiloclient.get_auth_plugin(
- aodh_endpoint, **kwargs)
+ endpoint, **kwargs)
else:
# Users may just provide ceilometer endpoint and token, and no
# auth_url, in this case, we need 'aodh_endpoint' also to be
# provided, otherwise we cannot get aodh endpoint from
- # keystone, and assume aodh is unavailable.
+ # keystone, and assume aodh is unavailable. Same applies to panko.
return None
try:
- # NOTE(sileht): try to use aodh
+ # NOTE(sileht): try to use redirect
c = ceiloclient._construct_http_client(**kwargs)
c.get("/")
return c