summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2015-03-13 09:02:35 +0000
committerGerrit Code Review <review@openstack.org>2015-03-13 09:02:35 +0000
commite727d22bf1fc4ff613699560717e4aa460f60b73 (patch)
tree061cbfa12b1578167cd031365d4aa41f31210bb5
parent4fc21b00dca96c7eb852e9a1570e9f190dd6907d (diff)
parente7b8c48c60e85378e1e1d3c30bfb4cfa79f3105a (diff)
downloadpython-ceilometerclient-e727d22bf1fc4ff613699560717e4aa460f60b73.tar.gz
Merge "Fixes bug with Client function not setting up SSL params"
-rw-r--r--ceilometerclient/client.py63
-rw-r--r--ceilometerclient/tests/test_client.py15
2 files changed, 44 insertions, 34 deletions
diff --git a/ceilometerclient/client.py b/ceilometerclient/client.py
index c0a8be5..3853f24 100644
--- a/ceilometerclient/client.py
+++ b/ceilometerclient/client.py
@@ -215,14 +215,29 @@ class AuthPlugin(auth.BaseAuthPlugin):
raise exceptions.AuthPluginOptionsMissing(missing_opts)
-def Client(version, *args, **kwargs):
- module = utils.import_versioned_module(version, 'client')
- client_class = getattr(module, 'Client')
- kwargs['token'] = kwargs.get('token') or kwargs.get('auth_token')
- return client_class(*args, **kwargs)
+def _adjust_kwargs(kwargs):
+ client_kwargs = {
+ 'username': kwargs.get('os_username'),
+ 'password': kwargs.get('os_password'),
+ 'tenant_id': kwargs.get('os_tenant_id'),
+ 'tenant_name': kwargs.get('os_tenant_name'),
+ 'auth_url': kwargs.get('os_auth_url'),
+ 'region_name': kwargs.get('os_region_name'),
+ 'service_type': kwargs.get('os_service_type'),
+ 'endpoint_type': kwargs.get('os_endpoint_type'),
+ 'cacert': kwargs.get('os_cacert'),
+ 'cert_file': kwargs.get('os_cert'),
+ 'key_file': kwargs.get('os_key'),
+ 'token': kwargs.get('os_token') or kwargs.get('os_auth_token'),
+ 'user_domain_name': kwargs.get('os_user_domain_name'),
+ 'user_domain_id': kwargs.get('os_user_domain_id'),
+ 'project_domain_name': kwargs.get('os_project_domain_name'),
+ 'project_domain_id': kwargs.get('os_project_domain_id'),
+ }
+ client_kwargs.update(kwargs)
+ client_kwargs['token'] = kwargs.get('token') or kwargs.get('auth_token')
-def _adjust_params(kwargs):
timeout = kwargs.get('timeout')
if timeout is not None:
timeout = int(timeout)
@@ -241,7 +256,17 @@ def _adjust_params(kwargs):
key = kwargs.get('key_file')
if cert and key:
cert = cert, key
- return {'verify': verify, 'cert': cert, 'timeout': timeout}
+
+ client_kwargs.update({'verify': verify, 'cert': cert, 'timeout': timeout})
+ return client_kwargs
+
+
+def Client(version, *args, **kwargs):
+ client_kwargs = _adjust_kwargs(kwargs)
+
+ module = utils.import_versioned_module(version, 'client')
+ client_class = getattr(module, 'Client')
+ return client_class(*args, **client_kwargs)
def get_client(version, **kwargs):
@@ -275,29 +300,7 @@ def get_client(version, **kwargs):
"""
endpoint = kwargs.get('os_endpoint') or kwargs.get('ceilometer_url')
- cli_kwargs = {
- 'username': kwargs.get('os_username'),
- 'password': kwargs.get('os_password'),
- 'tenant_id': kwargs.get('os_tenant_id'),
- 'tenant_name': kwargs.get('os_tenant_name'),
- 'auth_url': kwargs.get('os_auth_url'),
- 'region_name': kwargs.get('os_region_name'),
- 'service_type': kwargs.get('os_service_type'),
- 'endpoint_type': kwargs.get('os_endpoint_type'),
- 'cacert': kwargs.get('os_cacert'),
- 'cert_file': kwargs.get('os_cert'),
- 'key_file': kwargs.get('os_key'),
- 'token': kwargs.get('os_token') or kwargs.get('os_auth_token'),
- 'user_domain_name': kwargs.get('os_user_domain_name'),
- 'user_domain_id': kwargs.get('os_user_domain_id'),
- 'project_domain_name': kwargs.get('os_project_domain_name'),
- 'project_domain_id': kwargs.get('os_project_domain_id'),
- }
-
- cli_kwargs.update(kwargs)
- cli_kwargs.update(_adjust_params(cli_kwargs))
-
- return Client(version, endpoint, **cli_kwargs)
+ return Client(version, endpoint, **kwargs)
def get_auth_plugin(endpoint, **kwargs):
diff --git a/ceilometerclient/tests/test_client.py b/ceilometerclient/tests/test_client.py
index bfcf43a..45472a4 100644
--- a/ceilometerclient/tests/test_client.py
+++ b/ceilometerclient/tests/test_client.py
@@ -42,9 +42,6 @@ class ClientTest(utils.BaseTestCase):
return client.get_client(api_version, **env)
- def setUp(self):
- super(ClientTest, self).setUp()
-
def test_client_version(self):
c1 = self.create_client(env=FAKE_ENV, api_version=1)
self.assertIsInstance(c1, v1client.Client)
@@ -94,7 +91,7 @@ class ClientTest(utils.BaseTestCase):
'project_domain_id': None,
}
with mock.patch('ceilometerclient.client.AuthPlugin') as auth_plugin:
- self.create_client(env, api_version=2)
+ self.create_client(env, api_version=2, endpoint='http://no.where')
auth_plugin.assert_called_with(**expected)
def test_client_with_auth_plugin(self):
@@ -149,3 +146,13 @@ class ClientTest(utils.BaseTestCase):
client = self.create_client(env)
self.assertEqual(('/path/to/cert', '/path/to/keycert'),
client.client.cert)
+
+
+class ClientTest2(ClientTest):
+ @staticmethod
+ 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)
+
+ # Run the same tests with direct instantiation of the Client
+ return client.Client(api_version, endpoint, **env)