Remove CONF values from Token clients
To move Token clients to tempest-lib, this patch moves CONF values from Token clients to the client setting and classes instantiate Token clients. Also making necessary changes in tests files. Change-Id: Ie405ba6a71d29258e99d2f0b68afb013a9619e9b
This commit is contained in:
parent
d26b5cd7b8
commit
5ff763f5ac
|
@ -14,8 +14,11 @@ from tempest.api.identity import base
|
|||
from tempest import auth
|
||||
from tempest import clients
|
||||
from tempest.common.utils import data_utils
|
||||
from tempest import config
|
||||
from tempest import test
|
||||
|
||||
CONF = config.CONF
|
||||
|
||||
|
||||
class TestDefaultProjectId (base.BaseIdentityV3AdminTest):
|
||||
|
||||
|
@ -71,7 +74,8 @@ class TestDefaultProjectId (base.BaseIdentityV3AdminTest):
|
|||
creds = auth.KeystoneV3Credentials(username=user_name,
|
||||
password=user_name,
|
||||
domain_name=dom_name)
|
||||
auth_provider = auth.KeystoneV3AuthProvider(creds)
|
||||
auth_provider = auth.KeystoneV3AuthProvider(creds,
|
||||
CONF.identity.uri_v3)
|
||||
creds = auth_provider.fill_credentials()
|
||||
admin_client = clients.Manager(credentials=creds)
|
||||
|
||||
|
|
|
@ -186,9 +186,9 @@ class KeystoneAuthProvider(AuthProvider):
|
|||
|
||||
token_expiry_threshold = datetime.timedelta(seconds=60)
|
||||
|
||||
def __init__(self, credentials):
|
||||
def __init__(self, credentials, auth_url):
|
||||
super(KeystoneAuthProvider, self).__init__(credentials)
|
||||
self.auth_client = self._auth_client()
|
||||
self.auth_client = self._auth_client(auth_url)
|
||||
|
||||
def _decorate_request(self, filters, method, url, headers=None, body=None,
|
||||
auth_data=None):
|
||||
|
@ -236,8 +236,8 @@ class KeystoneV2AuthProvider(KeystoneAuthProvider):
|
|||
|
||||
EXPIRY_DATE_FORMAT = '%Y-%m-%dT%H:%M:%SZ'
|
||||
|
||||
def _auth_client(self):
|
||||
return json_id.TokenClientJSON()
|
||||
def _auth_client(self, auth_url):
|
||||
return json_id.TokenClientJSON(auth_url)
|
||||
|
||||
def _auth_params(self):
|
||||
return dict(
|
||||
|
@ -314,8 +314,8 @@ class KeystoneV3AuthProvider(KeystoneAuthProvider):
|
|||
|
||||
EXPIRY_DATE_FORMAT = '%Y-%m-%dT%H:%M:%S.%fZ'
|
||||
|
||||
def _auth_client(self):
|
||||
return json_v3id.V3TokenClientJSON()
|
||||
def _auth_client(self, auth_url):
|
||||
return json_v3id.V3TokenClientJSON(auth_url)
|
||||
|
||||
def _auth_params(self):
|
||||
return dict(
|
||||
|
@ -430,10 +430,12 @@ def is_identity_version_supported(identity_version):
|
|||
return identity_version in IDENTITY_VERSION
|
||||
|
||||
|
||||
def get_credentials(fill_in=True, identity_version='v2', **kwargs):
|
||||
def get_credentials(auth_url, fill_in=True, identity_version='v2', **kwargs):
|
||||
"""
|
||||
Builds a credentials object based on the configured auth_version
|
||||
|
||||
:param auth_url (string): Full URI of the OpenStack Identity API(Keystone)
|
||||
which is used to fetch the token from Identity service.
|
||||
:param fill_in (boolean): obtain a token and fill in all credential
|
||||
details provided by the identity service. When fill_in is not
|
||||
specified, credentials are not validated. Validation can be invoked
|
||||
|
@ -460,7 +462,7 @@ def get_credentials(fill_in=True, identity_version='v2', **kwargs):
|
|||
creds = credential_class(**kwargs)
|
||||
# Fill in the credentials fields that were not specified
|
||||
if fill_in:
|
||||
auth_provider = auth_provider_class(creds)
|
||||
auth_provider = auth_provider_class(creds, auth_url)
|
||||
creds = auth_provider.fill_credentials()
|
||||
return creds
|
||||
|
||||
|
|
|
@ -320,9 +320,9 @@ class Manager(manager.Manager):
|
|||
self.region_client = RegionClientJSON(self.auth_provider, **params)
|
||||
self.credentials_client = CredentialsClientJSON(self.auth_provider,
|
||||
**params)
|
||||
self.token_client = TokenClientJSON()
|
||||
self.token_client = TokenClientJSON(CONF.identity.uri)
|
||||
if CONF.identity_feature_enabled.api_v3:
|
||||
self.token_v3_client = V3TokenClientJSON()
|
||||
self.token_v3_client = V3TokenClientJSON(CONF.identity.uri_v3)
|
||||
|
||||
def _set_volume_clients(self):
|
||||
params = {
|
||||
|
|
|
@ -176,7 +176,7 @@ class OSClient(object):
|
|||
username=user,
|
||||
password=pw,
|
||||
tenant_name=tenant)
|
||||
_auth = tempest.auth.KeystoneV2AuthProvider(_creds)
|
||||
_auth = tempest.auth.KeystoneV2AuthProvider(_creds, CONF.identity.uri)
|
||||
self.identity = identity_client.IdentityClientJSON(
|
||||
_auth,
|
||||
CONF.identity.catalog_type,
|
||||
|
|
|
@ -76,7 +76,11 @@ def get_credentials(fill_in=True, identity_version=None, **kwargs):
|
|||
if 'domain' in x)
|
||||
if not domain_fields.intersection(kwargs.keys()):
|
||||
kwargs['user_domain_name'] = CONF.identity.admin_domain_name
|
||||
return auth.get_credentials(fill_in=fill_in,
|
||||
auth_url = CONF.identity.uri_v3
|
||||
else:
|
||||
auth_url = CONF.identity.uri
|
||||
return auth.get_credentials(auth_url,
|
||||
fill_in=fill_in,
|
||||
identity_version=identity_version,
|
||||
**kwargs)
|
||||
|
||||
|
|
|
@ -54,14 +54,14 @@ class Manager(object):
|
|||
@classmethod
|
||||
def get_auth_provider_class(cls, credentials):
|
||||
if isinstance(credentials, auth.KeystoneV3Credentials):
|
||||
return auth.KeystoneV3AuthProvider
|
||||
return auth.KeystoneV3AuthProvider, CONF.identity.uri_v3
|
||||
else:
|
||||
return auth.KeystoneV2AuthProvider
|
||||
return auth.KeystoneV2AuthProvider, CONF.identity.uri
|
||||
|
||||
def get_auth_provider(self, credentials):
|
||||
if credentials is None:
|
||||
raise exceptions.InvalidCredentials(
|
||||
'Credentials must be specified')
|
||||
auth_provider_class = self.get_auth_provider_class(credentials)
|
||||
return auth_provider_class(
|
||||
credentials=credentials)
|
||||
auth_provider_class, auth_url = self.get_auth_provider_class(
|
||||
credentials)
|
||||
return auth_provider_class(credentials, auth_url)
|
||||
|
|
|
@ -16,17 +16,13 @@ import json
|
|||
from tempest_lib import exceptions as lib_exc
|
||||
|
||||
from tempest.common import service_client
|
||||
from tempest import config
|
||||
from tempest import exceptions
|
||||
|
||||
CONF = config.CONF
|
||||
|
||||
|
||||
class TokenClientJSON(service_client.ServiceClient):
|
||||
|
||||
def __init__(self):
|
||||
def __init__(self, auth_url):
|
||||
super(TokenClientJSON, self).__init__(None, None, None)
|
||||
auth_url = CONF.identity.uri
|
||||
|
||||
# Normalize URI to ensure /tokens is in it.
|
||||
if 'tokens' not in auth_url:
|
||||
|
|
|
@ -16,17 +16,13 @@ import json
|
|||
from tempest_lib import exceptions as lib_exc
|
||||
|
||||
from tempest.common import service_client
|
||||
from tempest import config
|
||||
from tempest import exceptions
|
||||
|
||||
CONF = config.CONF
|
||||
|
||||
|
||||
class V3TokenClientJSON(service_client.ServiceClient):
|
||||
|
||||
def __init__(self):
|
||||
def __init__(self, auth_url):
|
||||
super(V3TokenClientJSON, self).__init__(None, None, None)
|
||||
auth_url = CONF.identity.uri_v3
|
||||
if not auth_url:
|
||||
raise exceptions.InvalidConfiguration('you must specify a v3 uri '
|
||||
'if using the v3 identity '
|
||||
|
|
|
@ -73,7 +73,8 @@ class TestAccount(base.TestCase):
|
|||
test_account_class = accounts.Accounts('test_name')
|
||||
hash_list = self._get_hash_list(self.test_accounts)
|
||||
test_cred_dict = self.test_accounts[3]
|
||||
test_creds = auth.get_credentials(**test_cred_dict)
|
||||
test_creds = auth.get_credentials(fake_identity.FAKE_AUTH_URL,
|
||||
**test_cred_dict)
|
||||
results = test_account_class.get_hash(test_creds)
|
||||
self.assertEqual(hash_list[3], results)
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@ import json
|
|||
|
||||
import httplib2
|
||||
|
||||
FAKE_AUTH_URL = 'http://fake_uri.com/auth'
|
||||
|
||||
TOKEN = "fake_token"
|
||||
ALT_TOKEN = "alt_fake_token"
|
||||
|
|
|
@ -38,11 +38,11 @@ class BaseAuthTestsSetUp(base.TestCase):
|
|||
_auth_provider_class = None
|
||||
credentials = fake_credentials.FakeCredentials()
|
||||
|
||||
def _auth(self, credentials, **params):
|
||||
def _auth(self, credentials, auth_url, **params):
|
||||
"""
|
||||
returns auth method according to keystone
|
||||
"""
|
||||
return self._auth_provider_class(credentials, **params)
|
||||
return self._auth_provider_class(credentials, auth_url, **params)
|
||||
|
||||
def setUp(self):
|
||||
super(BaseAuthTestsSetUp, self).setUp()
|
||||
|
@ -50,7 +50,8 @@ class BaseAuthTestsSetUp(base.TestCase):
|
|||
self.stubs.Set(config, 'TempestConfigPrivate', fake_config.FakePrivate)
|
||||
self.fake_http = fake_http.fake_httplib2(return_type=200)
|
||||
self.stubs.Set(auth, 'get_credentials', fake_get_credentials)
|
||||
self.auth_provider = self._auth(self.credentials)
|
||||
self.auth_provider = self._auth(self.credentials,
|
||||
fake_identity.FAKE_AUTH_URL)
|
||||
|
||||
|
||||
class TestBaseAuthProvider(BaseAuthTestsSetUp):
|
||||
|
@ -78,6 +79,12 @@ class TestBaseAuthProvider(BaseAuthTestsSetUp):
|
|||
|
||||
_auth_provider_class = FakeAuthProviderImpl
|
||||
|
||||
def _auth(self, credentials, auth_url, **params):
|
||||
"""
|
||||
returns auth method according to keystone
|
||||
"""
|
||||
return self._auth_provider_class(credentials, **params)
|
||||
|
||||
def test_check_credentials_bad_type(self):
|
||||
self.assertFalse(self.auth_provider.check_credentials([]))
|
||||
|
||||
|
|
|
@ -84,7 +84,8 @@ class KeystoneV2CredentialsTests(CredentialsTests):
|
|||
self.identity_response)
|
||||
|
||||
def _verify_credentials(self, credentials_class, creds_dict, filled=True):
|
||||
creds = auth.get_credentials(fill_in=filled,
|
||||
creds = auth.get_credentials(fake_identity.FAKE_AUTH_URL,
|
||||
fill_in=filled,
|
||||
identity_version=self.identity_version,
|
||||
**creds_dict)
|
||||
self._check(creds, credentials_class, filled)
|
||||
|
|
Loading…
Reference in New Issue