fix v2 fetch of Cloud Provider ID

Corrects a bug that caused retrieval of the keystone ID to be used as
the Cloud Provider ID to fail when using keystone v2.

Change-Id: Id378e8ff31472fd2eb194fd59ecd8042297229d8
Closes-Bug: #1497067
This commit is contained in:
Matthew Edmonds
2015-09-17 22:23:59 -04:00
committed by Paul Van Eck
parent ecba34b7dd
commit d16248ff02
2 changed files with 10 additions and 14 deletions

View File

@@ -131,30 +131,26 @@ class RefstackClient:
auth_version = ( auth_version = (
'v3' if (conf_file.has_option('identity-feature-enabled', 'v3' if (conf_file.has_option('identity-feature-enabled',
'api_v3') 'api_v3')
and conf_file.get('identity-feature-enabled', and conf_file.getboolean('identity-feature-enabled',
'api_v3') 'api_v3')
and conf_file.has_option('identity', 'uri_v3')) and conf_file.has_option('identity', 'uri_v3'))
else 'v2') else 'v2')
args = {'insecure': self.args.insecure} args = {
'insecure': self.args.insecure,
auth_args = {
'username': conf_file.get('identity', 'username'), 'username': conf_file.get('identity', 'username'),
'password': conf_file.get('identity', 'password') 'password': conf_file.get('identity', 'password')
} }
if self.conf.has_option('identity', 'tenant_id'): if self.conf.has_option('identity', 'tenant_id'):
auth_args['tenant_id'] = conf_file.get('identity', args['tenant_id'] = conf_file.get('identity', 'tenant_id')
'tenant_id')
else: else:
auth_args['tenant_name'] = conf_file.get('identity', args['tenant_name'] = conf_file.get('identity', 'tenant_name')
'tenant_name')
args.update(auth_args)
if auth_version == 'v2': if auth_version == 'v2':
args['auth_url'] = conf_file.get('identity', 'uri') args['auth_url'] = conf_file.get('identity', 'uri')
client = ksclient2.Client(**args) client = ksclient2.Client(**args)
token = client.tokens.authenticate(**auth_args) token = client.auth_ref
for service in token.serviceCatalog: for service in token['serviceCatalog']:
if service['type'] == 'identity': if service['type'] == 'identity':
return service['endpoints'][0]['id'] return service['endpoints'][0]['id']
elif auth_version == 'v3': elif auth_version == 'v3':

View File

@@ -76,8 +76,8 @@ class TestRefstackClient(unittest.TestCase):
'id': 'test-id'} 'id': 'test-id'}
self.mock_ks2_client = MagicMock( self.mock_ks2_client = MagicMock(
name='ks_client', name='ks_client',
**{'tokens.authenticate.return_value.serviceCatalog': **{'auth_ref':
[self.mock_identity_service_v2]} {'serviceCatalog': [self.mock_identity_service_v2]}}
) )
self.mock_ks3_client = MagicMock( self.mock_ks3_client = MagicMock(
name='ks_client', name='ks_client',