From b9e87ef8633e29a7777bd061ba810756d4e48863 Mon Sep 17 00:00:00 2001 From: Nikolay Mahotkin Date: Thu, 1 Sep 2016 12:50:27 +0300 Subject: [PATCH] Fixing getting mistral_url from keystone catalog Closes-Bug: #1598018 Depends-On: I1b61bd1de6811a5f65c2375dde956aafe33445b2 Change-Id: I16f1a5ff412d98371dfaab863cb24b47438d2d1e --- mistralclient/auth/keystone.py | 3 +-- mistralclient/tests/unit/test_client.py | 33 +++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/mistralclient/auth/keystone.py b/mistralclient/auth/keystone.py index 000da3a9..88729f5d 100644 --- a/mistralclient/auth/keystone.py +++ b/mistralclient/auth/keystone.py @@ -58,8 +58,7 @@ def authenticate(mistral_url=None, username=None, if service_type in catalog: service = catalog.get(service_type) - mistral_url = service[0].get( - endpoint_type) if service else None + mistral_url = service[0].get('url') if service else None return mistral_url, token, project_id, user_id diff --git a/mistralclient/tests/unit/test_client.py b/mistralclient/tests/unit/test_client.py index 34eab994..89bc8e67 100644 --- a/mistralclient/tests/unit/test_client.py +++ b/mistralclient/tests/unit/test_client.py @@ -32,6 +32,39 @@ PROFILER_HMAC_KEY = 'SECRET_HMAC_KEY' class BaseClientTests(testtools.TestCase): + @mock.patch('keystoneclient.v3.client.Client') + def test_mistral_url_from_catalog(self, keystone_client_mock): + keystone_client_instance = keystone_client_mock.return_value + keystone_client_instance.auth_token = str(uuid.uuid4()) + keystone_client_instance.project_id = str(uuid.uuid4()) + keystone_client_instance.user_id = str(uuid.uuid4()) + + get_endpoints = mock.Mock() + get_endpoints.return_value = { + 'workflowv2': [ + { + 'url': 'http://mistral_host:8989/v2', + 'interface': 'public', + 'region': None, + 'region_id': None, + 'id': '446eca511e8d45acae0924aea42a4c9f' + } + ] + } + + keystone_client_instance.service_catalog.get_endpoints = get_endpoints + + mistralclient = client.client( + username='mistral', + project_name='mistral', + auth_url=AUTH_HTTP_URL, + service_type='workflowv2' + ) + + self.assertEqual( + 'http://mistral_host:8989/v2', + mistralclient.http_client.base_url + ) @mock.patch('keystoneclient.v3.client.Client') @mock.patch('mistralclient.api.httpclient.HTTPClient')