From b63f52fa53e60b876ba03403fa4c26cba7ba9d4e Mon Sep 17 00:00:00 2001 From: Sergey Reshetnyak Date: Thu, 23 Apr 2015 22:56:14 +0300 Subject: [PATCH] Try getting old service type if session used If set up old sahara service type in keystone service catalog (data_processing) then if you use keystone session for auth, saharaclient do not checks old service type. This patch fixes this problem. Change-Id: I148c0f59fde791c1c1cff63ea27fd6d489744ce1 Closes-bug: #1447797 --- saharaclient/api/client.py | 12 ++++++++---- saharaclient/tests/unit/nova/test_shell.py | 9 ++++----- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/saharaclient/api/client.py b/saharaclient/api/client.py index 4f95b389..3c5bfc48 100644 --- a/saharaclient/api/client.py +++ b/saharaclient/api/client.py @@ -76,10 +76,14 @@ class Client(object): verify = cacert session = keystone_session.Session(verify=verify) - service_type = self._determine_service_type(session, - auth, - service_type, - endpoint_type) + + if not auth: + auth = session.auth + + service_type = self._determine_service_type(session, + auth, + service_type, + endpoint_type) kwargs['user_agent'] = USER_AGENT kwargs.setdefault('interface', endpoint_type) diff --git a/saharaclient/tests/unit/nova/test_shell.py b/saharaclient/tests/unit/nova/test_shell.py index c9572ae5..04034190 100644 --- a/saharaclient/tests/unit/nova/test_shell.py +++ b/saharaclient/tests/unit/nova/test_shell.py @@ -353,15 +353,14 @@ class ShellTestKeystoneV3(ShellTest): '' ]) - mock_session_class_name = 'keystoneclient.adapter.LegacyJsonAdapter' + mock_get_service_type_method_name = ( + 'saharaclient.api.client.Client._determine_service_type') mock_job_executions_class_name = ( 'saharaclient.api.job_executions.JobExecutionsManager') - with mock.patch(mock_session_class_name) as mock_session: + with mock.patch(mock_get_service_type_method_name) as mock_st: with mock.patch(mock_job_executions_class_name): - ms = mock_session.return_value - ms.session.get_endpoint.return_value = 'http://no.where' - + mock_st.return_value = 'data-processing' self.make_env() stdout, stderr = self.shell('job-list') self.assertEqual((stdout + stderr), expected)