ZhiQiang Fan | 39f9722 | 2013-09-20 04:49:44 +0800 | [diff] [blame] | 1 | # Copyright 2012 OpenStack Foundation |
Jay Pipes | 051075a | 2012-04-28 17:39:37 -0400 | [diff] [blame] | 2 | # 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 Frittoli | f9cde7e | 2014-02-18 09:57:04 +0000 | [diff] [blame] | 16 | from tempest import auth |
| 17 | from tempest import config |
Jay Pipes | 051075a | 2012-04-28 17:39:37 -0400 | [diff] [blame] | 18 | from tempest import exceptions |
Jay Pipes | 051075a | 2012-04-28 17:39:37 -0400 | [diff] [blame] | 19 | |
Andrea Frittoli | f9cde7e | 2014-02-18 09:57:04 +0000 | [diff] [blame] | 20 | CONF = config.CONF |
| 21 | |
Jay Pipes | 051075a | 2012-04-28 17:39:37 -0400 | [diff] [blame] | 22 | |
| 23 | class 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 Frittoli | 422fbdf | 2014-03-20 10:05:18 +0000 | [diff] [blame] | 32 | def __init__(self, credentials=None): |
Andrea Frittoli | f9cde7e | 2014-02-18 09:57:04 +0000 | [diff] [blame] | 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 |
Andrea Frittoli | 422fbdf | 2014-03-20 10:05:18 +0000 | [diff] [blame] | 41 | if credentials is None: |
| 42 | self.credentials = auth.get_default_credentials('user') |
Andrea Frittoli | f9cde7e | 2014-02-18 09:57:04 +0000 | [diff] [blame] | 43 | else: |
Andrea Frittoli | 422fbdf | 2014-03-20 10:05:18 +0000 | [diff] [blame] | 44 | self.credentials = credentials |
| 45 | # Check if passed or default credentials are valid |
| 46 | if not self.credentials.is_valid(): |
| 47 | raise exceptions.InvalidCredentials() |
Andrea Frittoli | f9cde7e | 2014-02-18 09:57:04 +0000 | [diff] [blame] | 48 | # Creates an auth provider for the credentials |
| 49 | self.auth_provider = self.get_auth_provider(self.credentials) |
| 50 | # FIXME(andreaf) unused |
Maru Newby | dec13ec | 2012-08-30 11:19:17 -0700 | [diff] [blame] | 51 | self.client_attr_names = [] |
Jay Pipes | 051075a | 2012-04-28 17:39:37 -0400 | [diff] [blame] | 52 | |
Andrea Frittoli | f9cde7e | 2014-02-18 09:57:04 +0000 | [diff] [blame] | 53 | @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 Frittoli | 3099ffb | 2014-03-12 18:43:31 +0000 | [diff] [blame] | 60 | def get_auth_provider(self, credentials): |
| 61 | if credentials is None: |
| 62 | raise exceptions.InvalidCredentials( |
| 63 | 'Credentials must be specified') |
Andrea Frittoli | f9cde7e | 2014-02-18 09:57:04 +0000 | [diff] [blame] | 64 | auth_provider_class = self.get_auth_provider_class(self.auth_version) |
Andrea Frittoli | 3099ffb | 2014-03-12 18:43:31 +0000 | [diff] [blame] | 65 | return auth_provider_class( |
| 66 | client_type=getattr(self, 'client_type', None), |
| 67 | interface=getattr(self, 'interface', None), |
| 68 | credentials=credentials) |