| 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 | 
| lpiwowar | 10a649b | 2021-08-10 15:25:28 +0200 | [diff] [blame] | 16 | from oslo_log import log as logging | 
| Marc Koderer | d2690fe | 2014-07-16 14:17:47 +0200 | [diff] [blame] | 17 |  | 
| Andrea Frittoli (andreaf) | db9672e | 2016-02-23 14:07:24 -0500 | [diff] [blame] | 18 | from tempest.lib import auth | 
| Andrea Frittoli (andreaf) | af4f7cf | 2016-06-13 15:12:26 +0100 | [diff] [blame] | 19 | from tempest.lib import exceptions | 
| Marc Koderer | d2690fe | 2014-07-16 14:17:47 +0200 | [diff] [blame] | 20 |  | 
| lpiwowar | 10a649b | 2021-08-10 15:25:28 +0200 | [diff] [blame] | 21 | LOG = logging.getLogger(__name__) | 
|  | 22 |  | 
| Andrea Frittoli | 878d5ab | 2015-01-30 13:22:50 +0000 | [diff] [blame] | 23 |  | 
| songwenping | 4c3bf8f | 2021-01-05 03:27:09 +0000 | [diff] [blame] | 24 | class CredentialProvider(object, metaclass=abc.ABCMeta): | 
| Andrea Frittoli | dcd9100 | 2017-07-18 11:34:13 +0100 | [diff] [blame] | 25 | def __init__(self, identity_version, name=None, | 
|  | 26 | network_resources=None, credentials_domain=None, | 
|  | 27 | admin_role=None, identity_uri=None): | 
| Andrea Frittoli | c328015 | 2015-02-26 12:42:34 +0000 | [diff] [blame] | 28 | """A CredentialProvider supplies credentials to test classes. | 
| Ken'ichi Ohmichi | cb67d2d | 2015-11-19 08:23:22 +0000 | [diff] [blame] | 29 |  | 
| Andrea Frittoli (andreaf) | 32d0de1 | 2015-10-09 14:43:53 +0100 | [diff] [blame] | 30 | :param identity_version: Identity version of the credentials provided | 
| Ken'ichi Ohmichi | 592eb13 | 2015-07-01 04:08:30 +0000 | [diff] [blame] | 31 | :param name: Name of the calling test. Included in provisioned | 
|  | 32 | credentials when credentials are provisioned on the fly | 
|  | 33 | :param network_resources: Network resources required for the | 
|  | 34 | credentials | 
| Andrea Frittoli (andreaf) | 1eb0496 | 2015-10-09 14:48:06 +0100 | [diff] [blame] | 35 | :param credentials_domain: Domain credentials belong to | 
| Andrea Frittoli (andreaf) | 29491a7 | 2015-10-13 11:24:17 +0100 | [diff] [blame] | 36 | :param admin_role: Name of the role of the admin account | 
| Andrea Frittoli | dcd9100 | 2017-07-18 11:34:13 +0100 | [diff] [blame] | 37 | :param identity_uri: Identity URI of the target cloud. This *must* be | 
|  | 38 | specified for anything to work. | 
| Andrea Frittoli | c328015 | 2015-02-26 12:42:34 +0000 | [diff] [blame] | 39 | """ | 
| Andrea Frittoli (andreaf) | 32d0de1 | 2015-10-09 14:43:53 +0100 | [diff] [blame] | 40 | self.identity_version = identity_version | 
| Andrea Frittoli | dcd9100 | 2017-07-18 11:34:13 +0100 | [diff] [blame] | 41 | self.identity_uri = identity_uri | 
| Andrea Frittoli (andreaf) | 1eb0496 | 2015-10-09 14:48:06 +0100 | [diff] [blame] | 42 | self.name = name or "test_creds" | 
|  | 43 | self.network_resources = network_resources | 
|  | 44 | self.credentials_domain = credentials_domain or 'Default' | 
| Andrea Frittoli (andreaf) | 29491a7 | 2015-10-13 11:24:17 +0100 | [diff] [blame] | 45 | self.admin_role = admin_role | 
| Andrea Frittoli | c328015 | 2015-02-26 12:42:34 +0000 | [diff] [blame] | 46 | if not auth.is_identity_version_supported(self.identity_version): | 
|  | 47 | raise exceptions.InvalidIdentityVersion( | 
|  | 48 | identity_version=self.identity_version) | 
| Marc Koderer | d2690fe | 2014-07-16 14:17:47 +0200 | [diff] [blame] | 49 |  | 
|  | 50 | @abc.abstractmethod | 
|  | 51 | def get_primary_creds(self): | 
|  | 52 | return | 
|  | 53 |  | 
|  | 54 | @abc.abstractmethod | 
|  | 55 | def get_admin_creds(self): | 
|  | 56 | return | 
|  | 57 |  | 
|  | 58 | @abc.abstractmethod | 
|  | 59 | def get_alt_creds(self): | 
|  | 60 | return | 
|  | 61 |  | 
|  | 62 | @abc.abstractmethod | 
| Ghanshyam Mann | 32e0557 | 2021-01-29 11:24:56 -0600 | [diff] [blame] | 63 | def get_system_admin_creds(self): | 
|  | 64 | return | 
|  | 65 |  | 
|  | 66 | @abc.abstractmethod | 
|  | 67 | def get_system_member_creds(self): | 
|  | 68 | return | 
|  | 69 |  | 
|  | 70 | @abc.abstractmethod | 
|  | 71 | def get_system_reader_creds(self): | 
|  | 72 | return | 
|  | 73 |  | 
|  | 74 | @abc.abstractmethod | 
|  | 75 | def get_domain_admin_creds(self): | 
|  | 76 | return | 
|  | 77 |  | 
|  | 78 | @abc.abstractmethod | 
| Markus Hentsch | a0199bf | 2024-07-15 11:22:37 +0200 | [diff] [blame] | 79 | def get_domain_manager_creds(self): | 
|  | 80 | return | 
|  | 81 |  | 
|  | 82 | @abc.abstractmethod | 
| Ghanshyam Mann | 32e0557 | 2021-01-29 11:24:56 -0600 | [diff] [blame] | 83 | def get_domain_member_creds(self): | 
|  | 84 | return | 
|  | 85 |  | 
|  | 86 | @abc.abstractmethod | 
|  | 87 | def get_domain_reader_creds(self): | 
|  | 88 | return | 
|  | 89 |  | 
|  | 90 | @abc.abstractmethod | 
|  | 91 | def get_project_admin_creds(self): | 
|  | 92 | return | 
|  | 93 |  | 
|  | 94 | @abc.abstractmethod | 
| Ghanshyam Mann | 420586c | 2021-01-29 13:23:18 -0600 | [diff] [blame] | 95 | def get_project_alt_admin_creds(self): | 
|  | 96 | return | 
|  | 97 |  | 
|  | 98 | @abc.abstractmethod | 
| Markus Hentsch | a0199bf | 2024-07-15 11:22:37 +0200 | [diff] [blame] | 99 | def get_project_manager_creds(self): | 
|  | 100 | return | 
|  | 101 |  | 
|  | 102 | @abc.abstractmethod | 
| Ghanshyam Mann | 32e0557 | 2021-01-29 11:24:56 -0600 | [diff] [blame] | 103 | def get_project_member_creds(self): | 
|  | 104 | return | 
|  | 105 |  | 
|  | 106 | @abc.abstractmethod | 
| Ghanshyam Mann | 420586c | 2021-01-29 13:23:18 -0600 | [diff] [blame] | 107 | def get_project_alt_member_creds(self): | 
|  | 108 | return | 
|  | 109 |  | 
|  | 110 | @abc.abstractmethod | 
| Ghanshyam Mann | 32e0557 | 2021-01-29 11:24:56 -0600 | [diff] [blame] | 111 | def get_project_reader_creds(self): | 
|  | 112 | return | 
|  | 113 |  | 
|  | 114 | @abc.abstractmethod | 
| Ghanshyam Mann | 420586c | 2021-01-29 13:23:18 -0600 | [diff] [blame] | 115 | def get_project_alt_reader_creds(self): | 
|  | 116 | return | 
|  | 117 |  | 
|  | 118 | @abc.abstractmethod | 
| Andrea Frittoli (andreaf) | 17209bb | 2015-05-22 10:16:57 -0700 | [diff] [blame] | 119 | def clear_creds(self): | 
| Marc Koderer | d2690fe | 2014-07-16 14:17:47 +0200 | [diff] [blame] | 120 | return | 
| Andrea Frittoli | 8283b4e | 2014-07-17 13:28:58 +0100 | [diff] [blame] | 121 |  | 
|  | 122 | @abc.abstractmethod | 
|  | 123 | def is_multi_user(self): | 
|  | 124 | return | 
| Yair Fried | 76488d7 | 2014-10-21 10:13:19 +0300 | [diff] [blame] | 125 |  | 
|  | 126 | @abc.abstractmethod | 
|  | 127 | def is_multi_tenant(self): | 
|  | 128 | return | 
| Matthew Treinish | 976e8df | 2014-12-19 14:21:54 -0500 | [diff] [blame] | 129 |  | 
|  | 130 | @abc.abstractmethod | 
| Ghanshyam Mann | 2d0da04 | 2021-03-05 09:09:30 -0600 | [diff] [blame] | 131 | def get_creds_by_roles(self, roles, force_new=False, scope=None): | 
| Matthew Treinish | 976e8df | 2014-12-19 14:21:54 -0500 | [diff] [blame] | 132 | return | 
| Matthew Treinish | 4a59693 | 2015-03-06 20:37:01 -0500 | [diff] [blame] | 133 |  | 
|  | 134 | @abc.abstractmethod | 
|  | 135 | def is_role_available(self, role): | 
|  | 136 | return | 
| Andrea Frittoli (andreaf) | 9540dfd | 2015-03-25 17:06:50 -0400 | [diff] [blame] | 137 |  | 
| lpiwowar | 10a649b | 2021-08-10 15:25:28 +0200 | [diff] [blame] | 138 | def cleanup_default_secgroup(self, security_group_client, tenant): | 
|  | 139 | resp_body = security_group_client.list_security_groups( | 
|  | 140 | tenant_id=tenant, | 
|  | 141 | name="default") | 
|  | 142 | secgroups_to_delete = resp_body['security_groups'] | 
|  | 143 | for secgroup in secgroups_to_delete: | 
|  | 144 | try: | 
|  | 145 | security_group_client.delete_security_group(secgroup['id']) | 
|  | 146 | except exceptions.NotFound: | 
|  | 147 | LOG.warning('Security group %s, id %s not found for clean-up', | 
|  | 148 | secgroup['name'], secgroup['id']) | 
|  | 149 |  | 
| Andrea Frittoli (andreaf) | 9540dfd | 2015-03-25 17:06:50 -0400 | [diff] [blame] | 150 |  | 
|  | 151 | class TestResources(object): | 
|  | 152 | """Readonly Credentials, with network resources added.""" | 
|  | 153 |  | 
|  | 154 | def __init__(self, credentials): | 
|  | 155 | self._credentials = credentials | 
|  | 156 | self.network = None | 
|  | 157 | self.subnet = None | 
|  | 158 | self.router = None | 
|  | 159 |  | 
|  | 160 | def __getattr__(self, item): | 
|  | 161 | return getattr(self._credentials, item) | 
|  | 162 |  | 
| Andrea Frittoli (andreaf) | a1edb2d | 2016-05-10 16:09:59 +0100 | [diff] [blame] | 163 | def __str__(self): | 
|  | 164 | _format = "Credentials: %s, Network: %s, Subnet: %s, Router: %s" | 
|  | 165 | return _format % (self._credentials, self.network, self.subnet, | 
|  | 166 | self.router) | 
|  | 167 |  | 
| Andrea Frittoli (andreaf) | 9540dfd | 2015-03-25 17:06:50 -0400 | [diff] [blame] | 168 | def set_resources(self, **kwargs): | 
| Joe H. Rahme | a72f2c6 | 2016-07-11 16:28:19 +0200 | [diff] [blame] | 169 | for key in kwargs: | 
| Andrea Frittoli (andreaf) | 9540dfd | 2015-03-25 17:06:50 -0400 | [diff] [blame] | 170 | if hasattr(self, key): | 
|  | 171 | setattr(self, key, kwargs[key]) | 
|  | 172 |  | 
|  | 173 | @property | 
|  | 174 | def credentials(self): | 
|  | 175 | return self._credentials |