Use generic keystone client instead of versioned

This will allow the usage of versionless keystone endpoints. However,
the versioned ones still work, as the generic client uses keystone
discovery to determine the version to use.

Change-Id: I6d66c1b80b79fa1dcb31fbd3c165e4fca6940414
This commit is contained in:
Juan Antonio Osorio Robles 2017-03-08 14:59:07 +02:00
parent d1508e0991
commit ca313b0de4
2 changed files with 14 additions and 26 deletions

View File

@ -12,21 +12,13 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
from keystoneclient import client
from mistralclient import auth from mistralclient import auth
from oslo_serialization import jsonutils from oslo_serialization import jsonutils
import mistralclient.api.httpclient as api import mistralclient.api.httpclient as api
def _get_keystone_client(auth_url):
if 'v2.0' in auth_url:
from keystoneclient.v2_0 import client
else:
from keystoneclient.v3 import client
return client
class KeystoneAuthHandler(auth.AuthHandler): class KeystoneAuthHandler(auth.AuthHandler):
def authenticate(self, req): def authenticate(self, req):
@ -85,9 +77,7 @@ class KeystoneAuthHandler(auth.AuthHandler):
auth_response = {} auth_response = {}
if auth_url: if auth_url:
keystone_client = _get_keystone_client(auth_url) keystone = client.Client(
keystone = keystone_client.Client(
username=username, username=username,
user_id=user_id, user_id=user_id,
password=api_key, password=api_key,
@ -95,7 +85,6 @@ class KeystoneAuthHandler(auth.AuthHandler):
tenant_id=project_id, tenant_id=project_id,
tenant_name=project_name, tenant_name=project_name,
auth_url=auth_url, auth_url=auth_url,
endpoint=auth_url,
cacert=cacert, cacert=cacert,
insecure=insecure, insecure=insecure,
user_domain_name=user_domain_name, user_domain_name=user_domain_name,
@ -123,17 +112,16 @@ class KeystoneAuthHandler(auth.AuthHandler):
auth_response['mistral_url'] = mistral_url auth_response['mistral_url'] = mistral_url
if target_auth_url: if target_auth_url:
target_keystone_client = _get_keystone_client(target_auth_url) target_keystone = client.Client(
target_keystone = target_keystone_client.Client(
username=target_username, username=target_username,
user_id=target_user_id, user_id=target_user_id,
password=target_api_key, password=target_api_key,
token=target_auth_token, token=target_auth_token,
tenant_id=target_project_id, tenant_id=target_project_id,
tenant_name=target_project_name, tenant_name=target_project_name,
project_id=target_project_id,
project_name=target_project_name,
auth_url=target_auth_url, auth_url=target_auth_url,
endpoint=target_auth_url,
cacert=target_cacert, cacert=target_cacert,
insecure=target_insecure, insecure=target_insecure,
region_name=target_region_name, region_name=target_region_name,

View File

@ -43,7 +43,7 @@ class BaseClientTests(base.BaseTestCase):
keystone_client_instance.auth_ref = str(json.dumps({})) keystone_client_instance.auth_ref = str(json.dumps({}))
return keystone_client_instance return keystone_client_instance
@mock.patch('keystoneclient.v2_0.client.Client') @mock.patch('keystoneclient.client.Client')
def test_mistral_url_from_catalog_v2(self, keystone_client_mock): def test_mistral_url_from_catalog_v2(self, keystone_client_mock):
keystone_client_instance = self.setup_keystone_mock( keystone_client_instance = self.setup_keystone_mock(
keystone_client_mock keystone_client_mock
@ -64,7 +64,7 @@ class BaseClientTests(base.BaseTestCase):
mistralclient.actions.http_client.base_url mistralclient.actions.http_client.base_url
) )
@mock.patch('keystoneclient.v3.client.Client') @mock.patch('keystoneclient.client.Client')
def test_mistral_url_from_catalog(self, keystone_client_mock): def test_mistral_url_from_catalog(self, keystone_client_mock):
keystone_client_instance = self.setup_keystone_mock( keystone_client_instance = self.setup_keystone_mock(
keystone_client_mock keystone_client_mock
@ -86,7 +86,7 @@ class BaseClientTests(base.BaseTestCase):
mistralclient.actions.http_client.base_url mistralclient.actions.http_client.base_url
) )
@mock.patch('keystoneclient.v3.client.Client') @mock.patch('keystoneclient.client.Client')
@mock.patch('mistralclient.api.httpclient.HTTPClient') @mock.patch('mistralclient.api.httpclient.HTTPClient')
def test_mistral_url_default(self, http_client_mock, keystone_client_mock): def test_mistral_url_default(self, http_client_mock, keystone_client_mock):
keystone_client_instance = self.setup_keystone_mock( keystone_client_instance = self.setup_keystone_mock(
@ -116,7 +116,7 @@ class BaseClientTests(base.BaseTestCase):
keystone_client_instance.user_id, kwargs['user_id'] keystone_client_instance.user_id, kwargs['user_id']
) )
@mock.patch('keystoneclient.v3.client.Client') @mock.patch('keystoneclient.client.Client')
@mock.patch('mistralclient.api.httpclient.HTTPClient') @mock.patch('mistralclient.api.httpclient.HTTPClient')
def test_target_parameters_processed( def test_target_parameters_processed(
self, self,
@ -156,7 +156,7 @@ class BaseClientTests(base.BaseTestCase):
for key in expected_values: for key in expected_values:
self.assertEqual(expected_values[key], kwargs[key]) self.assertEqual(expected_values[key], kwargs[key])
@mock.patch('keystoneclient.v3.client.Client') @mock.patch('keystoneclient.client.Client')
@mock.patch('mistralclient.api.httpclient.HTTPClient') @mock.patch('mistralclient.api.httpclient.HTTPClient')
def test_mistral_url_https_insecure(self, http_client_mock, def test_mistral_url_https_insecure(self, http_client_mock,
keystone_client_mock): keystone_client_mock):
@ -181,7 +181,7 @@ class BaseClientTests(base.BaseTestCase):
self.assertEqual(http_client_mock.call_args[0], expected_args) self.assertEqual(http_client_mock.call_args[0], expected_args)
self.assertEqual(http_client_mock.call_args[1]['insecure'], True) self.assertEqual(http_client_mock.call_args[1]['insecure'], True)
@mock.patch('keystoneclient.v3.client.Client') @mock.patch('keystoneclient.client.Client')
@mock.patch('mistralclient.api.httpclient.HTTPClient') @mock.patch('mistralclient.api.httpclient.HTTPClient')
def test_mistral_url_https_secure(self, http_client_mock, def test_mistral_url_https_secure(self, http_client_mock,
keystone_client_mock): keystone_client_mock):
@ -212,7 +212,7 @@ class BaseClientTests(base.BaseTestCase):
self.assertEqual(http_client_mock.call_args[0], expected_args) self.assertEqual(http_client_mock.call_args[0], expected_args)
self.assertEqual(http_client_mock.call_args[1]['cacert'], cert_path) self.assertEqual(http_client_mock.call_args[1]['cacert'], cert_path)
@mock.patch('keystoneclient.v3.client.Client') @mock.patch('keystoneclient.client.Client')
def test_mistral_url_https_bad_cacert(self, keystone_client_mock): def test_mistral_url_https_bad_cacert(self, keystone_client_mock):
keystone_client_instance = self.setup_keystone_mock( # noqa keystone_client_instance = self.setup_keystone_mock( # noqa
keystone_client_mock keystone_client_mock
@ -230,7 +230,7 @@ class BaseClientTests(base.BaseTestCase):
) )
@mock.patch('logging.Logger.warning') @mock.patch('logging.Logger.warning')
@mock.patch('keystoneclient.v3.client.Client') @mock.patch('keystoneclient.client.Client')
def test_mistral_url_https_bad_insecure(self, keystone_client_mock, def test_mistral_url_https_bad_insecure(self, keystone_client_mock,
log_warning_mock): log_warning_mock):
fd, path = tempfile.mkstemp(suffix='.pem') fd, path = tempfile.mkstemp(suffix='.pem')
@ -254,7 +254,7 @@ class BaseClientTests(base.BaseTestCase):
self.assertTrue(log_warning_mock.called) self.assertTrue(log_warning_mock.called)
@mock.patch('keystoneclient.v3.client.Client') @mock.patch('keystoneclient.client.Client')
@mock.patch('mistralclient.api.httpclient.HTTPClient') @mock.patch('mistralclient.api.httpclient.HTTPClient')
def test_mistral_profile_enabled(self, http_client_mock, def test_mistral_profile_enabled(self, http_client_mock,
keystone_client_mock): keystone_client_mock):