From 278463cae0510e7f5e120e542742dcc4c4cf373b Mon Sep 17 00:00:00 2001 From: "Andrea Frittoli (andreaf)" Date: Thu, 8 Oct 2015 15:04:09 +0100 Subject: [PATCH] Prepare cred_client for migration Prepare the cred_client module for migration to tempest-lib, by removing dependencies from config (indirectly via removing dependencies from the credentials module), and also by using tempest-lib only exceptions. Migration to tempest lib canont take place until the idenity clients are migrated to tempest. Change-Id: Iad84f84faff71d1e7d7f4fa06b4e467b1d4b94f0 --- tempest/common/cred_client.py | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/tempest/common/cred_client.py b/tempest/common/cred_client.py index 4d391d00eb..79a502a280 100644 --- a/tempest/common/cred_client.py +++ b/tempest/common/cred_client.py @@ -14,14 +14,11 @@ import abc from oslo_log import log as logging import six +from tempest_lib import auth from tempest_lib import exceptions as lib_exc -from tempest.common import cred_provider -from tempest import config -from tempest import exceptions from tempest.services.identity.v2.json import identity_client as v2_identity -CONF = config.CONF LOG = logging.getLogger(__name__) @@ -36,7 +33,6 @@ class CredsClient(object): def __init__(self, identity_client): # The client implies version and credentials self.identity_client = identity_client - self.credentials = self.identity_client.auth_provider.credentials def create_user(self, username, password, project, email): user = self.identity_client.create_user( @@ -75,6 +71,13 @@ class CredsClient(object): @abc.abstractmethod def get_credentials(self, user, project, password): + """Produces a Credentials object from the details provided + + :param user: a user dict + :param project: a project dict + :param password: the password as a string + :return: a Credentials object with all the available credential details + """ pass def delete_user(self, user_id): @@ -93,7 +96,11 @@ class V2CredsClient(CredsClient): return tenant def get_credentials(self, user, project, password): - return cred_provider.get_credentials( + # User and project already include both ID and name here, + # so there's no need to use the fill_in mode + return auth.get_credentials( + auth_url=None, + fill_in=False, identity_version='v2', username=user['name'], user_id=user['id'], tenant_name=project['name'], tenant_id=project['id'], @@ -114,8 +121,8 @@ class V3CredsClient(CredsClient): params={'name': domain_name})['domains'][0] except lib_exc.NotFound: # TODO(andrea) we could probably create the domain on the fly - msg = "Configured domain %s could not be found" % domain_name - raise exceptions.InvalidConfiguration(msg) + msg = "Requested domain %s could not be found" % domain_name + raise lib_exc.InvalidCredentials(msg) def create_project(self, name, description): project = self.identity_client.create_project( @@ -124,11 +131,16 @@ class V3CredsClient(CredsClient): return project def get_credentials(self, user, project, password): - return cred_provider.get_credentials( + # User, project and domain already include both ID and name here, + # so there's no need to use the fill_in mode. + return auth.get_credentials( + auth_url=None, + fill_in=False, identity_version='v3', username=user['name'], user_id=user['id'], project_name=project['name'], project_id=project['id'], password=password, + project_domain_id=self.creds_domain['id'], project_domain_name=self.creds_domain['name']) def delete_project(self, project_id):