blob: bcbcf43a26905744509ad1ebd8647d9f30be8fd6 [file] [log] [blame]
ZhiQiang Fan39f97222013-09-20 04:49:44 +08001# Copyright 2012 OpenStack Foundation
Rohit Karajgidd47d7e2012-07-31 04:11:01 -07002# 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
Ken'ichi Ohmichi8c189082017-04-03 13:47:54 -070016from tempest.api.volume import api_microversion_fixture
Joseph Lanouxa074c012015-08-04 15:44:07 +000017from tempest.common import compute
Yaroslav Lobankoved3a35b2016-03-24 22:41:30 -050018from tempest.common import waiters
Matthew Treinish4d352bc2014-01-29 18:29:18 +000019from tempest import config
Ken'ichi Ohmichi8c189082017-04-03 13:47:54 -070020from tempest.lib.common import api_version_utils
Ken'ichi Ohmichief1c1ce2017-03-10 11:07:10 -080021from tempest.lib.common.utils import data_utils
Jordan Pittier9e227c52016-02-09 14:35:18 +010022from tempest.lib.common.utils import test_utils
Matthew Treinish4217a702016-10-07 17:27:11 -040023from tempest.lib import exceptions
Attila Fazekasdc216422013-01-29 15:12:14 +010024import tempest.test
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070025
Matthew Treinish4d352bc2014-01-29 18:29:18 +000026CONF = config.CONF
27
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070028
Ken'ichi Ohmichi8c189082017-04-03 13:47:54 -070029class BaseVolumeTest(api_version_utils.BaseMicroversionTest,
30 tempest.test.BaseTestCase):
Sean Daguef237ccb2013-01-04 15:19:14 -050031 """Base test case class for all Cinder API tests."""
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070032
Ghanshyam Mann7d91b692020-03-03 10:21:50 -060033 # Set this to True in subclasses to create a default network. See
34 # https://bugs.launchpad.net/tempest/+bug/1844568
35 create_default_network = False
Zhi Kun Liu6e6cf832014-05-08 17:25:22 +080036 _api_version = 2
zhufl15292a32018-01-02 15:18:39 +080037 # if api_v2 is not enabled while api_v3 is enabled, the volume v2 classes
38 # should be transferred to volume v3 classes.
39 if (not CONF.volume_feature_enabled.api_v2 and
40 CONF.volume_feature_enabled.api_v3):
41 _api_version = 3
Andrea Frittolib21de6c2015-02-06 20:12:38 +000042 credentials = ['primary']
Zhi Kun Liu6e6cf832014-05-08 17:25:22 +080043
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070044 @classmethod
Rohan Kanade05749152015-01-30 17:15:18 +053045 def skip_checks(cls):
46 super(BaseVolumeTest, cls).skip_checks()
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070047
Matthew Treinish4d352bc2014-01-29 18:29:18 +000048 if not CONF.service_available.cinder:
Matthew Treinish4c412922013-07-16 15:27:42 -040049 skip_msg = ("%s skipped as Cinder is not available" % cls.__name__)
50 raise cls.skipException(skip_msg)
Ken'ichi Ohmichic4fcdbb2017-03-15 16:53:28 -070051 if cls._api_version == 2:
Rohan Kanade05749152015-01-30 17:15:18 +053052 if not CONF.volume_feature_enabled.api_v2:
53 msg = "Volume API v2 is disabled"
54 raise cls.skipException(msg)
Andrew Kerrfcb0b682016-04-01 16:01:34 -040055 elif cls._api_version == 3:
56 if not CONF.volume_feature_enabled.api_v3:
57 msg = "Volume API v3 is disabled"
58 raise cls.skipException(msg)
Rohan Kanade05749152015-01-30 17:15:18 +053059 else:
60 msg = ("Invalid Cinder API version (%s)" % cls._api_version)
zhuflff30ede2016-12-27 10:29:13 +080061 raise exceptions.InvalidConfiguration(msg)
Rohan Kanade05749152015-01-30 17:15:18 +053062
Ken'ichi Ohmichi8c189082017-04-03 13:47:54 -070063 api_version_utils.check_skip_with_microversion(
64 cls.min_microversion, cls.max_microversion,
65 CONF.volume.min_microversion, CONF.volume.max_microversion)
66
Rohan Kanade05749152015-01-30 17:15:18 +053067 @classmethod
68 def setup_credentials(cls):
Ghanshyam Mann7d91b692020-03-03 10:21:50 -060069 cls.set_network_resources(
70 network=cls.create_default_network,
71 subnet=cls.create_default_network)
Rohan Kanade05749152015-01-30 17:15:18 +053072 super(BaseVolumeTest, cls).setup_credentials()
Rohan Kanade05749152015-01-30 17:15:18 +053073
74 @classmethod
75 def setup_clients(cls):
76 super(BaseVolumeTest, cls).setup_clients()
Jordan Pittier8160d312017-04-18 11:52:23 +020077 cls.servers_client = cls.os_primary.servers_client
Rohan Kanade05749152015-01-30 17:15:18 +053078
jeremy.zhang0a427162017-04-21 12:47:56 +080079 if CONF.service_available.glance:
Jordan Pittier8160d312017-04-18 11:52:23 +020080 cls.images_client = cls.os_primary.image_client_v2
jeremy.zhang0a427162017-04-21 12:47:56 +080081
ghanshyam6c682ff2018-08-06 09:54:45 +000082 cls.backups_client = cls.os_primary.backups_client_latest
83 cls.volumes_client = cls.os_primary.volumes_client_latest
84 cls.messages_client = cls.os_primary.volume_messages_client_latest
85 cls.versions_client = cls.os_primary.volume_versions_client_latest
86 cls.groups_client = cls.os_primary.groups_client_latest
87 cls.group_snapshots_client = (
88 cls.os_primary.group_snapshots_client_latest)
89 cls.snapshots_client = cls.os_primary.snapshots_client_latest
Jordan Pittier8160d312017-04-18 11:52:23 +020090 cls.volumes_extension_client =\
ghanshyam6c682ff2018-08-06 09:54:45 +000091 cls.os_primary.volumes_extension_client_latest
Ken'ichi Ohmichic4fcdbb2017-03-15 16:53:28 -070092 cls.availability_zone_client = (
ghanshyam6c682ff2018-08-06 09:54:45 +000093 cls.os_primary.volume_availability_zone_client_latest)
94 cls.volume_limits_client = cls.os_primary.volume_limits_client_latest
jeremy.zhang79a1cbf2017-05-07 16:09:17 +080095
Ken'ichi Ohmichi8c189082017-04-03 13:47:54 -070096 def setUp(self):
97 super(BaseVolumeTest, self).setUp()
98 self.useFixture(api_microversion_fixture.APIMicroversionFixture(
99 self.request_microversion))
Rohan Kanade05749152015-01-30 17:15:18 +0530100
101 @classmethod
102 def resource_setup(cls):
103 super(BaseVolumeTest, cls).resource_setup()
Ken'ichi Ohmichi8c189082017-04-03 13:47:54 -0700104 cls.request_microversion = (
105 api_version_utils.select_request_microversion(
106 cls.min_microversion,
107 CONF.volume.min_microversion))
Rohan Kanade05749152015-01-30 17:15:18 +0530108
Rohan Kanade05749152015-01-30 17:15:18 +0530109 cls.image_ref = CONF.compute.image_ref
110 cls.flavor_ref = CONF.compute.flavor_ref
111 cls.build_interval = CONF.volume.build_interval
112 cls.build_timeout = CONF.volume.build_timeout
113
Rohit Karajgidd47d7e2012-07-31 04:11:01 -0700114 @classmethod
Benny Kopilov8a33ee12016-11-09 10:35:23 +0200115 def create_volume(cls, wait_until='available', **kwargs):
116 """Wrapper utility that returns a test volume.
117
118 :param wait_until: wait till volume status.
119 """
Ken'ichi Ohmichiadb905e2016-08-26 15:16:23 -0700120 if 'size' not in kwargs:
121 kwargs['size'] = CONF.volume.volume_size
122
Nuno Santosb746d992016-11-17 15:41:55 -0500123 if 'imageRef' in kwargs:
jeremy.zhangcb0dd582017-04-25 08:48:38 +0800124 image = cls.images_client.show_image(kwargs['imageRef'])
125 min_disk = image['min_disk']
Nuno Santosb746d992016-11-17 15:41:55 -0500126 kwargs['size'] = max(kwargs['size'], min_disk)
127
zhufla57530c2017-03-23 11:38:12 +0800128 if 'name' not in kwargs:
zhufl354b2fb2016-10-24 15:24:22 +0800129 name = data_utils.rand_name(cls.__name__ + '-Volume')
zhufla57530c2017-03-23 11:38:12 +0800130 kwargs['name'] = name
Zhi Kun Liu3d6d9862014-06-16 16:43:59 +0800131
Martin Kopec00e6d6c2019-06-05 14:30:06 +0000132 if CONF.compute.compute_volume_common_az:
133 kwargs.setdefault('availability_zone',
134 CONF.compute.compute_volume_common_az)
135
Ghanshyam8fc0ed22015-12-18 10:25:14 +0900136 volume = cls.volumes_client.create_volume(**kwargs)['volume']
zhuflcae2a752017-11-24 12:43:43 +0800137 cls.addClassResourceCleanup(test_utils.call_and_ignore_notfound_exc,
138 cls.delete_volume, cls.volumes_client,
139 volume['id'])
lkuchlan52d7b0d2016-11-07 20:53:19 +0200140 waiters.wait_for_volume_resource_status(cls.volumes_client,
141 volume['id'], wait_until)
Zhi Kun Liu6e6cf832014-05-08 17:25:22 +0800142 return volume
143
144 @classmethod
Attila Fazekas36b1fcf2013-01-31 16:41:04 +0100145 def create_snapshot(cls, volume_id=1, **kwargs):
146 """Wrapper utility that returns a test snapshot."""
zhufla57530c2017-03-23 11:38:12 +0800147 if 'name' not in kwargs:
zhufl354b2fb2016-10-24 15:24:22 +0800148 name = data_utils.rand_name(cls.__name__ + '-Snapshot')
zhufla57530c2017-03-23 11:38:12 +0800149 kwargs['name'] = name
zhufl354b2fb2016-10-24 15:24:22 +0800150
John Warrenff7faf62015-08-17 16:59:06 +0000151 snapshot = cls.snapshots_client.create_snapshot(
Ghanshyam0b75b632015-12-11 15:08:28 +0900152 volume_id=volume_id, **kwargs)['snapshot']
zhuflcae2a752017-11-24 12:43:43 +0800153 cls.addClassResourceCleanup(test_utils.call_and_ignore_notfound_exc,
154 cls.delete_snapshot, snapshot['id'])
lkuchlan52d7b0d2016-11-07 20:53:19 +0200155 waiters.wait_for_volume_resource_status(cls.snapshots_client,
156 snapshot['id'], 'available')
Attila Fazekas36b1fcf2013-01-31 16:41:04 +0100157 return snapshot
158
Ghanshyam Mannb0d15bf2017-05-02 04:55:47 +0000159 def create_backup(self, volume_id, backup_client=None, **kwargs):
lkuchlana2beb492016-08-17 12:42:44 +0300160 """Wrapper utility that returns a test backup."""
161 if backup_client is None:
162 backup_client = self.backups_client
zhuflefe033a2017-03-31 15:45:15 +0800163 if 'name' not in kwargs:
164 name = data_utils.rand_name(self.__class__.__name__ + '-Backup')
165 kwargs['name'] = name
lkuchlana2beb492016-08-17 12:42:44 +0300166
167 backup = backup_client.create_backup(
168 volume_id=volume_id, **kwargs)['backup']
Ghanshyam Mannb0d15bf2017-05-02 04:55:47 +0000169 self.addCleanup(backup_client.delete_backup, backup['id'])
170 waiters.wait_for_volume_resource_status(backup_client, backup['id'],
171 'available')
lkuchlana2beb492016-08-17 12:42:44 +0300172 return backup
173
Attila Fazekasf7f34f92013-08-01 17:01:44 +0200174 # NOTE(afazekas): these create_* and clean_* could be defined
Attila Fazekas36b1fcf2013-01-31 16:41:04 +0100175 # only in a single location in the source, and could be more general.
176
lkuchlane9a15952017-01-08 08:11:23 +0200177 @staticmethod
178 def delete_volume(client, volume_id):
lkuchlan9bf9fac2016-06-19 15:32:33 +0300179 """Delete volume by the given client"""
180 client.delete_volume(volume_id)
181 client.wait_for_resource_deletion(volume_id)
182
zhuflcae2a752017-11-24 12:43:43 +0800183 @classmethod
184 def delete_snapshot(cls, snapshot_id, snapshots_client=None):
lkuchlancb2f8592016-07-17 15:18:01 +0300185 """Delete snapshot by the given client"""
lkuchlan5b2b3622017-02-14 15:48:36 +0200186 if snapshots_client is None:
zhuflcae2a752017-11-24 12:43:43 +0800187 snapshots_client = cls.snapshots_client
lkuchlan5b2b3622017-02-14 15:48:36 +0200188 snapshots_client.delete_snapshot(snapshot_id)
189 snapshots_client.wait_for_resource_deletion(snapshot_id)
lkuchlancb2f8592016-07-17 15:18:01 +0300190
Erlon R. Cruzba19bc72016-09-28 14:32:11 -0300191 def attach_volume(self, server_id, volume_id):
lkuchlan46437232017-01-08 08:29:25 +0200192 """Attach a volume to a server"""
Erlon R. Cruzba19bc72016-09-28 14:32:11 -0300193 self.servers_client.attach_volume(
194 server_id, volumeId=volume_id,
195 device='/dev/%s' % CONF.compute.volume_device_name)
lkuchlan52d7b0d2016-11-07 20:53:19 +0200196 waiters.wait_for_volume_resource_status(self.volumes_client,
197 volume_id, 'in-use')
198 self.addCleanup(waiters.wait_for_volume_resource_status,
199 self.volumes_client, volume_id, 'available')
Erlon R. Cruzba19bc72016-09-28 14:32:11 -0300200 self.addCleanup(self.servers_client.detach_volume, server_id,
zhufleba284e2016-12-16 10:44:41 +0800201 volume_id)
Erlon R. Cruzba19bc72016-09-28 14:32:11 -0300202
lkuchland4ecd0e2017-06-11 12:01:27 +0300203 def create_server(self, wait_until='ACTIVE', **kwargs):
zhufl22403a02016-10-26 10:25:19 +0800204 name = kwargs.pop(
zhufl7867a6e2016-10-18 15:37:12 +0800205 'name',
206 data_utils.rand_name(self.__class__.__name__ + '-instance'))
207
lkuchlan5fc69362016-09-05 08:42:34 +0300208 tenant_network = self.get_tenant_network()
Joseph Lanouxa074c012015-08-04 15:44:07 +0000209 body, _ = compute.create_test_server(
zhufl04190882017-05-23 10:21:48 +0800210 self.os_primary,
Joseph Lanouxa074c012015-08-04 15:44:07 +0000211 tenant_network=tenant_network,
212 name=name,
lkuchland4ecd0e2017-06-11 12:01:27 +0300213 wait_until=wait_until,
Joseph Lanouxa074c012015-08-04 15:44:07 +0000214 **kwargs)
lkuchlan5fc69362016-09-05 08:42:34 +0300215
Matthew Treinish445f5982016-09-14 19:27:04 -0400216 self.addCleanup(test_utils.call_and_ignore_notfound_exc,
217 waiters.wait_for_server_termination,
218 self.servers_client, body['id'])
lkuchlan5fc69362016-09-05 08:42:34 +0300219 self.addCleanup(test_utils.call_and_ignore_notfound_exc,
220 self.servers_client.delete_server, body['id'])
Joseph Lanouxa074c012015-08-04 15:44:07 +0000221 return body
Rohan Kanade9ce97df2013-12-10 18:59:35 +0530222
jeremy.zhang2abe00a2017-11-21 10:14:09 +0800223 def create_group(self, **kwargs):
224 if 'name' not in kwargs:
225 kwargs['name'] = data_utils.rand_name(
226 self.__class__.__name__ + '-Group')
227
228 group = self.groups_client.create_group(**kwargs)['group']
229 self.addCleanup(test_utils.call_and_ignore_notfound_exc,
230 self.delete_group, group['id'])
231 waiters.wait_for_volume_resource_status(
232 self.groups_client, group['id'], 'available')
233 return group
234
235 def delete_group(self, group_id, delete_volumes=True):
236 self.groups_client.delete_group(group_id, delete_volumes)
237 if delete_volumes:
238 vols = self.volumes_client.list_volumes(detail=True)['volumes']
239 for vol in vols:
240 if vol['group_id'] == group_id:
241 self.volumes_client.wait_for_resource_deletion(vol['id'])
242 self.groups_client.wait_for_resource_deletion(group_id)
243
James E. Blaire6d8ee12013-01-18 21:33:45 +0000244
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000245class BaseVolumeAdminTest(BaseVolumeTest):
Attila Fazekas3dcdae12013-02-14 12:50:04 +0100246 """Base test case class for all Volume Admin API tests."""
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000247
Andrea Frittolib21de6c2015-02-06 20:12:38 +0000248 credentials = ['primary', 'admin']
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000249
Rohan Kanade05749152015-01-30 17:15:18 +0530250 @classmethod
251 def setup_clients(cls):
252 super(BaseVolumeAdminTest, cls).setup_clients()
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000253
ghanshyam6c682ff2018-08-06 09:54:45 +0000254 cls.admin_volume_qos_client = cls.os_admin.volume_qos_client_latest
Ken'ichi Ohmichic4fcdbb2017-03-15 16:53:28 -0700255 cls.admin_volume_services_client = \
ghanshyam6c682ff2018-08-06 09:54:45 +0000256 cls.os_admin.volume_services_client_latest
257 cls.admin_volume_types_client = cls.os_admin.volume_types_client_latest
258 cls.admin_volume_manage_client = (
259 cls.os_admin.volume_manage_client_latest)
260 cls.admin_volume_client = cls.os_admin.volumes_client_latest
261 cls.admin_groups_client = cls.os_admin.groups_client_latest
262 cls.admin_messages_client = cls.os_admin.volume_messages_client_latest
263 cls.admin_group_snapshots_client = \
264 cls.os_admin.group_snapshots_client_latest
265 cls.admin_group_types_client = cls.os_admin.group_types_client_latest
266 cls.admin_hosts_client = cls.os_admin.volume_hosts_client_latest
Ken'ichi Ohmichic4fcdbb2017-03-15 16:53:28 -0700267 cls.admin_snapshot_manage_client = \
ghanshyam6c682ff2018-08-06 09:54:45 +0000268 cls.os_admin.snapshot_manage_client_latest
269 cls.admin_snapshots_client = cls.os_admin.snapshots_client_latest
270 cls.admin_backups_client = cls.os_admin.backups_client_latest
Ken'ichi Ohmichic4fcdbb2017-03-15 16:53:28 -0700271 cls.admin_encryption_types_client = \
ghanshyam6c682ff2018-08-06 09:54:45 +0000272 cls.os_admin.encryption_types_client_latest
jeremy.zhang644b01d2017-04-13 12:59:49 +0800273 cls.admin_quota_classes_client = \
ghanshyam6c682ff2018-08-06 09:54:45 +0000274 cls.os_admin.volume_quota_classes_client_latest
275 cls.admin_quotas_client = cls.os_admin.volume_quotas_client_latest
276 cls.admin_volume_limits_client = (
277 cls.os_admin.volume_limits_client_latest)
Ken'ichi Ohmichic4fcdbb2017-03-15 16:53:28 -0700278 cls.admin_capabilities_client = \
ghanshyam6c682ff2018-08-06 09:54:45 +0000279 cls.os_admin.volume_capabilities_client_latest
Ken'ichi Ohmichic4fcdbb2017-03-15 16:53:28 -0700280 cls.admin_scheduler_stats_client = \
ghanshyam6c682ff2018-08-06 09:54:45 +0000281 cls.os_admin.volume_scheduler_stats_client_latest
jeremy.zhang79a1cbf2017-05-07 16:09:17 +0800282
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000283 @classmethod
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000284 def create_test_qos_specs(cls, name=None, consumer=None, **kwargs):
285 """create a test Qos-Specs."""
286 name = name or data_utils.rand_name(cls.__name__ + '-QoS')
287 consumer = consumer or 'front-end'
bkopilov62d21752016-06-08 10:16:11 +0300288 qos_specs = cls.admin_volume_qos_client.create_qos(
Jordan Pittier0359c4d2015-12-09 14:34:58 +0100289 name=name, consumer=consumer, **kwargs)['qos_specs']
zhuflcae2a752017-11-24 12:43:43 +0800290 cls.addClassResourceCleanup(cls.clear_qos_spec, qos_specs['id'])
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000291 return qos_specs
292
293 @classmethod
lkuchlan76650572016-05-23 12:30:10 +0300294 def create_volume_type(cls, name=None, **kwargs):
295 """Create a test volume-type"""
zhuflc6ce5392016-08-17 14:34:37 +0800296 name = name or data_utils.rand_name(cls.__name__ + '-volume-type')
lkuchlan76650572016-05-23 12:30:10 +0300297 volume_type = cls.admin_volume_types_client.create_volume_type(
298 name=name, **kwargs)['volume_type']
zhuflcae2a752017-11-24 12:43:43 +0800299 cls.addClassResourceCleanup(cls.clear_volume_type, volume_type['id'])
lkuchlan76650572016-05-23 12:30:10 +0300300 return volume_type
301
Xing Yang0ddf83e2015-11-17 22:15:25 -0500302 def create_group_type(self, name=None, **kwargs):
303 """Create a test group-type"""
304 name = name or data_utils.rand_name(
305 self.__class__.__name__ + '-group-type')
306 group_type = self.admin_group_types_client.create_group_type(
307 name=name, **kwargs)['group_type']
308 self.addCleanup(self.admin_group_types_client.delete_group_type,
309 group_type['id'])
310 return group_type
311
lkuchlan76650572016-05-23 12:30:10 +0300312 @classmethod
zhuflcae2a752017-11-24 12:43:43 +0800313 def clear_qos_spec(cls, qos_id):
314 test_utils.call_and_ignore_notfound_exc(
315 cls.admin_volume_qos_client.delete_qos, qos_id)
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000316
zhuflcae2a752017-11-24 12:43:43 +0800317 test_utils.call_and_ignore_notfound_exc(
318 cls.admin_volume_qos_client.wait_for_resource_deletion, qos_id)
lkuchlan76650572016-05-23 12:30:10 +0300319
320 @classmethod
zhuflcae2a752017-11-24 12:43:43 +0800321 def clear_volume_type(cls, vol_type_id):
322 test_utils.call_and_ignore_notfound_exc(
323 cls.admin_volume_types_client.delete_volume_type, vol_type_id)
lkuchlan76650572016-05-23 12:30:10 +0300324
zhuflcae2a752017-11-24 12:43:43 +0800325 test_utils.call_and_ignore_notfound_exc(
326 cls.admin_volume_types_client.wait_for_resource_deletion,
327 vol_type_id)