summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMonty Taylor <mordred@inaugust.com>2015-11-06 09:04:12 -0500
committerMonty Taylor <mordred@inaugust.com>2015-11-06 09:04:12 -0500
commit13b6fbabeb27a346c91a9fb3a1fb86c7adbd2779 (patch)
tree615a6d085a4ddc4309450920dbbe7711c787076c
parent5b993208b97a459429bcb5f6fb852372c576cdaf (diff)
downloados-client-config-1.10.1.tar.gz
Work around a bug in keystoneclient constructor1.10.1
keystoneclient bug #1513839 means that even when you proerly pass a Session (like we do) to the discovery constructor (what you'd be calling if you were passing "pass_version_arg = True") ksc fails because you didn't send a URL. We _HAVE_ an appropriate URL that we can pull from the Session. So until ksc learns how to pull the URL from the Session itself, do it for them. Change-Id: I38eb4cfa750fab5196b86989c2cd498d41bf37ac
-rw-r--r--os_client_config/cloud_config.py11
-rw-r--r--os_client_config/tests/test_cloud_config.py37
2 files changed, 47 insertions, 1 deletions
diff --git a/os_client_config/cloud_config.py b/os_client_config/cloud_config.py
index 79a6ebf..37029f1 100644
--- a/os_client_config/cloud_config.py
+++ b/os_client_config/cloud_config.py
@@ -258,7 +258,16 @@ class CloudConfig(object):
constructor_args = []
if pass_version_arg:
version = self.get_api_version(service_key)
- constructor_args.append(version)
+ if service_key == 'identity':
+ # keystoneclient takes version as a tuple.
+ version = tuple(str(float(version)).split('.'))
+ constructor_kwargs['version'] = version
+ # Workaround for bug#1513839
+ if 'endpoint' not in constructor_kwargs:
+ endpoint = self.get_session_endpoint('identity')
+ constructor_kwargs['endpoint'] = endpoint
+ else:
+ constructor_args.append(version)
return client_class(*constructor_args, **constructor_kwargs)
diff --git a/os_client_config/tests/test_cloud_config.py b/os_client_config/tests/test_cloud_config.py
index 080f100..deaec4d 100644
--- a/os_client_config/tests/test_cloud_config.py
+++ b/os_client_config/tests/test_cloud_config.py
@@ -278,3 +278,40 @@ class TestCloudConfig(base.TestCase):
service_type='compute',
session=mock.ANY,
service_name=None)
+
+ @mock.patch.object(cloud_config.CloudConfig, 'get_session_endpoint')
+ def test_legacy_client_identity(self, mock_get_session_endpoint):
+ mock_client = mock.Mock()
+ mock_get_session_endpoint.return_value = 'http://example.com/v2'
+ config_dict = defaults.get_defaults()
+ config_dict.update(fake_services_dict)
+ cc = cloud_config.CloudConfig(
+ "test1", "region-al", config_dict, auth_plugin=mock.Mock())
+ cc.get_legacy_client('identity', mock_client)
+ mock_client.assert_called_with(
+ version=('2', '0'),
+ endpoint='http://example.com/v2',
+ endpoint_type='admin',
+ region_name='region-al',
+ service_type='identity',
+ session=mock.ANY,
+ service_name='locks')
+
+ @mock.patch.object(cloud_config.CloudConfig, 'get_session_endpoint')
+ def test_legacy_client_identity_v3(self, mock_get_session_endpoint):
+ mock_client = mock.Mock()
+ mock_get_session_endpoint.return_value = 'http://example.com'
+ config_dict = defaults.get_defaults()
+ config_dict.update(fake_services_dict)
+ config_dict['identity_api_version'] = '3'
+ cc = cloud_config.CloudConfig(
+ "test1", "region-al", config_dict, auth_plugin=mock.Mock())
+ cc.get_legacy_client('identity', mock_client)
+ mock_client.assert_called_with(
+ version=('3', '0'),
+ endpoint='http://example.com',
+ endpoint_type='admin',
+ region_name='region-al',
+ service_type='identity',
+ session=mock.ANY,
+ service_name='locks')