blob: 63235dbc4c4694dbf8254d2642c1805bbe264416 [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
17from tempest import config
Jay Pipes051075a2012-04-28 17:39:37 -040018from tempest import exceptions
Jay Pipes051075a2012-04-28 17:39:37 -040019
Andrea Frittolif9cde7e2014-02-18 09:57:04 +000020CONF = config.CONF
21
Jay Pipes051075a2012-04-28 17:39:37 -040022
23class Manager(object):
24
25 """
26 Base manager class
27
28 Manager objects are responsible for providing a configuration object
29 and a client object for a test case to use in performing actions.
30 """
31
Andrea Frittolif9cde7e2014-02-18 09:57:04 +000032 def __init__(self, username=None, password=None, tenant_name=None):
33 """
34 We allow overriding of the credentials used within the various
35 client classes managed by the Manager object. Left as None, the
36 standard username/password/tenant_name[/domain_name] is used.
37
38 :param credentials: Override of the credentials
39 """
40 self.auth_version = CONF.identity.auth_version
41 # FIXME(andreaf) Change Manager __init__ to accept a credentials dict
42 if username is None or password is None:
43 # Tenant None is a valid use case
44 self.credentials = self.get_default_credentials()
45 else:
46 self.credentials = dict(username=username, password=password,
47 tenant_name=tenant_name)
48 if self.auth_version == 'v3':
49 self.credentials['domain_name'] = 'Default'
50 # Creates an auth provider for the credentials
51 self.auth_provider = self.get_auth_provider(self.credentials)
52 # FIXME(andreaf) unused
Maru Newbydec13ec2012-08-30 11:19:17 -070053 self.client_attr_names = []
Jay Pipes051075a2012-04-28 17:39:37 -040054
Sean Dague43cd9052013-07-19 12:20:04 -040055 # we do this everywhere, have it be part of the super class
56 def _validate_credentials(self, username, password, tenant_name):
57 if None in (username, password, tenant_name):
58 msg = ("Missing required credentials. "
59 "username: %(u)s, password: %(p)s, "
60 "tenant_name: %(t)s" %
61 {'u': username, 'p': password, 't': tenant_name})
62 raise exceptions.InvalidConfiguration(msg)
Andrea Frittolif9cde7e2014-02-18 09:57:04 +000063
64 @classmethod
65 def get_auth_provider_class(cls, auth_version):
66 if auth_version == 'v2':
67 return auth.KeystoneV2AuthProvider
68 else:
69 return auth.KeystoneV3AuthProvider
70
71 def get_default_credentials(self):
72 return dict(
73 username=CONF.identity.username,
74 password=CONF.identity.password,
75 tenant_name=CONF.identity.tenant_name
76 )
77
Andrea Frittoli3099ffb2014-03-12 18:43:31 +000078 def get_auth_provider(self, credentials):
79 if credentials is None:
80 raise exceptions.InvalidCredentials(
81 'Credentials must be specified')
Andrea Frittolif9cde7e2014-02-18 09:57:04 +000082 auth_provider_class = self.get_auth_provider_class(self.auth_version)
Andrea Frittoli3099ffb2014-03-12 18:43:31 +000083 return auth_provider_class(
84 client_type=getattr(self, 'client_type', None),
85 interface=getattr(self, 'interface', None),
86 credentials=credentials)