blob: 93b9586ee5da925eed17a31b8769f03b3f4b50b6 [file] [log] [blame]
Andrea Frittoli8283b4e2014-07-17 13:28:58 +01001# Copyright (c) 2014 Deutsche Telekom AG
2# Copyright (c) 2014 Hewlett-Packard Development Company, L.P.
Marc Kodererd2690fe2014-07-16 14:17:47 +02003# 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
15import abc
lpiwowar10a649b2021-08-10 15:25:28 +020016from oslo_log import log as logging
Marc Kodererd2690fe2014-07-16 14:17:47 +020017
Andrea Frittoli (andreaf)db9672e2016-02-23 14:07:24 -050018from tempest.lib import auth
Andrea Frittoli (andreaf)af4f7cf2016-06-13 15:12:26 +010019from tempest.lib import exceptions
Marc Kodererd2690fe2014-07-16 14:17:47 +020020
lpiwowar10a649b2021-08-10 15:25:28 +020021LOG = logging.getLogger(__name__)
22
Andrea Frittoli878d5ab2015-01-30 13:22:50 +000023
songwenping4c3bf8f2021-01-05 03:27:09 +000024class CredentialProvider(object, metaclass=abc.ABCMeta):
Andrea Frittolidcd91002017-07-18 11:34:13 +010025 def __init__(self, identity_version, name=None,
26 network_resources=None, credentials_domain=None,
27 admin_role=None, identity_uri=None):
Andrea Frittolic3280152015-02-26 12:42:34 +000028 """A CredentialProvider supplies credentials to test classes.
Ken'ichi Ohmichicb67d2d2015-11-19 08:23:22 +000029
Andrea Frittoli (andreaf)32d0de12015-10-09 14:43:53 +010030 :param identity_version: Identity version of the credentials provided
Ken'ichi Ohmichi592eb132015-07-01 04:08:30 +000031 :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)1eb04962015-10-09 14:48:06 +010035 :param credentials_domain: Domain credentials belong to
Andrea Frittoli (andreaf)29491a72015-10-13 11:24:17 +010036 :param admin_role: Name of the role of the admin account
Andrea Frittolidcd91002017-07-18 11:34:13 +010037 :param identity_uri: Identity URI of the target cloud. This *must* be
38 specified for anything to work.
Andrea Frittolic3280152015-02-26 12:42:34 +000039 """
Andrea Frittoli (andreaf)32d0de12015-10-09 14:43:53 +010040 self.identity_version = identity_version
Andrea Frittolidcd91002017-07-18 11:34:13 +010041 self.identity_uri = identity_uri
Andrea Frittoli (andreaf)1eb04962015-10-09 14:48:06 +010042 self.name = name or "test_creds"
43 self.network_resources = network_resources
44 self.credentials_domain = credentials_domain or 'Default'
Andrea Frittoli (andreaf)29491a72015-10-13 11:24:17 +010045 self.admin_role = admin_role
Andrea Frittolic3280152015-02-26 12:42:34 +000046 if not auth.is_identity_version_supported(self.identity_version):
47 raise exceptions.InvalidIdentityVersion(
48 identity_version=self.identity_version)
Marc Kodererd2690fe2014-07-16 14:17:47 +020049
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 Mann32e05572021-01-29 11:24:56 -060063 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 Hentscha0199bf2024-07-15 11:22:37 +020079 def get_domain_manager_creds(self):
80 return
81
82 @abc.abstractmethod
Ghanshyam Mann32e05572021-01-29 11:24:56 -060083 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 Mann420586c2021-01-29 13:23:18 -060095 def get_project_alt_admin_creds(self):
96 return
97
98 @abc.abstractmethod
Markus Hentscha0199bf2024-07-15 11:22:37 +020099 def get_project_manager_creds(self):
100 return
101
102 @abc.abstractmethod
Ghanshyam Mann32e05572021-01-29 11:24:56 -0600103 def get_project_member_creds(self):
104 return
105
106 @abc.abstractmethod
Ghanshyam Mann420586c2021-01-29 13:23:18 -0600107 def get_project_alt_member_creds(self):
108 return
109
110 @abc.abstractmethod
Ghanshyam Mann32e05572021-01-29 11:24:56 -0600111 def get_project_reader_creds(self):
112 return
113
114 @abc.abstractmethod
Ghanshyam Mann420586c2021-01-29 13:23:18 -0600115 def get_project_alt_reader_creds(self):
116 return
117
118 @abc.abstractmethod
Andrea Frittoli (andreaf)17209bb2015-05-22 10:16:57 -0700119 def clear_creds(self):
Marc Kodererd2690fe2014-07-16 14:17:47 +0200120 return
Andrea Frittoli8283b4e2014-07-17 13:28:58 +0100121
122 @abc.abstractmethod
123 def is_multi_user(self):
124 return
Yair Fried76488d72014-10-21 10:13:19 +0300125
126 @abc.abstractmethod
127 def is_multi_tenant(self):
128 return
Matthew Treinish976e8df2014-12-19 14:21:54 -0500129
130 @abc.abstractmethod
Ghanshyam Mann2d0da042021-03-05 09:09:30 -0600131 def get_creds_by_roles(self, roles, force_new=False, scope=None):
Matthew Treinish976e8df2014-12-19 14:21:54 -0500132 return
Matthew Treinish4a596932015-03-06 20:37:01 -0500133
134 @abc.abstractmethod
135 def is_role_available(self, role):
136 return
Andrea Frittoli (andreaf)9540dfd2015-03-25 17:06:50 -0400137
lpiwowar10a649b2021-08-10 15:25:28 +0200138 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)9540dfd2015-03-25 17:06:50 -0400150
151class 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)a1edb2d2016-05-10 16:09:59 +0100163 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)9540dfd2015-03-25 17:06:50 -0400168 def set_resources(self, **kwargs):
Joe H. Rahmea72f2c62016-07-11 16:28:19 +0200169 for key in kwargs:
Andrea Frittoli (andreaf)9540dfd2015-03-25 17:06:50 -0400170 if hasattr(self, key):
171 setattr(self, key, kwargs[key])
172
173 @property
174 def credentials(self):
175 return self._credentials