blob: a256f255a2fdc0a0bf737ec0fcb7ae0b0f53b085 [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
Andrea Frittolif9cde7e2014-02-18 09:57:04 +000016from tempest import auth
Andrea Frittoli9efbe952015-01-29 12:43:09 +000017from tempest.common import cred_provider
Andrea Frittolif9cde7e2014-02-18 09:57:04 +000018from tempest import config
Jay Pipes051075a2012-04-28 17:39:37 -040019from tempest import exceptions
Jay Pipes051075a2012-04-28 17:39:37 -040020
Andrea Frittolif9cde7e2014-02-18 09:57:04 +000021CONF = config.CONF
22
Jay Pipes051075a2012-04-28 17:39:37 -040023
24class Manager(object):
25
26 """
27 Base manager class
28
29 Manager objects are responsible for providing a configuration object
30 and a client object for a test case to use in performing actions.
31 """
32
Andrea Frittoli422fbdf2014-03-20 10:05:18 +000033 def __init__(self, credentials=None):
Andrea Frittolif9cde7e2014-02-18 09:57:04 +000034 """
35 We allow overriding of the credentials used within the various
36 client classes managed by the Manager object. Left as None, the
37 standard username/password/tenant_name[/domain_name] is used.
38
39 :param credentials: Override of the credentials
40 """
41 self.auth_version = CONF.identity.auth_version
Andrea Frittoli422fbdf2014-03-20 10:05:18 +000042 if credentials is None:
Andrea Frittoli9efbe952015-01-29 12:43:09 +000043 self.credentials = cred_provider.get_configured_credentials('user')
Andrea Frittolif9cde7e2014-02-18 09:57:04 +000044 else:
Andrea Frittoli422fbdf2014-03-20 10:05:18 +000045 self.credentials = credentials
46 # Check if passed or default credentials are valid
47 if not self.credentials.is_valid():
48 raise exceptions.InvalidCredentials()
Andrea Frittolif9cde7e2014-02-18 09:57:04 +000049 # Creates an auth provider for the credentials
Andrea Frittoli90012352015-02-25 21:58:02 +000050 self.auth_provider = get_auth_provider(self.credentials)
Andrea Frittolif9cde7e2014-02-18 09:57:04 +000051 # FIXME(andreaf) unused
Maru Newbydec13ec2012-08-30 11:19:17 -070052 self.client_attr_names = []
Jay Pipes051075a2012-04-28 17:39:37 -040053
Andrea Frittolif9cde7e2014-02-18 09:57:04 +000054
Andrea Frittoli90012352015-02-25 21:58:02 +000055def get_auth_provider_class(credentials):
56 if isinstance(credentials, auth.KeystoneV3Credentials):
57 return auth.KeystoneV3AuthProvider, CONF.identity.uri_v3
58 else:
59 return auth.KeystoneV2AuthProvider, CONF.identity.uri
60
61
62def get_auth_provider(credentials):
63 default_params = {
64 'disable_ssl_certificate_validation':
65 CONF.identity.disable_ssl_certificate_validation,
66 'ca_certs': CONF.identity.ca_certificates_file,
67 'trace_requests': CONF.debug.trace_requests
68 }
69 if credentials is None:
70 raise exceptions.InvalidCredentials(
71 'Credentials must be specified')
72 auth_provider_class, auth_url = get_auth_provider_class(
73 credentials)
74 return auth_provider_class(credentials, auth_url, **default_params)