blob: b0541e8e597aa0c66c7037fa3d7134dde4305c8f [file] [log] [blame]
ZhiQiang Fan39f97222013-09-20 04:49:44 +08001# Copyright 2012 OpenStack Foundation
Jay Pipes051075a2012-04-28 17:39:37 -04002# All Rights Reserved.
3#
4# Licensed under the Apache License, Version 2.0 (the "License"); you may
5# not use this file except in compliance with the License. You may obtain
6# a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13# License for the specific language governing permissions and limitations
14# under the License.
15
andreafb8a52282015-03-19 22:21:54 +000016from tempest_lib import auth
17
Andrea Frittoli9efbe952015-01-29 12:43:09 +000018from tempest.common import cred_provider
Andrea Frittolif9cde7e2014-02-18 09:57:04 +000019from tempest import config
Jay Pipes051075a2012-04-28 17:39:37 -040020from tempest import exceptions
Jay Pipes051075a2012-04-28 17:39:37 -040021
Andrea Frittolif9cde7e2014-02-18 09:57:04 +000022CONF = config.CONF
23
Jay Pipes051075a2012-04-28 17:39:37 -040024
25class Manager(object):
26
27 """
28 Base manager class
29
30 Manager objects are responsible for providing a configuration object
31 and a client object for a test case to use in performing actions.
32 """
33
Andrea Frittoli (andreaf)290b3e12015-10-08 10:25:02 +010034 def __init__(self, credentials):
Andrea Frittolif9cde7e2014-02-18 09:57:04 +000035 """
Andrea Frittoli (andreaf)290b3e12015-10-08 10:25:02 +010036 Credentials to be used within the various client classes managed by the
37 Manager object must be defined.
Andrea Frittolif9cde7e2014-02-18 09:57:04 +000038
Andrea Frittoli (andreaf)290b3e12015-10-08 10:25:02 +010039 :param credentials: type Credentials or TestResources
Andrea Frittolif9cde7e2014-02-18 09:57:04 +000040 """
Andrea Frittoli (andreaf)290b3e12015-10-08 10:25:02 +010041 self.credentials = credentials
Andrea Frittoli422fbdf2014-03-20 10:05:18 +000042 # Check if passed or default credentials are valid
43 if not self.credentials.is_valid():
44 raise exceptions.InvalidCredentials()
Andrea Frittoli (andreaf)290b3e12015-10-08 10:25:02 +010045 self.auth_version = CONF.identity.auth_version
Andrea Frittoli (andreaf)f9e01262015-05-22 10:24:12 -070046 # Tenant isolation creates TestResources, but
47 # PreProvisionedCredentialProvider and some tests create Credentials
Andrea Frittoli (andreaf)9540dfd2015-03-25 17:06:50 -040048 if isinstance(credentials, cred_provider.TestResources):
49 creds = self.credentials.credentials
50 else:
51 creds = self.credentials
Andrea Frittolif9cde7e2014-02-18 09:57:04 +000052 # Creates an auth provider for the credentials
Andrea Frittoli (andreaf)c625bcf2015-10-09 12:09:05 +010053 self.auth_provider = get_auth_provider(creds, pre_auth=True)
Andrea Frittolif9cde7e2014-02-18 09:57:04 +000054 # FIXME(andreaf) unused
Maru Newbydec13ec2012-08-30 11:19:17 -070055 self.client_attr_names = []
Jay Pipes051075a2012-04-28 17:39:37 -040056
Andrea Frittolif9cde7e2014-02-18 09:57:04 +000057
Andrea Frittoli90012352015-02-25 21:58:02 +000058def get_auth_provider_class(credentials):
59 if isinstance(credentials, auth.KeystoneV3Credentials):
60 return auth.KeystoneV3AuthProvider, CONF.identity.uri_v3
61 else:
62 return auth.KeystoneV2AuthProvider, CONF.identity.uri
63
64
Andrea Frittoli (andreaf)c625bcf2015-10-09 12:09:05 +010065def get_auth_provider(credentials, pre_auth=False):
Andrea Frittoli90012352015-02-25 21:58:02 +000066 default_params = {
67 'disable_ssl_certificate_validation':
68 CONF.identity.disable_ssl_certificate_validation,
69 'ca_certs': CONF.identity.ca_certificates_file,
70 'trace_requests': CONF.debug.trace_requests
71 }
72 if credentials is None:
73 raise exceptions.InvalidCredentials(
74 'Credentials must be specified')
75 auth_provider_class, auth_url = get_auth_provider_class(
76 credentials)
Andrea Frittoli (andreaf)c625bcf2015-10-09 12:09:05 +010077 _auth_provider = auth_provider_class(credentials, auth_url,
78 **default_params)
79 if pre_auth:
80 _auth_provider.set_auth()
81 return _auth_provider