Andrea Frittoli | 8283b4e | 2014-07-17 13:28:58 +0100 | [diff] [blame] | 1 | # Copyright (c) 2014 Deutsche Telekom AG |
| 2 | # Copyright (c) 2014 Hewlett-Packard Development Company, L.P. |
Marc Koderer | d2690fe | 2014-07-16 14:17:47 +0200 | [diff] [blame] | 3 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | # you may not use this file except in compliance with the License. |
| 5 | # You may obtain a copy of the License at |
| 6 | # |
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | # See the License for the specific language governing permissions and |
| 13 | # limitations under the License. |
| 14 | |
| 15 | import abc |
Matthew Treinish | 96e9e88 | 2014-06-09 18:37:19 -0400 | [diff] [blame] | 16 | |
Marc Koderer | d2690fe | 2014-07-16 14:17:47 +0200 | [diff] [blame] | 17 | import six |
| 18 | |
Andrea Frittoli (andreaf) | db9672e | 2016-02-23 14:07:24 -0500 | [diff] [blame] | 19 | from tempest.lib import auth |
Andrea Frittoli (andreaf) | af4f7cf | 2016-06-13 15:12:26 +0100 | [diff] [blame] | 20 | from tempest.lib import exceptions |
Marc Koderer | d2690fe | 2014-07-16 14:17:47 +0200 | [diff] [blame] | 21 | |
Andrea Frittoli | 878d5ab | 2015-01-30 13:22:50 +0000 | [diff] [blame] | 22 | |
Marc Koderer | d2690fe | 2014-07-16 14:17:47 +0200 | [diff] [blame] | 23 | @six.add_metaclass(abc.ABCMeta) |
| 24 | class CredentialProvider(object): |
Andrea Frittoli (andreaf) | 1eb0496 | 2015-10-09 14:48:06 +0100 | [diff] [blame] | 25 | def __init__(self, identity_version, name=None, network_resources=None, |
Andrea Frittoli (andreaf) | 29491a7 | 2015-10-13 11:24:17 +0100 | [diff] [blame] | 26 | credentials_domain=None, admin_role=None): |
Andrea Frittoli | c328015 | 2015-02-26 12:42:34 +0000 | [diff] [blame] | 27 | """A CredentialProvider supplies credentials to test classes. |
Ken'ichi Ohmichi | cb67d2d | 2015-11-19 08:23:22 +0000 | [diff] [blame] | 28 | |
Andrea Frittoli (andreaf) | 32d0de1 | 2015-10-09 14:43:53 +0100 | [diff] [blame] | 29 | :param identity_version: Identity version of the credentials provided |
Ken'ichi Ohmichi | 592eb13 | 2015-07-01 04:08:30 +0000 | [diff] [blame] | 30 | :param name: Name of the calling test. Included in provisioned |
| 31 | credentials when credentials are provisioned on the fly |
| 32 | :param network_resources: Network resources required for the |
| 33 | credentials |
Andrea Frittoli (andreaf) | 1eb0496 | 2015-10-09 14:48:06 +0100 | [diff] [blame] | 34 | :param credentials_domain: Domain credentials belong to |
Andrea Frittoli (andreaf) | 29491a7 | 2015-10-13 11:24:17 +0100 | [diff] [blame] | 35 | :param admin_role: Name of the role of the admin account |
Andrea Frittoli | c328015 | 2015-02-26 12:42:34 +0000 | [diff] [blame] | 36 | """ |
Andrea Frittoli (andreaf) | 32d0de1 | 2015-10-09 14:43:53 +0100 | [diff] [blame] | 37 | self.identity_version = identity_version |
Andrea Frittoli (andreaf) | 1eb0496 | 2015-10-09 14:48:06 +0100 | [diff] [blame] | 38 | self.name = name or "test_creds" |
| 39 | self.network_resources = network_resources |
| 40 | self.credentials_domain = credentials_domain or 'Default' |
Andrea Frittoli (andreaf) | 29491a7 | 2015-10-13 11:24:17 +0100 | [diff] [blame] | 41 | self.admin_role = admin_role |
Andrea Frittoli | c328015 | 2015-02-26 12:42:34 +0000 | [diff] [blame] | 42 | if not auth.is_identity_version_supported(self.identity_version): |
| 43 | raise exceptions.InvalidIdentityVersion( |
| 44 | identity_version=self.identity_version) |
Marc Koderer | d2690fe | 2014-07-16 14:17:47 +0200 | [diff] [blame] | 45 | |
| 46 | @abc.abstractmethod |
| 47 | def get_primary_creds(self): |
| 48 | return |
| 49 | |
| 50 | @abc.abstractmethod |
| 51 | def get_admin_creds(self): |
| 52 | return |
| 53 | |
| 54 | @abc.abstractmethod |
| 55 | def get_alt_creds(self): |
| 56 | return |
| 57 | |
| 58 | @abc.abstractmethod |
Andrea Frittoli (andreaf) | 17209bb | 2015-05-22 10:16:57 -0700 | [diff] [blame] | 59 | def clear_creds(self): |
Marc Koderer | d2690fe | 2014-07-16 14:17:47 +0200 | [diff] [blame] | 60 | return |
Andrea Frittoli | 8283b4e | 2014-07-17 13:28:58 +0100 | [diff] [blame] | 61 | |
| 62 | @abc.abstractmethod |
| 63 | def is_multi_user(self): |
| 64 | return |
Yair Fried | 76488d7 | 2014-10-21 10:13:19 +0300 | [diff] [blame] | 65 | |
| 66 | @abc.abstractmethod |
| 67 | def is_multi_tenant(self): |
| 68 | return |
Matthew Treinish | 976e8df | 2014-12-19 14:21:54 -0500 | [diff] [blame] | 69 | |
| 70 | @abc.abstractmethod |
| 71 | def get_creds_by_roles(self, roles, force_new=False): |
| 72 | return |
Matthew Treinish | 4a59693 | 2015-03-06 20:37:01 -0500 | [diff] [blame] | 73 | |
| 74 | @abc.abstractmethod |
| 75 | def is_role_available(self, role): |
| 76 | return |
Andrea Frittoli (andreaf) | 9540dfd | 2015-03-25 17:06:50 -0400 | [diff] [blame] | 77 | |
| 78 | |
| 79 | class TestResources(object): |
| 80 | """Readonly Credentials, with network resources added.""" |
| 81 | |
| 82 | def __init__(self, credentials): |
| 83 | self._credentials = credentials |
| 84 | self.network = None |
| 85 | self.subnet = None |
| 86 | self.router = None |
| 87 | |
| 88 | def __getattr__(self, item): |
| 89 | return getattr(self._credentials, item) |
| 90 | |
Andrea Frittoli (andreaf) | a1edb2d | 2016-05-10 16:09:59 +0100 | [diff] [blame] | 91 | def __str__(self): |
| 92 | _format = "Credentials: %s, Network: %s, Subnet: %s, Router: %s" |
| 93 | return _format % (self._credentials, self.network, self.subnet, |
| 94 | self.router) |
| 95 | |
Andrea Frittoli (andreaf) | 9540dfd | 2015-03-25 17:06:50 -0400 | [diff] [blame] | 96 | def set_resources(self, **kwargs): |
Joe H. Rahme | a72f2c6 | 2016-07-11 16:28:19 +0200 | [diff] [blame] | 97 | for key in kwargs: |
Andrea Frittoli (andreaf) | 9540dfd | 2015-03-25 17:06:50 -0400 | [diff] [blame] | 98 | if hasattr(self, key): |
| 99 | setattr(self, key, kwargs[key]) |
| 100 | |
| 101 | @property |
| 102 | def credentials(self): |
| 103 | return self._credentials |