blob: 81fd6e66578ea5e079f5c1f1b6a6a25d04bf8233 [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
Xing Yang0ddf83e2015-11-17 22:15:25 -050077 if cls._api_version == 3:
jeremy.zhangf4ce4172017-07-05 12:27:35 +080078 cls.backups_client = cls.os_primary.backups_v3_client
Xing Yang0ddf83e2015-11-17 22:15:25 -050079 cls.volumes_client = cls.os_primary.volumes_v3_client
Lucian Petrut4f0887c2017-08-31 15:00:24 +030080 cls.messages_client = cls.os_primary.volume_v3_messages_client
81 cls.versions_client = cls.os_primary.volume_v3_versions_client
82 cls.groups_client = cls.os_primary.groups_v3_client
83 cls.group_snapshots_client = (
84 cls.os_primary.group_snapshots_v3_client)
jeremy.zhangf4ce4172017-07-05 12:27:35 +080085 else:
86 cls.backups_client = cls.os_primary.backups_v2_client
87 cls.volumes_client = cls.os_primary.volumes_v2_client
88
89 cls.snapshots_client = cls.os_primary.snapshots_v2_client
Jordan Pittier8160d312017-04-18 11:52:23 +020090 cls.volumes_extension_client =\
91 cls.os_primary.volumes_v2_extension_client
Ken'ichi Ohmichic4fcdbb2017-03-15 16:53:28 -070092 cls.availability_zone_client = (
Jordan Pittier8160d312017-04-18 11:52:23 +020093 cls.os_primary.volume_v2_availability_zone_client)
94 cls.volume_limits_client = cls.os_primary.volume_v2_limits_client
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
Ghanshyam8fc0ed22015-12-18 10:25:14 +0900132 volume = cls.volumes_client.create_volume(**kwargs)['volume']
zhuflcae2a752017-11-24 12:43:43 +0800133 cls.addClassResourceCleanup(test_utils.call_and_ignore_notfound_exc,
134 cls.delete_volume, cls.volumes_client,
135 volume['id'])
lkuchlan52d7b0d2016-11-07 20:53:19 +0200136 waiters.wait_for_volume_resource_status(cls.volumes_client,
137 volume['id'], wait_until)
Zhi Kun Liu6e6cf832014-05-08 17:25:22 +0800138 return volume
139
140 @classmethod
Attila Fazekas36b1fcf2013-01-31 16:41:04 +0100141 def create_snapshot(cls, volume_id=1, **kwargs):
142 """Wrapper utility that returns a test snapshot."""
zhufla57530c2017-03-23 11:38:12 +0800143 if 'name' not in kwargs:
zhufl354b2fb2016-10-24 15:24:22 +0800144 name = data_utils.rand_name(cls.__name__ + '-Snapshot')
zhufla57530c2017-03-23 11:38:12 +0800145 kwargs['name'] = name
zhufl354b2fb2016-10-24 15:24:22 +0800146
John Warrenff7faf62015-08-17 16:59:06 +0000147 snapshot = cls.snapshots_client.create_snapshot(
Ghanshyam0b75b632015-12-11 15:08:28 +0900148 volume_id=volume_id, **kwargs)['snapshot']
zhuflcae2a752017-11-24 12:43:43 +0800149 cls.addClassResourceCleanup(test_utils.call_and_ignore_notfound_exc,
150 cls.delete_snapshot, snapshot['id'])
lkuchlan52d7b0d2016-11-07 20:53:19 +0200151 waiters.wait_for_volume_resource_status(cls.snapshots_client,
152 snapshot['id'], 'available')
Attila Fazekas36b1fcf2013-01-31 16:41:04 +0100153 return snapshot
154
Ghanshyam Mannb0d15bf2017-05-02 04:55:47 +0000155 def create_backup(self, volume_id, backup_client=None, **kwargs):
lkuchlana2beb492016-08-17 12:42:44 +0300156 """Wrapper utility that returns a test backup."""
157 if backup_client is None:
158 backup_client = self.backups_client
zhuflefe033a2017-03-31 15:45:15 +0800159 if 'name' not in kwargs:
160 name = data_utils.rand_name(self.__class__.__name__ + '-Backup')
161 kwargs['name'] = name
lkuchlana2beb492016-08-17 12:42:44 +0300162
163 backup = backup_client.create_backup(
164 volume_id=volume_id, **kwargs)['backup']
Ghanshyam Mannb0d15bf2017-05-02 04:55:47 +0000165 self.addCleanup(backup_client.delete_backup, backup['id'])
166 waiters.wait_for_volume_resource_status(backup_client, backup['id'],
167 'available')
lkuchlana2beb492016-08-17 12:42:44 +0300168 return backup
169
Attila Fazekasf7f34f92013-08-01 17:01:44 +0200170 # NOTE(afazekas): these create_* and clean_* could be defined
Attila Fazekas36b1fcf2013-01-31 16:41:04 +0100171 # only in a single location in the source, and could be more general.
172
lkuchlane9a15952017-01-08 08:11:23 +0200173 @staticmethod
174 def delete_volume(client, volume_id):
lkuchlan9bf9fac2016-06-19 15:32:33 +0300175 """Delete volume by the given client"""
176 client.delete_volume(volume_id)
177 client.wait_for_resource_deletion(volume_id)
178
zhuflcae2a752017-11-24 12:43:43 +0800179 @classmethod
180 def delete_snapshot(cls, snapshot_id, snapshots_client=None):
lkuchlancb2f8592016-07-17 15:18:01 +0300181 """Delete snapshot by the given client"""
lkuchlan5b2b3622017-02-14 15:48:36 +0200182 if snapshots_client is None:
zhuflcae2a752017-11-24 12:43:43 +0800183 snapshots_client = cls.snapshots_client
lkuchlan5b2b3622017-02-14 15:48:36 +0200184 snapshots_client.delete_snapshot(snapshot_id)
185 snapshots_client.wait_for_resource_deletion(snapshot_id)
lkuchlancb2f8592016-07-17 15:18:01 +0300186
Erlon R. Cruzba19bc72016-09-28 14:32:11 -0300187 def attach_volume(self, server_id, volume_id):
lkuchlan46437232017-01-08 08:29:25 +0200188 """Attach a volume to a server"""
Erlon R. Cruzba19bc72016-09-28 14:32:11 -0300189 self.servers_client.attach_volume(
190 server_id, volumeId=volume_id,
191 device='/dev/%s' % CONF.compute.volume_device_name)
lkuchlan52d7b0d2016-11-07 20:53:19 +0200192 waiters.wait_for_volume_resource_status(self.volumes_client,
193 volume_id, 'in-use')
194 self.addCleanup(waiters.wait_for_volume_resource_status,
195 self.volumes_client, volume_id, 'available')
Erlon R. Cruzba19bc72016-09-28 14:32:11 -0300196 self.addCleanup(self.servers_client.detach_volume, server_id,
zhufleba284e2016-12-16 10:44:41 +0800197 volume_id)
Erlon R. Cruzba19bc72016-09-28 14:32:11 -0300198
lkuchland4ecd0e2017-06-11 12:01:27 +0300199 def create_server(self, wait_until='ACTIVE', **kwargs):
zhufl22403a02016-10-26 10:25:19 +0800200 name = kwargs.pop(
zhufl7867a6e2016-10-18 15:37:12 +0800201 'name',
202 data_utils.rand_name(self.__class__.__name__ + '-instance'))
203
lkuchlan5fc69362016-09-05 08:42:34 +0300204 tenant_network = self.get_tenant_network()
Joseph Lanouxa074c012015-08-04 15:44:07 +0000205 body, _ = compute.create_test_server(
zhufl04190882017-05-23 10:21:48 +0800206 self.os_primary,
Joseph Lanouxa074c012015-08-04 15:44:07 +0000207 tenant_network=tenant_network,
208 name=name,
lkuchland4ecd0e2017-06-11 12:01:27 +0300209 wait_until=wait_until,
Joseph Lanouxa074c012015-08-04 15:44:07 +0000210 **kwargs)
lkuchlan5fc69362016-09-05 08:42:34 +0300211
Matthew Treinish445f5982016-09-14 19:27:04 -0400212 self.addCleanup(test_utils.call_and_ignore_notfound_exc,
213 waiters.wait_for_server_termination,
214 self.servers_client, body['id'])
lkuchlan5fc69362016-09-05 08:42:34 +0300215 self.addCleanup(test_utils.call_and_ignore_notfound_exc,
216 self.servers_client.delete_server, body['id'])
Joseph Lanouxa074c012015-08-04 15:44:07 +0000217 return body
Rohan Kanade9ce97df2013-12-10 18:59:35 +0530218
jeremy.zhang2abe00a2017-11-21 10:14:09 +0800219 def create_group(self, **kwargs):
220 if 'name' not in kwargs:
221 kwargs['name'] = data_utils.rand_name(
222 self.__class__.__name__ + '-Group')
223
224 group = self.groups_client.create_group(**kwargs)['group']
225 self.addCleanup(test_utils.call_and_ignore_notfound_exc,
226 self.delete_group, group['id'])
227 waiters.wait_for_volume_resource_status(
228 self.groups_client, group['id'], 'available')
229 return group
230
231 def delete_group(self, group_id, delete_volumes=True):
232 self.groups_client.delete_group(group_id, delete_volumes)
233 if delete_volumes:
234 vols = self.volumes_client.list_volumes(detail=True)['volumes']
235 for vol in vols:
236 if vol['group_id'] == group_id:
237 self.volumes_client.wait_for_resource_deletion(vol['id'])
238 self.groups_client.wait_for_resource_deletion(group_id)
239
James E. Blaire6d8ee12013-01-18 21:33:45 +0000240
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000241class BaseVolumeAdminTest(BaseVolumeTest):
Attila Fazekas3dcdae12013-02-14 12:50:04 +0100242 """Base test case class for all Volume Admin API tests."""
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000243
Andrea Frittolib21de6c2015-02-06 20:12:38 +0000244 credentials = ['primary', 'admin']
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000245
Rohan Kanade05749152015-01-30 17:15:18 +0530246 @classmethod
247 def setup_clients(cls):
248 super(BaseVolumeAdminTest, cls).setup_clients()
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000249
Jordan Pittier8160d312017-04-18 11:52:23 +0200250 cls.admin_volume_qos_client = cls.os_admin.volume_qos_v2_client
Ken'ichi Ohmichic4fcdbb2017-03-15 16:53:28 -0700251 cls.admin_volume_services_client = \
Jordan Pittier8160d312017-04-18 11:52:23 +0200252 cls.os_admin.volume_services_v2_client
253 cls.admin_volume_types_client = cls.os_admin.volume_types_v2_client
254 cls.admin_volume_manage_client = cls.os_admin.volume_manage_v2_client
255 cls.admin_volume_client = cls.os_admin.volumes_v2_client
Xing Yang0ddf83e2015-11-17 22:15:25 -0500256 if cls._api_version == 3:
257 cls.admin_volume_client = cls.os_admin.volumes_v3_client
Lucian Petrut4f0887c2017-08-31 15:00:24 +0300258 cls.admin_groups_client = cls.os_admin.groups_v3_client
259 cls.admin_messages_client = cls.os_admin.volume_v3_messages_client
260 cls.admin_group_snapshots_client = \
261 cls.os_admin.group_snapshots_v3_client
262 cls.admin_group_types_client = cls.os_admin.group_types_v3_client
Jordan Pittier8160d312017-04-18 11:52:23 +0200263 cls.admin_hosts_client = cls.os_admin.volume_hosts_v2_client
Ken'ichi Ohmichic4fcdbb2017-03-15 16:53:28 -0700264 cls.admin_snapshot_manage_client = \
Jordan Pittier8160d312017-04-18 11:52:23 +0200265 cls.os_admin.snapshot_manage_v2_client
266 cls.admin_snapshots_client = cls.os_admin.snapshots_v2_client
267 cls.admin_backups_client = cls.os_admin.backups_v2_client
Ken'ichi Ohmichic4fcdbb2017-03-15 16:53:28 -0700268 cls.admin_encryption_types_client = \
Jordan Pittier8160d312017-04-18 11:52:23 +0200269 cls.os_admin.encryption_types_v2_client
jeremy.zhang644b01d2017-04-13 12:59:49 +0800270 cls.admin_quota_classes_client = \
Jordan Pittier8160d312017-04-18 11:52:23 +0200271 cls.os_admin.volume_quota_classes_v2_client
272 cls.admin_quotas_client = cls.os_admin.volume_quotas_v2_client
273 cls.admin_volume_limits_client = cls.os_admin.volume_v2_limits_client
Ken'ichi Ohmichic4fcdbb2017-03-15 16:53:28 -0700274 cls.admin_capabilities_client = \
Jordan Pittier8160d312017-04-18 11:52:23 +0200275 cls.os_admin.volume_capabilities_v2_client
Ken'ichi Ohmichic4fcdbb2017-03-15 16:53:28 -0700276 cls.admin_scheduler_stats_client = \
Jordan Pittier8160d312017-04-18 11:52:23 +0200277 cls.os_admin.volume_scheduler_stats_v2_client
jeremy.zhang79a1cbf2017-05-07 16:09:17 +0800278
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000279 @classmethod
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000280 def create_test_qos_specs(cls, name=None, consumer=None, **kwargs):
281 """create a test Qos-Specs."""
282 name = name or data_utils.rand_name(cls.__name__ + '-QoS')
283 consumer = consumer or 'front-end'
bkopilov62d21752016-06-08 10:16:11 +0300284 qos_specs = cls.admin_volume_qos_client.create_qos(
Jordan Pittier0359c4d2015-12-09 14:34:58 +0100285 name=name, consumer=consumer, **kwargs)['qos_specs']
zhuflcae2a752017-11-24 12:43:43 +0800286 cls.addClassResourceCleanup(cls.clear_qos_spec, qos_specs['id'])
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000287 return qos_specs
288
289 @classmethod
lkuchlan76650572016-05-23 12:30:10 +0300290 def create_volume_type(cls, name=None, **kwargs):
291 """Create a test volume-type"""
zhuflc6ce5392016-08-17 14:34:37 +0800292 name = name or data_utils.rand_name(cls.__name__ + '-volume-type')
lkuchlan76650572016-05-23 12:30:10 +0300293 volume_type = cls.admin_volume_types_client.create_volume_type(
294 name=name, **kwargs)['volume_type']
zhuflcae2a752017-11-24 12:43:43 +0800295 cls.addClassResourceCleanup(cls.clear_volume_type, volume_type['id'])
lkuchlan76650572016-05-23 12:30:10 +0300296 return volume_type
297
Xing Yang0ddf83e2015-11-17 22:15:25 -0500298 def create_group_type(self, name=None, **kwargs):
299 """Create a test group-type"""
300 name = name or data_utils.rand_name(
301 self.__class__.__name__ + '-group-type')
302 group_type = self.admin_group_types_client.create_group_type(
303 name=name, **kwargs)['group_type']
304 self.addCleanup(self.admin_group_types_client.delete_group_type,
305 group_type['id'])
306 return group_type
307
lkuchlan76650572016-05-23 12:30:10 +0300308 @classmethod
zhuflcae2a752017-11-24 12:43:43 +0800309 def clear_qos_spec(cls, qos_id):
310 test_utils.call_and_ignore_notfound_exc(
311 cls.admin_volume_qos_client.delete_qos, qos_id)
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000312
zhuflcae2a752017-11-24 12:43:43 +0800313 test_utils.call_and_ignore_notfound_exc(
314 cls.admin_volume_qos_client.wait_for_resource_deletion, qos_id)
lkuchlan76650572016-05-23 12:30:10 +0300315
316 @classmethod
zhuflcae2a752017-11-24 12:43:43 +0800317 def clear_volume_type(cls, vol_type_id):
318 test_utils.call_and_ignore_notfound_exc(
319 cls.admin_volume_types_client.delete_volume_type, vol_type_id)
lkuchlan76650572016-05-23 12:30:10 +0300320
zhuflcae2a752017-11-24 12:43:43 +0800321 test_utils.call_and_ignore_notfound_exc(
322 cls.admin_volume_types_client.wait_for_resource_deletion,
323 vol_type_id)