From 455e84498e959105feeb00f6286376915ccc86b2 Mon Sep 17 00:00:00 2001 From: Andrea Frittoli Date: Thu, 25 Sep 2014 12:00:19 +0100 Subject: [PATCH] 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 --- tempest/auth.py | 80 +++++++++++++++++----------------------------- tempest/clients.py | 1 - tempest/manager.py | 1 - 3 files changed, 30 insertions(+), 52 deletions(-) diff --git a/tempest/auth.py b/tempest/auth.py index c84ad6bb59..b1ead29ade 100644 --- a/tempest/auth.py +++ b/tempest/auth.py @@ -40,11 +40,9 @@ class AuthProvider(object): Provide authentication """ - def __init__(self, credentials, client_type='tempest', - interface=None): + def __init__(self, credentials, interface=None): """ :param credentials: credentials for authentication - :param client_type: 'tempest' or 'official' :param interface: 'json' or 'xml'. Applicable for tempest client only """ credentials = self._convert_credentials(credentials) @@ -52,9 +50,8 @@ class AuthProvider(object): self.credentials = credentials else: raise TypeError("Invalid credentials") - self.client_type = client_type self.interface = interface - if self.client_type == 'tempest' and self.interface is None: + if self.interface is None: self.interface = 'json' self.cache = None self.alt_auth_data = None @@ -68,11 +65,10 @@ class AuthProvider(object): return credentials def __str__(self): - return "Creds :{creds}, client type: {client_type}, interface: " \ - "{interface}, cached auth data: {cache}".format( - creds=self.credentials, client_type=self.client_type, - interface=self.interface, cache=self.cache - ) + return "Creds :{creds}, interface: {interface}, " \ + "cached auth data: {cache}".format( + creds=self.credentials, interface=self.interface, + cache=self.cache) @abc.abstractmethod 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) - def __init__(self, credentials, client_type='tempest', interface=None): - super(KeystoneAuthProvider, self).__init__(credentials, client_type, - interface) + def __init__(self, credentials, interface=None): + super(KeystoneAuthProvider, self).__init__(credentials, interface) self.auth_client = self._auth_client() def _decorate_request(self, filters, method, url, headers=None, body=None, @@ -244,15 +239,12 @@ class KeystoneAuthProvider(AuthProvider): def _get_auth(self): # Bypasses the cache - if self.client_type == 'tempest': - auth_func = getattr(self.auth_client, 'get_token') - auth_params = self._auth_params() + auth_func = getattr(self.auth_client, 'get_token') + auth_params = self._auth_params() - # returns token, auth_data - token, auth_data = auth_func(**auth_params) - return token, auth_data - else: - raise NotImplementedError + # returns token, auth_data + token, auth_data = auth_func(**auth_params) + return token, auth_data def get_token(self): return self.auth_data[0] @@ -263,23 +255,17 @@ class KeystoneV2AuthProvider(KeystoneAuthProvider): EXPIRY_DATE_FORMAT = '%Y-%m-%dT%H:%M:%SZ' def _auth_client(self): - if self.client_type == 'tempest': - if self.interface == 'json': - return json_id.TokenClientJSON() - else: - return xml_id.TokenClientXML() + if self.interface == 'json': + return json_id.TokenClientJSON() else: - raise NotImplementedError + return xml_id.TokenClientXML() def _auth_params(self): - if self.client_type == 'tempest': - return dict( - user=self.credentials.username, - password=self.credentials.password, - tenant=self.credentials.tenant_name, - auth_data=True) - else: - raise NotImplementedError + return dict( + user=self.credentials.username, + password=self.credentials.password, + tenant=self.credentials.tenant_name, + auth_data=True) def _fill_credentials(self, auth_data_body): tenant = auth_data_body['token']['tenant'] @@ -350,24 +336,18 @@ class KeystoneV3AuthProvider(KeystoneAuthProvider): EXPIRY_DATE_FORMAT = '%Y-%m-%dT%H:%M:%S.%fZ' def _auth_client(self): - if self.client_type == 'tempest': - if self.interface == 'json': - return json_v3id.V3TokenClientJSON() - else: - return xml_v3id.V3TokenClientXML() + if self.interface == 'json': + return json_v3id.V3TokenClientJSON() else: - raise NotImplementedError + return xml_v3id.V3TokenClientXML() def _auth_params(self): - if self.client_type == 'tempest': - return dict( - user=self.credentials.username, - password=self.credentials.password, - tenant=self.credentials.tenant_name, - domain=self.credentials.user_domain_name, - auth_data=True) - else: - raise NotImplementedError + return dict( + user=self.credentials.username, + password=self.credentials.password, + tenant=self.credentials.tenant_name, + domain=self.credentials.user_domain_name, + auth_data=True) def _fill_credentials(self, auth_data_body): # project or domain, depending on the scope diff --git a/tempest/clients.py b/tempest/clients.py index 1dda66ace3..2d07852a20 100644 --- a/tempest/clients.py +++ b/tempest/clients.py @@ -225,7 +225,6 @@ class Manager(manager.Manager): def __init__(self, credentials=None, interface='json', service=None): # Set interface and client type first self.interface = interface - self.client_type = 'tempest' # super cares for credentials validation super(Manager, self).__init__(credentials=credentials) diff --git a/tempest/manager.py b/tempest/manager.py index 75aee961e2..538b619fc7 100644 --- a/tempest/manager.py +++ b/tempest/manager.py @@ -63,6 +63,5 @@ class Manager(object): 'Credentials must be specified') auth_provider_class = self.get_auth_provider_class(credentials) return auth_provider_class( - client_type=getattr(self, 'client_type', None), interface=getattr(self, 'interface', None), credentials=credentials)