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
diff --git a/tempest/api/identity/admin/v3/test_default_project_id.py b/tempest/api/identity/admin/v3/test_default_project_id.py
index 72d323a..dab092d 100644
--- a/tempest/api/identity/admin/v3/test_default_project_id.py
+++ b/tempest/api/identity/admin/v3/test_default_project_id.py
@@ -14,8 +14,11 @@
 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 @@
         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)
 
diff --git a/tempest/auth.py b/tempest/auth.py
index f78bb20..7b00f2a 100644
--- a/tempest/auth.py
+++ b/tempest/auth.py
@@ -186,9 +186,9 @@
 
     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 @@
 
     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 @@
 
     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 @@
     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 @@
     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
 
diff --git a/tempest/clients.py b/tempest/clients.py
index bb08d87..fa3f65e 100644
--- a/tempest/clients.py
+++ b/tempest/clients.py
@@ -320,9 +320,9 @@
         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 = {
diff --git a/tempest/cmd/javelin.py b/tempest/cmd/javelin.py
index 503745c..b11a3c8 100755
--- a/tempest/cmd/javelin.py
+++ b/tempest/cmd/javelin.py
@@ -176,7 +176,7 @@
             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,
diff --git a/tempest/common/cred_provider.py b/tempest/common/cred_provider.py
index d899303..033410e 100644
--- a/tempest/common/cred_provider.py
+++ b/tempest/common/cred_provider.py
@@ -76,7 +76,11 @@
                             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)
 
diff --git a/tempest/manager.py b/tempest/manager.py
index 421d2de..50f7e6e 100644
--- a/tempest/manager.py
+++ b/tempest/manager.py
@@ -54,14 +54,14 @@
     @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)
diff --git a/tempest/services/identity/json/token_client.py b/tempest/services/identity/json/token_client.py
index 1e8b31e..b28dabb 100644
--- a/tempest/services/identity/json/token_client.py
+++ b/tempest/services/identity/json/token_client.py
@@ -16,17 +16,13 @@
 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:
diff --git a/tempest/services/identity/v3/json/token_client.py b/tempest/services/identity/v3/json/token_client.py
index 5d75efa..582897a 100644
--- a/tempest/services/identity/v3/json/token_client.py
+++ b/tempest/services/identity/v3/json/token_client.py
@@ -16,17 +16,13 @@
 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 '
diff --git a/tempest/tests/common/test_accounts.py b/tempest/tests/common/test_accounts.py
index f45f2cf..a836a20 100644
--- a/tempest/tests/common/test_accounts.py
+++ b/tempest/tests/common/test_accounts.py
@@ -73,7 +73,8 @@
         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)
 
diff --git a/tempest/tests/fake_identity.py b/tempest/tests/fake_identity.py
index 97098e1..ad78f85 100644
--- a/tempest/tests/fake_identity.py
+++ b/tempest/tests/fake_identity.py
@@ -17,6 +17,7 @@
 
 import httplib2
 
+FAKE_AUTH_URL = 'http://fake_uri.com/auth'
 
 TOKEN = "fake_token"
 ALT_TOKEN = "alt_fake_token"
diff --git a/tempest/tests/test_auth.py b/tempest/tests/test_auth.py
index 0317ad6..c236dbe 100644
--- a/tempest/tests/test_auth.py
+++ b/tempest/tests/test_auth.py
@@ -38,11 +38,11 @@
     _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 @@
         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 @@
 
     _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([]))
 
diff --git a/tempest/tests/test_credentials.py b/tempest/tests/test_credentials.py
index 7621f6e..54a3360 100644
--- a/tempest/tests/test_credentials.py
+++ b/tempest/tests/test_credentials.py
@@ -84,7 +84,8 @@
                        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)