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
This commit is contained in:
parent
9c79845e58
commit
278463cae0
@ -14,14 +14,11 @@ import abc
|
|||||||
|
|
||||||
from oslo_log import log as logging
|
from oslo_log import log as logging
|
||||||
import six
|
import six
|
||||||
|
from tempest_lib import auth
|
||||||
from tempest_lib import exceptions as lib_exc
|
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
|
from tempest.services.identity.v2.json import identity_client as v2_identity
|
||||||
|
|
||||||
CONF = config.CONF
|
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
@ -36,7 +33,6 @@ class CredsClient(object):
|
|||||||
def __init__(self, identity_client):
|
def __init__(self, identity_client):
|
||||||
# The client implies version and credentials
|
# The client implies version and credentials
|
||||||
self.identity_client = identity_client
|
self.identity_client = identity_client
|
||||||
self.credentials = self.identity_client.auth_provider.credentials
|
|
||||||
|
|
||||||
def create_user(self, username, password, project, email):
|
def create_user(self, username, password, project, email):
|
||||||
user = self.identity_client.create_user(
|
user = self.identity_client.create_user(
|
||||||
@ -75,6 +71,13 @@ class CredsClient(object):
|
|||||||
|
|
||||||
@abc.abstractmethod
|
@abc.abstractmethod
|
||||||
def get_credentials(self, user, project, password):
|
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
|
pass
|
||||||
|
|
||||||
def delete_user(self, user_id):
|
def delete_user(self, user_id):
|
||||||
@ -93,7 +96,11 @@ class V2CredsClient(CredsClient):
|
|||||||
return tenant
|
return tenant
|
||||||
|
|
||||||
def get_credentials(self, user, project, password):
|
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',
|
identity_version='v2',
|
||||||
username=user['name'], user_id=user['id'],
|
username=user['name'], user_id=user['id'],
|
||||||
tenant_name=project['name'], tenant_id=project['id'],
|
tenant_name=project['name'], tenant_id=project['id'],
|
||||||
@ -114,8 +121,8 @@ class V3CredsClient(CredsClient):
|
|||||||
params={'name': domain_name})['domains'][0]
|
params={'name': domain_name})['domains'][0]
|
||||||
except lib_exc.NotFound:
|
except lib_exc.NotFound:
|
||||||
# TODO(andrea) we could probably create the domain on the fly
|
# TODO(andrea) we could probably create the domain on the fly
|
||||||
msg = "Configured domain %s could not be found" % domain_name
|
msg = "Requested domain %s could not be found" % domain_name
|
||||||
raise exceptions.InvalidConfiguration(msg)
|
raise lib_exc.InvalidCredentials(msg)
|
||||||
|
|
||||||
def create_project(self, name, description):
|
def create_project(self, name, description):
|
||||||
project = self.identity_client.create_project(
|
project = self.identity_client.create_project(
|
||||||
@ -124,11 +131,16 @@ class V3CredsClient(CredsClient):
|
|||||||
return project
|
return project
|
||||||
|
|
||||||
def get_credentials(self, user, project, password):
|
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',
|
identity_version='v3',
|
||||||
username=user['name'], user_id=user['id'],
|
username=user['name'], user_id=user['id'],
|
||||||
project_name=project['name'], project_id=project['id'],
|
project_name=project['name'], project_id=project['id'],
|
||||||
password=password,
|
password=password,
|
||||||
|
project_domain_id=self.creds_domain['id'],
|
||||||
project_domain_name=self.creds_domain['name'])
|
project_domain_name=self.creds_domain['name'])
|
||||||
|
|
||||||
def delete_project(self, project_id):
|
def delete_project(self, project_id):
|
||||||
|
Loading…
Reference in New Issue
Block a user