blob: d21f380ead1d37dec8ade9204a9e600ff590c68e [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
Joseph Lanouxa074c012015-08-04 15:44:07 +000016from tempest.common import compute
Fei Long Wangd39431f2015-05-14 11:30:48 +120017from tempest.common.utils import data_utils
Yaroslav Lobankoved3a35b2016-03-24 22:41:30 -050018from tempest.common import waiters
Matthew Treinish4d352bc2014-01-29 18:29:18 +000019from tempest import config
Jordan Pittier9e227c52016-02-09 14:35:18 +010020from tempest.lib.common.utils import test_utils
Matthew Treinish4217a702016-10-07 17:27:11 -040021from tempest.lib import exceptions
Attila Fazekasdc216422013-01-29 15:12:14 +010022import tempest.test
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070023
Matthew Treinish4d352bc2014-01-29 18:29:18 +000024CONF = config.CONF
25
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070026
Attila Fazekasdc216422013-01-29 15:12:14 +010027class BaseVolumeTest(tempest.test.BaseTestCase):
Sean Daguef237ccb2013-01-04 15:19:14 -050028 """Base test case class for all Cinder API tests."""
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070029
Zhi Kun Liu6e6cf832014-05-08 17:25:22 +080030 _api_version = 2
Andrea Frittolib21de6c2015-02-06 20:12:38 +000031 credentials = ['primary']
Zhi Kun Liu6e6cf832014-05-08 17:25:22 +080032
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070033 @classmethod
Rohan Kanade05749152015-01-30 17:15:18 +053034 def skip_checks(cls):
35 super(BaseVolumeTest, cls).skip_checks()
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070036
Matthew Treinish4d352bc2014-01-29 18:29:18 +000037 if not CONF.service_available.cinder:
Matthew Treinish4c412922013-07-16 15:27:42 -040038 skip_msg = ("%s skipped as Cinder is not available" % cls.__name__)
39 raise cls.skipException(skip_msg)
Zhi Kun Liu6e6cf832014-05-08 17:25:22 +080040 if cls._api_version == 1:
41 if not CONF.volume_feature_enabled.api_v1:
42 msg = "Volume API v1 is disabled"
43 raise cls.skipException(msg)
Rohan Kanade05749152015-01-30 17:15:18 +053044 elif cls._api_version == 2:
45 if not CONF.volume_feature_enabled.api_v2:
46 msg = "Volume API v2 is disabled"
47 raise cls.skipException(msg)
Andrew Kerrfcb0b682016-04-01 16:01:34 -040048 elif cls._api_version == 3:
49 if not CONF.volume_feature_enabled.api_v3:
50 msg = "Volume API v3 is disabled"
51 raise cls.skipException(msg)
Rohan Kanade05749152015-01-30 17:15:18 +053052 else:
53 msg = ("Invalid Cinder API version (%s)" % cls._api_version)
zhuflff30ede2016-12-27 10:29:13 +080054 raise exceptions.InvalidConfiguration(msg)
Rohan Kanade05749152015-01-30 17:15:18 +053055
56 @classmethod
57 def setup_credentials(cls):
58 cls.set_network_resources()
59 super(BaseVolumeTest, cls).setup_credentials()
Rohan Kanade05749152015-01-30 17:15:18 +053060
61 @classmethod
62 def setup_clients(cls):
63 super(BaseVolumeTest, cls).setup_clients()
Rohan Kanade05749152015-01-30 17:15:18 +053064 cls.servers_client = cls.os.servers_client
John Warren9487a182015-09-14 18:12:56 -040065 cls.compute_networks_client = cls.os.compute_networks_client
Ghanshyamae76c122015-12-22 13:41:35 +090066 cls.compute_images_client = cls.os.compute_images_client
Rohan Kanade05749152015-01-30 17:15:18 +053067
68 if cls._api_version == 1:
Zhi Kun Liu6e6cf832014-05-08 17:25:22 +080069 cls.snapshots_client = cls.os.snapshots_client
70 cls.volumes_client = cls.os.volumes_client
71 cls.backups_client = cls.os.backups_client
72 cls.volume_services_client = cls.os.volume_services_client
73 cls.volumes_extension_client = cls.os.volumes_extension_client
74 cls.availability_zone_client = (
75 cls.os.volume_availability_zone_client)
bkopilov14193082016-05-31 10:01:28 +030076 cls.volume_limits_client = cls.os.volume_limits_client
Rohan Kanade05749152015-01-30 17:15:18 +053077 else:
Zhi Kun Liu38641c62014-07-10 20:12:48 +080078 cls.snapshots_client = cls.os.snapshots_v2_client
Zhi Kun Liu6e6cf832014-05-08 17:25:22 +080079 cls.volumes_client = cls.os.volumes_v2_client
lkuchlan9dea88e2016-06-07 17:12:01 +030080 cls.backups_client = cls.os.backups_v2_client
Zhi Kun Liu53395522014-07-18 16:05:52 +080081 cls.volumes_extension_client = cls.os.volumes_v2_extension_client
82 cls.availability_zone_client = (
83 cls.os.volume_v2_availability_zone_client)
bkopilov14193082016-05-31 10:01:28 +030084 cls.volume_limits_client = cls.os.volume_v2_limits_client
Rohan Kanade05749152015-01-30 17:15:18 +053085
86 @classmethod
87 def resource_setup(cls):
88 super(BaseVolumeTest, cls).resource_setup()
89
90 cls.snapshots = []
91 cls.volumes = []
92 cls.image_ref = CONF.compute.image_ref
93 cls.flavor_ref = CONF.compute.flavor_ref
94 cls.build_interval = CONF.volume.build_interval
95 cls.build_timeout = CONF.volume.build_timeout
96
97 if cls._api_version == 1:
98 # Special fields and resp code for cinder v1
99 cls.special_fields = {'name_field': 'display_name',
100 'descrip_field': 'display_description'}
101 else:
Zhi Kun Liu3d6d9862014-06-16 16:43:59 +0800102 # Special fields and resp code for cinder v2
103 cls.special_fields = {'name_field': 'name',
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000104 'descrip_field': 'description'}
Zhi Kun Liu6e6cf832014-05-08 17:25:22 +0800105
Rohit Karajgidd47d7e2012-07-31 04:11:01 -0700106 @classmethod
Andrea Frittoli61a12e22014-09-15 13:14:54 +0100107 def resource_cleanup(cls):
Attila Fazekas36b1fcf2013-01-31 16:41:04 +0100108 cls.clear_snapshots()
109 cls.clear_volumes()
Andrea Frittoli61a12e22014-09-15 13:14:54 +0100110 super(BaseVolumeTest, cls).resource_cleanup()
Rohit Karajgidd47d7e2012-07-31 04:11:01 -0700111
Attila Fazekas36b1fcf2013-01-31 16:41:04 +0100112 @classmethod
Benny Kopilov8a33ee12016-11-09 10:35:23 +0200113 def create_volume(cls, wait_until='available', **kwargs):
114 """Wrapper utility that returns a test volume.
115
116 :param wait_until: wait till volume status.
117 """
Ken'ichi Ohmichiadb905e2016-08-26 15:16:23 -0700118 if 'size' not in kwargs:
119 kwargs['size'] = CONF.volume.volume_size
120
Nuno Santosb746d992016-11-17 15:41:55 -0500121 if 'imageRef' in kwargs:
122 image = cls.compute_images_client.show_image(
123 kwargs['imageRef'])['image']
124 min_disk = image.get('minDisk')
125 kwargs['size'] = max(kwargs['size'], min_disk)
126
Zhi Kun Liu3d6d9862014-06-16 16:43:59 +0800127 name_field = cls.special_fields['name_field']
zhufl354b2fb2016-10-24 15:24:22 +0800128 if name_field not in kwargs:
129 name = data_utils.rand_name(cls.__name__ + '-Volume')
130 kwargs[name_field] = 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']
Zhi Kun Liu6e6cf832014-05-08 17:25:22 +0800133 cls.volumes.append(volume)
Benny Kopilov8a33ee12016-11-09 10:35:23 +0200134 waiters.wait_for_volume_status(cls.volumes_client, volume['id'],
135 wait_until)
Zhi Kun Liu6e6cf832014-05-08 17:25:22 +0800136 return volume
137
138 @classmethod
Attila Fazekas36b1fcf2013-01-31 16:41:04 +0100139 def create_snapshot(cls, volume_id=1, **kwargs):
140 """Wrapper utility that returns a test snapshot."""
zhufl354b2fb2016-10-24 15:24:22 +0800141 name_field = cls.special_fields['name_field']
142 if name_field not in kwargs:
143 name = data_utils.rand_name(cls.__name__ + '-Snapshot')
144 kwargs[name_field] = name
145
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']
Giulio Fidente02f42982013-06-17 16:25:56 +0200148 cls.snapshots.append(snapshot)
Yaroslav Lobankov667aaa22016-03-24 23:13:28 -0500149 waiters.wait_for_snapshot_status(cls.snapshots_client,
150 snapshot['id'], 'available')
Attila Fazekas36b1fcf2013-01-31 16:41:04 +0100151 return snapshot
152
lkuchlana2beb492016-08-17 12:42:44 +0300153 def create_backup(self, volume_id, backup_client=None, **kwargs):
154 """Wrapper utility that returns a test backup."""
155 if backup_client is None:
156 backup_client = self.backups_client
157
158 backup = backup_client.create_backup(
159 volume_id=volume_id, **kwargs)['backup']
160 self.addCleanup(backup_client.delete_backup, backup['id'])
161 waiters.wait_for_backup_status(backup_client, backup['id'],
162 'available')
163 return backup
164
Attila Fazekasf7f34f92013-08-01 17:01:44 +0200165 # NOTE(afazekas): these create_* and clean_* could be defined
Attila Fazekas36b1fcf2013-01-31 16:41:04 +0100166 # only in a single location in the source, and could be more general.
167
168 @classmethod
lkuchlan9bf9fac2016-06-19 15:32:33 +0300169 def delete_volume(cls, client, volume_id):
170 """Delete volume by the given client"""
171 client.delete_volume(volume_id)
172 client.wait_for_resource_deletion(volume_id)
173
lkuchlancb2f8592016-07-17 15:18:01 +0300174 def delete_snapshot(self, client, snapshot_id):
175 """Delete snapshot by the given client"""
176 client.delete_snapshot(snapshot_id)
177 client.wait_for_resource_deletion(snapshot_id)
178
Erlon R. Cruzba19bc72016-09-28 14:32:11 -0300179 def attach_volume(self, server_id, volume_id):
180 """Attachs a volume to a server"""
181 self.servers_client.attach_volume(
182 server_id, volumeId=volume_id,
183 device='/dev/%s' % CONF.compute.volume_device_name)
184 waiters.wait_for_volume_status(self.volumes_client,
185 volume_id, 'in-use')
186 self.addCleanup(waiters.wait_for_volume_status, self.volumes_client,
187 volume_id, 'available')
188 self.addCleanup(self.servers_client.detach_volume, server_id,
zhufleba284e2016-12-16 10:44:41 +0800189 volume_id)
Erlon R. Cruzba19bc72016-09-28 14:32:11 -0300190
lkuchlan9bf9fac2016-06-19 15:32:33 +0300191 @classmethod
Attila Fazekas36b1fcf2013-01-31 16:41:04 +0100192 def clear_volumes(cls):
193 for volume in cls.volumes:
194 try:
Giulio Fidente26d16ed2013-04-30 12:05:56 +0200195 cls.volumes_client.delete_volume(volume['id'])
Attila Fazekas36b1fcf2013-01-31 16:41:04 +0100196 except Exception:
197 pass
198
199 for volume in cls.volumes:
200 try:
Giulio Fidente26d16ed2013-04-30 12:05:56 +0200201 cls.volumes_client.wait_for_resource_deletion(volume['id'])
Attila Fazekas36b1fcf2013-01-31 16:41:04 +0100202 except Exception:
203 pass
204
205 @classmethod
206 def clear_snapshots(cls):
207 for snapshot in cls.snapshots:
lkuchlan90c06a12016-08-26 14:50:43 +0300208 test_utils.call_and_ignore_notfound_exc(
209 cls.snapshots_client.delete_snapshot, snapshot['id'])
Attila Fazekas36b1fcf2013-01-31 16:41:04 +0100210
211 for snapshot in cls.snapshots:
lkuchlan90c06a12016-08-26 14:50:43 +0300212 test_utils.call_and_ignore_notfound_exc(
213 cls.snapshots_client.wait_for_resource_deletion,
214 snapshot['id'])
Attila Fazekas36b1fcf2013-01-31 16:41:04 +0100215
zhufl7867a6e2016-10-18 15:37:12 +0800216 def create_server(self, **kwargs):
zhufl22403a02016-10-26 10:25:19 +0800217 name = kwargs.pop(
zhufl7867a6e2016-10-18 15:37:12 +0800218 'name',
219 data_utils.rand_name(self.__class__.__name__ + '-instance'))
220
lkuchlan5fc69362016-09-05 08:42:34 +0300221 tenant_network = self.get_tenant_network()
Joseph Lanouxa074c012015-08-04 15:44:07 +0000222 body, _ = compute.create_test_server(
lkuchlan5fc69362016-09-05 08:42:34 +0300223 self.os,
Joseph Lanouxa074c012015-08-04 15:44:07 +0000224 tenant_network=tenant_network,
225 name=name,
226 **kwargs)
lkuchlan5fc69362016-09-05 08:42:34 +0300227
Matthew Treinish445f5982016-09-14 19:27:04 -0400228 self.addCleanup(test_utils.call_and_ignore_notfound_exc,
229 waiters.wait_for_server_termination,
230 self.servers_client, body['id'])
lkuchlan5fc69362016-09-05 08:42:34 +0300231 self.addCleanup(test_utils.call_and_ignore_notfound_exc,
232 self.servers_client.delete_server, body['id'])
Joseph Lanouxa074c012015-08-04 15:44:07 +0000233 return body
Rohan Kanade9ce97df2013-12-10 18:59:35 +0530234
James E. Blaire6d8ee12013-01-18 21:33:45 +0000235
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000236class BaseVolumeAdminTest(BaseVolumeTest):
Attila Fazekas3dcdae12013-02-14 12:50:04 +0100237 """Base test case class for all Volume Admin API tests."""
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000238
Andrea Frittolib21de6c2015-02-06 20:12:38 +0000239 credentials = ['primary', 'admin']
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000240
Rohan Kanade05749152015-01-30 17:15:18 +0530241 @classmethod
242 def setup_clients(cls):
243 super(BaseVolumeAdminTest, cls).setup_clients()
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000244
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000245 if cls._api_version == 1:
bkopilov62d21752016-06-08 10:16:11 +0300246 cls.admin_volume_qos_client = cls.os_adm.volume_qos_client
jun xie9f123822014-11-20 14:21:23 +0800247 cls.admin_volume_services_client = \
248 cls.os_adm.volume_services_client
bkopilov62d21752016-06-08 10:16:11 +0300249 cls.admin_volume_types_client = cls.os_adm.volume_types_client
Chandan Kumaree3f4bd2014-10-29 23:09:29 +0530250 cls.admin_volume_client = cls.os_adm.volumes_client
bkopilov62d21752016-06-08 10:16:11 +0300251 cls.admin_hosts_client = cls.os_adm.volume_hosts_client
Chandan Kumar457d1632014-11-18 13:46:08 +0530252 cls.admin_snapshots_client = cls.os_adm.snapshots_client
bkopilov62d21752016-06-08 10:16:11 +0300253 cls.admin_backups_client = cls.os_adm.backups_client
Ken'ichi Ohmichia6ebf622016-08-25 11:52:27 -0700254 cls.admin_encryption_types_client = \
255 cls.os_adm.encryption_types_client
bkopilov62d21752016-06-08 10:16:11 +0300256 cls.admin_quotas_client = cls.os_adm.volume_quotas_client
bkopilov14193082016-05-31 10:01:28 +0300257 cls.admin_volume_limits_client = cls.os_adm.volume_limits_client
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000258 elif cls._api_version == 2:
bkopilov62d21752016-06-08 10:16:11 +0300259 cls.admin_volume_qos_client = cls.os_adm.volume_qos_v2_client
jun xie9f123822014-11-20 14:21:23 +0800260 cls.admin_volume_services_client = \
261 cls.os_adm.volume_services_v2_client
bkopilov62d21752016-06-08 10:16:11 +0300262 cls.admin_volume_types_client = cls.os_adm.volume_types_v2_client
Chandan Kumaree3f4bd2014-10-29 23:09:29 +0530263 cls.admin_volume_client = cls.os_adm.volumes_v2_client
bkopilov62d21752016-06-08 10:16:11 +0300264 cls.admin_hosts_client = cls.os_adm.volume_hosts_v2_client
lkuchlancb2f8592016-07-17 15:18:01 +0300265 cls.admin_snapshot_manage_client = \
266 cls.os_adm.snapshot_manage_v2_client
Chandan Kumar457d1632014-11-18 13:46:08 +0530267 cls.admin_snapshots_client = cls.os_adm.snapshots_v2_client
bkopilov62d21752016-06-08 10:16:11 +0300268 cls.admin_backups_client = cls.os_adm.backups_v2_client
Ken'ichi Ohmichia6ebf622016-08-25 11:52:27 -0700269 cls.admin_encryption_types_client = \
270 cls.os_adm.encryption_types_v2_client
bkopilov62d21752016-06-08 10:16:11 +0300271 cls.admin_quotas_client = cls.os_adm.volume_quotas_v2_client
bkopilov14193082016-05-31 10:01:28 +0300272 cls.admin_volume_limits_client = cls.os_adm.volume_v2_limits_client
lkuchlan7bba16c2016-09-04 12:36:04 +0300273 cls.admin_capabilities_client = \
274 cls.os_adm.volume_capabilities_v2_client
275 cls.admin_scheduler_stats_client = \
276 cls.os_adm.volume_scheduler_stats_v2_client
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000277
278 @classmethod
Rohan Kanade05749152015-01-30 17:15:18 +0530279 def resource_setup(cls):
280 super(BaseVolumeAdminTest, cls).resource_setup()
281
282 cls.qos_specs = []
lkuchlan76650572016-05-23 12:30:10 +0300283 cls.volume_types = []
Rohan Kanade05749152015-01-30 17:15:18 +0530284
285 @classmethod
Andrea Frittoli61a12e22014-09-15 13:14:54 +0100286 def resource_cleanup(cls):
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000287 cls.clear_qos_specs()
Andrea Frittoli61a12e22014-09-15 13:14:54 +0100288 super(BaseVolumeAdminTest, cls).resource_cleanup()
lkuchlan76650572016-05-23 12:30:10 +0300289 cls.clear_volume_types()
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000290
291 @classmethod
292 def create_test_qos_specs(cls, name=None, consumer=None, **kwargs):
293 """create a test Qos-Specs."""
294 name = name or data_utils.rand_name(cls.__name__ + '-QoS')
295 consumer = consumer or 'front-end'
bkopilov62d21752016-06-08 10:16:11 +0300296 qos_specs = cls.admin_volume_qos_client.create_qos(
Jordan Pittier0359c4d2015-12-09 14:34:58 +0100297 name=name, consumer=consumer, **kwargs)['qos_specs']
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000298 cls.qos_specs.append(qos_specs['id'])
299 return qos_specs
300
301 @classmethod
lkuchlan76650572016-05-23 12:30:10 +0300302 def create_volume_type(cls, name=None, **kwargs):
303 """Create a test volume-type"""
zhuflc6ce5392016-08-17 14:34:37 +0800304 name = name or data_utils.rand_name(cls.__name__ + '-volume-type')
lkuchlan76650572016-05-23 12:30:10 +0300305 volume_type = cls.admin_volume_types_client.create_volume_type(
306 name=name, **kwargs)['volume_type']
307 cls.volume_types.append(volume_type['id'])
308 return volume_type
309
310 @classmethod
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000311 def clear_qos_specs(cls):
312 for qos_id in cls.qos_specs:
Jordan Pittier9e227c52016-02-09 14:35:18 +0100313 test_utils.call_and_ignore_notfound_exc(
bkopilov62d21752016-06-08 10:16:11 +0300314 cls.admin_volume_qos_client.delete_qos, qos_id)
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000315
316 for qos_id in cls.qos_specs:
Jordan Pittier9e227c52016-02-09 14:35:18 +0100317 test_utils.call_and_ignore_notfound_exc(
bkopilov62d21752016-06-08 10:16:11 +0300318 cls.admin_volume_qos_client.wait_for_resource_deletion, qos_id)
lkuchlan76650572016-05-23 12:30:10 +0300319
320 @classmethod
321 def clear_volume_types(cls):
322 for vol_type in cls.volume_types:
323 test_utils.call_and_ignore_notfound_exc(
324 cls.admin_volume_types_client.delete_volume_type, vol_type)
325
326 for vol_type in cls.volume_types:
lkuchlan76650572016-05-23 12:30:10 +0300327 test_utils.call_and_ignore_notfound_exc(
328 cls.admin_volume_types_client.wait_for_resource_deletion,
Ken'ichi Ohmichia6ebf622016-08-25 11:52:27 -0700329 vol_type)