blob: 1bfd075249328264e3a2ec8dd51dae39a5fd3bf8 [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
Zhi Kun Liu6e6cf832014-05-08 17:25:22 +080033 _api_version = 2
zhufl15292a32018-01-02 15:18:39 +080034 # if api_v2 is not enabled while api_v3 is enabled, the volume v2 classes
35 # should be transferred to volume v3 classes.
36 if (not CONF.volume_feature_enabled.api_v2 and
37 CONF.volume_feature_enabled.api_v3):
38 _api_version = 3
Andrea Frittolib21de6c2015-02-06 20:12:38 +000039 credentials = ['primary']
Zhi Kun Liu6e6cf832014-05-08 17:25:22 +080040
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070041 @classmethod
Rohan Kanade05749152015-01-30 17:15:18 +053042 def skip_checks(cls):
43 super(BaseVolumeTest, cls).skip_checks()
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070044
Matthew Treinish4d352bc2014-01-29 18:29:18 +000045 if not CONF.service_available.cinder:
Matthew Treinish4c412922013-07-16 15:27:42 -040046 skip_msg = ("%s skipped as Cinder is not available" % cls.__name__)
47 raise cls.skipException(skip_msg)
Ken'ichi Ohmichic4fcdbb2017-03-15 16:53:28 -070048 if cls._api_version == 2:
Rohan Kanade05749152015-01-30 17:15:18 +053049 if not CONF.volume_feature_enabled.api_v2:
50 msg = "Volume API v2 is disabled"
51 raise cls.skipException(msg)
Andrew Kerrfcb0b682016-04-01 16:01:34 -040052 elif cls._api_version == 3:
53 if not CONF.volume_feature_enabled.api_v3:
54 msg = "Volume API v3 is disabled"
55 raise cls.skipException(msg)
Rohan Kanade05749152015-01-30 17:15:18 +053056 else:
57 msg = ("Invalid Cinder API version (%s)" % cls._api_version)
zhuflff30ede2016-12-27 10:29:13 +080058 raise exceptions.InvalidConfiguration(msg)
Rohan Kanade05749152015-01-30 17:15:18 +053059
Ken'ichi Ohmichi8c189082017-04-03 13:47:54 -070060 api_version_utils.check_skip_with_microversion(
61 cls.min_microversion, cls.max_microversion,
62 CONF.volume.min_microversion, CONF.volume.max_microversion)
63
Rohan Kanade05749152015-01-30 17:15:18 +053064 @classmethod
65 def setup_credentials(cls):
66 cls.set_network_resources()
67 super(BaseVolumeTest, cls).setup_credentials()
Rohan Kanade05749152015-01-30 17:15:18 +053068
69 @classmethod
70 def setup_clients(cls):
71 super(BaseVolumeTest, cls).setup_clients()
Jordan Pittier8160d312017-04-18 11:52:23 +020072 cls.servers_client = cls.os_primary.servers_client
Rohan Kanade05749152015-01-30 17:15:18 +053073
jeremy.zhang0a427162017-04-21 12:47:56 +080074 if CONF.service_available.glance:
Jordan Pittier8160d312017-04-18 11:52:23 +020075 cls.images_client = cls.os_primary.image_client_v2
jeremy.zhang0a427162017-04-21 12:47:56 +080076
ghanshyam6c682ff2018-08-06 09:54:45 +000077 cls.backups_client = cls.os_primary.backups_client_latest
78 cls.volumes_client = cls.os_primary.volumes_client_latest
79 cls.messages_client = cls.os_primary.volume_messages_client_latest
80 cls.versions_client = cls.os_primary.volume_versions_client_latest
81 cls.groups_client = cls.os_primary.groups_client_latest
82 cls.group_snapshots_client = (
83 cls.os_primary.group_snapshots_client_latest)
84 cls.snapshots_client = cls.os_primary.snapshots_client_latest
Jordan Pittier8160d312017-04-18 11:52:23 +020085 cls.volumes_extension_client =\
ghanshyam6c682ff2018-08-06 09:54:45 +000086 cls.os_primary.volumes_extension_client_latest
Ken'ichi Ohmichic4fcdbb2017-03-15 16:53:28 -070087 cls.availability_zone_client = (
ghanshyam6c682ff2018-08-06 09:54:45 +000088 cls.os_primary.volume_availability_zone_client_latest)
89 cls.volume_limits_client = cls.os_primary.volume_limits_client_latest
jeremy.zhang79a1cbf2017-05-07 16:09:17 +080090
Ken'ichi Ohmichi8c189082017-04-03 13:47:54 -070091 def setUp(self):
92 super(BaseVolumeTest, self).setUp()
93 self.useFixture(api_microversion_fixture.APIMicroversionFixture(
94 self.request_microversion))
Rohan Kanade05749152015-01-30 17:15:18 +053095
96 @classmethod
97 def resource_setup(cls):
98 super(BaseVolumeTest, cls).resource_setup()
Ken'ichi Ohmichi8c189082017-04-03 13:47:54 -070099 cls.request_microversion = (
100 api_version_utils.select_request_microversion(
101 cls.min_microversion,
102 CONF.volume.min_microversion))
Rohan Kanade05749152015-01-30 17:15:18 +0530103
Rohan Kanade05749152015-01-30 17:15:18 +0530104 cls.image_ref = CONF.compute.image_ref
105 cls.flavor_ref = CONF.compute.flavor_ref
106 cls.build_interval = CONF.volume.build_interval
107 cls.build_timeout = CONF.volume.build_timeout
108
Rohit Karajgidd47d7e2012-07-31 04:11:01 -0700109 @classmethod
Benny Kopilov8a33ee12016-11-09 10:35:23 +0200110 def create_volume(cls, wait_until='available', **kwargs):
111 """Wrapper utility that returns a test volume.
112
113 :param wait_until: wait till volume status.
114 """
Ken'ichi Ohmichiadb905e2016-08-26 15:16:23 -0700115 if 'size' not in kwargs:
116 kwargs['size'] = CONF.volume.volume_size
117
Nuno Santosb746d992016-11-17 15:41:55 -0500118 if 'imageRef' in kwargs:
jeremy.zhangcb0dd582017-04-25 08:48:38 +0800119 image = cls.images_client.show_image(kwargs['imageRef'])
120 min_disk = image['min_disk']
Nuno Santosb746d992016-11-17 15:41:55 -0500121 kwargs['size'] = max(kwargs['size'], min_disk)
122
zhufla57530c2017-03-23 11:38:12 +0800123 if 'name' not in kwargs:
zhufl354b2fb2016-10-24 15:24:22 +0800124 name = data_utils.rand_name(cls.__name__ + '-Volume')
zhufla57530c2017-03-23 11:38:12 +0800125 kwargs['name'] = name
Zhi Kun Liu3d6d9862014-06-16 16:43:59 +0800126
Martin Kopec00e6d6c2019-06-05 14:30:06 +0000127 if CONF.compute.compute_volume_common_az:
128 kwargs.setdefault('availability_zone',
129 CONF.compute.compute_volume_common_az)
130
Ghanshyam8fc0ed22015-12-18 10:25:14 +0900131 volume = cls.volumes_client.create_volume(**kwargs)['volume']
zhuflcae2a752017-11-24 12:43:43 +0800132 cls.addClassResourceCleanup(test_utils.call_and_ignore_notfound_exc,
133 cls.delete_volume, cls.volumes_client,
134 volume['id'])
lkuchlan52d7b0d2016-11-07 20:53:19 +0200135 waiters.wait_for_volume_resource_status(cls.volumes_client,
136 volume['id'], wait_until)
Zhi Kun Liu6e6cf832014-05-08 17:25:22 +0800137 return volume
138
139 @classmethod
Attila Fazekas36b1fcf2013-01-31 16:41:04 +0100140 def create_snapshot(cls, volume_id=1, **kwargs):
141 """Wrapper utility that returns a test snapshot."""
zhufla57530c2017-03-23 11:38:12 +0800142 if 'name' not in kwargs:
zhufl354b2fb2016-10-24 15:24:22 +0800143 name = data_utils.rand_name(cls.__name__ + '-Snapshot')
zhufla57530c2017-03-23 11:38:12 +0800144 kwargs['name'] = name
zhufl354b2fb2016-10-24 15:24:22 +0800145
John Warrenff7faf62015-08-17 16:59:06 +0000146 snapshot = cls.snapshots_client.create_snapshot(
Ghanshyam0b75b632015-12-11 15:08:28 +0900147 volume_id=volume_id, **kwargs)['snapshot']
zhuflcae2a752017-11-24 12:43:43 +0800148 cls.addClassResourceCleanup(test_utils.call_and_ignore_notfound_exc,
149 cls.delete_snapshot, snapshot['id'])
lkuchlan52d7b0d2016-11-07 20:53:19 +0200150 waiters.wait_for_volume_resource_status(cls.snapshots_client,
151 snapshot['id'], 'available')
Attila Fazekas36b1fcf2013-01-31 16:41:04 +0100152 return snapshot
153
Ghanshyam Mannb0d15bf2017-05-02 04:55:47 +0000154 def create_backup(self, volume_id, backup_client=None, **kwargs):
lkuchlana2beb492016-08-17 12:42:44 +0300155 """Wrapper utility that returns a test backup."""
156 if backup_client is None:
157 backup_client = self.backups_client
zhuflefe033a2017-03-31 15:45:15 +0800158 if 'name' not in kwargs:
159 name = data_utils.rand_name(self.__class__.__name__ + '-Backup')
160 kwargs['name'] = name
lkuchlana2beb492016-08-17 12:42:44 +0300161
162 backup = backup_client.create_backup(
163 volume_id=volume_id, **kwargs)['backup']
Ghanshyam Mannb0d15bf2017-05-02 04:55:47 +0000164 self.addCleanup(backup_client.delete_backup, backup['id'])
165 waiters.wait_for_volume_resource_status(backup_client, backup['id'],
166 'available')
lkuchlana2beb492016-08-17 12:42:44 +0300167 return backup
168
Attila Fazekasf7f34f92013-08-01 17:01:44 +0200169 # NOTE(afazekas): these create_* and clean_* could be defined
Attila Fazekas36b1fcf2013-01-31 16:41:04 +0100170 # only in a single location in the source, and could be more general.
171
lkuchlane9a15952017-01-08 08:11:23 +0200172 @staticmethod
173 def delete_volume(client, volume_id):
lkuchlan9bf9fac2016-06-19 15:32:33 +0300174 """Delete volume by the given client"""
175 client.delete_volume(volume_id)
176 client.wait_for_resource_deletion(volume_id)
177
zhuflcae2a752017-11-24 12:43:43 +0800178 @classmethod
179 def delete_snapshot(cls, snapshot_id, snapshots_client=None):
lkuchlancb2f8592016-07-17 15:18:01 +0300180 """Delete snapshot by the given client"""
lkuchlan5b2b3622017-02-14 15:48:36 +0200181 if snapshots_client is None:
zhuflcae2a752017-11-24 12:43:43 +0800182 snapshots_client = cls.snapshots_client
lkuchlan5b2b3622017-02-14 15:48:36 +0200183 snapshots_client.delete_snapshot(snapshot_id)
184 snapshots_client.wait_for_resource_deletion(snapshot_id)
lkuchlancb2f8592016-07-17 15:18:01 +0300185
Erlon R. Cruzba19bc72016-09-28 14:32:11 -0300186 def attach_volume(self, server_id, volume_id):
lkuchlan46437232017-01-08 08:29:25 +0200187 """Attach a volume to a server"""
Erlon R. Cruzba19bc72016-09-28 14:32:11 -0300188 self.servers_client.attach_volume(
189 server_id, volumeId=volume_id,
190 device='/dev/%s' % CONF.compute.volume_device_name)
lkuchlan52d7b0d2016-11-07 20:53:19 +0200191 waiters.wait_for_volume_resource_status(self.volumes_client,
192 volume_id, 'in-use')
193 self.addCleanup(waiters.wait_for_volume_resource_status,
194 self.volumes_client, volume_id, 'available')
Erlon R. Cruzba19bc72016-09-28 14:32:11 -0300195 self.addCleanup(self.servers_client.detach_volume, server_id,
zhufleba284e2016-12-16 10:44:41 +0800196 volume_id)
Erlon R. Cruzba19bc72016-09-28 14:32:11 -0300197
lkuchland4ecd0e2017-06-11 12:01:27 +0300198 def create_server(self, wait_until='ACTIVE', **kwargs):
zhufl22403a02016-10-26 10:25:19 +0800199 name = kwargs.pop(
zhufl7867a6e2016-10-18 15:37:12 +0800200 'name',
201 data_utils.rand_name(self.__class__.__name__ + '-instance'))
202
lkuchlan5fc69362016-09-05 08:42:34 +0300203 tenant_network = self.get_tenant_network()
Joseph Lanouxa074c012015-08-04 15:44:07 +0000204 body, _ = compute.create_test_server(
zhufl04190882017-05-23 10:21:48 +0800205 self.os_primary,
Joseph Lanouxa074c012015-08-04 15:44:07 +0000206 tenant_network=tenant_network,
207 name=name,
lkuchland4ecd0e2017-06-11 12:01:27 +0300208 wait_until=wait_until,
Joseph Lanouxa074c012015-08-04 15:44:07 +0000209 **kwargs)
lkuchlan5fc69362016-09-05 08:42:34 +0300210
Matthew Treinish445f5982016-09-14 19:27:04 -0400211 self.addCleanup(test_utils.call_and_ignore_notfound_exc,
212 waiters.wait_for_server_termination,
213 self.servers_client, body['id'])
lkuchlan5fc69362016-09-05 08:42:34 +0300214 self.addCleanup(test_utils.call_and_ignore_notfound_exc,
215 self.servers_client.delete_server, body['id'])
Joseph Lanouxa074c012015-08-04 15:44:07 +0000216 return body
Rohan Kanade9ce97df2013-12-10 18:59:35 +0530217
jeremy.zhang2abe00a2017-11-21 10:14:09 +0800218 def create_group(self, **kwargs):
219 if 'name' not in kwargs:
220 kwargs['name'] = data_utils.rand_name(
221 self.__class__.__name__ + '-Group')
222
223 group = self.groups_client.create_group(**kwargs)['group']
224 self.addCleanup(test_utils.call_and_ignore_notfound_exc,
225 self.delete_group, group['id'])
226 waiters.wait_for_volume_resource_status(
227 self.groups_client, group['id'], 'available')
228 return group
229
230 def delete_group(self, group_id, delete_volumes=True):
231 self.groups_client.delete_group(group_id, delete_volumes)
232 if delete_volumes:
233 vols = self.volumes_client.list_volumes(detail=True)['volumes']
234 for vol in vols:
235 if vol['group_id'] == group_id:
236 self.volumes_client.wait_for_resource_deletion(vol['id'])
237 self.groups_client.wait_for_resource_deletion(group_id)
238
James E. Blaire6d8ee12013-01-18 21:33:45 +0000239
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000240class BaseVolumeAdminTest(BaseVolumeTest):
Attila Fazekas3dcdae12013-02-14 12:50:04 +0100241 """Base test case class for all Volume Admin API tests."""
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000242
Andrea Frittolib21de6c2015-02-06 20:12:38 +0000243 credentials = ['primary', 'admin']
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000244
Rohan Kanade05749152015-01-30 17:15:18 +0530245 @classmethod
246 def setup_clients(cls):
247 super(BaseVolumeAdminTest, cls).setup_clients()
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000248
ghanshyam6c682ff2018-08-06 09:54:45 +0000249 cls.admin_volume_qos_client = cls.os_admin.volume_qos_client_latest
Ken'ichi Ohmichic4fcdbb2017-03-15 16:53:28 -0700250 cls.admin_volume_services_client = \
ghanshyam6c682ff2018-08-06 09:54:45 +0000251 cls.os_admin.volume_services_client_latest
252 cls.admin_volume_types_client = cls.os_admin.volume_types_client_latest
253 cls.admin_volume_manage_client = (
254 cls.os_admin.volume_manage_client_latest)
255 cls.admin_volume_client = cls.os_admin.volumes_client_latest
256 cls.admin_groups_client = cls.os_admin.groups_client_latest
257 cls.admin_messages_client = cls.os_admin.volume_messages_client_latest
258 cls.admin_group_snapshots_client = \
259 cls.os_admin.group_snapshots_client_latest
260 cls.admin_group_types_client = cls.os_admin.group_types_client_latest
261 cls.admin_hosts_client = cls.os_admin.volume_hosts_client_latest
Ken'ichi Ohmichic4fcdbb2017-03-15 16:53:28 -0700262 cls.admin_snapshot_manage_client = \
ghanshyam6c682ff2018-08-06 09:54:45 +0000263 cls.os_admin.snapshot_manage_client_latest
264 cls.admin_snapshots_client = cls.os_admin.snapshots_client_latest
265 cls.admin_backups_client = cls.os_admin.backups_client_latest
Ken'ichi Ohmichic4fcdbb2017-03-15 16:53:28 -0700266 cls.admin_encryption_types_client = \
ghanshyam6c682ff2018-08-06 09:54:45 +0000267 cls.os_admin.encryption_types_client_latest
jeremy.zhang644b01d2017-04-13 12:59:49 +0800268 cls.admin_quota_classes_client = \
ghanshyam6c682ff2018-08-06 09:54:45 +0000269 cls.os_admin.volume_quota_classes_client_latest
270 cls.admin_quotas_client = cls.os_admin.volume_quotas_client_latest
271 cls.admin_volume_limits_client = (
272 cls.os_admin.volume_limits_client_latest)
Ken'ichi Ohmichic4fcdbb2017-03-15 16:53:28 -0700273 cls.admin_capabilities_client = \
ghanshyam6c682ff2018-08-06 09:54:45 +0000274 cls.os_admin.volume_capabilities_client_latest
Ken'ichi Ohmichic4fcdbb2017-03-15 16:53:28 -0700275 cls.admin_scheduler_stats_client = \
ghanshyam6c682ff2018-08-06 09:54:45 +0000276 cls.os_admin.volume_scheduler_stats_client_latest
jeremy.zhang79a1cbf2017-05-07 16:09:17 +0800277
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000278 @classmethod
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000279 def create_test_qos_specs(cls, name=None, consumer=None, **kwargs):
280 """create a test Qos-Specs."""
281 name = name or data_utils.rand_name(cls.__name__ + '-QoS')
282 consumer = consumer or 'front-end'
bkopilov62d21752016-06-08 10:16:11 +0300283 qos_specs = cls.admin_volume_qos_client.create_qos(
Jordan Pittier0359c4d2015-12-09 14:34:58 +0100284 name=name, consumer=consumer, **kwargs)['qos_specs']
zhuflcae2a752017-11-24 12:43:43 +0800285 cls.addClassResourceCleanup(cls.clear_qos_spec, qos_specs['id'])
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000286 return qos_specs
287
288 @classmethod
lkuchlan76650572016-05-23 12:30:10 +0300289 def create_volume_type(cls, name=None, **kwargs):
290 """Create a test volume-type"""
zhuflc6ce5392016-08-17 14:34:37 +0800291 name = name or data_utils.rand_name(cls.__name__ + '-volume-type')
lkuchlan76650572016-05-23 12:30:10 +0300292 volume_type = cls.admin_volume_types_client.create_volume_type(
293 name=name, **kwargs)['volume_type']
zhuflcae2a752017-11-24 12:43:43 +0800294 cls.addClassResourceCleanup(cls.clear_volume_type, volume_type['id'])
lkuchlan76650572016-05-23 12:30:10 +0300295 return volume_type
296
Xing Yang0ddf83e2015-11-17 22:15:25 -0500297 def create_group_type(self, name=None, **kwargs):
298 """Create a test group-type"""
299 name = name or data_utils.rand_name(
300 self.__class__.__name__ + '-group-type')
301 group_type = self.admin_group_types_client.create_group_type(
302 name=name, **kwargs)['group_type']
303 self.addCleanup(self.admin_group_types_client.delete_group_type,
304 group_type['id'])
305 return group_type
306
lkuchlan76650572016-05-23 12:30:10 +0300307 @classmethod
zhuflcae2a752017-11-24 12:43:43 +0800308 def clear_qos_spec(cls, qos_id):
309 test_utils.call_and_ignore_notfound_exc(
310 cls.admin_volume_qos_client.delete_qos, qos_id)
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000311
zhuflcae2a752017-11-24 12:43:43 +0800312 test_utils.call_and_ignore_notfound_exc(
313 cls.admin_volume_qos_client.wait_for_resource_deletion, qos_id)
lkuchlan76650572016-05-23 12:30:10 +0300314
315 @classmethod
zhuflcae2a752017-11-24 12:43:43 +0800316 def clear_volume_type(cls, vol_type_id):
317 test_utils.call_and_ignore_notfound_exc(
318 cls.admin_volume_types_client.delete_volume_type, vol_type_id)
lkuchlan76650572016-05-23 12:30:10 +0300319
zhuflcae2a752017-11-24 12:43:43 +0800320 test_utils.call_and_ignore_notfound_exc(
321 cls.admin_volume_types_client.wait_for_resource_deletion,
322 vol_type_id)