blob: 42c2fabe698ac5e199f7700c215dec7377407ad0 [file] [log] [blame]
Marc Koderer0abc93b2015-07-15 09:18:35 +02001# 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
16import copy
Valeriy Ponomaryov2abf5d72016-06-01 18:30:12 +030017import re
Marc Koderer0abc93b2015-07-15 09:18:35 +020018import traceback
19
Marc Koderer0abc93b2015-07-15 09:18:35 +020020from oslo_log import log
Valeriy Ponomaryov48a2bd72015-11-05 13:22:44 +020021from tempest import config
Goutham Pacha Ravic678e212020-03-20 11:13:47 -070022from tempest.lib.common import cred_client
Ben Swartzlander1c4ff522016-03-02 22:16:23 -050023from tempest.lib.common.utils import data_utils
24from tempest.lib import exceptions
Valeriy Ponomaryov48a2bd72015-11-05 13:22:44 +020025from tempest import test
Marc Koderer0abc93b2015-07-15 09:18:35 +020026
Andrea Frittoli (andreaf)369391a2016-06-27 18:59:13 +010027from manila_tempest_tests import clients
Yogeshbdb88102015-09-29 23:41:02 -040028from manila_tempest_tests.common import constants
lkuchlan540e74a2021-01-19 18:08:25 +020029from manila_tempest_tests.common import waiters
Marc Koderer0abc93b2015-07-15 09:18:35 +020030from manila_tempest_tests import share_exceptions
Valeriy Ponomaryovfcde7712015-12-14 18:06:13 +020031from manila_tempest_tests import utils
Marc Koderer0abc93b2015-07-15 09:18:35 +020032
lkuchlan1d1461d2020-08-04 11:19:11 +030033
Marc Koderer0abc93b2015-07-15 09:18:35 +020034CONF = config.CONF
35LOG = log.getLogger(__name__)
36
Valeriy Ponomaryov2abf5d72016-06-01 18:30:12 +030037# Test tags related to test direction
38TAG_POSITIVE = "positive"
39TAG_NEGATIVE = "negative"
40
41# Test tags related to service involvement
Tom Barron69f96962019-07-29 17:07:03 -040042# Only requires that manila-api service running.
Valeriy Ponomaryov2abf5d72016-06-01 18:30:12 +030043TAG_API = "api"
Tom Barron69f96962019-07-29 17:07:03 -040044# Requires all manila services running, intended to test back-end
45# (manila-share) behavior.
Valeriy Ponomaryov2abf5d72016-06-01 18:30:12 +030046TAG_BACKEND = "backend"
Tom Barron69f96962019-07-29 17:07:03 -040047# Requires all manila services running, intended to test API behavior.
Valeriy Ponomaryov2abf5d72016-06-01 18:30:12 +030048TAG_API_WITH_BACKEND = "api_with_backend"
49
50TAGS_MAPPER = {
51 "p": TAG_POSITIVE,
52 "n": TAG_NEGATIVE,
53 "a": TAG_API,
54 "b": TAG_BACKEND,
55 "ab": TAG_API_WITH_BACKEND,
56}
57TAGS_PATTERN = re.compile(
58 r"(?=.*\[.*\b(%(p)s|%(n)s)\b.*\])(?=.*\[.*\b(%(a)s|%(b)s|%(ab)s)\b.*\])" %
59 TAGS_MAPPER)
60
lkuchlanad511b62022-05-08 09:23:23 +030061LATEST_MICROVERSION = CONF.share.max_api_microversion
62
Valeriy Ponomaryov2abf5d72016-06-01 18:30:12 +030063
64def 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 Koderer0abc93b2015-07-15 09:18:35 +020074
75class 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: "
junbolib236c242017-07-18 18:12:37 +080094 "\n%s", traceback.format_exc())
Marc Koderer0abc93b2015-07-15 09:18:35 +020095 return True # Suppress error if any
96
97
Marc Koderer0abc93b2015-07-15 09:18:35 +020098class BaseSharesTest(test.BaseTestCase):
99 """Base test case class for all Manila API tests."""
100
Valeriy Ponomaryov39cdf722016-05-30 18:16:15 +0300101 credentials = ('primary', )
Marc Koderer0abc93b2015-07-15 09:18:35 +0200102 force_tenant_isolation = False
Vitaliy Levitksicfebfff2016-12-15 16:16:35 +0200103 protocols = ["nfs", "cifs", "glusterfs", "hdfs", "cephfs", "maprfs"]
Marc Koderer0abc93b2015-07-15 09:18:35 +0200104
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)369391a2016-06-27 18:59:13 +0100111 # 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 Koderer0abc93b2015-07-15 09:18:35 +0200115 @classmethod
Daniel Melladoe5269142017-01-12 12:17:58 +0000116 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")
lkuchlana3b6f7a2020-01-07 10:45:45 +0200120 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 Melladoe5269142017-01-12 12:17:58 +0000123
124 @classmethod
Marc Koderer0abc93b2015-07-15 09:18:35 +0200125 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 Ravi4a0b7322020-06-30 19:42:45 -0700131 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 Ponomaryov39cdf722016-05-30 18:16:15 +0300149 def setup_clients(cls):
150 super(BaseSharesTest, cls).setup_clients()
151 os = getattr(cls, 'os_%s' % cls.credentials[0])
Andrea Frittoli (andreaf)369391a2016-06-27 18:59:13 +0100152 # 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 Ravi4a0b7322020-06-30 19:42:45 -0700156 cls.networks_client = None
157 cls.subnets_client = None
Andrea Frittoli (andreaf)369391a2016-06-27 18:59:13 +0100158 if CONF.service_available.neutron:
159 cls.networks_client = os.network.NetworksClient()
160 cls.subnets_client = os.network.SubnetsClient()
Valeriy Ponomaryov4fb305f2016-10-21 13:46:47 +0300161
Goutham Pacha Ravi4a0b7322020-06-30 19:42:45 -0700162 # If DHSS=True, create a share network and set it in the client
163 # for easy access.
Valeriy Ponomaryov39cdf722016-05-30 18:16:15 +0300164 if CONF.share.multitenancy_enabled:
Valeriy Ponomaryovc5dae272016-06-10 18:29:24 +0300165 if (not CONF.service_available.neutron and
166 CONF.share.create_networks_when_multitenancy_enabled):
Goutham Pacha Ravi4a0b7322020-06-30 19:42:45 -0700167 raise cls.skipException(
168 "Neutron support is required when "
169 "CONF.share.create_networks_when_multitenancy_enabled "
170 "is set to True")
Valeriy Ponomaryov39cdf722016-05-30 18:16:15 +0300171 share_network_id = cls.provide_share_network(
Goutham Pacha Ravi4a0b7322020-06-30 19:42:45 -0700172 cls.shares_client, cls.networks_client)
Valeriy Ponomaryov39cdf722016-05-30 18:16:15 +0300173 cls.shares_client.share_network_id = share_network_id
174 cls.shares_v2_client.share_network_id = share_network_id
175
Marc Koderer0abc93b2015-07-15 09:18:35 +0200176 def setUp(self):
177 super(BaseSharesTest, self).setUp()
Valeriy Ponomaryovdd162cb2016-01-20 19:09:49 +0200178 self.addCleanup(self.clear_resources)
Valeriy Ponomaryov2abf5d72016-06-01 18:30:12 +0300179 verify_test_has_appropriate_tags(self)
Marc Koderer0abc93b2015-07-15 09:18:35 +0200180
181 @classmethod
182 def resource_cleanup(cls):
Marc Koderer0abc93b2015-07-15 09:18:35 +0200183 cls.clear_resources(cls.class_resources)
Sam Wan241029c2016-07-26 03:37:42 -0400184 super(BaseSharesTest, cls).resource_cleanup()
Marc Koderer0abc93b2015-07-15 09:18:35 +0200185
186 @classmethod
debeltrami1753a592020-05-11 18:27:30 +0000187 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 Ponomaryov48a2bd72015-11-05 13:22:44 +0200270 def provide_share_network(cls, shares_client, networks_client,
Rodrigo Barbieri58d9de32016-09-06 13:16:47 -0300271 ignore_multitenancy_config=False):
Goutham Pacha Ravi4a0b7322020-06-30 19:42:45 -0700272 """Get or create share network for DHSS=True drivers
Marc Koderer0abc93b2015-07-15 09:18:35 +0200273
Goutham Pacha Ravi4a0b7322020-06-30 19:42:45 -0700274 When testing DHSS=True (multitenancy_enabled) drivers, shares must
275 be requested on share networks.
Marc Koderer0abc93b2015-07-15 09:18:35 +0200276 :returns: str -- share network id for shares_client tenant
Goutham Pacha Ravi4a0b7322020-06-30 19:42:45 -0700277 :returns: None -- if single-tenant driver (DHSS=False) is used
Marc Koderer0abc93b2015-07-15 09:18:35 +0200278 """
279
Rodrigo Barbieri58d9de32016-09-06 13:16:47 -0300280 if (not ignore_multitenancy_config and
281 not CONF.share.multitenancy_enabled):
Goutham Pacha Ravi4a0b7322020-06-30 19:42:45 -0700282 # Assumed usage of a single-tenant driver (DHSS=False)
debeltrami1753a592020-05-11 18:27:30 +0000283 return None
Goutham Pacha Raviaf448262020-06-29 14:24:13 -0700284
Goutham Pacha Ravi4a0b7322020-06-30 19:42:45 -0700285 if shares_client.share_network_id:
286 # Share-network already exists, use it
287 return shares_client.share_network_id
debeltrami1753a592020-05-11 18:27:30 +0000288
Goutham Pacha Ravi4a0b7322020-06-30 19:42:45 -0700289 sn_name = "autogenerated_by_tempest"
290 sn_desc = "This share-network was created by tempest"
Rodrigo Barbieri58d9de32016-09-06 13:16:47 -0300291
Goutham Pacha Ravi4a0b7322020-06-30 19:42:45 -0700292 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 Koderer0abc93b2015-07-15 09:18:35 +0200304
Goutham Pacha Ravi4a0b7322020-06-30 19:42:45 -0700305 # 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 )
debeltrami1753a592020-05-11 18:27:30 +0000314
Goutham Pacha Ravi4a0b7322020-06-30 19:42:45 -0700315 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.")
debeltrami1753a592020-05-11 18:27:30 +0000323
Goutham Pacha Ravi4a0b7322020-06-30 19:42:45 -0700324 net_id = tenant_networks_with_subnet[0]['id']
325 subnet_id = tenant_networks_with_subnet[0]['subnets'][0]
debeltrami1753a592020-05-11 18:27:30 +0000326
Goutham Pacha Ravi4a0b7322020-06-30 19:42:45 -0700327 # 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)
debeltrami1753a592020-05-11 18:27:30 +0000335
Goutham Pacha Ravi4a0b7322020-06-30 19:42:45 -0700336 return sn['id']
Marc Koderer0abc93b2015-07-15 09:18:35 +0200337
338 @classmethod
marcusvrne0d7cfd2016-06-24 12:27:55 -0300339 def _create_share(cls, share_protocol=None, size=None, name=None,
Marc Koderer0abc93b2015-07-15 09:18:35 +0200340 snapshot_id=None, description=None, metadata=None,
341 share_network_id=None, share_type_id=None,
Andrew Kerrb8436922016-06-01 15:32:43 -0400342 share_group_id=None, client=None,
Clinton Knighte5c8f092015-08-27 15:00:23 -0400343 cleanup_in_class=True, is_public=False, **kwargs):
Valeriy Ponomaryov1aaa72d2015-09-08 12:59:41 +0300344 client = client or cls.shares_v2_client
Marc Koderer0abc93b2015-07-15 09:18:35 +0200345 description = description or "Tempest's share"
yogesh06f519f2017-06-26 13:16:12 -0400346 share_network_id = (share_network_id or
347 CONF.share.share_network_id or
348 client.share_network_id or None)
Marc Koderer0abc93b2015-07-15 09:18:35 +0200349 metadata = metadata or {}
marcusvrne0d7cfd2016-06-24 12:27:55 -0300350 size = size or CONF.share.share_size
Clinton Knighte5c8f092015-08-27 15:00:23 -0400351 kwargs.update({
Marc Koderer0abc93b2015-07-15 09:18:35 +0200352 '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 Knighte5c8f092015-08-27 15:00:23 -0400361 })
Andrew Kerrb8436922016-06-01 15:32:43 -0400362 if share_group_id:
363 kwargs['share_group_id'] = share_group_id
Andrew Kerrbf31e912015-07-29 10:39:38 -0400364
lkuchlan86f24322021-04-27 14:23:05 +0300365 share = client.create_share(**kwargs)['share']
Andrew Kerrbf31e912015-07-29 10:39:38 -0400366 resource = {"type": "share", "id": share["id"], "client": client,
Andrew Kerrb8436922016-06-01 15:32:43 -0400367 "share_group_id": share_group_id}
Marc Koderer0abc93b2015-07-15 09:18:35 +0200368 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 Barbieri427bc052016-06-06 17:10:06 -0300374 def migrate_share(
375 cls, share_id, dest_host, wait_for_status, client=None,
Rodrigo Barbieri027df982016-11-24 15:52:03 -0200376 force_host_assisted_migration=False, writable=False,
377 nondisruptive=False, preserve_metadata=False,
378 preserve_snapshots=False, new_share_network_id=None,
Rodrigo Barbierid38d2f52016-07-19 22:24:56 -0300379 new_share_type_id=None, **kwargs):
Clinton Knighte5c8f092015-08-27 15:00:23 -0400380 client = client or cls.shares_v2_client
Rodrigo Barbieri427bc052016-06-06 17:10:06 -0300381 client.migrate_share(
382 share_id, dest_host,
383 force_host_assisted_migration=force_host_assisted_migration,
Rodrigo Barbieri027df982016-11-24 15:52:03 -0200384 writable=writable, preserve_metadata=preserve_metadata,
385 nondisruptive=nondisruptive, preserve_snapshots=preserve_snapshots,
Rodrigo Barbieri427bc052016-06-06 17:10:06 -0300386 new_share_network_id=new_share_network_id,
Rodrigo Barbierid38d2f52016-07-19 22:24:56 -0300387 new_share_type_id=new_share_type_id, **kwargs)
lkuchlan540e74a2021-01-19 18:08:25 +0200388 share = waiters.wait_for_migration_status(
389 client, share_id, dest_host, wait_for_status, **kwargs)
Rodrigo Barbierie3305122016-02-03 14:32:24 -0200390 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)
lkuchlan540e74a2021-01-19 18:08:25 +0200396 share = waiters.wait_for_migration_status(
397 client, share_id, dest_host, 'migration_success', **kwargs)
Rodrigo Barbierib7137ad2015-09-06 22:53:16 -0300398 return share
399
400 @classmethod
Rodrigo Barbieric9abf282016-08-24 22:01:31 -0300401 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)
lkuchlan540e74a2021-01-19 18:08:25 +0200404 share = waiters.wait_for_migration_status(
405 client, share_id, dest_host, 'migration_cancelled', **kwargs)
Rodrigo Barbieric9abf282016-08-24 22:01:31 -0300406 return share
407
408 @classmethod
Marc Koderer0abc93b2015-07-15 09:18:35 +0200409 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 Ponomaryov39cdf722016-05-30 18:16:15 +0300431 for d in share_data_list:
Marc Koderer0abc93b2015-07-15 09:18:35 +0200432 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 Ponomaryov39cdf722016-05-30 18:16:15 +0300443
444 data = []
445 for d in share_data_list:
446 client = d["kwargs"].pop("client", cls.shares_v2_client)
yogeshdb32f462016-09-28 15:09:50 -0400447 wait_for_status = d["kwargs"].pop("wait_for_status", True)
Valeriy Ponomaryov39cdf722016-05-30 18:16:15 +0300448 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
yogeshdb32f462016-09-28 15:09:50 -0400457 local_d["wait_for_status"] = wait_for_status
Valeriy Ponomaryov39cdf722016-05-30 18:16:15 +0300458 data.append(local_d)
Marc Koderer0abc93b2015-07-15 09:18:35 +0200459
460 while not all(d["available"] for d in data):
461 for d in data:
yogeshdb32f462016-09-28 15:09:50 -0400462 if not d["wait_for_status"]:
463 d["available"] = True
Marc Koderer0abc93b2015-07-15 09:18:35 +0200464 if d["available"]:
465 continue
Valeriy Ponomaryov1a3e3382016-06-08 15:17:16 +0300466 client = d["kwargs"]["client"]
467 share_id = d["share"]["id"]
Marc Koderer0abc93b2015-07-15 09:18:35 +0200468 try:
lkuchlanf7fc5b62021-01-26 14:53:43 +0200469 waiters.wait_for_resource_status(
lkuchlan540e74a2021-01-19 18:08:25 +0200470 client, share_id, "available")
Marc Koderer0abc93b2015-07-15 09:18:35 +0200471 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 Ponomaryov1a3e3382016-06-08 15:17:16 +0300477 "Trying create another." % share_id)
Marc Koderer0abc93b2015-07-15 09:18:35 +0200478 LOG.error(msg)
479 LOG.error(e)
Valeriy Ponomaryov1a3e3382016-06-08 15:17:16 +0300480 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 Koderer0abc93b2015-07-15 09:18:35 +0200489 d["share"] = cls._create_share(
490 *d["args"], **d["kwargs"])
491 else:
gecong197358663802016-08-25 11:08:45 +0800492 raise
Marc Koderer0abc93b2015-07-15 09:18:35 +0200493
494 return [d["share"] for d in data]
495
496 @classmethod
Andrew Kerrb8436922016-06-01 15:32:43 -0400497 def create_share_group(cls, client=None, cleanup_in_class=True,
498 share_network_id=None, **kwargs):
Clinton Knighte5c8f092015-08-27 15:00:23 -0400499 client = client or cls.shares_v2_client
Andrew Kerrb8436922016-06-01 15:32:43 -0400500 if kwargs.get('source_share_group_snapshot_id') is None:
Goutham Pacha Ravi9221f5e2016-04-21 13:17:49 -0400501 kwargs['share_network_id'] = (share_network_id or
502 client.share_network_id or None)
lkuchlan86f24322021-04-27 14:23:05 +0300503 share_group = client.create_share_group(**kwargs)['share_group']
Andrew Kerrbf31e912015-07-29 10:39:38 -0400504 resource = {
Andrew Kerrb8436922016-06-01 15:32:43 -0400505 "type": "share_group",
506 "id": share_group["id"],
507 "client": client,
508 }
Andrew Kerrbf31e912015-07-29 10:39:38 -0400509 if cleanup_in_class:
510 cls.class_resources.insert(0, resource)
511 else:
512 cls.method_resources.insert(0, resource)
513
Andrew Kerrb8436922016-06-01 15:32:43 -0400514 if kwargs.get('source_share_group_snapshot_id'):
515 new_share_group_shares = client.list_shares(
Andrew Kerrbf31e912015-07-29 10:39:38 -0400516 detailed=True,
lkuchlan86f24322021-04-27 14:23:05 +0300517 params={'share_group_id': share_group['id']})['shares']
Andrew Kerrbf31e912015-07-29 10:39:38 -0400518
Andrew Kerrb8436922016-06-01 15:32:43 -0400519 for share in new_share_group_shares:
Andrew Kerrbf31e912015-07-29 10:39:38 -0400520 resource = {"type": "share",
521 "id": share["id"],
522 "client": client,
Andrew Kerrb8436922016-06-01 15:32:43 -0400523 "share_group_id": share.get("share_group_id")}
Andrew Kerrbf31e912015-07-29 10:39:38 -0400524 if cleanup_in_class:
525 cls.class_resources.insert(0, resource)
526 else:
527 cls.method_resources.insert(0, resource)
528
lkuchlanf7fc5b62021-01-26 14:53:43 +0200529 waiters.wait_for_resource_status(
530 client, share_group['id'], 'available',
531 resource_name='share_group')
Andrew Kerrb8436922016-06-01 15:32:43 -0400532 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 Ponomaryove92f09f2017-03-16 17:25:47 +0300539 if (group_specs is None and
540 CONF.share.capability_sg_consistent_snapshot_support):
Valeriy Ponomaryov3c188932017-03-15 19:06:23 +0300541 group_specs = {
542 'consistent_snapshot_support': (
543 CONF.share.capability_sg_consistent_snapshot_support),
544 }
Andrew Kerrb8436922016-06-01 15:32:43 -0400545 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,
lkuchlan86f24322021-04-27 14:23:05 +0300550 **kwargs)['share_group_type']
Andrew Kerrb8436922016-06-01 15:32:43 -0400551 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 Kerrbf31e912015-07-29 10:39:38 -0400561
562 @classmethod
Marc Koderer0abc93b2015-07-15 09:18:35 +0200563 def create_snapshot_wait_for_active(cls, share_id, name=None,
564 description=None, force=False,
Ashley Rodriguezc45cb4b2022-02-04 21:29:33 +0000565 metadata=None, client=None,
566 cleanup_in_class=True):
Marc Koderer0abc93b2015-07-15 09:18:35 +0200567 if client is None:
Yogesh1f931ff2015-09-29 23:41:02 -0400568 client = cls.shares_v2_client
Marc Koderer0abc93b2015-07-15 09:18:35 +0200569 if description is None:
570 description = "Tempest's snapshot"
lkuchlan86f24322021-04-27 14:23:05 +0300571 snapshot = client.create_snapshot(
Ashley Rodriguezc45cb4b2022-02-04 21:29:33 +0000572 share_id, name, description, force, metadata)['snapshot']
Marc Koderer0abc93b2015-07-15 09:18:35 +0200573 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)
lkuchlanf7fc5b62021-01-26 14:53:43 +0200582 waiters.wait_for_resource_status(client, snapshot["id"], "available",
583 resource_name='snapshot')
Marc Koderer0abc93b2015-07-15 09:18:35 +0200584 return snapshot
585
586 @classmethod
Andrew Kerrb8436922016-06-01 15:32:43 -0400587 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 Knighte5c8f092015-08-27 15:00:23 -0400590 client = client or cls.shares_v2_client
Andrew Kerrbf31e912015-07-29 10:39:38 -0400591 if description is None:
Andrew Kerrb8436922016-06-01 15:32:43 -0400592 description = "Tempest's share group snapshot"
593 sg_snapshot = client.create_share_group_snapshot(
lkuchlan86f24322021-04-27 14:23:05 +0300594 share_group_id, name=name, description=description,
595 **kwargs)['share_group_snapshot']
Andrew Kerrbf31e912015-07-29 10:39:38 -0400596 resource = {
Andrew Kerrb8436922016-06-01 15:32:43 -0400597 "type": "share_group_snapshot",
598 "id": sg_snapshot["id"],
Andrew Kerrbf31e912015-07-29 10:39:38 -0400599 "client": client,
600 }
601 if cleanup_in_class:
602 cls.class_resources.insert(0, resource)
603 else:
604 cls.method_resources.insert(0, resource)
lkuchlanf7fc5b62021-01-26 14:53:43 +0200605 waiters.wait_for_resource_status(
606 client, sg_snapshot["id"], "available",
607 resource_name="share_group_snapshot")
Andrew Kerrb8436922016-06-01 15:32:43 -0400608 return sg_snapshot
Andrew Kerrbf31e912015-07-29 10:39:38 -0400609
610 @classmethod
Goutham Pacha Ravi839c98b2019-01-14 23:16:23 -0800611 def get_availability_zones(cls, client=None, backends=None):
Yogeshbdb88102015-09-29 23:41:02 -0400612 """List the availability zones for "manila-share" services
613
614 that are currently in "up" state.
615 """
Goutham Pacha Ravi839c98b2019-01-14 23:16:23 -0800616 client = client or cls.admin_shares_v2_client
617 backends = (
618 '|'.join(['^%s$' % backend for backend in backends])
619 if backends else '.*'
620 )
lkuchlan86f24322021-04-27 14:23:05 +0300621 cls.services = client.list_services()['services']
Yogeshbdb88102015-09-29 23:41:02 -0400622 zones = [service['zone'] for service in cls.services if
Goutham Pacha Ravi839c98b2019-01-14 23:16:23 -0800623 service['binary'] == 'manila-share' and
624 service['state'] == 'up' and
625 re.search(backends, service['host'])]
Douglas Viroel161f1802020-04-25 17:18:14 -0300626 return list(set(zones))
Yogeshbdb88102015-09-29 23:41:02 -0400627
Goutham Pacha Ravi839c98b2019-01-14 23:16:23 -0800628 @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(
andrebeltrami3b4d4852020-02-04 19:11:54 +0000633 detail=True,
Goutham Pacha Ravi839c98b2019-01-14 23:16:23 -0800634 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] = (
haixin48895812020-09-30 13:50:37 +0800641 True if str(v).lower() == 'true'
642 else False if str(v).lower() == 'false' else v
Goutham Pacha Ravi839c98b2019-01-14 23:16:23 -0800643 )
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 Pawar59745062021-11-01 12:37:49 +0000662 def get_pools_for_replication_domain(self, share=None):
Yogesh1f931ff2015-09-29 23:41:02 -0400663 # Get the list of pools for the replication domain
664 pools = self.admin_client.list_pools(detail=True)['pools']
Kiran Pawar59745062021-11-01 12:37:49 +0000665 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']
Yogesh1f931ff2015-09-29 23:41:02 -0400671 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
Yogeshbdb88102015-09-29 23:41:02 -0400677 @classmethod
debeltrami0d523bb2020-08-20 12:48:49 +0000678 def create_share_replica(cls, share_id, availability_zone=None,
679 client=None, cleanup_in_class=False,
680 cleanup=True,
Kiran Pawar59745062021-11-01 12:37:49 +0000681 version=CONF.share.max_api_microversion,
682 scheduler_hints=None):
Yogeshbdb88102015-09-29 23:41:02 -0400683 client = client or cls.shares_v2_client
Douglas Viroelbd4e78c2019-09-02 17:16:30 -0300684 replica = client.create_share_replica(
lkuchlan86f24322021-04-27 14:23:05 +0300685 share_id, availability_zone=availability_zone,
Kiran Pawar59745062021-11-01 12:37:49 +0000686 version=version, scheduler_hints=scheduler_hints)['share_replica']
Yogeshbdb88102015-09-29 23:41:02 -0400687 resource = {
688 "type": "share_replica",
689 "id": replica["id"],
690 "client": client,
691 "share_id": share_id,
692 }
693 # NOTE(Yogi1): Cleanup needs to be disabled during promotion tests.
694 if cleanup:
695 if cleanup_in_class:
696 cls.class_resources.insert(0, resource)
697 else:
698 cls.method_resources.insert(0, resource)
lkuchlanf7fc5b62021-01-26 14:53:43 +0200699 waiters.wait_for_resource_status(
700 client, replica["id"], constants.STATUS_AVAILABLE,
701 resource_name='share_replica')
Yogeshbdb88102015-09-29 23:41:02 -0400702 return replica
703
704 @classmethod
silvacarlossd354d672020-08-23 18:49:52 +0000705 def delete_share_replica(cls, replica_id, client=None,
706 version=CONF.share.max_api_microversion):
Yogeshbdb88102015-09-29 23:41:02 -0400707 client = client or cls.shares_v2_client
Yogesh1f931ff2015-09-29 23:41:02 -0400708 try:
silvacarlossd354d672020-08-23 18:49:52 +0000709 client.delete_share_replica(replica_id, version=version)
Yogesh1f931ff2015-09-29 23:41:02 -0400710 client.wait_for_resource_deletion(replica_id=replica_id)
711 except exceptions.NotFound:
712 pass
Yogeshbdb88102015-09-29 23:41:02 -0400713
714 @classmethod
silvacarlossd354d672020-08-23 18:49:52 +0000715 def promote_share_replica(cls, replica_id, client=None,
716 version=CONF.share.max_api_microversion):
Yogeshbdb88102015-09-29 23:41:02 -0400717 client = client or cls.shares_v2_client
lkuchlan86f24322021-04-27 14:23:05 +0300718 replica = client.promote_share_replica(
719 replica_id, version=version)['share_replica']
lkuchlanf7fc5b62021-01-26 14:53:43 +0200720 waiters.wait_for_resource_status(
lkuchlan540e74a2021-01-19 18:08:25 +0200721 client, replica["id"], constants.REPLICATION_STATE_ACTIVE,
lkuchlanf7fc5b62021-01-26 14:53:43 +0200722 resource_name='share_replica', status_attr="replica_state")
Yogeshbdb88102015-09-29 23:41:02 -0400723 return replica
724
Goutham Pacha Ravi1727f7a2020-05-22 13:41:40 -0700725 @classmethod
726 def _get_access_rule_data_from_config(cls):
yogeshdb32f462016-09-28 15:09:50 -0400727 """Get the first available access type/to combination from config.
728
729 This method opportunistically picks the first configured protocol
730 to create the share. Do not use this method in tests where you need
731 to test depth and breadth in the access types and access recipients.
732 """
Goutham Pacha Ravi1727f7a2020-05-22 13:41:40 -0700733 protocol = cls.shares_v2_client.share_protocol
yogeshdb32f462016-09-28 15:09:50 -0400734
735 if protocol in CONF.share.enable_ip_rules_for_protocols:
736 access_type = "ip"
737 access_to = utils.rand_ip()
738 elif protocol in CONF.share.enable_user_rules_for_protocols:
739 access_type = "user"
740 access_to = CONF.share.username_for_user_rules
741 elif protocol in CONF.share.enable_cert_rules_for_protocols:
742 access_type = "cert"
743 access_to = "client3.com"
744 elif protocol in CONF.share.enable_cephx_rules_for_protocols:
745 access_type = "cephx"
lkuchlan5af7cb42020-07-14 18:05:09 +0300746 access_to = data_utils.rand_name(
747 cls.__class__.__name__ + '-cephx-id')
yogeshdb32f462016-09-28 15:09:50 -0400748 else:
749 message = "Unrecognized protocol and access rules configuration."
Goutham Pacha Ravi1727f7a2020-05-22 13:41:40 -0700750 raise cls.skipException(message)
yogeshdb32f462016-09-28 15:09:50 -0400751
752 return access_type, access_to
753
Yogeshbdb88102015-09-29 23:41:02 -0400754 @classmethod
Marc Koderer0abc93b2015-07-15 09:18:35 +0200755 def create_share_network(cls, client=None,
debeltrami1753a592020-05-11 18:27:30 +0000756 cleanup_in_class=False,
757 add_security_services=True, **kwargs):
758
Marc Koderer0abc93b2015-07-15 09:18:35 +0200759 if client is None:
760 client = cls.shares_client
lkuchlan86f24322021-04-27 14:23:05 +0300761 share_network = client.create_share_network(**kwargs)['share_network']
Marc Koderer0abc93b2015-07-15 09:18:35 +0200762 resource = {
763 "type": "share_network",
764 "id": share_network["id"],
765 "client": client,
766 }
debeltrami1753a592020-05-11 18:27:30 +0000767
Marc Koderer0abc93b2015-07-15 09:18:35 +0200768 if cleanup_in_class:
769 cls.class_resources.insert(0, resource)
770 else:
771 cls.method_resources.insert(0, resource)
debeltrami1753a592020-05-11 18:27:30 +0000772
773 if add_security_services:
774 cls.provide_and_associate_security_services(
775 client, share_network["id"], cleanup_in_class=cleanup_in_class)
776
Marc Koderer0abc93b2015-07-15 09:18:35 +0200777 return share_network
778
779 @classmethod
debeltrami1753a592020-05-11 18:27:30 +0000780 def create_share_network_subnet(cls,
781 client=None,
782 cleanup_in_class=False,
783 **kwargs):
Douglas Viroelb7e27e72019-08-06 19:40:37 -0300784 if client is None:
785 client = cls.shares_v2_client
lkuchlan86f24322021-04-27 14:23:05 +0300786 share_network_subnet = client.create_subnet(
787 **kwargs)['share_network_subnet']
Douglas Viroelb7e27e72019-08-06 19:40:37 -0300788 resource = {
789 "type": "share-network-subnet",
790 "id": share_network_subnet["id"],
791 "extra_params": {
792 "share_network_id": share_network_subnet["share_network_id"]
793 },
794 "client": client,
795 }
796 if cleanup_in_class:
797 cls.class_resources.insert(0, resource)
798 else:
799 cls.method_resources.insert(0, resource)
800 return share_network_subnet
801
802 @classmethod
Marc Koderer0abc93b2015-07-15 09:18:35 +0200803 def create_security_service(cls, ss_type="ldap", client=None,
804 cleanup_in_class=False, **kwargs):
805 if client is None:
806 client = cls.shares_client
lkuchlan86f24322021-04-27 14:23:05 +0300807 security_service = client.create_security_service(
808 ss_type, **kwargs)['security_service']
Marc Koderer0abc93b2015-07-15 09:18:35 +0200809 resource = {
810 "type": "security_service",
811 "id": security_service["id"],
812 "client": client,
813 }
814 if cleanup_in_class:
815 cls.class_resources.insert(0, resource)
816 else:
817 cls.method_resources.insert(0, resource)
818 return security_service
819
820 @classmethod
haixin0d1d29f2019-08-02 16:50:45 +0800821 def update_share_type(cls, share_type_id, name=None,
822 is_public=None, description=None,
823 client=None):
824 if client is None:
825 client = cls.shares_v2_client
826 share_type = client.update_share_type(share_type_id, name,
827 is_public, description)
828 return share_type
829
Goutham Pacha Raviaf448262020-06-29 14:24:13 -0700830 @classmethod
831 def update_quotas(cls, project_id, user_id=None, cleanup=True,
832 client=None, **kwargs):
833 client = client or cls.shares_v2_client
834 updated_quotas = client.update_quotas(project_id,
835 user_id=user_id,
lkuchlan86f24322021-04-27 14:23:05 +0300836 **kwargs)['quota_set']
Goutham Pacha Raviaf448262020-06-29 14:24:13 -0700837 resource = {
838 "type": "quotas",
839 "id": project_id,
840 "client": client,
841 "user_id": user_id,
842 }
843 if cleanup:
844 cls.method_resources.insert(0, resource)
845 return updated_quotas
846
Marc Koderer0abc93b2015-07-15 09:18:35 +0200847 @classmethod
Yogesh1f931ff2015-09-29 23:41:02 -0400848 def clear_share_replicas(cls, share_id, client=None):
849 client = client or cls.shares_v2_client
850 share_replicas = client.list_share_replicas(
lkuchlan86f24322021-04-27 14:23:05 +0300851 share_id=share_id)['share_replicas']
Yogesh1f931ff2015-09-29 23:41:02 -0400852
853 for replica in share_replicas:
854 try:
855 cls.delete_share_replica(replica['id'])
856 except exceptions.BadRequest:
857 # Ignore the exception due to deletion of last active replica
858 pass
859
860 @classmethod
Marc Koderer0abc93b2015-07-15 09:18:35 +0200861 def clear_resources(cls, resources=None):
862 """Deletes resources, that were created in test suites.
863
864 This method tries to remove resources from resource list,
865 if it is not found, assumed it was deleted in test itself.
866 It is expected, that all resources were added as LIFO
867 due to restriction of deletion resources, that is in the chain.
868
869 :param resources: dict with keys 'type','id','client' and 'deleted'
870 """
Marc Koderer0abc93b2015-07-15 09:18:35 +0200871 if resources is None:
872 resources = cls.method_resources
873 for res in resources:
874 if "deleted" not in res.keys():
875 res["deleted"] = False
876 if "client" not in res.keys():
877 res["client"] = cls.shares_client
878 if not(res["deleted"]):
879 res_id = res['id']
880 client = res["client"]
881 with handle_cleanup_exceptions():
Andreas Jaeger0cb685b2020-04-01 13:38:38 +0200882 if res["type"] == "share":
Yogesh1f931ff2015-09-29 23:41:02 -0400883 cls.clear_share_replicas(res_id)
Andrew Kerrb8436922016-06-01 15:32:43 -0400884 share_group_id = res.get('share_group_id')
885 if share_group_id:
886 params = {'share_group_id': share_group_id}
Clinton Knighte5c8f092015-08-27 15:00:23 -0400887 client.delete_share(res_id, params=params)
888 else:
889 client.delete_share(res_id)
Marc Koderer0abc93b2015-07-15 09:18:35 +0200890 client.wait_for_resource_deletion(share_id=res_id)
Andreas Jaeger0cb685b2020-04-01 13:38:38 +0200891 elif res["type"] == "snapshot":
Marc Koderer0abc93b2015-07-15 09:18:35 +0200892 client.delete_snapshot(res_id)
893 client.wait_for_resource_deletion(snapshot_id=res_id)
Andreas Jaeger0cb685b2020-04-01 13:38:38 +0200894 elif (res["type"] == "share_network" and
yogesh06f519f2017-06-26 13:16:12 -0400895 res_id != CONF.share.share_network_id):
Victoria Martinez de la Cruzcad92012018-06-08 14:46:35 -0400896 client.delete_share_network(res_id)
897 client.wait_for_resource_deletion(sn_id=res_id)
debeltrami1753a592020-05-11 18:27:30 +0000898 elif res["type"] == "dissociate_security_service":
899 sn_id = res["extra_params"]["share_network_id"]
900 client.remove_sec_service_from_share_network(
901 sn_id=sn_id, ss_id=res_id
902 )
Andreas Jaeger0cb685b2020-04-01 13:38:38 +0200903 elif res["type"] == "security_service":
Marc Koderer0abc93b2015-07-15 09:18:35 +0200904 client.delete_security_service(res_id)
905 client.wait_for_resource_deletion(ss_id=res_id)
Andreas Jaeger0cb685b2020-04-01 13:38:38 +0200906 elif res["type"] == "share_type":
Marc Koderer0abc93b2015-07-15 09:18:35 +0200907 client.delete_share_type(res_id)
908 client.wait_for_resource_deletion(st_id=res_id)
Andreas Jaeger0cb685b2020-04-01 13:38:38 +0200909 elif res["type"] == "share_group":
Andrew Kerrb8436922016-06-01 15:32:43 -0400910 client.delete_share_group(res_id)
911 client.wait_for_resource_deletion(
912 share_group_id=res_id)
Andreas Jaeger0cb685b2020-04-01 13:38:38 +0200913 elif res["type"] == "share_group_type":
Andrew Kerrb8436922016-06-01 15:32:43 -0400914 client.delete_share_group_type(res_id)
915 client.wait_for_resource_deletion(
916 share_group_type_id=res_id)
Andreas Jaeger0cb685b2020-04-01 13:38:38 +0200917 elif res["type"] == "share_group_snapshot":
Andrew Kerrb8436922016-06-01 15:32:43 -0400918 client.delete_share_group_snapshot(res_id)
919 client.wait_for_resource_deletion(
920 share_group_snapshot_id=res_id)
Andreas Jaeger0cb685b2020-04-01 13:38:38 +0200921 elif res["type"] == "share_replica":
Yogeshbdb88102015-09-29 23:41:02 -0400922 client.delete_share_replica(res_id)
923 client.wait_for_resource_deletion(replica_id=res_id)
Andreas Jaeger0cb685b2020-04-01 13:38:38 +0200924 elif res["type"] == "share_network_subnet":
Douglas Viroelb7e27e72019-08-06 19:40:37 -0300925 sn_id = res["extra_params"]["share_network_id"]
926 client.delete_subnet(sn_id, res_id)
927 client.wait_for_resource_deletion(
928 share_network_subnet_id=res_id,
929 sn_id=sn_id)
Goutham Pacha Raviaf448262020-06-29 14:24:13 -0700930 elif res["type"] == "quotas":
931 user_id = res.get('user_id')
932 client.reset_quotas(res_id, user_id=user_id)
Marc Koderer0abc93b2015-07-15 09:18:35 +0200933 else:
huayue97bacbf2016-01-04 09:57:39 +0800934 LOG.warning("Provided unsupported resource type for "
junbolib236c242017-07-18 18:12:37 +0800935 "cleanup '%s'. Skipping.", res["type"])
Marc Koderer0abc93b2015-07-15 09:18:35 +0200936 res["deleted"] = True
937
938 @classmethod
939 def generate_share_network_data(self):
940 data = {
941 "name": data_utils.rand_name("sn-name"),
942 "description": data_utils.rand_name("sn-desc"),
943 "neutron_net_id": data_utils.rand_name("net-id"),
944 "neutron_subnet_id": data_utils.rand_name("subnet-id"),
945 }
946 return data
947
948 @classmethod
Douglas Viroelb7e27e72019-08-06 19:40:37 -0300949 def generate_subnet_data(self):
950 data = {
951 "neutron_net_id": data_utils.rand_name("net-id"),
952 "neutron_subnet_id": data_utils.rand_name("subnet-id"),
953 }
954 return data
955
956 @classmethod
Maurice Schreiber5ac37172018-02-01 15:17:31 +0100957 def generate_security_service_data(self, set_ou=False):
Marc Koderer0abc93b2015-07-15 09:18:35 +0200958 data = {
959 "name": data_utils.rand_name("ss-name"),
960 "description": data_utils.rand_name("ss-desc"),
Valeriy Ponomaryovfcde7712015-12-14 18:06:13 +0200961 "dns_ip": utils.rand_ip(),
962 "server": utils.rand_ip(),
Marc Koderer0abc93b2015-07-15 09:18:35 +0200963 "domain": data_utils.rand_name("ss-domain"),
964 "user": data_utils.rand_name("ss-user"),
965 "password": data_utils.rand_name("ss-password"),
966 }
Maurice Schreiber5ac37172018-02-01 15:17:31 +0100967 if set_ou:
968 data["ou"] = data_utils.rand_name("ss-ou")
969
Marc Koderer0abc93b2015-07-15 09:18:35 +0200970 return data
971
972 # Useful assertions
973 def assertDictMatch(self, d1, d2, approx_equal=False, tolerance=0.001):
974 """Assert two dicts are equivalent.
975
976 This is a 'deep' match in the sense that it handles nested
977 dictionaries appropriately.
978
979 NOTE:
980
981 If you don't care (or don't know) a given value, you can specify
982 the string DONTCARE as the value. This will cause that dict-item
983 to be skipped.
984
985 """
986 def raise_assertion(msg):
987 d1str = str(d1)
988 d2str = str(d2)
989 base_msg = ('Dictionaries do not match. %(msg)s d1: %(d1str)s '
990 'd2: %(d2str)s' %
991 {"msg": msg, "d1str": d1str, "d2str": d2str})
992 raise AssertionError(base_msg)
993
994 d1keys = set(d1.keys())
995 d2keys = set(d2.keys())
996 if d1keys != d2keys:
997 d1only = d1keys - d2keys
998 d2only = d2keys - d1keys
999 raise_assertion('Keys in d1 and not d2: %(d1only)s. '
1000 'Keys in d2 and not d1: %(d2only)s' %
1001 {"d1only": d1only, "d2only": d2only})
1002
1003 for key in d1keys:
1004 d1value = d1[key]
1005 d2value = d2[key]
1006 try:
1007 error = abs(float(d1value) - float(d2value))
1008 within_tolerance = error <= tolerance
1009 except (ValueError, TypeError):
daiki kato6914b1a2016-03-16 17:16:57 +09001010 # If both values aren't convertible to float, just ignore
Marc Koderer0abc93b2015-07-15 09:18:35 +02001011 # ValueError if arg is a str, TypeError if it's something else
1012 # (like None)
1013 within_tolerance = False
1014
1015 if hasattr(d1value, 'keys') and hasattr(d2value, 'keys'):
1016 self.assertDictMatch(d1value, d2value)
1017 elif 'DONTCARE' in (d1value, d2value):
1018 continue
1019 elif approx_equal and within_tolerance:
1020 continue
1021 elif d1value != d2value:
1022 raise_assertion("d1['%(key)s']=%(d1value)s != "
1023 "d2['%(key)s']=%(d2value)s" %
1024 {
1025 "key": key,
1026 "d1value": d1value,
1027 "d2value": d2value
1028 })
1029
Alex Meadeba8a1602016-05-06 09:33:09 -04001030 def create_user_message(self):
1031 """Trigger a 'no valid host' situation to generate a message."""
1032 extra_specs = {
1033 'vendor_name': 'foobar',
1034 'driver_handles_share_servers': CONF.share.multitenancy_enabled,
1035 }
1036 share_type_name = data_utils.rand_name("share-type")
1037
1038 bogus_type = self.create_share_type(
Goutham Pacha Raviaf448262020-06-29 14:24:13 -07001039 client=self.admin_shares_v2_client,
Alex Meadeba8a1602016-05-06 09:33:09 -04001040 name=share_type_name,
1041 extra_specs=extra_specs)['share_type']
1042
1043 params = {'share_type_id': bogus_type['id'],
1044 'share_network_id': self.shares_v2_client.share_network_id}
lkuchlan86f24322021-04-27 14:23:05 +03001045 share = self.shares_v2_client.create_share(**params)['share']
Alex Meadeba8a1602016-05-06 09:33:09 -04001046 self.addCleanup(self.shares_v2_client.delete_share, share['id'])
lkuchlanf7fc5b62021-01-26 14:53:43 +02001047 waiters.wait_for_resource_status(
lkuchlan540e74a2021-01-19 18:08:25 +02001048 self.shares_v2_client, share['id'], "error")
1049 return waiters.wait_for_message(self.shares_v2_client, share['id'])
Alex Meadeba8a1602016-05-06 09:33:09 -04001050
lkuchlan5af7cb42020-07-14 18:05:09 +03001051 def allow_access(self, share_id, client=None, access_type=None,
lkuchlanad511b62022-05-08 09:23:23 +03001052 access_level='rw', access_to=None, metadata=None,
1053 version=LATEST_MICROVERSION, status='active',
lkuchlan5af7cb42020-07-14 18:05:09 +03001054 raise_rule_in_error_state=True, cleanup=True):
1055
1056 client = client or self.shares_v2_client
1057 a_type, a_to = self._get_access_rule_data_from_config()
1058 access_type = access_type or a_type
1059 access_to = access_to or a_to
1060
lkuchlanad511b62022-05-08 09:23:23 +03001061 kwargs = {
1062 'access_type': access_type,
1063 'access_to': access_to,
1064 'access_level': access_level
1065 }
1066 if client is self.shares_v2_client:
1067 kwargs.update({'metadata': metadata, 'version': version})
1068
1069 rule = client.create_access_rule(share_id, **kwargs)['access']
lkuchlanf7fc5b62021-01-26 14:53:43 +02001070 waiters.wait_for_resource_status(
1071 client, share_id, status, resource_name='access_rule',
lkuchlanad511b62022-05-08 09:23:23 +03001072 rule_id=rule['id'], version=version,
lkuchlanf7fc5b62021-01-26 14:53:43 +02001073 raise_rule_in_error_state=raise_rule_in_error_state)
lkuchlan5af7cb42020-07-14 18:05:09 +03001074 if cleanup:
lkuchlanad511b62022-05-08 09:23:23 +03001075 self.addCleanup(
1076 client.wait_for_resource_deletion, rule_id=rule['id'],
1077 share_id=share_id, version=version)
lkuchlan5af7cb42020-07-14 18:05:09 +03001078 self.addCleanup(client.delete_access_rule, share_id, rule['id'])
1079 return rule
1080
Marc Koderer0abc93b2015-07-15 09:18:35 +02001081
Marc Koderer0abc93b2015-07-15 09:18:35 +02001082class BaseSharesAdminTest(BaseSharesTest):
1083 """Base test case class for all Shares Admin API tests."""
Valeriy Ponomaryov39cdf722016-05-30 18:16:15 +03001084 credentials = ('admin', )
1085
Victoria Martinez de la Cruzf6bc6fa2018-02-01 11:27:00 -05001086 @classmethod
1087 def setup_clients(cls):
1088 super(BaseSharesAdminTest, cls).setup_clients()
1089 # Initialise share clients
lkuchlan3af822b2021-06-06 10:35:30 +03001090 cls.admin_shares_client = cls.os_admin.share_v1.SharesClient()
Victoria Martinez de la Cruzf6bc6fa2018-02-01 11:27:00 -05001091 cls.admin_shares_v2_client = cls.os_admin.share_v2.SharesV2Client()
1092
lkuchlan3af822b2021-06-06 10:35:30 +03001093 @staticmethod
1094 def add_extra_specs_to_dict(extra_specs=None):
1095 """Add any required extra-specs to share type dictionary"""
haixin48895812020-09-30 13:50:37 +08001096 dhss = str(CONF.share.multitenancy_enabled)
lkuchlan3af822b2021-06-06 10:35:30 +03001097 extra_specs_dict = {"driver_handles_share_servers": dhss}
1098 if extra_specs:
1099 extra_specs_dict.update(extra_specs)
Felipe Rodrigues6e566772021-08-23 14:57:50 -03001100 if CONF.share.capability_thin_provisioned:
1101 extra_specs_dict['thin_provisioning'] = 'True'
lkuchlan3af822b2021-06-06 10:35:30 +03001102 return extra_specs_dict
1103
Victoria Martinez de la Cruzf6bc6fa2018-02-01 11:27:00 -05001104 @classmethod
lkuchlan3af822b2021-06-06 10:35:30 +03001105 def create_share_type(cls, name=None, is_public=True, client=None,
1106 cleanup_in_class=True, extra_specs=None, **kwargs):
1107 name = name or data_utils.rand_name(
1108 cls.__class__.__name__ + 'share-type')
1109 client = client or cls.admin_shares_v2_client
1110 extra_specs = cls.add_extra_specs_to_dict(extra_specs=extra_specs)
1111 share_type = client.create_share_type(name, is_public,
1112 extra_specs=extra_specs,
1113 **kwargs)['share_type']
1114 resource = {
1115 "type": "share_type",
1116 "id": share_type["id"],
1117 "client": client,
1118 }
1119 if cleanup_in_class:
1120 cls.class_resources.insert(0, resource)
1121 else:
1122 cls.method_resources.insert(0, resource)
1123 return share_type
Victoria Martinez de la Cruzf6bc6fa2018-02-01 11:27:00 -05001124
1125 @classmethod
1126 def _create_share_group_type(cls):
1127 share_group_type_name = data_utils.rand_name("unique_sgtype_name")
1128 return cls.create_share_group_type(
1129 name=share_group_type_name, share_types=[cls.share_type_id],
1130 client=cls.admin_shares_v2_client)
1131
Lucio Seki37056942019-01-24 15:40:20 -02001132 def _create_share_for_manage(self):
1133 creation_data = {
lkuchlan3af822b2021-06-06 10:35:30 +03001134 'share_type_id': self.st['id'],
Lucio Seki37056942019-01-24 15:40:20 -02001135 'share_protocol': self.protocol,
1136 }
1137
1138 share = self.create_share(**creation_data)
lkuchlan86f24322021-04-27 14:23:05 +03001139 share = self.shares_v2_client.get_share(share['id'])['share']
Lucio Seki37056942019-01-24 15:40:20 -02001140
1141 if utils.is_microversion_ge(CONF.share.max_api_microversion, "2.9"):
lkuchlan86f24322021-04-27 14:23:05 +03001142 el = self.shares_v2_client.list_share_export_locations(
1143 share["id"])['export_locations']
Lucio Seki37056942019-01-24 15:40:20 -02001144 share["export_locations"] = el
1145
1146 return share
1147
1148 def _unmanage_share_and_wait(self, share):
1149 self.shares_v2_client.unmanage_share(share['id'])
1150 self.shares_v2_client.wait_for_resource_deletion(share_id=share['id'])
1151
1152 def _reset_state_and_delete_share(self, share):
1153 self.shares_v2_client.reset_state(share['id'])
1154 self._delete_share_and_wait(share)
1155
1156 def _delete_snapshot_and_wait(self, snap):
1157 self.shares_v2_client.delete_snapshot(snap['id'])
1158 self.shares_v2_client.wait_for_resource_deletion(
1159 snapshot_id=snap['id']
1160 )
1161 self.assertRaises(exceptions.NotFound,
1162 self.shares_v2_client.get_snapshot,
1163 snap['id'])
1164
1165 def _delete_share_and_wait(self, share):
1166 self.shares_v2_client.delete_share(share['id'])
1167 self.shares_v2_client.wait_for_resource_deletion(share_id=share['id'])
1168 self.assertRaises(exceptions.NotFound,
1169 self.shares_v2_client.get_share,
1170 share['id'])
1171
1172 def _manage_share(self, share, name, description, share_server_id):
1173 managed_share = self.shares_v2_client.manage_share(
1174 service_host=share['host'],
1175 export_path=share['export_locations'][0],
1176 protocol=share['share_proto'],
lkuchlan3af822b2021-06-06 10:35:30 +03001177 share_type_id=self.share_type['id'],
Lucio Seki37056942019-01-24 15:40:20 -02001178 name=name,
1179 description=description,
1180 share_server_id=share_server_id
lkuchlan86f24322021-04-27 14:23:05 +03001181 )['share']
lkuchlanf7fc5b62021-01-26 14:53:43 +02001182 waiters.wait_for_resource_status(
lkuchlan540e74a2021-01-19 18:08:25 +02001183 self.shares_v2_client, managed_share['id'],
1184 constants.STATUS_AVAILABLE
Lucio Seki37056942019-01-24 15:40:20 -02001185 )
1186
1187 return managed_share
1188
1189 def _unmanage_share_server_and_wait(self, server):
1190 self.shares_v2_client.unmanage_share_server(server['id'])
1191 self.shares_v2_client.wait_for_resource_deletion(
1192 server_id=server['id']
1193 )
1194
1195 def _manage_share_server(self, share_server, fields=None):
1196 params = fields or {}
Douglas Viroelb7e27e72019-08-06 19:40:37 -03001197 subnet_id = params.get('share_network_subnet_id', None)
Lucio Seki37056942019-01-24 15:40:20 -02001198 managed_share_server = self.shares_v2_client.manage_share_server(
1199 params.get('host', share_server['host']),
1200 params.get('share_network_id', share_server['share_network_id']),
1201 params.get('identifier', share_server['identifier']),
Douglas Viroelb7e27e72019-08-06 19:40:37 -03001202 share_network_subnet_id=subnet_id,
lkuchlan86f24322021-04-27 14:23:05 +03001203 )['share_server']
lkuchlanf7fc5b62021-01-26 14:53:43 +02001204 waiters.wait_for_resource_status(
lkuchlan540e74a2021-01-19 18:08:25 +02001205 self.shares_v2_client, managed_share_server['id'],
lkuchlanf7fc5b62021-01-26 14:53:43 +02001206 constants.SERVER_STATE_ACTIVE, resource_name='share_server'
Lucio Seki37056942019-01-24 15:40:20 -02001207 )
1208
1209 return managed_share_server
1210
1211 def _delete_share_server_and_wait(self, share_server_id):
1212 self.shares_v2_client.delete_share_server(
1213 share_server_id
1214 )
1215 self.shares_v2_client.wait_for_resource_deletion(
1216 server_id=share_server_id)
1217
lkuchlan3af822b2021-06-06 10:35:30 +03001218 def create_user_message(self):
1219 """Trigger a 'no valid host' situation to generate a message."""
1220 extra_specs = {
1221 'vendor_name': 'foobar',
1222 'driver_handles_share_servers': CONF.share.multitenancy_enabled,
1223 }
1224 share_type_name = data_utils.rand_name("share-type")
Valeriy Ponomaryov39cdf722016-05-30 18:16:15 +03001225
lkuchlan3af822b2021-06-06 10:35:30 +03001226 bogus_type = self.create_share_type(
1227 client=self.admin_shares_v2_client,
1228 name=share_type_name,
1229 extra_specs=extra_specs)
1230
1231 params = {'share_type_id': bogus_type['id'],
1232 'share_network_id': self.shares_v2_client.share_network_id}
lkuchlan86f24322021-04-27 14:23:05 +03001233 share = self.shares_v2_client.create_share(**params)['share']
lkuchlan3af822b2021-06-06 10:35:30 +03001234 self.addCleanup(self.shares_v2_client.delete_share, share['id'])
1235 waiters.wait_for_resource_status(
1236 self.shares_v2_client, share['id'], "error")
1237 return waiters.wait_for_message(self.shares_v2_client, share['id'])
1238
1239
1240class BaseSharesMixedTest(BaseSharesAdminTest):
1241 """Base test case class for all Shares API tests with all user roles.
1242
1243 Tests deriving from this class can use the primary project's clients
1244 (self.shares_client, self.shares_v2_client) and the alt project user's
1245 clients (self.alt_shares_client, self.alt_shares_v2_client) to perform
1246 API calls and validations. Although admin clients are available for use,
1247 their use should be limited to performing bootstrapping (e.g., creating
1248 a share type, or resetting state of a resource, etc.). No API validation
1249 must be performed against admin APIs. Use BaseAdminTest as a base class
1250 for such tests.
1251 """
Valeriy Ponomaryov39cdf722016-05-30 18:16:15 +03001252 credentials = ('primary', 'alt', 'admin')
Marc Koderer0abc93b2015-07-15 09:18:35 +02001253
Goutham Pacha Ravic678e212020-03-20 11:13:47 -07001254 # Will be cleaned up in resource_cleanup if the class
1255 class_project_users_created = []
1256
1257 @classmethod
1258 def resource_cleanup(cls):
1259 cls.clear_project_users(cls.class_project_users_created)
1260 super(BaseSharesMixedTest, cls).resource_cleanup()
1261
1262 @classmethod
1263 def clear_project_users(cls, users=None):
1264 users = users or cls.class_project_users_created
1265 for user in users:
1266 with handle_cleanup_exceptions():
1267 cls.os_admin.creds_client.delete_user(user['id'])
1268
Marc Koderer0abc93b2015-07-15 09:18:35 +02001269 @classmethod
Valeriy Ponomaryov39cdf722016-05-30 18:16:15 +03001270 def setup_clients(cls):
1271 super(BaseSharesMixedTest, cls).setup_clients()
Andrea Frittoli (andreaf)369391a2016-06-27 18:59:13 +01001272 cls.alt_shares_client = cls.os_alt.share_v1.SharesClient()
1273 cls.alt_shares_v2_client = cls.os_alt.share_v2.SharesV2Client()
1274 # Initialise network clients
1275 cls.os_admin.networks_client = cls.os_admin.network.NetworksClient()
1276 cls.os_alt.networks_client = cls.os_alt.network.NetworksClient()
Goutham Pacha Ravic678e212020-03-20 11:13:47 -07001277 # Initialise identity clients
1278 cls.admin_project = cls.os_admin.auth_provider.auth_data[1]['project']
1279 identity_clients = getattr(
1280 cls.os_admin, 'identity_%s' % CONF.identity.auth_version)
1281 cls.os_admin.identity_client = identity_clients.IdentityClient()
1282 cls.os_admin.projects_client = identity_clients.ProjectsClient()
1283 cls.os_admin.users_client = identity_clients.UsersClient()
1284 cls.os_admin.roles_client = identity_clients.RolesClient()
1285 cls.os_admin.domains_client = (
1286 cls.os_admin.identity_v3.DomainsClient() if
1287 CONF.identity.auth_version == 'v3' else None)
Goutham Pacha Ravi10d49492021-02-23 16:05:21 -08001288 cls.admin_project_member_client = cls.create_user_and_get_client(
1289 project=cls.admin_project, add_member_role=True)
Valeriy Ponomaryov39cdf722016-05-30 18:16:15 +03001290
1291 if CONF.share.multitenancy_enabled:
1292 admin_share_network_id = cls.provide_share_network(
1293 cls.admin_shares_v2_client, cls.os_admin.networks_client)
1294 cls.admin_shares_client.share_network_id = admin_share_network_id
1295 cls.admin_shares_v2_client.share_network_id = (
1296 admin_share_network_id)
1297
1298 alt_share_network_id = cls.provide_share_network(
1299 cls.alt_shares_v2_client, cls.os_alt.networks_client)
1300 cls.alt_shares_client.share_network_id = alt_share_network_id
1301 cls.alt_shares_v2_client.share_network_id = alt_share_network_id
Victoria Martinez de la Cruzf6bc6fa2018-02-01 11:27:00 -05001302
1303 @classmethod
Goutham Pacha Ravi10d49492021-02-23 16:05:21 -08001304 def create_user_and_get_client(cls, project=None, add_member_role=True):
Goutham Pacha Ravic678e212020-03-20 11:13:47 -07001305 """Create a user in specified project & set share clients for user
1306
1307 The user will have all roles specified in tempest.conf
1308 :param: project: a dictionary with project ID and name, if not
1309 specified, the value will be cls.admin_project
1310 """
1311 project_domain_name = (
1312 cls.os_admin.identity_client.auth_provider.credentials.get(
1313 'project_domain_name', 'Default'))
1314 cls.os_admin.creds_client = cred_client.get_creds_client(
1315 cls.os_admin.identity_client, cls.os_admin.projects_client,
1316 cls.os_admin.users_client, cls.os_admin.roles_client,
1317 cls.os_admin.domains_client, project_domain_name)
1318
1319 # User info
1320 project = project or cls.admin_project
1321 username = data_utils.rand_name('manila_%s' % project['id'])
1322 password = data_utils.rand_password()
1323 email = '%s@example.org' % username
1324
1325 user = cls.os_admin.creds_client.create_user(
1326 username, password, project, email)
1327 cls.class_project_users_created.append(user)
1328
Goutham Pacha Ravi10d49492021-02-23 16:05:21 -08001329 tempest_roles_to_assign = CONF.auth.tempest_roles or []
1330 if "member" not in tempest_roles_to_assign and add_member_role:
1331 tempest_roles_to_assign.append("member")
1332
1333 for role in tempest_roles_to_assign:
1334 cls.os_admin.creds_client.assign_user_role(user, project, role)
Goutham Pacha Ravic678e212020-03-20 11:13:47 -07001335
1336 user_creds = cls.os_admin.creds_client.get_credentials(
1337 user, project, password)
1338 os = clients.Clients(user_creds)
1339 os.shares_v1_client = os.share_v1.SharesClient()
1340 os.shares_v2_client = os.share_v2.SharesV2Client()
1341 return os