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')