Marc Koderer | 0abc93b | 2015-07-15 09:18:35 +0200 | [diff] [blame] | 1 | # Copyright 2014 Mirantis Inc. |
| 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 | |
| 16 | import copy |
Valeriy Ponomaryov | 2abf5d7 | 2016-06-01 18:30:12 +0300 | [diff] [blame] | 17 | import re |
Marc Koderer | 0abc93b | 2015-07-15 09:18:35 +0200 | [diff] [blame] | 18 | import traceback |
| 19 | |
Marc Koderer | 0abc93b | 2015-07-15 09:18:35 +0200 | [diff] [blame] | 20 | from oslo_log import log |
Valeriy Ponomaryov | 48a2bd7 | 2015-11-05 13:22:44 +0200 | [diff] [blame] | 21 | from tempest import config |
Goutham Pacha Ravi | c678e21 | 2020-03-20 11:13:47 -0700 | [diff] [blame] | 22 | from tempest.lib.common import cred_client |
Ben Swartzlander | 1c4ff52 | 2016-03-02 22:16:23 -0500 | [diff] [blame] | 23 | from tempest.lib.common.utils import data_utils |
| 24 | from tempest.lib import exceptions |
Valeriy Ponomaryov | 48a2bd7 | 2015-11-05 13:22:44 +0200 | [diff] [blame] | 25 | from tempest import test |
Marc Koderer | 0abc93b | 2015-07-15 09:18:35 +0200 | [diff] [blame] | 26 | |
Andrea Frittoli (andreaf) | 369391a | 2016-06-27 18:59:13 +0100 | [diff] [blame] | 27 | from manila_tempest_tests import clients |
Yogesh | bdb8810 | 2015-09-29 23:41:02 -0400 | [diff] [blame] | 28 | from manila_tempest_tests.common import constants |
lkuchlan | 540e74a | 2021-01-19 18:08:25 +0200 | [diff] [blame] | 29 | from manila_tempest_tests.common import waiters |
Marc Koderer | 0abc93b | 2015-07-15 09:18:35 +0200 | [diff] [blame] | 30 | from manila_tempest_tests import share_exceptions |
Valeriy Ponomaryov | fcde771 | 2015-12-14 18:06:13 +0200 | [diff] [blame] | 31 | from manila_tempest_tests import utils |
Marc Koderer | 0abc93b | 2015-07-15 09:18:35 +0200 | [diff] [blame] | 32 | |
lkuchlan | 1d1461d | 2020-08-04 11:19:11 +0300 | [diff] [blame] | 33 | |
Marc Koderer | 0abc93b | 2015-07-15 09:18:35 +0200 | [diff] [blame] | 34 | CONF = config.CONF |
| 35 | LOG = log.getLogger(__name__) |
| 36 | |
Valeriy Ponomaryov | 2abf5d7 | 2016-06-01 18:30:12 +0300 | [diff] [blame] | 37 | # Test tags related to test direction |
| 38 | TAG_POSITIVE = "positive" |
| 39 | TAG_NEGATIVE = "negative" |
| 40 | |
| 41 | # Test tags related to service involvement |
Tom Barron | 69f9696 | 2019-07-29 17:07:03 -0400 | [diff] [blame] | 42 | # Only requires that manila-api service running. |
Valeriy Ponomaryov | 2abf5d7 | 2016-06-01 18:30:12 +0300 | [diff] [blame] | 43 | TAG_API = "api" |
Tom Barron | 69f9696 | 2019-07-29 17:07:03 -0400 | [diff] [blame] | 44 | # Requires all manila services running, intended to test back-end |
| 45 | # (manila-share) behavior. |
Valeriy Ponomaryov | 2abf5d7 | 2016-06-01 18:30:12 +0300 | [diff] [blame] | 46 | TAG_BACKEND = "backend" |
Tom Barron | 69f9696 | 2019-07-29 17:07:03 -0400 | [diff] [blame] | 47 | # Requires all manila services running, intended to test API behavior. |
Valeriy Ponomaryov | 2abf5d7 | 2016-06-01 18:30:12 +0300 | [diff] [blame] | 48 | TAG_API_WITH_BACKEND = "api_with_backend" |
| 49 | |
| 50 | TAGS_MAPPER = { |
| 51 | "p": TAG_POSITIVE, |
| 52 | "n": TAG_NEGATIVE, |
| 53 | "a": TAG_API, |
| 54 | "b": TAG_BACKEND, |
| 55 | "ab": TAG_API_WITH_BACKEND, |
| 56 | } |
| 57 | TAGS_PATTERN = re.compile( |
| 58 | r"(?=.*\[.*\b(%(p)s|%(n)s)\b.*\])(?=.*\[.*\b(%(a)s|%(b)s|%(ab)s)\b.*\])" % |
| 59 | TAGS_MAPPER) |
| 60 | |
lkuchlan | ad511b6 | 2022-05-08 09:23:23 +0300 | [diff] [blame] | 61 | LATEST_MICROVERSION = CONF.share.max_api_microversion |
| 62 | |
Valeriy Ponomaryov | 2abf5d7 | 2016-06-01 18:30:12 +0300 | [diff] [blame] | 63 | |
| 64 | def verify_test_has_appropriate_tags(self): |
| 65 | if not TAGS_PATTERN.match(self.id()): |
| 66 | msg = ( |
| 67 | "Required attributes either not set or set improperly. " |
| 68 | "Two test attributes are expected:\n" |
| 69 | " - one of '%(p)s' or '%(n)s' and \n" |
| 70 | " - one of '%(a)s', '%(b)s' or '%(ab)s'." |
| 71 | ) % TAGS_MAPPER |
| 72 | raise self.failureException(msg) |
| 73 | |
Marc Koderer | 0abc93b | 2015-07-15 09:18:35 +0200 | [diff] [blame] | 74 | |
| 75 | class handle_cleanup_exceptions(object): |
| 76 | """Handle exceptions raised with cleanup operations. |
| 77 | |
| 78 | Always suppress errors when exceptions.NotFound or exceptions.Forbidden |
| 79 | are raised. |
| 80 | Suppress all other exceptions only in case config opt |
| 81 | 'suppress_errors_in_cleanup' in config group 'share' is True. |
| 82 | """ |
| 83 | |
| 84 | def __enter__(self): |
| 85 | return self |
| 86 | |
| 87 | def __exit__(self, exc_type, exc_value, exc_traceback): |
| 88 | if not (isinstance(exc_value, |
| 89 | (exceptions.NotFound, exceptions.Forbidden)) or |
| 90 | CONF.share.suppress_errors_in_cleanup): |
| 91 | return False # Do not suppress error if any |
| 92 | if exc_traceback: |
| 93 | LOG.error("Suppressed cleanup error in Manila: " |
junboli | b236c24 | 2017-07-18 18:12:37 +0800 | [diff] [blame] | 94 | "\n%s", traceback.format_exc()) |
Marc Koderer | 0abc93b | 2015-07-15 09:18:35 +0200 | [diff] [blame] | 95 | return True # Suppress error if any |
| 96 | |
| 97 | |
Marc Koderer | 0abc93b | 2015-07-15 09:18:35 +0200 | [diff] [blame] | 98 | class BaseSharesTest(test.BaseTestCase): |
| 99 | """Base test case class for all Manila API tests.""" |
| 100 | |
Valeriy Ponomaryov | 39cdf72 | 2016-05-30 18:16:15 +0300 | [diff] [blame] | 101 | credentials = ('primary', ) |
Marc Koderer | 0abc93b | 2015-07-15 09:18:35 +0200 | [diff] [blame] | 102 | force_tenant_isolation = False |
Vitaliy Levitksi | cfebfff | 2016-12-15 16:16:35 +0200 | [diff] [blame] | 103 | protocols = ["nfs", "cifs", "glusterfs", "hdfs", "cephfs", "maprfs"] |
Marc Koderer | 0abc93b | 2015-07-15 09:18:35 +0200 | [diff] [blame] | 104 | |
| 105 | # Will be cleaned up in resource_cleanup |
| 106 | class_resources = [] |
| 107 | |
| 108 | # Will be cleaned up in tearDown method |
| 109 | method_resources = [] |
| 110 | |
Andrea Frittoli (andreaf) | 369391a | 2016-06-27 18:59:13 +0100 | [diff] [blame] | 111 | # NOTE(andreaf) Override the client manager class to be used, so that |
| 112 | # a stable class is used, which includes plugin registered services as well |
| 113 | client_manager = clients.Clients |
| 114 | |
Marc Koderer | 0abc93b | 2015-07-15 09:18:35 +0200 | [diff] [blame] | 115 | @classmethod |
Daniel Mellado | e526914 | 2017-01-12 12:17:58 +0000 | [diff] [blame] | 116 | def skip_checks(cls): |
| 117 | super(BaseSharesTest, cls).skip_checks() |
| 118 | if not CONF.service_available.manila: |
| 119 | raise cls.skipException("Manila support is required") |
lkuchlan | a3b6f7a | 2020-01-07 10:45:45 +0200 | [diff] [blame] | 120 | if not any(p in CONF.share.enable_protocols for p in cls.protocols): |
| 121 | skip_msg = "%s tests are disabled" % CONF.share.enable_protocols |
| 122 | raise cls.skipException(skip_msg) |
Daniel Mellado | e526914 | 2017-01-12 12:17:58 +0000 | [diff] [blame] | 123 | |
| 124 | @classmethod |
Marc Koderer | 0abc93b | 2015-07-15 09:18:35 +0200 | [diff] [blame] | 125 | def verify_nonempty(cls, *args): |
| 126 | if not all(args): |
| 127 | msg = "Missing API credentials in configuration." |
| 128 | raise cls.skipException(msg) |
| 129 | |
| 130 | @classmethod |
Goutham Pacha Ravi | 4a0b732 | 2020-06-30 19:42:45 -0700 | [diff] [blame] | 131 | def setup_credentials(cls): |
| 132 | # This call is used to tell the credential allocator to create |
| 133 | # network resources for this test case. NOTE: it must go before the |
| 134 | # super call, to override decisions in the base classes. |
| 135 | network_resources = {} |
| 136 | if (CONF.share.multitenancy_enabled and |
| 137 | CONF.share.create_networks_when_multitenancy_enabled): |
| 138 | # We're testing a DHSS=True driver, and manila is configured with |
| 139 | # NeutronNetworkPlugin (or a derivative) that supports creating |
| 140 | # share networks with project neutron networks, so lets ask for |
| 141 | # neutron network resources to be created with test credentials |
| 142 | network_resources.update({'network': True, |
| 143 | 'subnet': True, |
| 144 | 'router': True}) |
| 145 | cls.set_network_resources(**network_resources) |
| 146 | super(BaseSharesTest, cls).setup_credentials() |
| 147 | |
| 148 | @classmethod |
Valeriy Ponomaryov | 39cdf72 | 2016-05-30 18:16:15 +0300 | [diff] [blame] | 149 | def setup_clients(cls): |
| 150 | super(BaseSharesTest, cls).setup_clients() |
| 151 | os = getattr(cls, 'os_%s' % cls.credentials[0]) |
Andrea Frittoli (andreaf) | 369391a | 2016-06-27 18:59:13 +0100 | [diff] [blame] | 152 | # Initialise share clients for test credentials |
| 153 | cls.shares_client = os.share_v1.SharesClient() |
| 154 | cls.shares_v2_client = os.share_v2.SharesV2Client() |
| 155 | # Initialise network clients for test credentials |
Goutham Pacha Ravi | 4a0b732 | 2020-06-30 19:42:45 -0700 | [diff] [blame] | 156 | cls.networks_client = None |
| 157 | cls.subnets_client = None |
Andrea Frittoli (andreaf) | 369391a | 2016-06-27 18:59:13 +0100 | [diff] [blame] | 158 | if CONF.service_available.neutron: |
| 159 | cls.networks_client = os.network.NetworksClient() |
| 160 | cls.subnets_client = os.network.SubnetsClient() |
Valeriy Ponomaryov | 4fb305f | 2016-10-21 13:46:47 +0300 | [diff] [blame] | 161 | |
Goutham Pacha Ravi | 4a0b732 | 2020-06-30 19:42:45 -0700 | [diff] [blame] | 162 | # If DHSS=True, create a share network and set it in the client |
| 163 | # for easy access. |
Valeriy Ponomaryov | 39cdf72 | 2016-05-30 18:16:15 +0300 | [diff] [blame] | 164 | if CONF.share.multitenancy_enabled: |
Valeriy Ponomaryov | c5dae27 | 2016-06-10 18:29:24 +0300 | [diff] [blame] | 165 | if (not CONF.service_available.neutron and |
| 166 | CONF.share.create_networks_when_multitenancy_enabled): |
Goutham Pacha Ravi | 4a0b732 | 2020-06-30 19:42:45 -0700 | [diff] [blame] | 167 | raise cls.skipException( |
| 168 | "Neutron support is required when " |
| 169 | "CONF.share.create_networks_when_multitenancy_enabled " |
| 170 | "is set to True") |
Valeriy Ponomaryov | 39cdf72 | 2016-05-30 18:16:15 +0300 | [diff] [blame] | 171 | share_network_id = cls.provide_share_network( |
Goutham Pacha Ravi | 4a0b732 | 2020-06-30 19:42:45 -0700 | [diff] [blame] | 172 | cls.shares_client, cls.networks_client) |
Valeriy Ponomaryov | 39cdf72 | 2016-05-30 18:16:15 +0300 | [diff] [blame] | 173 | cls.shares_client.share_network_id = share_network_id |
| 174 | cls.shares_v2_client.share_network_id = share_network_id |
| 175 | |
Marc Koderer | 0abc93b | 2015-07-15 09:18:35 +0200 | [diff] [blame] | 176 | def setUp(self): |
| 177 | super(BaseSharesTest, self).setUp() |
Valeriy Ponomaryov | dd162cb | 2016-01-20 19:09:49 +0200 | [diff] [blame] | 178 | self.addCleanup(self.clear_resources) |
Valeriy Ponomaryov | 2abf5d7 | 2016-06-01 18:30:12 +0300 | [diff] [blame] | 179 | verify_test_has_appropriate_tags(self) |
Marc Koderer | 0abc93b | 2015-07-15 09:18:35 +0200 | [diff] [blame] | 180 | |
| 181 | @classmethod |
| 182 | def resource_cleanup(cls): |
Marc Koderer | 0abc93b | 2015-07-15 09:18:35 +0200 | [diff] [blame] | 183 | cls.clear_resources(cls.class_resources) |
Sam Wan | 241029c | 2016-07-26 03:37:42 -0400 | [diff] [blame] | 184 | super(BaseSharesTest, cls).resource_cleanup() |
Marc Koderer | 0abc93b | 2015-07-15 09:18:35 +0200 | [diff] [blame] | 185 | |
| 186 | @classmethod |
debeltrami | 1753a59 | 2020-05-11 18:27:30 +0000 | [diff] [blame] | 187 | def provide_and_associate_security_services( |
| 188 | cls, shares_client, share_network_id, cleanup_in_class=True): |
| 189 | """Creates a security service and associates to a share network. |
| 190 | |
| 191 | This method creates security services based on the Multiopt |
| 192 | defined in tempest configuration named security_service. When this |
| 193 | configuration is not provided, the method will return None. |
| 194 | After the security service creation, this method also associates |
| 195 | the security service to a share network. |
| 196 | |
| 197 | :param shares_client: shares client, which requires the provisioning |
| 198 | :param share_network_id: id of the share network to associate the |
| 199 | security service |
| 200 | :param cleanup_in_class: if the security service and the association |
| 201 | will be removed in the method teardown or class teardown |
| 202 | :returns: None -- if the security service configuration is not |
| 203 | defined |
| 204 | """ |
| 205 | |
| 206 | ss_configs = CONF.share.security_service |
| 207 | if not ss_configs: |
| 208 | return |
| 209 | |
| 210 | for ss_config in ss_configs: |
| 211 | ss_name = "ss_autogenerated_by_tempest_%s" % ( |
| 212 | ss_config.get("ss_type")) |
| 213 | |
| 214 | ss_params = { |
| 215 | "name": ss_name, |
| 216 | "dns_ip": ss_config.get("ss_dns_ip"), |
| 217 | "server": ss_config.get("ss_server"), |
| 218 | "domain": ss_config.get("ss_domain"), |
| 219 | "user": ss_config.get("ss_user"), |
| 220 | "password": ss_config.get("ss_password") |
| 221 | } |
| 222 | ss_type = ss_config.get("ss_type") |
| 223 | security_service = cls.create_security_service( |
| 224 | ss_type, |
| 225 | client=shares_client, |
| 226 | cleanup_in_class=cleanup_in_class, |
| 227 | **ss_params) |
| 228 | |
| 229 | cls.add_sec_service_to_share_network( |
| 230 | shares_client, share_network_id, |
| 231 | security_service["id"], |
| 232 | cleanup_in_class=cleanup_in_class) |
| 233 | |
| 234 | @classmethod |
| 235 | def add_sec_service_to_share_network( |
| 236 | cls, client, share_network_id, |
| 237 | security_service_id, cleanup_in_class=True): |
| 238 | """Associates a security service to a share network. |
| 239 | |
| 240 | This method associates a security service provided by |
| 241 | the security service configuration with a specific |
| 242 | share network. |
| 243 | |
| 244 | :param share_network_id: the share network id to be |
| 245 | associate with a given security service |
| 246 | :param security_service_id: the security service id |
| 247 | to be associate with a given share network |
| 248 | :param cleanup_in_class: if the resources will be |
| 249 | dissociate in the method teardown or class teardown |
| 250 | """ |
| 251 | |
| 252 | client.add_sec_service_to_share_network( |
| 253 | share_network_id, |
| 254 | security_service_id) |
| 255 | resource = { |
| 256 | "type": "dissociate_security_service", |
| 257 | "id": security_service_id, |
| 258 | "extra_params": { |
| 259 | "share_network_id": share_network_id |
| 260 | }, |
| 261 | "client": client, |
| 262 | } |
| 263 | |
| 264 | if cleanup_in_class: |
| 265 | cls.class_resources.insert(0, resource) |
| 266 | else: |
| 267 | cls.method_resources.insert(0, resource) |
| 268 | |
| 269 | @classmethod |
Valeriy Ponomaryov | 48a2bd7 | 2015-11-05 13:22:44 +0200 | [diff] [blame] | 270 | def provide_share_network(cls, shares_client, networks_client, |
Rodrigo Barbieri | 58d9de3 | 2016-09-06 13:16:47 -0300 | [diff] [blame] | 271 | ignore_multitenancy_config=False): |
Goutham Pacha Ravi | 4a0b732 | 2020-06-30 19:42:45 -0700 | [diff] [blame] | 272 | """Get or create share network for DHSS=True drivers |
Marc Koderer | 0abc93b | 2015-07-15 09:18:35 +0200 | [diff] [blame] | 273 | |
Goutham Pacha Ravi | 4a0b732 | 2020-06-30 19:42:45 -0700 | [diff] [blame] | 274 | When testing DHSS=True (multitenancy_enabled) drivers, shares must |
| 275 | be requested on share networks. |
Marc Koderer | 0abc93b | 2015-07-15 09:18:35 +0200 | [diff] [blame] | 276 | :returns: str -- share network id for shares_client tenant |
Goutham Pacha Ravi | 4a0b732 | 2020-06-30 19:42:45 -0700 | [diff] [blame] | 277 | :returns: None -- if single-tenant driver (DHSS=False) is used |
Marc Koderer | 0abc93b | 2015-07-15 09:18:35 +0200 | [diff] [blame] | 278 | """ |
| 279 | |
Rodrigo Barbieri | 58d9de3 | 2016-09-06 13:16:47 -0300 | [diff] [blame] | 280 | if (not ignore_multitenancy_config and |
| 281 | not CONF.share.multitenancy_enabled): |
Goutham Pacha Ravi | 4a0b732 | 2020-06-30 19:42:45 -0700 | [diff] [blame] | 282 | # Assumed usage of a single-tenant driver (DHSS=False) |
debeltrami | 1753a59 | 2020-05-11 18:27:30 +0000 | [diff] [blame] | 283 | return None |
Goutham Pacha Ravi | af44826 | 2020-06-29 14:24:13 -0700 | [diff] [blame] | 284 | |
Goutham Pacha Ravi | 4a0b732 | 2020-06-30 19:42:45 -0700 | [diff] [blame] | 285 | if shares_client.share_network_id: |
| 286 | # Share-network already exists, use it |
| 287 | return shares_client.share_network_id |
debeltrami | 1753a59 | 2020-05-11 18:27:30 +0000 | [diff] [blame] | 288 | |
Goutham Pacha Ravi | 4a0b732 | 2020-06-30 19:42:45 -0700 | [diff] [blame] | 289 | sn_name = "autogenerated_by_tempest" |
| 290 | sn_desc = "This share-network was created by tempest" |
Rodrigo Barbieri | 58d9de3 | 2016-09-06 13:16:47 -0300 | [diff] [blame] | 291 | |
Goutham Pacha Ravi | 4a0b732 | 2020-06-30 19:42:45 -0700 | [diff] [blame] | 292 | if not CONF.share.create_networks_when_multitenancy_enabled: |
| 293 | # We need a new share network, but don't need to associate |
| 294 | # any neutron networks to it - this configuration is used |
| 295 | # when manila is configured with "StandaloneNetworkPlugin" |
| 296 | # or "NeutronSingleNetworkPlugin" where all tenants share |
| 297 | # a single backend network where shares are exported. |
| 298 | sn = cls.create_share_network(cleanup_in_class=True, |
| 299 | client=shares_client, |
| 300 | add_security_services=True, |
| 301 | name=sn_name, |
| 302 | description=sn_desc) |
| 303 | return sn['id'] |
Marc Koderer | 0abc93b | 2015-07-15 09:18:35 +0200 | [diff] [blame] | 304 | |
Goutham Pacha Ravi | 4a0b732 | 2020-06-30 19:42:45 -0700 | [diff] [blame] | 305 | # Retrieve non-public network list owned by the tenant |
| 306 | filters = {'project_id': shares_client.tenant_id, |
| 307 | 'shared': False} |
| 308 | tenant_networks = ( |
| 309 | networks_client.list_networks(**filters).get('networks', []) |
| 310 | ) |
| 311 | tenant_networks_with_subnet = ( |
| 312 | [n for n in tenant_networks if n['subnets']] |
| 313 | ) |
debeltrami | 1753a59 | 2020-05-11 18:27:30 +0000 | [diff] [blame] | 314 | |
Goutham Pacha Ravi | 4a0b732 | 2020-06-30 19:42:45 -0700 | [diff] [blame] | 315 | if not tenant_networks_with_subnet: |
| 316 | # This can only occur if using tempest's pre-provisioned |
| 317 | # credentials and not allocating networks to them |
| 318 | raise cls.skipException( |
| 319 | "Test credentials must provide at least one " |
| 320 | "non-shared project network with a valid subnet when " |
| 321 | "CONF.share.create_networks_when_multitenancy_enabled is " |
| 322 | "set to True.") |
debeltrami | 1753a59 | 2020-05-11 18:27:30 +0000 | [diff] [blame] | 323 | |
Goutham Pacha Ravi | 4a0b732 | 2020-06-30 19:42:45 -0700 | [diff] [blame] | 324 | net_id = tenant_networks_with_subnet[0]['id'] |
| 325 | subnet_id = tenant_networks_with_subnet[0]['subnets'][0] |
debeltrami | 1753a59 | 2020-05-11 18:27:30 +0000 | [diff] [blame] | 326 | |
Goutham Pacha Ravi | 4a0b732 | 2020-06-30 19:42:45 -0700 | [diff] [blame] | 327 | # Create suitable share-network |
| 328 | sn = cls.create_share_network(cleanup_in_class=True, |
| 329 | client=shares_client, |
| 330 | add_security_services=True, |
| 331 | name=sn_name, |
| 332 | description=sn_desc, |
| 333 | neutron_net_id=net_id, |
| 334 | neutron_subnet_id=subnet_id) |
debeltrami | 1753a59 | 2020-05-11 18:27:30 +0000 | [diff] [blame] | 335 | |
Goutham Pacha Ravi | 4a0b732 | 2020-06-30 19:42:45 -0700 | [diff] [blame] | 336 | return sn['id'] |
Marc Koderer | 0abc93b | 2015-07-15 09:18:35 +0200 | [diff] [blame] | 337 | |
| 338 | @classmethod |
marcusvrn | e0d7cfd | 2016-06-24 12:27:55 -0300 | [diff] [blame] | 339 | def _create_share(cls, share_protocol=None, size=None, name=None, |
Marc Koderer | 0abc93b | 2015-07-15 09:18:35 +0200 | [diff] [blame] | 340 | snapshot_id=None, description=None, metadata=None, |
| 341 | share_network_id=None, share_type_id=None, |
Andrew Kerr | b843692 | 2016-06-01 15:32:43 -0400 | [diff] [blame] | 342 | share_group_id=None, client=None, |
Clinton Knight | e5c8f09 | 2015-08-27 15:00:23 -0400 | [diff] [blame] | 343 | cleanup_in_class=True, is_public=False, **kwargs): |
Valeriy Ponomaryov | 1aaa72d | 2015-09-08 12:59:41 +0300 | [diff] [blame] | 344 | client = client or cls.shares_v2_client |
Marc Koderer | 0abc93b | 2015-07-15 09:18:35 +0200 | [diff] [blame] | 345 | description = description or "Tempest's share" |
yogesh | 06f519f | 2017-06-26 13:16:12 -0400 | [diff] [blame] | 346 | share_network_id = (share_network_id or |
| 347 | CONF.share.share_network_id or |
| 348 | client.share_network_id or None) |
Marc Koderer | 0abc93b | 2015-07-15 09:18:35 +0200 | [diff] [blame] | 349 | metadata = metadata or {} |
marcusvrn | e0d7cfd | 2016-06-24 12:27:55 -0300 | [diff] [blame] | 350 | size = size or CONF.share.share_size |
Clinton Knight | e5c8f09 | 2015-08-27 15:00:23 -0400 | [diff] [blame] | 351 | kwargs.update({ |
Marc Koderer | 0abc93b | 2015-07-15 09:18:35 +0200 | [diff] [blame] | 352 | 'share_protocol': share_protocol, |
| 353 | 'size': size, |
| 354 | 'name': name, |
| 355 | 'snapshot_id': snapshot_id, |
| 356 | 'description': description, |
| 357 | 'metadata': metadata, |
| 358 | 'share_network_id': share_network_id, |
| 359 | 'share_type_id': share_type_id, |
| 360 | 'is_public': is_public, |
Clinton Knight | e5c8f09 | 2015-08-27 15:00:23 -0400 | [diff] [blame] | 361 | }) |
Andrew Kerr | b843692 | 2016-06-01 15:32:43 -0400 | [diff] [blame] | 362 | if share_group_id: |
| 363 | kwargs['share_group_id'] = share_group_id |
Andrew Kerr | bf31e91 | 2015-07-29 10:39:38 -0400 | [diff] [blame] | 364 | |
lkuchlan | 86f2432 | 2021-04-27 14:23:05 +0300 | [diff] [blame] | 365 | share = client.create_share(**kwargs)['share'] |
Andrew Kerr | bf31e91 | 2015-07-29 10:39:38 -0400 | [diff] [blame] | 366 | resource = {"type": "share", "id": share["id"], "client": client, |
Andrew Kerr | b843692 | 2016-06-01 15:32:43 -0400 | [diff] [blame] | 367 | "share_group_id": share_group_id} |
Marc Koderer | 0abc93b | 2015-07-15 09:18:35 +0200 | [diff] [blame] | 368 | cleanup_list = (cls.class_resources if cleanup_in_class else |
| 369 | cls.method_resources) |
| 370 | cleanup_list.insert(0, resource) |
| 371 | return share |
| 372 | |
| 373 | @classmethod |
Rodrigo Barbieri | 427bc05 | 2016-06-06 17:10:06 -0300 | [diff] [blame] | 374 | def migrate_share( |
| 375 | cls, share_id, dest_host, wait_for_status, client=None, |
Rodrigo Barbieri | 027df98 | 2016-11-24 15:52:03 -0200 | [diff] [blame] | 376 | force_host_assisted_migration=False, writable=False, |
| 377 | nondisruptive=False, preserve_metadata=False, |
| 378 | preserve_snapshots=False, new_share_network_id=None, |
Rodrigo Barbieri | d38d2f5 | 2016-07-19 22:24:56 -0300 | [diff] [blame] | 379 | new_share_type_id=None, **kwargs): |
Clinton Knight | e5c8f09 | 2015-08-27 15:00:23 -0400 | [diff] [blame] | 380 | client = client or cls.shares_v2_client |
Rodrigo Barbieri | 427bc05 | 2016-06-06 17:10:06 -0300 | [diff] [blame] | 381 | client.migrate_share( |
| 382 | share_id, dest_host, |
| 383 | force_host_assisted_migration=force_host_assisted_migration, |
Rodrigo Barbieri | 027df98 | 2016-11-24 15:52:03 -0200 | [diff] [blame] | 384 | writable=writable, preserve_metadata=preserve_metadata, |
| 385 | nondisruptive=nondisruptive, preserve_snapshots=preserve_snapshots, |
Rodrigo Barbieri | 427bc05 | 2016-06-06 17:10:06 -0300 | [diff] [blame] | 386 | new_share_network_id=new_share_network_id, |
Rodrigo Barbieri | d38d2f5 | 2016-07-19 22:24:56 -0300 | [diff] [blame] | 387 | new_share_type_id=new_share_type_id, **kwargs) |
lkuchlan | 540e74a | 2021-01-19 18:08:25 +0200 | [diff] [blame] | 388 | share = waiters.wait_for_migration_status( |
| 389 | client, share_id, dest_host, wait_for_status, **kwargs) |
Rodrigo Barbieri | e330512 | 2016-02-03 14:32:24 -0200 | [diff] [blame] | 390 | return share |
| 391 | |
| 392 | @classmethod |
| 393 | def migration_complete(cls, share_id, dest_host, client=None, **kwargs): |
| 394 | client = client or cls.shares_v2_client |
| 395 | client.migration_complete(share_id, **kwargs) |
lkuchlan | 540e74a | 2021-01-19 18:08:25 +0200 | [diff] [blame] | 396 | share = waiters.wait_for_migration_status( |
| 397 | client, share_id, dest_host, 'migration_success', **kwargs) |
Rodrigo Barbieri | b7137ad | 2015-09-06 22:53:16 -0300 | [diff] [blame] | 398 | return share |
| 399 | |
| 400 | @classmethod |
Rodrigo Barbieri | c9abf28 | 2016-08-24 22:01:31 -0300 | [diff] [blame] | 401 | def migration_cancel(cls, share_id, dest_host, client=None, **kwargs): |
| 402 | client = client or cls.shares_v2_client |
| 403 | client.migration_cancel(share_id, **kwargs) |
lkuchlan | 540e74a | 2021-01-19 18:08:25 +0200 | [diff] [blame] | 404 | share = waiters.wait_for_migration_status( |
| 405 | client, share_id, dest_host, 'migration_cancelled', **kwargs) |
Rodrigo Barbieri | c9abf28 | 2016-08-24 22:01:31 -0300 | [diff] [blame] | 406 | return share |
| 407 | |
| 408 | @classmethod |
Marc Koderer | 0abc93b | 2015-07-15 09:18:35 +0200 | [diff] [blame] | 409 | def create_share(cls, *args, **kwargs): |
| 410 | """Create one share and wait for available state. Retry if allowed.""" |
| 411 | result = cls.create_shares([{"args": args, "kwargs": kwargs}]) |
| 412 | return result[0] |
| 413 | |
| 414 | @classmethod |
| 415 | def create_shares(cls, share_data_list): |
| 416 | """Creates several shares in parallel with retries. |
| 417 | |
| 418 | Use this method when you want to create more than one share at same |
| 419 | time. Especially if config option 'share.share_creation_retry_number' |
| 420 | has value more than zero (0). |
| 421 | All shares will be expected to have 'available' status with or without |
| 422 | recreation else error will be raised. |
| 423 | |
| 424 | :param share_data_list: list -- list of dictionaries with 'args' and |
| 425 | 'kwargs' for '_create_share' method of this base class. |
| 426 | example of data: |
| 427 | share_data_list=[{'args': ['quuz'], 'kwargs': {'foo': 'bar'}}}] |
| 428 | :returns: list -- list of shares created using provided data. |
| 429 | """ |
| 430 | |
Valeriy Ponomaryov | 39cdf72 | 2016-05-30 18:16:15 +0300 | [diff] [blame] | 431 | for d in share_data_list: |
Marc Koderer | 0abc93b | 2015-07-15 09:18:35 +0200 | [diff] [blame] | 432 | if not isinstance(d, dict): |
| 433 | raise exceptions.TempestException( |
| 434 | "Expected 'dict', got '%s'" % type(d)) |
| 435 | if "args" not in d: |
| 436 | d["args"] = [] |
| 437 | if "kwargs" not in d: |
| 438 | d["kwargs"] = {} |
| 439 | if len(d) > 2: |
| 440 | raise exceptions.TempestException( |
| 441 | "Expected only 'args' and 'kwargs' keys. " |
| 442 | "Provided %s" % list(d)) |
Valeriy Ponomaryov | 39cdf72 | 2016-05-30 18:16:15 +0300 | [diff] [blame] | 443 | |
| 444 | data = [] |
| 445 | for d in share_data_list: |
| 446 | client = d["kwargs"].pop("client", cls.shares_v2_client) |
yogesh | db32f46 | 2016-09-28 15:09:50 -0400 | [diff] [blame] | 447 | wait_for_status = d["kwargs"].pop("wait_for_status", True) |
Valeriy Ponomaryov | 39cdf72 | 2016-05-30 18:16:15 +0300 | [diff] [blame] | 448 | local_d = { |
| 449 | "args": d["args"], |
| 450 | "kwargs": copy.deepcopy(d["kwargs"]), |
| 451 | } |
| 452 | local_d["kwargs"]["client"] = client |
| 453 | local_d["share"] = cls._create_share( |
| 454 | *local_d["args"], **local_d["kwargs"]) |
| 455 | local_d["cnt"] = 0 |
| 456 | local_d["available"] = False |
yogesh | db32f46 | 2016-09-28 15:09:50 -0400 | [diff] [blame] | 457 | local_d["wait_for_status"] = wait_for_status |
Valeriy Ponomaryov | 39cdf72 | 2016-05-30 18:16:15 +0300 | [diff] [blame] | 458 | data.append(local_d) |
Marc Koderer | 0abc93b | 2015-07-15 09:18:35 +0200 | [diff] [blame] | 459 | |
| 460 | while not all(d["available"] for d in data): |
| 461 | for d in data: |
yogesh | db32f46 | 2016-09-28 15:09:50 -0400 | [diff] [blame] | 462 | if not d["wait_for_status"]: |
| 463 | d["available"] = True |
Marc Koderer | 0abc93b | 2015-07-15 09:18:35 +0200 | [diff] [blame] | 464 | if d["available"]: |
| 465 | continue |
Valeriy Ponomaryov | 1a3e338 | 2016-06-08 15:17:16 +0300 | [diff] [blame] | 466 | client = d["kwargs"]["client"] |
| 467 | share_id = d["share"]["id"] |
Marc Koderer | 0abc93b | 2015-07-15 09:18:35 +0200 | [diff] [blame] | 468 | try: |
lkuchlan | f7fc5b6 | 2021-01-26 14:53:43 +0200 | [diff] [blame] | 469 | waiters.wait_for_resource_status( |
lkuchlan | 540e74a | 2021-01-19 18:08:25 +0200 | [diff] [blame] | 470 | client, share_id, "available") |
Marc Koderer | 0abc93b | 2015-07-15 09:18:35 +0200 | [diff] [blame] | 471 | d["available"] = True |
| 472 | except (share_exceptions.ShareBuildErrorException, |
| 473 | exceptions.TimeoutException) as e: |
| 474 | if CONF.share.share_creation_retry_number > d["cnt"]: |
| 475 | d["cnt"] += 1 |
| 476 | msg = ("Share '%s' failed to be built. " |
Valeriy Ponomaryov | 1a3e338 | 2016-06-08 15:17:16 +0300 | [diff] [blame] | 477 | "Trying create another." % share_id) |
Marc Koderer | 0abc93b | 2015-07-15 09:18:35 +0200 | [diff] [blame] | 478 | LOG.error(msg) |
| 479 | LOG.error(e) |
Valeriy Ponomaryov | 1a3e338 | 2016-06-08 15:17:16 +0300 | [diff] [blame] | 480 | cg_id = d["kwargs"].get("consistency_group_id") |
| 481 | if cg_id: |
| 482 | # NOTE(vponomaryov): delete errored share |
| 483 | # immediately in case share is part of CG. |
| 484 | client.delete_share( |
| 485 | share_id, |
| 486 | params={"consistency_group_id": cg_id}) |
| 487 | client.wait_for_resource_deletion( |
| 488 | share_id=share_id) |
Marc Koderer | 0abc93b | 2015-07-15 09:18:35 +0200 | [diff] [blame] | 489 | d["share"] = cls._create_share( |
| 490 | *d["args"], **d["kwargs"]) |
| 491 | else: |
gecong1973 | 5866380 | 2016-08-25 11:08:45 +0800 | [diff] [blame] | 492 | raise |
Marc Koderer | 0abc93b | 2015-07-15 09:18:35 +0200 | [diff] [blame] | 493 | |
| 494 | return [d["share"] for d in data] |
| 495 | |
| 496 | @classmethod |
Andrew Kerr | b843692 | 2016-06-01 15:32:43 -0400 | [diff] [blame] | 497 | def create_share_group(cls, client=None, cleanup_in_class=True, |
| 498 | share_network_id=None, **kwargs): |
Clinton Knight | e5c8f09 | 2015-08-27 15:00:23 -0400 | [diff] [blame] | 499 | client = client or cls.shares_v2_client |
Andrew Kerr | b843692 | 2016-06-01 15:32:43 -0400 | [diff] [blame] | 500 | if kwargs.get('source_share_group_snapshot_id') is None: |
Goutham Pacha Ravi | 9221f5e | 2016-04-21 13:17:49 -0400 | [diff] [blame] | 501 | kwargs['share_network_id'] = (share_network_id or |
| 502 | client.share_network_id or None) |
lkuchlan | 86f2432 | 2021-04-27 14:23:05 +0300 | [diff] [blame] | 503 | share_group = client.create_share_group(**kwargs)['share_group'] |
Andrew Kerr | bf31e91 | 2015-07-29 10:39:38 -0400 | [diff] [blame] | 504 | resource = { |
Andrew Kerr | b843692 | 2016-06-01 15:32:43 -0400 | [diff] [blame] | 505 | "type": "share_group", |
| 506 | "id": share_group["id"], |
| 507 | "client": client, |
| 508 | } |
Andrew Kerr | bf31e91 | 2015-07-29 10:39:38 -0400 | [diff] [blame] | 509 | if cleanup_in_class: |
| 510 | cls.class_resources.insert(0, resource) |
| 511 | else: |
| 512 | cls.method_resources.insert(0, resource) |
| 513 | |
Andrew Kerr | b843692 | 2016-06-01 15:32:43 -0400 | [diff] [blame] | 514 | if kwargs.get('source_share_group_snapshot_id'): |
| 515 | new_share_group_shares = client.list_shares( |
Andrew Kerr | bf31e91 | 2015-07-29 10:39:38 -0400 | [diff] [blame] | 516 | detailed=True, |
lkuchlan | 86f2432 | 2021-04-27 14:23:05 +0300 | [diff] [blame] | 517 | params={'share_group_id': share_group['id']})['shares'] |
Andrew Kerr | bf31e91 | 2015-07-29 10:39:38 -0400 | [diff] [blame] | 518 | |
Andrew Kerr | b843692 | 2016-06-01 15:32:43 -0400 | [diff] [blame] | 519 | for share in new_share_group_shares: |
Andrew Kerr | bf31e91 | 2015-07-29 10:39:38 -0400 | [diff] [blame] | 520 | resource = {"type": "share", |
| 521 | "id": share["id"], |
| 522 | "client": client, |
Andrew Kerr | b843692 | 2016-06-01 15:32:43 -0400 | [diff] [blame] | 523 | "share_group_id": share.get("share_group_id")} |
Andrew Kerr | bf31e91 | 2015-07-29 10:39:38 -0400 | [diff] [blame] | 524 | if cleanup_in_class: |
| 525 | cls.class_resources.insert(0, resource) |
| 526 | else: |
| 527 | cls.method_resources.insert(0, resource) |
| 528 | |
lkuchlan | f7fc5b6 | 2021-01-26 14:53:43 +0200 | [diff] [blame] | 529 | waiters.wait_for_resource_status( |
| 530 | client, share_group['id'], 'available', |
| 531 | resource_name='share_group') |
Andrew Kerr | b843692 | 2016-06-01 15:32:43 -0400 | [diff] [blame] | 532 | return share_group |
| 533 | |
| 534 | @classmethod |
| 535 | def create_share_group_type(cls, name=None, share_types=(), is_public=None, |
| 536 | group_specs=None, client=None, |
| 537 | cleanup_in_class=True, **kwargs): |
| 538 | client = client or cls.shares_v2_client |
Valeriy Ponomaryov | e92f09f | 2017-03-16 17:25:47 +0300 | [diff] [blame] | 539 | if (group_specs is None and |
| 540 | CONF.share.capability_sg_consistent_snapshot_support): |
Valeriy Ponomaryov | 3c18893 | 2017-03-15 19:06:23 +0300 | [diff] [blame] | 541 | group_specs = { |
| 542 | 'consistent_snapshot_support': ( |
| 543 | CONF.share.capability_sg_consistent_snapshot_support), |
| 544 | } |
Andrew Kerr | b843692 | 2016-06-01 15:32:43 -0400 | [diff] [blame] | 545 | share_group_type = client.create_share_group_type( |
| 546 | name=name, |
| 547 | share_types=share_types, |
| 548 | is_public=is_public, |
| 549 | group_specs=group_specs, |
lkuchlan | 86f2432 | 2021-04-27 14:23:05 +0300 | [diff] [blame] | 550 | **kwargs)['share_group_type'] |
Andrew Kerr | b843692 | 2016-06-01 15:32:43 -0400 | [diff] [blame] | 551 | resource = { |
| 552 | "type": "share_group_type", |
| 553 | "id": share_group_type["id"], |
| 554 | "client": client, |
| 555 | } |
| 556 | if cleanup_in_class: |
| 557 | cls.class_resources.insert(0, resource) |
| 558 | else: |
| 559 | cls.method_resources.insert(0, resource) |
| 560 | return share_group_type |
Andrew Kerr | bf31e91 | 2015-07-29 10:39:38 -0400 | [diff] [blame] | 561 | |
| 562 | @classmethod |
Marc Koderer | 0abc93b | 2015-07-15 09:18:35 +0200 | [diff] [blame] | 563 | def create_snapshot_wait_for_active(cls, share_id, name=None, |
| 564 | description=None, force=False, |
Ashley Rodriguez | c45cb4b | 2022-02-04 21:29:33 +0000 | [diff] [blame] | 565 | metadata=None, client=None, |
| 566 | cleanup_in_class=True): |
Marc Koderer | 0abc93b | 2015-07-15 09:18:35 +0200 | [diff] [blame] | 567 | if client is None: |
Yogesh | 1f931ff | 2015-09-29 23:41:02 -0400 | [diff] [blame] | 568 | client = cls.shares_v2_client |
Marc Koderer | 0abc93b | 2015-07-15 09:18:35 +0200 | [diff] [blame] | 569 | if description is None: |
| 570 | description = "Tempest's snapshot" |
lkuchlan | 86f2432 | 2021-04-27 14:23:05 +0300 | [diff] [blame] | 571 | snapshot = client.create_snapshot( |
Ashley Rodriguez | c45cb4b | 2022-02-04 21:29:33 +0000 | [diff] [blame] | 572 | share_id, name, description, force, metadata)['snapshot'] |
Marc Koderer | 0abc93b | 2015-07-15 09:18:35 +0200 | [diff] [blame] | 573 | resource = { |
| 574 | "type": "snapshot", |
| 575 | "id": snapshot["id"], |
| 576 | "client": client, |
| 577 | } |
| 578 | if cleanup_in_class: |
| 579 | cls.class_resources.insert(0, resource) |
| 580 | else: |
| 581 | cls.method_resources.insert(0, resource) |
lkuchlan | f7fc5b6 | 2021-01-26 14:53:43 +0200 | [diff] [blame] | 582 | waiters.wait_for_resource_status(client, snapshot["id"], "available", |
| 583 | resource_name='snapshot') |
Marc Koderer | 0abc93b | 2015-07-15 09:18:35 +0200 | [diff] [blame] | 584 | return snapshot |
| 585 | |
| 586 | @classmethod |
Andrew Kerr | b843692 | 2016-06-01 15:32:43 -0400 | [diff] [blame] | 587 | def create_share_group_snapshot_wait_for_active( |
| 588 | cls, share_group_id, name=None, description=None, client=None, |
| 589 | cleanup_in_class=True, **kwargs): |
Clinton Knight | e5c8f09 | 2015-08-27 15:00:23 -0400 | [diff] [blame] | 590 | client = client or cls.shares_v2_client |
Andrew Kerr | bf31e91 | 2015-07-29 10:39:38 -0400 | [diff] [blame] | 591 | if description is None: |
Andrew Kerr | b843692 | 2016-06-01 15:32:43 -0400 | [diff] [blame] | 592 | description = "Tempest's share group snapshot" |
| 593 | sg_snapshot = client.create_share_group_snapshot( |
lkuchlan | 86f2432 | 2021-04-27 14:23:05 +0300 | [diff] [blame] | 594 | share_group_id, name=name, description=description, |
| 595 | **kwargs)['share_group_snapshot'] |
Andrew Kerr | bf31e91 | 2015-07-29 10:39:38 -0400 | [diff] [blame] | 596 | resource = { |
Andrew Kerr | b843692 | 2016-06-01 15:32:43 -0400 | [diff] [blame] | 597 | "type": "share_group_snapshot", |
| 598 | "id": sg_snapshot["id"], |
Andrew Kerr | bf31e91 | 2015-07-29 10:39:38 -0400 | [diff] [blame] | 599 | "client": client, |
| 600 | } |
| 601 | if cleanup_in_class: |
| 602 | cls.class_resources.insert(0, resource) |
| 603 | else: |
| 604 | cls.method_resources.insert(0, resource) |
lkuchlan | f7fc5b6 | 2021-01-26 14:53:43 +0200 | [diff] [blame] | 605 | waiters.wait_for_resource_status( |
| 606 | client, sg_snapshot["id"], "available", |
| 607 | resource_name="share_group_snapshot") |
Andrew Kerr | b843692 | 2016-06-01 15:32:43 -0400 | [diff] [blame] | 608 | return sg_snapshot |
Andrew Kerr | bf31e91 | 2015-07-29 10:39:38 -0400 | [diff] [blame] | 609 | |
| 610 | @classmethod |
Goutham Pacha Ravi | 839c98b | 2019-01-14 23:16:23 -0800 | [diff] [blame] | 611 | def get_availability_zones(cls, client=None, backends=None): |
Yogesh | bdb8810 | 2015-09-29 23:41:02 -0400 | [diff] [blame] | 612 | """List the availability zones for "manila-share" services |
| 613 | |
| 614 | that are currently in "up" state. |
| 615 | """ |
Goutham Pacha Ravi | 839c98b | 2019-01-14 23:16:23 -0800 | [diff] [blame] | 616 | client = client or cls.admin_shares_v2_client |
| 617 | backends = ( |
| 618 | '|'.join(['^%s$' % backend for backend in backends]) |
| 619 | if backends else '.*' |
| 620 | ) |
lkuchlan | 86f2432 | 2021-04-27 14:23:05 +0300 | [diff] [blame] | 621 | cls.services = client.list_services()['services'] |
Yogesh | bdb8810 | 2015-09-29 23:41:02 -0400 | [diff] [blame] | 622 | zones = [service['zone'] for service in cls.services if |
Goutham Pacha Ravi | 839c98b | 2019-01-14 23:16:23 -0800 | [diff] [blame] | 623 | service['binary'] == 'manila-share' and |
| 624 | service['state'] == 'up' and |
| 625 | re.search(backends, service['host'])] |
Douglas Viroel | 161f180 | 2020-04-25 17:18:14 -0300 | [diff] [blame] | 626 | return list(set(zones)) |
Yogesh | bdb8810 | 2015-09-29 23:41:02 -0400 | [diff] [blame] | 627 | |
Goutham Pacha Ravi | 839c98b | 2019-01-14 23:16:23 -0800 | [diff] [blame] | 628 | @classmethod |
| 629 | def get_pools_matching_share_type(cls, share_type, client=None): |
| 630 | client = client or cls.admin_shares_v2_client |
| 631 | if utils.is_microversion_supported('2.23'): |
| 632 | return client.list_pools( |
andrebeltrami | 3b4d485 | 2020-02-04 19:11:54 +0000 | [diff] [blame] | 633 | detail=True, |
Goutham Pacha Ravi | 839c98b | 2019-01-14 23:16:23 -0800 | [diff] [blame] | 634 | search_opts={'share_type': share_type['id']})['pools'] |
| 635 | |
| 636 | pools = client.list_pools(detail=True)['pools'] |
| 637 | share_type = client.get_share_type(share_type['id'])['share_type'] |
| 638 | extra_specs = {} |
| 639 | for k, v in share_type['extra_specs'].items(): |
| 640 | extra_specs[k] = ( |
haixin | 4889581 | 2020-09-30 13:50:37 +0800 | [diff] [blame] | 641 | True if str(v).lower() == 'true' |
| 642 | else False if str(v).lower() == 'false' else v |
Goutham Pacha Ravi | 839c98b | 2019-01-14 23:16:23 -0800 | [diff] [blame] | 643 | ) |
| 644 | return [ |
| 645 | pool for pool in pools if all(y in pool['capabilities'].items() |
| 646 | for y in extra_specs.items()) |
| 647 | ] |
| 648 | |
| 649 | @classmethod |
| 650 | def get_availability_zones_matching_share_type(cls, share_type, |
| 651 | client=None): |
| 652 | |
| 653 | client = client or cls.admin_shares_v2_client |
| 654 | pools_matching_share_type = cls.get_pools_matching_share_type( |
| 655 | share_type, client=client) |
| 656 | backends_matching_share_type = set( |
| 657 | [pool['name'].split("#")[0] for pool in pools_matching_share_type] |
| 658 | ) |
| 659 | azs = cls.get_availability_zones(backends=backends_matching_share_type) |
| 660 | return azs |
| 661 | |
Kiran Pawar | 5974506 | 2021-11-01 12:37:49 +0000 | [diff] [blame] | 662 | def get_pools_for_replication_domain(self, share=None): |
Yogesh | 1f931ff | 2015-09-29 23:41:02 -0400 | [diff] [blame] | 663 | # Get the list of pools for the replication domain |
| 664 | pools = self.admin_client.list_pools(detail=True)['pools'] |
Kiran Pawar | 5974506 | 2021-11-01 12:37:49 +0000 | [diff] [blame] | 665 | if share: |
| 666 | instance_host = self.admin_client.get_share( |
| 667 | share['id'])['share']['host'] |
| 668 | else: |
| 669 | instance_host = self.admin_client.get_share( |
| 670 | self.shares[0]['id'])['share']['host'] |
Yogesh | 1f931ff | 2015-09-29 23:41:02 -0400 | [diff] [blame] | 671 | host_pool = [p for p in pools if p['name'] == instance_host][0] |
| 672 | rep_domain = host_pool['capabilities']['replication_domain'] |
| 673 | pools_in_rep_domain = [p for p in pools if p['capabilities'][ |
| 674 | 'replication_domain'] == rep_domain] |
| 675 | return rep_domain, pools_in_rep_domain |
| 676 | |
Yogesh | bdb8810 | 2015-09-29 23:41:02 -0400 | [diff] [blame] | 677 | @classmethod |
debeltrami | 0d523bb | 2020-08-20 12:48:49 +0000 | [diff] [blame] | 678 | def create_share_replica(cls, share_id, availability_zone=None, |
kpdev | 2521fbf | 2021-08-15 21:54:41 +0200 | [diff] [blame] | 679 | scheduler_hints=None, |
| 680 | share_network_id=None, |
debeltrami | 0d523bb | 2020-08-20 12:48:49 +0000 | [diff] [blame] | 681 | client=None, cleanup_in_class=False, |
| 682 | cleanup=True, |
kpdev | 2521fbf | 2021-08-15 21:54:41 +0200 | [diff] [blame] | 683 | version=CONF.share.max_api_microversion): |
Yogesh | bdb8810 | 2015-09-29 23:41:02 -0400 | [diff] [blame] | 684 | client = client or cls.shares_v2_client |
Douglas Viroel | bd4e78c | 2019-09-02 17:16:30 -0300 | [diff] [blame] | 685 | replica = client.create_share_replica( |
lkuchlan | 86f2432 | 2021-04-27 14:23:05 +0300 | [diff] [blame] | 686 | share_id, availability_zone=availability_zone, |
kpdev | 2521fbf | 2021-08-15 21:54:41 +0200 | [diff] [blame] | 687 | scheduler_hints=scheduler_hints, |
| 688 | share_network_id=share_network_id, |
| 689 | version=version)['share_replica'] |
Yogesh | bdb8810 | 2015-09-29 23:41:02 -0400 | [diff] [blame] | 690 | resource = { |
| 691 | "type": "share_replica", |
| 692 | "id": replica["id"], |
| 693 | "client": client, |
| 694 | "share_id": share_id, |
| 695 | } |
| 696 | # NOTE(Yogi1): Cleanup needs to be disabled during promotion tests. |
| 697 | if cleanup: |
| 698 | if cleanup_in_class: |
| 699 | cls.class_resources.insert(0, resource) |
| 700 | else: |
| 701 | cls.method_resources.insert(0, resource) |
lkuchlan | f7fc5b6 | 2021-01-26 14:53:43 +0200 | [diff] [blame] | 702 | waiters.wait_for_resource_status( |
| 703 | client, replica["id"], constants.STATUS_AVAILABLE, |
| 704 | resource_name='share_replica') |
Yogesh | bdb8810 | 2015-09-29 23:41:02 -0400 | [diff] [blame] | 705 | return replica |
| 706 | |
| 707 | @classmethod |
silvacarloss | d354d67 | 2020-08-23 18:49:52 +0000 | [diff] [blame] | 708 | def delete_share_replica(cls, replica_id, client=None, |
| 709 | version=CONF.share.max_api_microversion): |
Yogesh | bdb8810 | 2015-09-29 23:41:02 -0400 | [diff] [blame] | 710 | client = client or cls.shares_v2_client |
Yogesh | 1f931ff | 2015-09-29 23:41:02 -0400 | [diff] [blame] | 711 | try: |
silvacarloss | d354d67 | 2020-08-23 18:49:52 +0000 | [diff] [blame] | 712 | client.delete_share_replica(replica_id, version=version) |
Yogesh | 1f931ff | 2015-09-29 23:41:02 -0400 | [diff] [blame] | 713 | client.wait_for_resource_deletion(replica_id=replica_id) |
| 714 | except exceptions.NotFound: |
| 715 | pass |
Yogesh | bdb8810 | 2015-09-29 23:41:02 -0400 | [diff] [blame] | 716 | |
| 717 | @classmethod |
silvacarloss | d354d67 | 2020-08-23 18:49:52 +0000 | [diff] [blame] | 718 | def promote_share_replica(cls, replica_id, client=None, |
| 719 | version=CONF.share.max_api_microversion): |
Yogesh | bdb8810 | 2015-09-29 23:41:02 -0400 | [diff] [blame] | 720 | client = client or cls.shares_v2_client |
lkuchlan | 86f2432 | 2021-04-27 14:23:05 +0300 | [diff] [blame] | 721 | replica = client.promote_share_replica( |
| 722 | replica_id, version=version)['share_replica'] |
lkuchlan | f7fc5b6 | 2021-01-26 14:53:43 +0200 | [diff] [blame] | 723 | waiters.wait_for_resource_status( |
lkuchlan | 540e74a | 2021-01-19 18:08:25 +0200 | [diff] [blame] | 724 | client, replica["id"], constants.REPLICATION_STATE_ACTIVE, |
lkuchlan | f7fc5b6 | 2021-01-26 14:53:43 +0200 | [diff] [blame] | 725 | resource_name='share_replica', status_attr="replica_state") |
Yogesh | bdb8810 | 2015-09-29 23:41:02 -0400 | [diff] [blame] | 726 | return replica |
| 727 | |
Goutham Pacha Ravi | 1727f7a | 2020-05-22 13:41:40 -0700 | [diff] [blame] | 728 | @classmethod |
Marc Koderer | 0abc93b | 2015-07-15 09:18:35 +0200 | [diff] [blame] | 729 | def create_share_network(cls, client=None, |
debeltrami | 1753a59 | 2020-05-11 18:27:30 +0000 | [diff] [blame] | 730 | cleanup_in_class=False, |
| 731 | add_security_services=True, **kwargs): |
| 732 | |
Marc Koderer | 0abc93b | 2015-07-15 09:18:35 +0200 | [diff] [blame] | 733 | if client is None: |
| 734 | client = cls.shares_client |
lkuchlan | 86f2432 | 2021-04-27 14:23:05 +0300 | [diff] [blame] | 735 | share_network = client.create_share_network(**kwargs)['share_network'] |
Marc Koderer | 0abc93b | 2015-07-15 09:18:35 +0200 | [diff] [blame] | 736 | resource = { |
| 737 | "type": "share_network", |
| 738 | "id": share_network["id"], |
| 739 | "client": client, |
| 740 | } |
debeltrami | 1753a59 | 2020-05-11 18:27:30 +0000 | [diff] [blame] | 741 | |
Marc Koderer | 0abc93b | 2015-07-15 09:18:35 +0200 | [diff] [blame] | 742 | if cleanup_in_class: |
| 743 | cls.class_resources.insert(0, resource) |
| 744 | else: |
| 745 | cls.method_resources.insert(0, resource) |
debeltrami | 1753a59 | 2020-05-11 18:27:30 +0000 | [diff] [blame] | 746 | |
| 747 | if add_security_services: |
| 748 | cls.provide_and_associate_security_services( |
| 749 | client, share_network["id"], cleanup_in_class=cleanup_in_class) |
| 750 | |
Marc Koderer | 0abc93b | 2015-07-15 09:18:35 +0200 | [diff] [blame] | 751 | return share_network |
| 752 | |
| 753 | @classmethod |
debeltrami | 1753a59 | 2020-05-11 18:27:30 +0000 | [diff] [blame] | 754 | def create_share_network_subnet(cls, |
| 755 | client=None, |
| 756 | cleanup_in_class=False, |
| 757 | **kwargs): |
Douglas Viroel | b7e27e7 | 2019-08-06 19:40:37 -0300 | [diff] [blame] | 758 | if client is None: |
| 759 | client = cls.shares_v2_client |
lkuchlan | 86f2432 | 2021-04-27 14:23:05 +0300 | [diff] [blame] | 760 | share_network_subnet = client.create_subnet( |
| 761 | **kwargs)['share_network_subnet'] |
Douglas Viroel | b7e27e7 | 2019-08-06 19:40:37 -0300 | [diff] [blame] | 762 | resource = { |
| 763 | "type": "share-network-subnet", |
| 764 | "id": share_network_subnet["id"], |
| 765 | "extra_params": { |
| 766 | "share_network_id": share_network_subnet["share_network_id"] |
| 767 | }, |
| 768 | "client": client, |
| 769 | } |
| 770 | if cleanup_in_class: |
| 771 | cls.class_resources.insert(0, resource) |
| 772 | else: |
| 773 | cls.method_resources.insert(0, resource) |
| 774 | return share_network_subnet |
| 775 | |
| 776 | @classmethod |
Marc Koderer | 0abc93b | 2015-07-15 09:18:35 +0200 | [diff] [blame] | 777 | def create_security_service(cls, ss_type="ldap", client=None, |
| 778 | cleanup_in_class=False, **kwargs): |
| 779 | if client is None: |
| 780 | client = cls.shares_client |
lkuchlan | 86f2432 | 2021-04-27 14:23:05 +0300 | [diff] [blame] | 781 | security_service = client.create_security_service( |
| 782 | ss_type, **kwargs)['security_service'] |
Marc Koderer | 0abc93b | 2015-07-15 09:18:35 +0200 | [diff] [blame] | 783 | resource = { |
| 784 | "type": "security_service", |
| 785 | "id": security_service["id"], |
| 786 | "client": client, |
| 787 | } |
| 788 | if cleanup_in_class: |
| 789 | cls.class_resources.insert(0, resource) |
| 790 | else: |
| 791 | cls.method_resources.insert(0, resource) |
| 792 | return security_service |
| 793 | |
| 794 | @classmethod |
Goutham Pacha Ravi | 646fcd2 | 2023-07-14 12:47:47 -0700 | [diff] [blame^] | 795 | def create_resource_lock(cls, resource_id, resource_type='share', |
| 796 | resource_action='delete', lock_reason=None, |
| 797 | client=None, version=LATEST_MICROVERSION, |
| 798 | cleanup_in_class=True): |
| 799 | lock_reason = lock_reason or "locked by tempest tests" |
| 800 | client = client or cls.shares_v2_client |
| 801 | |
| 802 | lock = client.create_resource_lock(resource_id, |
| 803 | resource_type, |
| 804 | resource_action=resource_action, |
| 805 | lock_reason=lock_reason, |
| 806 | version=version)['resource_lock'] |
| 807 | resource = { |
| 808 | "type": "resource_lock", |
| 809 | "id": lock["id"], |
| 810 | "client": client, |
| 811 | } |
| 812 | if cleanup_in_class: |
| 813 | cls.class_resources.insert(0, resource) |
| 814 | else: |
| 815 | cls.method_resources.insert(0, resource) |
| 816 | return lock |
| 817 | |
| 818 | @classmethod |
haixin | 0d1d29f | 2019-08-02 16:50:45 +0800 | [diff] [blame] | 819 | def update_share_type(cls, share_type_id, name=None, |
| 820 | is_public=None, description=None, |
| 821 | client=None): |
| 822 | if client is None: |
| 823 | client = cls.shares_v2_client |
| 824 | share_type = client.update_share_type(share_type_id, name, |
| 825 | is_public, description) |
| 826 | return share_type |
| 827 | |
Goutham Pacha Ravi | af44826 | 2020-06-29 14:24:13 -0700 | [diff] [blame] | 828 | @classmethod |
| 829 | def update_quotas(cls, project_id, user_id=None, cleanup=True, |
| 830 | client=None, **kwargs): |
| 831 | client = client or cls.shares_v2_client |
| 832 | updated_quotas = client.update_quotas(project_id, |
| 833 | user_id=user_id, |
lkuchlan | 86f2432 | 2021-04-27 14:23:05 +0300 | [diff] [blame] | 834 | **kwargs)['quota_set'] |
Goutham Pacha Ravi | af44826 | 2020-06-29 14:24:13 -0700 | [diff] [blame] | 835 | resource = { |
| 836 | "type": "quotas", |
| 837 | "id": project_id, |
| 838 | "client": client, |
| 839 | "user_id": user_id, |
| 840 | } |
| 841 | if cleanup: |
| 842 | cls.method_resources.insert(0, resource) |
| 843 | return updated_quotas |
| 844 | |
Marc Koderer | 0abc93b | 2015-07-15 09:18:35 +0200 | [diff] [blame] | 845 | @classmethod |
Yogesh | 1f931ff | 2015-09-29 23:41:02 -0400 | [diff] [blame] | 846 | def clear_share_replicas(cls, share_id, client=None): |
| 847 | client = client or cls.shares_v2_client |
| 848 | share_replicas = client.list_share_replicas( |
lkuchlan | 86f2432 | 2021-04-27 14:23:05 +0300 | [diff] [blame] | 849 | share_id=share_id)['share_replicas'] |
Yogesh | 1f931ff | 2015-09-29 23:41:02 -0400 | [diff] [blame] | 850 | |
| 851 | for replica in share_replicas: |
| 852 | try: |
| 853 | cls.delete_share_replica(replica['id']) |
| 854 | except exceptions.BadRequest: |
| 855 | # Ignore the exception due to deletion of last active replica |
| 856 | pass |
| 857 | |
| 858 | @classmethod |
Marc Koderer | 0abc93b | 2015-07-15 09:18:35 +0200 | [diff] [blame] | 859 | def clear_resources(cls, resources=None): |
| 860 | """Deletes resources, that were created in test suites. |
| 861 | |
| 862 | This method tries to remove resources from resource list, |
| 863 | if it is not found, assumed it was deleted in test itself. |
| 864 | It is expected, that all resources were added as LIFO |
| 865 | due to restriction of deletion resources, that is in the chain. |
| 866 | |
| 867 | :param resources: dict with keys 'type','id','client' and 'deleted' |
| 868 | """ |
Marc Koderer | 0abc93b | 2015-07-15 09:18:35 +0200 | [diff] [blame] | 869 | if resources is None: |
| 870 | resources = cls.method_resources |
| 871 | for res in resources: |
| 872 | if "deleted" not in res.keys(): |
| 873 | res["deleted"] = False |
| 874 | if "client" not in res.keys(): |
| 875 | res["client"] = cls.shares_client |
| 876 | if not(res["deleted"]): |
| 877 | res_id = res['id'] |
| 878 | client = res["client"] |
| 879 | with handle_cleanup_exceptions(): |
Andreas Jaeger | 0cb685b | 2020-04-01 13:38:38 +0200 | [diff] [blame] | 880 | if res["type"] == "share": |
Yogesh | 1f931ff | 2015-09-29 23:41:02 -0400 | [diff] [blame] | 881 | cls.clear_share_replicas(res_id) |
Andrew Kerr | b843692 | 2016-06-01 15:32:43 -0400 | [diff] [blame] | 882 | share_group_id = res.get('share_group_id') |
| 883 | if share_group_id: |
| 884 | params = {'share_group_id': share_group_id} |
Clinton Knight | e5c8f09 | 2015-08-27 15:00:23 -0400 | [diff] [blame] | 885 | client.delete_share(res_id, params=params) |
| 886 | else: |
| 887 | client.delete_share(res_id) |
Marc Koderer | 0abc93b | 2015-07-15 09:18:35 +0200 | [diff] [blame] | 888 | client.wait_for_resource_deletion(share_id=res_id) |
Andreas Jaeger | 0cb685b | 2020-04-01 13:38:38 +0200 | [diff] [blame] | 889 | elif res["type"] == "snapshot": |
Marc Koderer | 0abc93b | 2015-07-15 09:18:35 +0200 | [diff] [blame] | 890 | client.delete_snapshot(res_id) |
| 891 | client.wait_for_resource_deletion(snapshot_id=res_id) |
Andreas Jaeger | 0cb685b | 2020-04-01 13:38:38 +0200 | [diff] [blame] | 892 | elif (res["type"] == "share_network" and |
yogesh | 06f519f | 2017-06-26 13:16:12 -0400 | [diff] [blame] | 893 | res_id != CONF.share.share_network_id): |
Victoria Martinez de la Cruz | cad9201 | 2018-06-08 14:46:35 -0400 | [diff] [blame] | 894 | client.delete_share_network(res_id) |
| 895 | client.wait_for_resource_deletion(sn_id=res_id) |
debeltrami | 1753a59 | 2020-05-11 18:27:30 +0000 | [diff] [blame] | 896 | elif res["type"] == "dissociate_security_service": |
| 897 | sn_id = res["extra_params"]["share_network_id"] |
| 898 | client.remove_sec_service_from_share_network( |
| 899 | sn_id=sn_id, ss_id=res_id |
| 900 | ) |
Andreas Jaeger | 0cb685b | 2020-04-01 13:38:38 +0200 | [diff] [blame] | 901 | elif res["type"] == "security_service": |
Marc Koderer | 0abc93b | 2015-07-15 09:18:35 +0200 | [diff] [blame] | 902 | client.delete_security_service(res_id) |
| 903 | client.wait_for_resource_deletion(ss_id=res_id) |
Andreas Jaeger | 0cb685b | 2020-04-01 13:38:38 +0200 | [diff] [blame] | 904 | elif res["type"] == "share_type": |
Marc Koderer | 0abc93b | 2015-07-15 09:18:35 +0200 | [diff] [blame] | 905 | client.delete_share_type(res_id) |
| 906 | client.wait_for_resource_deletion(st_id=res_id) |
Andreas Jaeger | 0cb685b | 2020-04-01 13:38:38 +0200 | [diff] [blame] | 907 | elif res["type"] == "share_group": |
Andrew Kerr | b843692 | 2016-06-01 15:32:43 -0400 | [diff] [blame] | 908 | client.delete_share_group(res_id) |
| 909 | client.wait_for_resource_deletion( |
| 910 | share_group_id=res_id) |
Andreas Jaeger | 0cb685b | 2020-04-01 13:38:38 +0200 | [diff] [blame] | 911 | elif res["type"] == "share_group_type": |
Andrew Kerr | b843692 | 2016-06-01 15:32:43 -0400 | [diff] [blame] | 912 | client.delete_share_group_type(res_id) |
| 913 | client.wait_for_resource_deletion( |
| 914 | share_group_type_id=res_id) |
Andreas Jaeger | 0cb685b | 2020-04-01 13:38:38 +0200 | [diff] [blame] | 915 | elif res["type"] == "share_group_snapshot": |
Andrew Kerr | b843692 | 2016-06-01 15:32:43 -0400 | [diff] [blame] | 916 | client.delete_share_group_snapshot(res_id) |
| 917 | client.wait_for_resource_deletion( |
| 918 | share_group_snapshot_id=res_id) |
Andreas Jaeger | 0cb685b | 2020-04-01 13:38:38 +0200 | [diff] [blame] | 919 | elif res["type"] == "share_replica": |
Yogesh | bdb8810 | 2015-09-29 23:41:02 -0400 | [diff] [blame] | 920 | client.delete_share_replica(res_id) |
| 921 | client.wait_for_resource_deletion(replica_id=res_id) |
Andreas Jaeger | 0cb685b | 2020-04-01 13:38:38 +0200 | [diff] [blame] | 922 | elif res["type"] == "share_network_subnet": |
Douglas Viroel | b7e27e7 | 2019-08-06 19:40:37 -0300 | [diff] [blame] | 923 | sn_id = res["extra_params"]["share_network_id"] |
| 924 | client.delete_subnet(sn_id, res_id) |
| 925 | client.wait_for_resource_deletion( |
| 926 | share_network_subnet_id=res_id, |
| 927 | sn_id=sn_id) |
Goutham Pacha Ravi | af44826 | 2020-06-29 14:24:13 -0700 | [diff] [blame] | 928 | elif res["type"] == "quotas": |
| 929 | user_id = res.get('user_id') |
| 930 | client.reset_quotas(res_id, user_id=user_id) |
Goutham Pacha Ravi | 646fcd2 | 2023-07-14 12:47:47 -0700 | [diff] [blame^] | 931 | elif res["type"] == "resource_lock": |
| 932 | client.delete_resource_lock(res_id) |
Marc Koderer | 0abc93b | 2015-07-15 09:18:35 +0200 | [diff] [blame] | 933 | else: |
huayue | 97bacbf | 2016-01-04 09:57:39 +0800 | [diff] [blame] | 934 | LOG.warning("Provided unsupported resource type for " |
junboli | b236c24 | 2017-07-18 18:12:37 +0800 | [diff] [blame] | 935 | "cleanup '%s'. Skipping.", res["type"]) |
Marc Koderer | 0abc93b | 2015-07-15 09:18:35 +0200 | [diff] [blame] | 936 | res["deleted"] = True |
| 937 | |
Marc Koderer | 0abc93b | 2015-07-15 09:18:35 +0200 | [diff] [blame] | 938 | # Useful assertions |
| 939 | def assertDictMatch(self, d1, d2, approx_equal=False, tolerance=0.001): |
| 940 | """Assert two dicts are equivalent. |
| 941 | |
| 942 | This is a 'deep' match in the sense that it handles nested |
| 943 | dictionaries appropriately. |
| 944 | |
| 945 | NOTE: |
| 946 | |
| 947 | If you don't care (or don't know) a given value, you can specify |
| 948 | the string DONTCARE as the value. This will cause that dict-item |
| 949 | to be skipped. |
| 950 | |
| 951 | """ |
| 952 | def raise_assertion(msg): |
| 953 | d1str = str(d1) |
| 954 | d2str = str(d2) |
| 955 | base_msg = ('Dictionaries do not match. %(msg)s d1: %(d1str)s ' |
| 956 | 'd2: %(d2str)s' % |
| 957 | {"msg": msg, "d1str": d1str, "d2str": d2str}) |
| 958 | raise AssertionError(base_msg) |
| 959 | |
| 960 | d1keys = set(d1.keys()) |
| 961 | d2keys = set(d2.keys()) |
| 962 | if d1keys != d2keys: |
| 963 | d1only = d1keys - d2keys |
| 964 | d2only = d2keys - d1keys |
| 965 | raise_assertion('Keys in d1 and not d2: %(d1only)s. ' |
| 966 | 'Keys in d2 and not d1: %(d2only)s' % |
| 967 | {"d1only": d1only, "d2only": d2only}) |
| 968 | |
| 969 | for key in d1keys: |
| 970 | d1value = d1[key] |
| 971 | d2value = d2[key] |
| 972 | try: |
| 973 | error = abs(float(d1value) - float(d2value)) |
| 974 | within_tolerance = error <= tolerance |
| 975 | except (ValueError, TypeError): |
daiki kato | 6914b1a | 2016-03-16 17:16:57 +0900 | [diff] [blame] | 976 | # If both values aren't convertible to float, just ignore |
Marc Koderer | 0abc93b | 2015-07-15 09:18:35 +0200 | [diff] [blame] | 977 | # ValueError if arg is a str, TypeError if it's something else |
| 978 | # (like None) |
| 979 | within_tolerance = False |
| 980 | |
| 981 | if hasattr(d1value, 'keys') and hasattr(d2value, 'keys'): |
| 982 | self.assertDictMatch(d1value, d2value) |
| 983 | elif 'DONTCARE' in (d1value, d2value): |
| 984 | continue |
| 985 | elif approx_equal and within_tolerance: |
| 986 | continue |
| 987 | elif d1value != d2value: |
| 988 | raise_assertion("d1['%(key)s']=%(d1value)s != " |
| 989 | "d2['%(key)s']=%(d2value)s" % |
| 990 | { |
| 991 | "key": key, |
| 992 | "d1value": d1value, |
| 993 | "d2value": d2value |
| 994 | }) |
| 995 | |
Alex Meade | ba8a160 | 2016-05-06 09:33:09 -0400 | [diff] [blame] | 996 | def create_user_message(self): |
| 997 | """Trigger a 'no valid host' situation to generate a message.""" |
| 998 | extra_specs = { |
| 999 | 'vendor_name': 'foobar', |
| 1000 | 'driver_handles_share_servers': CONF.share.multitenancy_enabled, |
| 1001 | } |
| 1002 | share_type_name = data_utils.rand_name("share-type") |
| 1003 | |
| 1004 | bogus_type = self.create_share_type( |
Goutham Pacha Ravi | af44826 | 2020-06-29 14:24:13 -0700 | [diff] [blame] | 1005 | client=self.admin_shares_v2_client, |
Alex Meade | ba8a160 | 2016-05-06 09:33:09 -0400 | [diff] [blame] | 1006 | name=share_type_name, |
| 1007 | extra_specs=extra_specs)['share_type'] |
| 1008 | |
| 1009 | params = {'share_type_id': bogus_type['id'], |
| 1010 | 'share_network_id': self.shares_v2_client.share_network_id} |
lkuchlan | 86f2432 | 2021-04-27 14:23:05 +0300 | [diff] [blame] | 1011 | share = self.shares_v2_client.create_share(**params)['share'] |
Alex Meade | ba8a160 | 2016-05-06 09:33:09 -0400 | [diff] [blame] | 1012 | self.addCleanup(self.shares_v2_client.delete_share, share['id']) |
lkuchlan | f7fc5b6 | 2021-01-26 14:53:43 +0200 | [diff] [blame] | 1013 | waiters.wait_for_resource_status( |
lkuchlan | 540e74a | 2021-01-19 18:08:25 +0200 | [diff] [blame] | 1014 | self.shares_v2_client, share['id'], "error") |
| 1015 | return waiters.wait_for_message(self.shares_v2_client, share['id']) |
Alex Meade | ba8a160 | 2016-05-06 09:33:09 -0400 | [diff] [blame] | 1016 | |
lkuchlan | 5af7cb4 | 2020-07-14 18:05:09 +0300 | [diff] [blame] | 1017 | def allow_access(self, share_id, client=None, access_type=None, |
lkuchlan | ad511b6 | 2022-05-08 09:23:23 +0300 | [diff] [blame] | 1018 | access_level='rw', access_to=None, metadata=None, |
| 1019 | version=LATEST_MICROVERSION, status='active', |
lkuchlan | 5af7cb4 | 2020-07-14 18:05:09 +0300 | [diff] [blame] | 1020 | raise_rule_in_error_state=True, cleanup=True): |
| 1021 | |
| 1022 | client = client or self.shares_v2_client |
lkuchlan | 4a80316 | 2022-11-16 11:34:33 +0200 | [diff] [blame] | 1023 | a_type, a_to = utils.get_access_rule_data_from_config( |
| 1024 | client.share_protocol) |
lkuchlan | 5af7cb4 | 2020-07-14 18:05:09 +0300 | [diff] [blame] | 1025 | access_type = access_type or a_type |
| 1026 | access_to = access_to or a_to |
| 1027 | |
lkuchlan | ad511b6 | 2022-05-08 09:23:23 +0300 | [diff] [blame] | 1028 | kwargs = { |
| 1029 | 'access_type': access_type, |
| 1030 | 'access_to': access_to, |
| 1031 | 'access_level': access_level |
| 1032 | } |
| 1033 | if client is self.shares_v2_client: |
| 1034 | kwargs.update({'metadata': metadata, 'version': version}) |
| 1035 | |
| 1036 | rule = client.create_access_rule(share_id, **kwargs)['access'] |
lkuchlan | f7fc5b6 | 2021-01-26 14:53:43 +0200 | [diff] [blame] | 1037 | waiters.wait_for_resource_status( |
| 1038 | client, share_id, status, resource_name='access_rule', |
lkuchlan | ad511b6 | 2022-05-08 09:23:23 +0300 | [diff] [blame] | 1039 | rule_id=rule['id'], version=version, |
lkuchlan | f7fc5b6 | 2021-01-26 14:53:43 +0200 | [diff] [blame] | 1040 | raise_rule_in_error_state=raise_rule_in_error_state) |
lkuchlan | 5af7cb4 | 2020-07-14 18:05:09 +0300 | [diff] [blame] | 1041 | if cleanup: |
lkuchlan | ad511b6 | 2022-05-08 09:23:23 +0300 | [diff] [blame] | 1042 | self.addCleanup( |
| 1043 | client.wait_for_resource_deletion, rule_id=rule['id'], |
| 1044 | share_id=share_id, version=version) |
lkuchlan | 5af7cb4 | 2020-07-14 18:05:09 +0300 | [diff] [blame] | 1045 | self.addCleanup(client.delete_access_rule, share_id, rule['id']) |
| 1046 | return rule |
| 1047 | |
Marc Koderer | 0abc93b | 2015-07-15 09:18:35 +0200 | [diff] [blame] | 1048 | |
Marc Koderer | 0abc93b | 2015-07-15 09:18:35 +0200 | [diff] [blame] | 1049 | class BaseSharesAdminTest(BaseSharesTest): |
| 1050 | """Base test case class for all Shares Admin API tests.""" |
Valeriy Ponomaryov | 39cdf72 | 2016-05-30 18:16:15 +0300 | [diff] [blame] | 1051 | credentials = ('admin', ) |
| 1052 | |
Victoria Martinez de la Cruz | f6bc6fa | 2018-02-01 11:27:00 -0500 | [diff] [blame] | 1053 | @classmethod |
| 1054 | def setup_clients(cls): |
| 1055 | super(BaseSharesAdminTest, cls).setup_clients() |
| 1056 | # Initialise share clients |
lkuchlan | 3af822b | 2021-06-06 10:35:30 +0300 | [diff] [blame] | 1057 | cls.admin_shares_client = cls.os_admin.share_v1.SharesClient() |
Victoria Martinez de la Cruz | f6bc6fa | 2018-02-01 11:27:00 -0500 | [diff] [blame] | 1058 | cls.admin_shares_v2_client = cls.os_admin.share_v2.SharesV2Client() |
| 1059 | |
lkuchlan | 3af822b | 2021-06-06 10:35:30 +0300 | [diff] [blame] | 1060 | @staticmethod |
| 1061 | def add_extra_specs_to_dict(extra_specs=None): |
| 1062 | """Add any required extra-specs to share type dictionary""" |
haixin | 4889581 | 2020-09-30 13:50:37 +0800 | [diff] [blame] | 1063 | dhss = str(CONF.share.multitenancy_enabled) |
lkuchlan | 3af822b | 2021-06-06 10:35:30 +0300 | [diff] [blame] | 1064 | extra_specs_dict = {"driver_handles_share_servers": dhss} |
| 1065 | if extra_specs: |
| 1066 | extra_specs_dict.update(extra_specs) |
Felipe Rodrigues | 6e56677 | 2021-08-23 14:57:50 -0300 | [diff] [blame] | 1067 | if CONF.share.capability_thin_provisioned: |
| 1068 | extra_specs_dict['thin_provisioning'] = 'True' |
lkuchlan | 3af822b | 2021-06-06 10:35:30 +0300 | [diff] [blame] | 1069 | return extra_specs_dict |
| 1070 | |
Victoria Martinez de la Cruz | f6bc6fa | 2018-02-01 11:27:00 -0500 | [diff] [blame] | 1071 | @classmethod |
lkuchlan | 3af822b | 2021-06-06 10:35:30 +0300 | [diff] [blame] | 1072 | def create_share_type(cls, name=None, is_public=True, client=None, |
| 1073 | cleanup_in_class=True, extra_specs=None, **kwargs): |
| 1074 | name = name or data_utils.rand_name( |
| 1075 | cls.__class__.__name__ + 'share-type') |
| 1076 | client = client or cls.admin_shares_v2_client |
| 1077 | extra_specs = cls.add_extra_specs_to_dict(extra_specs=extra_specs) |
| 1078 | share_type = client.create_share_type(name, is_public, |
| 1079 | extra_specs=extra_specs, |
| 1080 | **kwargs)['share_type'] |
| 1081 | resource = { |
| 1082 | "type": "share_type", |
| 1083 | "id": share_type["id"], |
| 1084 | "client": client, |
| 1085 | } |
| 1086 | if cleanup_in_class: |
| 1087 | cls.class_resources.insert(0, resource) |
| 1088 | else: |
| 1089 | cls.method_resources.insert(0, resource) |
| 1090 | return share_type |
Victoria Martinez de la Cruz | f6bc6fa | 2018-02-01 11:27:00 -0500 | [diff] [blame] | 1091 | |
| 1092 | @classmethod |
| 1093 | def _create_share_group_type(cls): |
| 1094 | share_group_type_name = data_utils.rand_name("unique_sgtype_name") |
| 1095 | return cls.create_share_group_type( |
| 1096 | name=share_group_type_name, share_types=[cls.share_type_id], |
| 1097 | client=cls.admin_shares_v2_client) |
| 1098 | |
Lucio Seki | 3705694 | 2019-01-24 15:40:20 -0200 | [diff] [blame] | 1099 | def _create_share_for_manage(self): |
| 1100 | creation_data = { |
lkuchlan | 3af822b | 2021-06-06 10:35:30 +0300 | [diff] [blame] | 1101 | 'share_type_id': self.st['id'], |
Lucio Seki | 3705694 | 2019-01-24 15:40:20 -0200 | [diff] [blame] | 1102 | 'share_protocol': self.protocol, |
| 1103 | } |
| 1104 | |
| 1105 | share = self.create_share(**creation_data) |
lkuchlan | 86f2432 | 2021-04-27 14:23:05 +0300 | [diff] [blame] | 1106 | share = self.shares_v2_client.get_share(share['id'])['share'] |
Lucio Seki | 3705694 | 2019-01-24 15:40:20 -0200 | [diff] [blame] | 1107 | |
| 1108 | if utils.is_microversion_ge(CONF.share.max_api_microversion, "2.9"): |
lkuchlan | 86f2432 | 2021-04-27 14:23:05 +0300 | [diff] [blame] | 1109 | el = self.shares_v2_client.list_share_export_locations( |
| 1110 | share["id"])['export_locations'] |
Lucio Seki | 3705694 | 2019-01-24 15:40:20 -0200 | [diff] [blame] | 1111 | share["export_locations"] = el |
| 1112 | |
| 1113 | return share |
| 1114 | |
| 1115 | def _unmanage_share_and_wait(self, share): |
| 1116 | self.shares_v2_client.unmanage_share(share['id']) |
| 1117 | self.shares_v2_client.wait_for_resource_deletion(share_id=share['id']) |
| 1118 | |
| 1119 | def _reset_state_and_delete_share(self, share): |
| 1120 | self.shares_v2_client.reset_state(share['id']) |
| 1121 | self._delete_share_and_wait(share) |
| 1122 | |
| 1123 | def _delete_snapshot_and_wait(self, snap): |
| 1124 | self.shares_v2_client.delete_snapshot(snap['id']) |
| 1125 | self.shares_v2_client.wait_for_resource_deletion( |
| 1126 | snapshot_id=snap['id'] |
| 1127 | ) |
| 1128 | self.assertRaises(exceptions.NotFound, |
| 1129 | self.shares_v2_client.get_snapshot, |
| 1130 | snap['id']) |
| 1131 | |
| 1132 | def _delete_share_and_wait(self, share): |
| 1133 | self.shares_v2_client.delete_share(share['id']) |
| 1134 | self.shares_v2_client.wait_for_resource_deletion(share_id=share['id']) |
| 1135 | self.assertRaises(exceptions.NotFound, |
| 1136 | self.shares_v2_client.get_share, |
| 1137 | share['id']) |
| 1138 | |
| 1139 | def _manage_share(self, share, name, description, share_server_id): |
| 1140 | managed_share = self.shares_v2_client.manage_share( |
| 1141 | service_host=share['host'], |
| 1142 | export_path=share['export_locations'][0], |
| 1143 | protocol=share['share_proto'], |
lkuchlan | 3af822b | 2021-06-06 10:35:30 +0300 | [diff] [blame] | 1144 | share_type_id=self.share_type['id'], |
Lucio Seki | 3705694 | 2019-01-24 15:40:20 -0200 | [diff] [blame] | 1145 | name=name, |
| 1146 | description=description, |
| 1147 | share_server_id=share_server_id |
lkuchlan | 86f2432 | 2021-04-27 14:23:05 +0300 | [diff] [blame] | 1148 | )['share'] |
lkuchlan | f7fc5b6 | 2021-01-26 14:53:43 +0200 | [diff] [blame] | 1149 | waiters.wait_for_resource_status( |
lkuchlan | 540e74a | 2021-01-19 18:08:25 +0200 | [diff] [blame] | 1150 | self.shares_v2_client, managed_share['id'], |
| 1151 | constants.STATUS_AVAILABLE |
Lucio Seki | 3705694 | 2019-01-24 15:40:20 -0200 | [diff] [blame] | 1152 | ) |
| 1153 | |
| 1154 | return managed_share |
| 1155 | |
| 1156 | def _unmanage_share_server_and_wait(self, server): |
| 1157 | self.shares_v2_client.unmanage_share_server(server['id']) |
| 1158 | self.shares_v2_client.wait_for_resource_deletion( |
| 1159 | server_id=server['id'] |
| 1160 | ) |
| 1161 | |
| 1162 | def _manage_share_server(self, share_server, fields=None): |
| 1163 | params = fields or {} |
Douglas Viroel | b7e27e7 | 2019-08-06 19:40:37 -0300 | [diff] [blame] | 1164 | subnet_id = params.get('share_network_subnet_id', None) |
Lucio Seki | 3705694 | 2019-01-24 15:40:20 -0200 | [diff] [blame] | 1165 | managed_share_server = self.shares_v2_client.manage_share_server( |
| 1166 | params.get('host', share_server['host']), |
| 1167 | params.get('share_network_id', share_server['share_network_id']), |
| 1168 | params.get('identifier', share_server['identifier']), |
Douglas Viroel | b7e27e7 | 2019-08-06 19:40:37 -0300 | [diff] [blame] | 1169 | share_network_subnet_id=subnet_id, |
lkuchlan | 86f2432 | 2021-04-27 14:23:05 +0300 | [diff] [blame] | 1170 | )['share_server'] |
lkuchlan | f7fc5b6 | 2021-01-26 14:53:43 +0200 | [diff] [blame] | 1171 | waiters.wait_for_resource_status( |
lkuchlan | 540e74a | 2021-01-19 18:08:25 +0200 | [diff] [blame] | 1172 | self.shares_v2_client, managed_share_server['id'], |
lkuchlan | f7fc5b6 | 2021-01-26 14:53:43 +0200 | [diff] [blame] | 1173 | constants.SERVER_STATE_ACTIVE, resource_name='share_server' |
Lucio Seki | 3705694 | 2019-01-24 15:40:20 -0200 | [diff] [blame] | 1174 | ) |
| 1175 | |
| 1176 | return managed_share_server |
| 1177 | |
| 1178 | def _delete_share_server_and_wait(self, share_server_id): |
| 1179 | self.shares_v2_client.delete_share_server( |
| 1180 | share_server_id |
| 1181 | ) |
| 1182 | self.shares_v2_client.wait_for_resource_deletion( |
| 1183 | server_id=share_server_id) |
| 1184 | |
lkuchlan | 3af822b | 2021-06-06 10:35:30 +0300 | [diff] [blame] | 1185 | def create_user_message(self): |
| 1186 | """Trigger a 'no valid host' situation to generate a message.""" |
| 1187 | extra_specs = { |
| 1188 | 'vendor_name': 'foobar', |
| 1189 | 'driver_handles_share_servers': CONF.share.multitenancy_enabled, |
| 1190 | } |
| 1191 | share_type_name = data_utils.rand_name("share-type") |
Valeriy Ponomaryov | 39cdf72 | 2016-05-30 18:16:15 +0300 | [diff] [blame] | 1192 | |
lkuchlan | 3af822b | 2021-06-06 10:35:30 +0300 | [diff] [blame] | 1193 | bogus_type = self.create_share_type( |
| 1194 | client=self.admin_shares_v2_client, |
| 1195 | name=share_type_name, |
| 1196 | extra_specs=extra_specs) |
| 1197 | |
| 1198 | params = {'share_type_id': bogus_type['id'], |
| 1199 | 'share_network_id': self.shares_v2_client.share_network_id} |
lkuchlan | 86f2432 | 2021-04-27 14:23:05 +0300 | [diff] [blame] | 1200 | share = self.shares_v2_client.create_share(**params)['share'] |
lkuchlan | 3af822b | 2021-06-06 10:35:30 +0300 | [diff] [blame] | 1201 | self.addCleanup(self.shares_v2_client.delete_share, share['id']) |
| 1202 | waiters.wait_for_resource_status( |
| 1203 | self.shares_v2_client, share['id'], "error") |
| 1204 | return waiters.wait_for_message(self.shares_v2_client, share['id']) |
| 1205 | |
| 1206 | |
| 1207 | class BaseSharesMixedTest(BaseSharesAdminTest): |
| 1208 | """Base test case class for all Shares API tests with all user roles. |
| 1209 | |
| 1210 | Tests deriving from this class can use the primary project's clients |
| 1211 | (self.shares_client, self.shares_v2_client) and the alt project user's |
| 1212 | clients (self.alt_shares_client, self.alt_shares_v2_client) to perform |
| 1213 | API calls and validations. Although admin clients are available for use, |
| 1214 | their use should be limited to performing bootstrapping (e.g., creating |
| 1215 | a share type, or resetting state of a resource, etc.). No API validation |
| 1216 | must be performed against admin APIs. Use BaseAdminTest as a base class |
| 1217 | for such tests. |
| 1218 | """ |
Valeriy Ponomaryov | 39cdf72 | 2016-05-30 18:16:15 +0300 | [diff] [blame] | 1219 | credentials = ('primary', 'alt', 'admin') |
Marc Koderer | 0abc93b | 2015-07-15 09:18:35 +0200 | [diff] [blame] | 1220 | |
Goutham Pacha Ravi | c678e21 | 2020-03-20 11:13:47 -0700 | [diff] [blame] | 1221 | # Will be cleaned up in resource_cleanup if the class |
| 1222 | class_project_users_created = [] |
| 1223 | |
| 1224 | @classmethod |
| 1225 | def resource_cleanup(cls): |
| 1226 | cls.clear_project_users(cls.class_project_users_created) |
| 1227 | super(BaseSharesMixedTest, cls).resource_cleanup() |
| 1228 | |
| 1229 | @classmethod |
| 1230 | def clear_project_users(cls, users=None): |
| 1231 | users = users or cls.class_project_users_created |
| 1232 | for user in users: |
| 1233 | with handle_cleanup_exceptions(): |
| 1234 | cls.os_admin.creds_client.delete_user(user['id']) |
| 1235 | |
Marc Koderer | 0abc93b | 2015-07-15 09:18:35 +0200 | [diff] [blame] | 1236 | @classmethod |
Valeriy Ponomaryov | 39cdf72 | 2016-05-30 18:16:15 +0300 | [diff] [blame] | 1237 | def setup_clients(cls): |
| 1238 | super(BaseSharesMixedTest, cls).setup_clients() |
Andrea Frittoli (andreaf) | 369391a | 2016-06-27 18:59:13 +0100 | [diff] [blame] | 1239 | cls.alt_shares_client = cls.os_alt.share_v1.SharesClient() |
| 1240 | cls.alt_shares_v2_client = cls.os_alt.share_v2.SharesV2Client() |
| 1241 | # Initialise network clients |
| 1242 | cls.os_admin.networks_client = cls.os_admin.network.NetworksClient() |
| 1243 | cls.os_alt.networks_client = cls.os_alt.network.NetworksClient() |
Goutham Pacha Ravi | c678e21 | 2020-03-20 11:13:47 -0700 | [diff] [blame] | 1244 | # Initialise identity clients |
| 1245 | cls.admin_project = cls.os_admin.auth_provider.auth_data[1]['project'] |
| 1246 | identity_clients = getattr( |
| 1247 | cls.os_admin, 'identity_%s' % CONF.identity.auth_version) |
| 1248 | cls.os_admin.identity_client = identity_clients.IdentityClient() |
| 1249 | cls.os_admin.projects_client = identity_clients.ProjectsClient() |
| 1250 | cls.os_admin.users_client = identity_clients.UsersClient() |
| 1251 | cls.os_admin.roles_client = identity_clients.RolesClient() |
| 1252 | cls.os_admin.domains_client = ( |
| 1253 | cls.os_admin.identity_v3.DomainsClient() if |
| 1254 | CONF.identity.auth_version == 'v3' else None) |
Goutham Pacha Ravi | 10d4949 | 2021-02-23 16:05:21 -0800 | [diff] [blame] | 1255 | cls.admin_project_member_client = cls.create_user_and_get_client( |
| 1256 | project=cls.admin_project, add_member_role=True) |
Valeriy Ponomaryov | 39cdf72 | 2016-05-30 18:16:15 +0300 | [diff] [blame] | 1257 | |
| 1258 | if CONF.share.multitenancy_enabled: |
| 1259 | admin_share_network_id = cls.provide_share_network( |
| 1260 | cls.admin_shares_v2_client, cls.os_admin.networks_client) |
| 1261 | cls.admin_shares_client.share_network_id = admin_share_network_id |
| 1262 | cls.admin_shares_v2_client.share_network_id = ( |
| 1263 | admin_share_network_id) |
| 1264 | |
| 1265 | alt_share_network_id = cls.provide_share_network( |
| 1266 | cls.alt_shares_v2_client, cls.os_alt.networks_client) |
| 1267 | cls.alt_shares_client.share_network_id = alt_share_network_id |
| 1268 | cls.alt_shares_v2_client.share_network_id = alt_share_network_id |
Victoria Martinez de la Cruz | f6bc6fa | 2018-02-01 11:27:00 -0500 | [diff] [blame] | 1269 | |
| 1270 | @classmethod |
Goutham Pacha Ravi | 10d4949 | 2021-02-23 16:05:21 -0800 | [diff] [blame] | 1271 | def create_user_and_get_client(cls, project=None, add_member_role=True): |
Goutham Pacha Ravi | c678e21 | 2020-03-20 11:13:47 -0700 | [diff] [blame] | 1272 | """Create a user in specified project & set share clients for user |
| 1273 | |
| 1274 | The user will have all roles specified in tempest.conf |
| 1275 | :param: project: a dictionary with project ID and name, if not |
| 1276 | specified, the value will be cls.admin_project |
| 1277 | """ |
| 1278 | project_domain_name = ( |
| 1279 | cls.os_admin.identity_client.auth_provider.credentials.get( |
| 1280 | 'project_domain_name', 'Default')) |
| 1281 | cls.os_admin.creds_client = cred_client.get_creds_client( |
| 1282 | cls.os_admin.identity_client, cls.os_admin.projects_client, |
| 1283 | cls.os_admin.users_client, cls.os_admin.roles_client, |
| 1284 | cls.os_admin.domains_client, project_domain_name) |
| 1285 | |
| 1286 | # User info |
| 1287 | project = project or cls.admin_project |
| 1288 | username = data_utils.rand_name('manila_%s' % project['id']) |
| 1289 | password = data_utils.rand_password() |
| 1290 | email = '%s@example.org' % username |
| 1291 | |
| 1292 | user = cls.os_admin.creds_client.create_user( |
| 1293 | username, password, project, email) |
| 1294 | cls.class_project_users_created.append(user) |
| 1295 | |
Goutham Pacha Ravi | 10d4949 | 2021-02-23 16:05:21 -0800 | [diff] [blame] | 1296 | tempest_roles_to_assign = CONF.auth.tempest_roles or [] |
| 1297 | if "member" not in tempest_roles_to_assign and add_member_role: |
| 1298 | tempest_roles_to_assign.append("member") |
| 1299 | |
| 1300 | for role in tempest_roles_to_assign: |
| 1301 | cls.os_admin.creds_client.assign_user_role(user, project, role) |
Goutham Pacha Ravi | c678e21 | 2020-03-20 11:13:47 -0700 | [diff] [blame] | 1302 | |
| 1303 | user_creds = cls.os_admin.creds_client.get_credentials( |
| 1304 | user, project, password) |
| 1305 | os = clients.Clients(user_creds) |
| 1306 | os.shares_v1_client = os.share_v1.SharesClient() |
| 1307 | os.shares_v2_client = os.share_v2.SharesV2Client() |
| 1308 | return os |