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
# limitations under the License.
from keystoneclient import client
from mistralclient import auth
from oslo_serialization import jsonutils
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):
def authenticate(self, req):
@ -85,9 +77,7 @@ class KeystoneAuthHandler(auth.AuthHandler):
auth_response = {}
if auth_url:
keystone_client = _get_keystone_client(auth_url)
keystone = keystone_client.Client(
keystone = client.Client(
username=username,
user_id=user_id,
password=api_key,
@ -95,7 +85,6 @@ class KeystoneAuthHandler(auth.AuthHandler):
tenant_id=project_id,
tenant_name=project_name,
auth_url=auth_url,
endpoint=auth_url,
cacert=cacert,
insecure=insecure,
user_domain_name=user_domain_name,
@ -123,17 +112,16 @@ class KeystoneAuthHandler(auth.AuthHandler):
auth_response['mistral_url'] = mistral_url
if target_auth_url:
target_keystone_client = _get_keystone_client(target_auth_url)
target_keystone = target_keystone_client.Client(
target_keystone = client.Client(
username=target_username,
user_id=target_user_id,
password=target_api_key,
token=target_auth_token,
tenant_id=target_project_id,
tenant_name=target_project_name,
project_id=target_project_id,
project_name=target_project_name,
auth_url=target_auth_url,
endpoint=target_auth_url,
cacert=target_cacert,
insecure=target_insecure,
region_name=target_region_name,

View File

@ -43,7 +43,7 @@ class BaseClientTests(base.BaseTestCase):
keystone_client_instance.auth_ref = str(json.dumps({}))
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):
keystone_client_instance = self.setup_keystone_mock(
keystone_client_mock
@ -64,7 +64,7 @@ class BaseClientTests(base.BaseTestCase):
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):
keystone_client_instance = self.setup_keystone_mock(
keystone_client_mock
@ -86,7 +86,7 @@ class BaseClientTests(base.BaseTestCase):
mistralclient.actions.http_client.base_url
)
@mock.patch('keystoneclient.v3.client.Client')
@mock.patch('keystoneclient.client.Client')
@mock.patch('mistralclient.api.httpclient.HTTPClient')
def test_mistral_url_default(self, http_client_mock, keystone_client_mock):
keystone_client_instance = self.setup_keystone_mock(
@ -116,7 +116,7 @@ class BaseClientTests(base.BaseTestCase):
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')
def test_target_parameters_processed(
self,
@ -156,7 +156,7 @@ class BaseClientTests(base.BaseTestCase):
for key in expected_values:
self.assertEqual(expected_values[key], kwargs[key])
@mock.patch('keystoneclient.v3.client.Client')
@mock.patch('keystoneclient.client.Client')
@mock.patch('mistralclient.api.httpclient.HTTPClient')
def test_mistral_url_https_insecure(self, http_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[1]['insecure'], True)
@mock.patch('keystoneclient.v3.client.Client')
@mock.patch('keystoneclient.client.Client')
@mock.patch('mistralclient.api.httpclient.HTTPClient')
def test_mistral_url_https_secure(self, http_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[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):
keystone_client_instance = self.setup_keystone_mock( # noqa
keystone_client_mock
@ -230,7 +230,7 @@ class BaseClientTests(base.BaseTestCase):
)
@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,
log_warning_mock):
fd, path = tempfile.mkstemp(suffix='.pem')
@ -254,7 +254,7 @@ class BaseClientTests(base.BaseTestCase):
self.assertTrue(log_warning_mock.called)
@mock.patch('keystoneclient.v3.client.Client')
@mock.patch('keystoneclient.client.Client')
@mock.patch('mistralclient.api.httpclient.HTTPClient')
def test_mistral_profile_enabled(self, http_client_mock,
keystone_client_mock):