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:
ghanshyam 2015-02-18 16:15:58 +09:00
parent d26b5cd7b8
commit 5ff763f5ac
12 changed files with 45 additions and 33 deletions

View File

@ -14,8 +14,11 @@ from tempest.api.identity import base
from tempest import auth from tempest import auth
from tempest import clients from tempest import clients
from tempest.common.utils import data_utils from tempest.common.utils import data_utils
from tempest import config
from tempest import test from tempest import test
CONF = config.CONF
class TestDefaultProjectId (base.BaseIdentityV3AdminTest): class TestDefaultProjectId (base.BaseIdentityV3AdminTest):
@ -71,7 +74,8 @@ class TestDefaultProjectId (base.BaseIdentityV3AdminTest):
creds = auth.KeystoneV3Credentials(username=user_name, creds = auth.KeystoneV3Credentials(username=user_name,
password=user_name, password=user_name,
domain_name=dom_name) domain_name=dom_name)
auth_provider = auth.KeystoneV3AuthProvider(creds) auth_provider = auth.KeystoneV3AuthProvider(creds,
CONF.identity.uri_v3)
creds = auth_provider.fill_credentials() creds = auth_provider.fill_credentials()
admin_client = clients.Manager(credentials=creds) admin_client = clients.Manager(credentials=creds)

View File

@ -186,9 +186,9 @@ class KeystoneAuthProvider(AuthProvider):
token_expiry_threshold = datetime.timedelta(seconds=60) token_expiry_threshold = datetime.timedelta(seconds=60)
def __init__(self, credentials): def __init__(self, credentials, auth_url):
super(KeystoneAuthProvider, self).__init__(credentials) 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, def _decorate_request(self, filters, method, url, headers=None, body=None,
auth_data=None): auth_data=None):
@ -236,8 +236,8 @@ class KeystoneV2AuthProvider(KeystoneAuthProvider):
EXPIRY_DATE_FORMAT = '%Y-%m-%dT%H:%M:%SZ' EXPIRY_DATE_FORMAT = '%Y-%m-%dT%H:%M:%SZ'
def _auth_client(self): def _auth_client(self, auth_url):
return json_id.TokenClientJSON() return json_id.TokenClientJSON(auth_url)
def _auth_params(self): def _auth_params(self):
return dict( return dict(
@ -314,8 +314,8 @@ class KeystoneV3AuthProvider(KeystoneAuthProvider):
EXPIRY_DATE_FORMAT = '%Y-%m-%dT%H:%M:%S.%fZ' EXPIRY_DATE_FORMAT = '%Y-%m-%dT%H:%M:%S.%fZ'
def _auth_client(self): def _auth_client(self, auth_url):
return json_v3id.V3TokenClientJSON() return json_v3id.V3TokenClientJSON(auth_url)
def _auth_params(self): def _auth_params(self):
return dict( return dict(
@ -430,10 +430,12 @@ def is_identity_version_supported(identity_version):
return identity_version in 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 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 :param fill_in (boolean): obtain a token and fill in all credential
details provided by the identity service. When fill_in is not details provided by the identity service. When fill_in is not
specified, credentials are not validated. Validation can be invoked 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) creds = credential_class(**kwargs)
# Fill in the credentials fields that were not specified # Fill in the credentials fields that were not specified
if fill_in: if fill_in:
auth_provider = auth_provider_class(creds) auth_provider = auth_provider_class(creds, auth_url)
creds = auth_provider.fill_credentials() creds = auth_provider.fill_credentials()
return creds return creds

View File

@ -320,9 +320,9 @@ class Manager(manager.Manager):
self.region_client = RegionClientJSON(self.auth_provider, **params) self.region_client = RegionClientJSON(self.auth_provider, **params)
self.credentials_client = CredentialsClientJSON(self.auth_provider, self.credentials_client = CredentialsClientJSON(self.auth_provider,
**params) **params)
self.token_client = TokenClientJSON() self.token_client = TokenClientJSON(CONF.identity.uri)
if CONF.identity_feature_enabled.api_v3: 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): def _set_volume_clients(self):
params = { params = {

View File

@ -176,7 +176,7 @@ class OSClient(object):
username=user, username=user,
password=pw, password=pw,
tenant_name=tenant) tenant_name=tenant)
_auth = tempest.auth.KeystoneV2AuthProvider(_creds) _auth = tempest.auth.KeystoneV2AuthProvider(_creds, CONF.identity.uri)
self.identity = identity_client.IdentityClientJSON( self.identity = identity_client.IdentityClientJSON(
_auth, _auth,
CONF.identity.catalog_type, CONF.identity.catalog_type,

View File

@ -76,7 +76,11 @@ def get_credentials(fill_in=True, identity_version=None, **kwargs):
if 'domain' in x) if 'domain' in x)
if not domain_fields.intersection(kwargs.keys()): if not domain_fields.intersection(kwargs.keys()):
kwargs['user_domain_name'] = CONF.identity.admin_domain_name 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, identity_version=identity_version,
**kwargs) **kwargs)

View File

