Fixes bug with Client function not setting up SSL params
There are instances where some applications (heat, rally) instantiate ceilometer client using Client function (instead of get_client) which doesn't use the insecure and verify params properly. This fix will address that. Change-Id: I2f6346496e6ee36b5cd97ec6d9a732431532ff96 Closes-Bug: #1428370
This commit is contained in:
parent
0c23c62cef
commit
e7b8c48c60
@ -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):
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user