Drop client_type for auth module

Client type was designed to allow the auth module to consume
the official keystone client for tests based on the official clients.
Scenario tests have been migrated to tempest client, and CLI tests
are being moved out of tempest, and they don't need an external
auth provider anyways.
There's no need for client_type anymore, removing it.

Change-Id: I6eebd80ea2259b72e8013e65e9a83615f86a3f84
Partially-implemnts: bp/tempest-client-scenarios
This commit is contained in:
Andrea Frittoli 2014-09-25 12:00:19 +01:00
parent 486ede779b
commit 455e84498e
3 changed files with 30 additions and 52 deletions

View File

@ -40,11 +40,9 @@ class AuthProvider(object):
Provide authentication Provide authentication
""" """
def __init__(self, credentials, client_type='tempest', def __init__(self, credentials, interface=None):
interface=None):
""" """
:param credentials: credentials for authentication :param credentials: credentials for authentication
:param client_type: 'tempest' or 'official'
:param interface: 'json' or 'xml'. Applicable for tempest client only :param interface: 'json' or 'xml'. Applicable for tempest client only
""" """
credentials = self._convert_credentials(credentials) credentials = self._convert_credentials(credentials)
@ -52,9 +50,8 @@ class AuthProvider(object):
self.credentials = credentials self.credentials = credentials
else: else:
raise TypeError("Invalid credentials") raise TypeError("Invalid credentials")
self.client_type = client_type
self.interface = interface self.interface = interface
if self.client_type == 'tempest' and self.interface is None: if self.interface is None:
self.interface = 'json' self.interface = 'json'
self.cache = None self.cache = None
self.alt_auth_data = None self.alt_auth_data = None
@ -68,11 +65,10 @@ class AuthProvider(object):
return credentials return credentials
def __str__(self): def __str__(self):
return "Creds :{creds}, client type: {client_type}, interface: " \ return "Creds :{creds}, interface: {interface}, " \
"{interface}, cached auth data: {cache}".format( "cached auth data: {cache}".format(
creds=self.credentials, client_type=self.client_type, creds=self.credentials, interface=self.interface,
interface=self.interface, cache=self.cache cache=self.cache)
)
@abc.abstractmethod @abc.abstractmethod
def _decorate_request(self, filters, method, url, headers=None, body=None, def _decorate_request(self, filters, method, url, headers=None, body=None,
@ -208,9 +204,8 @@ class KeystoneAuthProvider(AuthProvider):
token_expiry_threshold = datetime.timedelta(seconds=60) token_expiry_threshold = datetime.timedelta(seconds=60)
def __init__(self, credentials, client_type='tempest', interface=None): def __init__(self, credentials, interface=None):
super(KeystoneAuthProvider, self).__init__(credentials, client_type, super(KeystoneAuthProvider, self).__init__(credentials, interface)
interface)
self.auth_client = self._auth_client() self.auth_client = self._auth_client()
def _decorate_request(self, filters, method, url, headers=None, body=None, def _decorate_request(self, filters, method, url, headers=None, body=None,
@ -244,15 +239,12 @@ class KeystoneAuthProvider(AuthProvider):
def _get_auth(self): def _get_auth(self):
# Bypasses the cache # Bypasses the cache
if self.client_type == 'tempest': auth_func = getattr(self.auth_client, 'get_token')
auth_func = getattr(self.auth_client, 'get_token') auth_params = self._auth_params()
auth_params = self._auth_params()
# returns token, auth_data # returns token, auth_data
token, auth_data = auth_func(**auth_params) token, auth_data = auth_func(**auth_params)
return token, auth_data return token, auth_data
else:
raise NotImplementedError
def get_token(self): def get_token(self):
return self.auth_data[0] return self.auth_data[0]
@ -263,23 +255,17 @@ 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):
if self.client_type == 'tempest': if self.interface == 'json':
if self.interface == 'json': return json_id.TokenClientJSON()
return json_id.TokenClientJSON()
else:
return xml_id.TokenClientXML()
else: else:
raise NotImplementedError return xml_id.TokenClientXML()
def _auth_params(self): def _auth_params(self):
if self.client_type == 'tempest': return dict(
return dict( user=self.credentials.username,
user=self.credentials.username, password=self.credentials.password,
password=self.credentials.password, tenant=self.credentials.tenant_name,
tenant=self.credentials.tenant_name, auth_data=True)
auth_data=True)
else:
raise NotImplementedError
def _fill_credentials(self, auth_data_body): def _fill_credentials(self, auth_data_body):
tenant = auth_data_body['token']['tenant'] tenant = auth_data_body['token']['tenant']
@ -350,24 +336,18 @@ 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):
if self.client_type == 'tempest': if self.interface == 'json':
if self.interface == 'json': return json_v3id.V3TokenClientJSON()
return json_v3id.V3TokenClientJSON()
else:
return xml_v3id.V3TokenClientXML()
else: else:
raise NotImplementedError return xml_v3id.V3TokenClientXML()
def _auth_params(self): def _auth_params(self):
if self.client_type == 'tempest': return dict(
return dict( user=self.credentials.username,
user=self.credentials.username, password=self.credentials.password,
password=self.credentials.password, tenant=self.credentials.tenant_name,
tenant=self.credentials.tenant_name, domain=self.credentials.user_domain_name,
domain=self.credentials.user_domain_name, auth_data=True)
auth_data=True)
else:
raise NotImplementedError
def _fill_credentials(self, auth_data_body): def _fill_credentials(self, auth_data_body):
# project or domain, depending on the scope # project or domain, depending on the scope

View File

@ -225,7 +225,6 @@ class Manager(manager.Manager):
def __init__(self, credentials=None, interface='json', service=None): def __init__(self, credentials=None, interface='json', service=None):
# Set interface and client type first # Set interface and client type first
self.interface = interface self.interface = interface
self.client_type = 'tempest'
# super cares for credentials validation # super cares for credentials validation
super(Manager, self).__init__(credentials=credentials) super(Manager, self).__init__(credentials=credentials)

View File

@ -63,6 +63,5 @@ class Manager(object):
'Credentials must be specified') 'Credentials must be specified')
auth_provider_class = self.get_auth_provider_class(credentials) auth_provider_class = self.get_auth_provider_class(credentials)
return auth_provider_class( return auth_provider_class(
client_type=getattr(self, 'client_type', None),
interface=getattr(self, 'interface', None), interface=getattr(self, 'interface', None),
credentials=credentials) credentials=credentials)