@ -54,14 +54,14 @@ class Manager(object):
@classmethod @classmethod
def get_auth_provider_class(cls, credentials): def get_auth_provider_class(cls, credentials):
if isinstance(credentials, auth.KeystoneV3Credentials): if isinstance(credentials, auth.KeystoneV3Credentials):
return auth.KeystoneV3AuthProvider return auth.KeystoneV3AuthProvider, CONF.identity.uri_v3
else: else:
return auth.KeystoneV2AuthProvider return auth.KeystoneV2AuthProvider, CONF.identity.uri
def get_auth_provider(self, credentials): def get_auth_provider(self, credentials):
if credentials is None: if credentials is None:
raise exceptions.InvalidCredentials( raise exceptions.InvalidCredentials(
'Credentials must be specified') 'Credentials must be specified')
auth_provider_class = self.get_auth_provider_class(credentials) auth_provider_class, auth_url = self.get_auth_provider_class(
return auth_provider_class( credentials)
credentials=credentials) return auth_provider_class(credentials, auth_url)

View File

@ -16,17 +16,13 @@ import json
from tempest_lib import exceptions as lib_exc from tempest_lib import exceptions as lib_exc
from tempest.common import service_client from tempest.common import service_client
from tempest import config
from tempest import exceptions from tempest import exceptions
CONF = config.CONF
class TokenClientJSON(service_client.ServiceClient): class TokenClientJSON(service_client.ServiceClient):
def __init__(self): def __init__(self, auth_url):
super(TokenClientJSON, self).__init__(None, None, None) super(TokenClientJSON, self).__init__(None, None, None)
auth_url = CONF.identity.uri
# Normalize URI to ensure /tokens is in it. # Normalize URI to ensure /tokens is in it.
if 'tokens' not in auth_url: if 'tokens' not in auth_url:

View File

@ -16,17 +16,13 @@ import json
from tempest_lib import exceptions as lib_exc from tempest_lib import exceptions as lib_exc
from tempest.common import service_client from tempest.common import service_client
from tempest import config
from tempest import exceptions from tempest import exceptions
CONF = config.CONF
class V3TokenClientJSON(service_client.ServiceClient): class V3TokenClientJSON(service_client.ServiceClient):
def __init__(self): def __init__(self, auth_url):
super(V3TokenClientJSON, self).__init__(None, None, None) super(V3TokenClientJSON, self).__init__(None, None, None)
auth_url = CONF.identity.uri_v3
if not auth_url: if not auth_url:
raise exceptions.InvalidConfiguration('you must specify a v3 uri ' raise exceptions.InvalidConfiguration('you must specify a v3 uri '
'if using the v3 identity ' 'if using the v3 identity '

View File

@ -73,7 +73,8 @@ class TestAccount(base.TestCase):
test_account_class = accounts.Accounts('test_name') test_account_class = accounts.Accounts('test_name')
hash_list = self._get_hash_list(self.test_accounts) hash_list = self._get_hash_list(self.test_accounts)
test_cred_dict = self.test_accounts[3] 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) results = test_account_class.get_hash(test_creds)
self.assertEqual(hash_list[3], results) self.assertEqual(hash_list[3], results)

View File

@ -17,6 +17,7 @@ import json
import httplib2 import httplib2
FAKE_AUTH_URL = 'http://fake_uri.com/auth'
TOKEN = "fake_token" TOKEN = "fake_token"
ALT_TOKEN = "alt_fake_token" ALT_TOKEN = "alt_fake_token"

View File

@ -38,11 +38,11 @@ class BaseAuthTestsSetUp(base.TestCase):
_auth_provider_class = None _auth_provider_class = None
credentials = fake_credentials.FakeCredentials() credentials = fake_credentials.FakeCredentials()
def _auth(self, credentials, **params): def _auth(self, credentials, auth_url, **params):
""" """
returns auth method according to keystone 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): def setUp(self):
super(BaseAuthTestsSetUp, self).setUp() super(BaseAuthTestsSetUp, self).setUp()
@ -50,7 +50,8 @@ class BaseAuthTestsSetUp(base.TestCase):
self.stubs.Set(config, 'TempestConfigPrivate', fake_config.FakePrivate) self.stubs.Set(config, 'TempestConfigPrivate', fake_config.FakePrivate)
self.fake_http = fake_http.fake_httplib2(return_type=200) self.fake_http = fake_http.fake_httplib2(return_type=200)
self.stubs.Set(auth, 'get_credentials', fake_get_credentials) 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): class TestBaseAuthProvider(BaseAuthTestsSetUp):
@ -78,6 +79,12 @@ class TestBaseAuthProvider(BaseAuthTestsSetUp):
_auth_provider_class = FakeAuthProviderImpl _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): def test_check_credentials_bad_type(self):
self.assertFalse(self.auth_provider.check_credentials([])) self.assertFalse(self.auth_provider.check_credentials([]))

View File

@ -84,7 +84,8 @@ class KeystoneV2CredentialsTests(CredentialsTests):
self.identity_response) self.identity_response)
def _verify_credentials(self, credentials_class, creds_dict, filled=True): 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, identity_version=self.identity_version,
**creds_dict) **creds_dict)
self._check(creds, credentials_class, filled) self._check(creds, credentials_class, filled)