blob: c39d3e5d1cd8f6a97619bbe6f7e36679020dca96 [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 Frittoli422fbdf2014-03-20 10:05:18 +000034 def __init__(self, credentials=None):
Andrea Frittolif9cde7e2014-02-18 09:57:04 +000035 """
36 We allow overriding of the credentials used within the various
37 client classes managed by the Manager object. Left as None, the
38 standard username/password/tenant_name[/domain_name] is used.
39
40 :param credentials: Override of the credentials
41 """
42 self.auth_version = CONF.identity.auth_version
Andrea Frittoli422fbdf2014-03-20 10:05:18 +000043 if credentials is None:
Andrea Frittoli9efbe952015-01-29 12:43:09 +000044 self.credentials = cred_provider.get_configured_credentials('user')
Andrea Frittolif9cde7e2014-02-18 09:57:04 +000045 else:
Andrea Frittoli422fbdf2014-03-20 10:05:18 +000046 self.credentials = credentials
47 # Check if passed or default credentials are valid
48 if not self.credentials.is_valid():
49 raise exceptions.InvalidCredentials()
Andrea Frittoli (andreaf)9540dfd2015-03-25 17:06:50 -040050 # Tenant isolation creates TestResources, but Accounts and some tests
51 # creates Credentials
52 if isinstance(credentials, cred_provider.TestResources):
53 creds = self.credentials.credentials
54 else:
55 creds = self.credentials
Andrea Frittolif9cde7e2014-02-18 09:57:04 +000056 # Creates an auth provider for the credentials
Andrea Frittoli (andreaf)9540dfd2015-03-25 17:06:50 -040057 self.auth_provider = get_auth_provider(creds)
Andrea Frittolif9cde7e2014-02-18 09:57:04 +000058 # FIXME(andreaf) unused
Maru Newbydec13ec2012-08-30 11:19:17 -070059 self.client_attr_names = []
Jay Pipes051075a2012-04-28 17:39:37 -040060
Andrea Frittolif9cde7e2014-02-18 09:57:04 +000061
Andrea Frittoli90012352015-02-25 21:58:02 +000062def get_auth_provider_class(credentials):
63 if isinstance(credentials, auth.KeystoneV3Credentials):
64 return auth.KeystoneV3AuthProvider, CONF.identity.uri_v3
65 else:
66 return auth.KeystoneV2AuthProvider, CONF.identity.uri
67
68
69def get_auth_provider(credentials):
70 default_params = {
71 'disable_ssl_certificate_validation':
72 CONF.identity.disable_ssl_certificate_validation,
73 'ca_certs': CONF.identity.ca_certificates_file,
74 'trace_requests': CONF.debug.trace_requests
75 }
76 if credentials is None:
77 raise exceptions.InvalidCredentials(
78 'Credentials must be specified')
79 auth_provider_class, auth_url = get_auth_provider_class(
80 credentials)
81 return auth_provider_class(credentials, auth_url, **default_params)