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 |
Andrea Frittoli | 9efbe95 | 2015-01-29 12:43:09 +0000 | [diff] [blame] | 17 | from tempest.common import cred_provider |
Andrea Frittoli | f9cde7e | 2014-02-18 09:57:04 +0000 | [diff] [blame] | 18 | from tempest import config |
Jay Pipes | 051075a | 2012-04-28 17:39:37 -0400 | [diff] [blame] | 19 | from tempest import exceptions |
Jay Pipes | 051075a | 2012-04-28 17:39:37 -0400 | [diff] [blame] | 20 | |
Andrea Frittoli | f9cde7e | 2014-02-18 09:57:04 +0000 | [diff] [blame] | 21 | CONF = config.CONF |
| 22 | |
Jay Pipes | 051075a | 2012-04-28 17:39:37 -0400 | [diff] [blame] | 23 | |
| 24 | class 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 Frittoli | 422fbdf | 2014-03-20 10:05:18 +0000 | [diff] [blame] | 33 | def __init__(self, credentials=None): |
Andrea Frittoli | f9cde7e | 2014-02-18 09:57:04 +0000 | [diff] [blame] | 34 | """ |
| 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 Frittoli | 422fbdf | 2014-03-20 10:05:18 +0000 | [diff] [blame] | 42 | if credentials is None: |
Andrea Frittoli | 9efbe95 | 2015-01-29 12:43:09 +0000 | [diff] [blame] | 43 | self.credentials = cred_provider.get_configured_credentials('user') |
Andrea Frittoli | f9cde7e | 2014-02-18 09:57:04 +0000 | [diff] [blame] | 44 | else: |
Andrea Frittoli | 422fbdf | 2014-03-20 10:05:18 +0000 | [diff] [blame] | 45 | self.credentials = credentials |
| 46 | # Check if passed or default credentials are valid |
| 47 | if not self.credentials.is_valid(): |
| 48 | raise exceptions.InvalidCredentials() |
Andrea Frittoli (andreaf) | 9540dfd | 2015-03-25 17:06:50 -0400 | [diff] [blame] | 49 | # Tenant isolation creates TestResources, but Accounts and some tests |
| 50 | # creates Credentials |
| 51 | if isinstance(credentials, cred_provider.TestResources): |
| 52 | creds = self.credentials.credentials |
| 53 | else: |
| 54 | creds = self.credentials |
Andrea Frittoli | f9cde7e | 2014-02-18 09:57:04 +0000 | [diff] [blame] | 55 | # Creates an auth provider for the credentials |
Andrea Frittoli (andreaf) | 9540dfd | 2015-03-25 17:06:50 -0400 | [diff] [blame] | 56 | self.auth_provider = get_auth_provider(creds) |
Andrea Frittoli | f9cde7e | 2014-02-18 09:57:04 +0000 | [diff] [blame] | 57 | # FIXME(andreaf) unused |
Maru Newby | dec13ec | 2012-08-30 11:19:17 -0700 | [diff] [blame] | 58 | self.client_attr_names = [] |
Jay Pipes | 051075a | 2012-04-28 17:39:37 -0400 | [diff] [blame] | 59 | |
Andrea Frittoli | f9cde7e | 2014-02-18 09:57:04 +0000 | [diff] [blame] | 60 | |
Andrea Frittoli | 9001235 | 2015-02-25 21:58:02 +0000 | [diff] [blame] | 61 | def get_auth_provider_class(credentials): |
| 62 | if isinstance(credentials, auth.KeystoneV3Credentials): |
| 63 | return auth.KeystoneV3AuthProvider, CONF.identity.uri_v3 |
| 64 | else: |
| 65 | return auth.KeystoneV2AuthProvider, CONF.identity.uri |
| 66 | |
| 67 | |
| 68 | def get_auth_provider(credentials): |
| 69 | default_params = { |
| 70 | 'disable_ssl_certificate_validation': |
| 71 | CONF.identity.disable_ssl_certificate_validation, |
| 72 | 'ca_certs': CONF.identity.ca_certificates_file, |
| 73 | 'trace_requests': CONF.debug.trace_requests |
| 74 | } |
| 75 | if credentials is None: |
| 76 | raise exceptions.InvalidCredentials( |
| 77 | 'Credentials must be specified') |
| 78 | auth_provider_class, auth_url = get_auth_provider_class( |
| 79 | credentials) |
| 80 | return auth_provider_class(credentials, auth_url, **default_params) |