blob: fb2842f5391cdc43957a66c5da2e37973d1991bf [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 Frittoli422fbdf2014-03-20 10:05:18 +000032 def __init__(self, credentials=None):
Andrea Frittolif9cde7e2014-02-18 09:57:04 +000033 """
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
Andrea Frittoli422fbdf2014-03-20 10:05:18 +000041 if credentials is None:
42 self.credentials = auth.get_default_credentials('user')
Andrea Frittolif9cde7e2014-02-18 09:57:04 +000043 else:
Andrea Frittoli422fbdf2014-03-20 10:05:18 +000044 self.credentials = credentials
45 # Check if passed or default credentials are valid
46 if not self.credentials.is_valid():
47 raise exceptions.InvalidCredentials()
Andrea Frittolif9cde7e2014-02-18 09:57:04 +000048 # Creates an auth provider for the credentials
49 self.auth_provider = self.get_auth_provider(self.credentials)
50 # FIXME(andreaf) unused
Maru Newbydec13ec2012-08-30 11:19:17 -070051 self.client_attr_names = []
Jay Pipes051075a2012-04-28 17:39:37 -040052
Andrea Frittolif9cde7e2014-02-18 09:57:04 +000053 @classmethod
54 def get_auth_provider_class(cls, auth_version):
55 if auth_version == 'v2':
56 return auth.KeystoneV2AuthProvider
57 else:
58 return auth.KeystoneV3AuthProvider
59
Andrea Frittoli3099ffb2014-03-12 18:43:31 +000060 def get_auth_provider(self, credentials):
61 if credentials is None:
62 raise exceptions.InvalidCredentials(
63 'Credentials must be specified')
Andrea Frittolif9cde7e2014-02-18 09:57:04 +000064 auth_provider_class = self.get_auth_provider_class(self.auth_version)
Andrea Frittoli3099ffb2014-03-12 18:43:31 +000065 return auth_provider_class(
66 client_type=getattr(self, 'client_type', None),
67 interface=getattr(self, 'interface', None),
68 credentials=credentials)