blob: e39d40ff47325b71d712c3ccfb737fb6629935a4 [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
Erlon R. Cruzba19bc72016-09-28 14:32:11 -0300174 def attach_volume(self, server_id, volume_id):
lkuchlan46437232017-01-08 08:29:25 +0200175 """Attach a volume to a server"""
Erlon R. Cruzba19bc72016-09-28 14:32:11 -0300176 self.servers_client.attach_volume(
177 server_id, volumeId=volume_id,
178 device='/dev/%s' % CONF.compute.volume_device_name)
179 waiters.wait_for_volume_status(self.volumes_client,
180 volume_id, 'in-use')
181 self.addCleanup(waiters.wait_for_volume_status, self.volumes_client,
182 volume_id, 'available')
183 self.addCleanup(self.servers_client.detach_volume, server_id,
zhufleba284e2016-12-16 10:44:41 +0800184 volume_id)
Erlon R. Cruzba19bc72016-09-28 14:32:11 -0300185
lkuchlan9bf9fac2016-06-19 15:32:33 +0300186 @classmethod
Attila Fazekas36b1fcf2013-01-31 16:41:04 +0100187 def clear_volumes(cls):
188 for volume in cls.volumes:
189 try:
Giulio Fidente26d16ed2013-04-30 12:05:56 +0200190 cls.volumes_client.delete_volume(volume['id'])
Attila Fazekas36b1fcf2013-01-31 16:41:04 +0100191 except Exception:
192 pass
193
194 for volume in cls.volumes:
195 try:
Giulio Fidente26d16ed2013-04-30 12:05:56 +0200196 cls.volumes_client.wait_for_resource_deletion(volume['id'])
Attila Fazekas36b1fcf2013-01-31 16:41:04 +0100197 except Exception:
198 pass
199
200 @classmethod
201 def clear_snapshots(cls):
202 for snapshot in cls.snapshots:
lkuchlan90c06a12016-08-26 14:50:43 +0300203 test_utils.call_and_ignore_notfound_exc(
204 cls.snapshots_client.delete_snapshot, snapshot['id'])
Attila Fazekas36b1fcf2013-01-31 16:41:04 +0100205
206 for snapshot in cls.snapshots:
lkuchlan90c06a12016-08-26 14:50:43 +0300207 test_utils.call_and_ignore_notfound_exc(
208 cls.snapshots_client.wait_for_resource_deletion,
209 snapshot['id'])
Attila Fazekas36b1fcf2013-01-31 16:41:04 +0100210
zhufl7867a6e2016-10-18 15:37:12 +0800211 def create_server(self, **kwargs):
zhufl22403a02016-10-26 10:25:19 +0800212 name = kwargs.pop(
zhufl7867a6e2016-10-18 15:37:12 +0800213 'name',
214 data_utils.rand_name(self.__class__.__name__ + '-instance'))
215
lkuchlan5fc69362016-09-05 08:42:34 +0300216 tenant_network = self.get_tenant_network()
Joseph Lanouxa074c012015-08-04 15:44:07 +0000217 body, _ = compute.create_test_server(
lkuchlan5fc69362016-09-05 08:42:34 +0300218 self.os,
Joseph Lanouxa074c012015-08-04 15:44:07 +0000219 tenant_network=tenant_network,
220 name=name,
221 **kwargs)
lkuchlan5fc69362016-09-05 08:42:34 +0300222
Matthew Treinish445f5982016-09-14 19:27:04 -0400223 self.addCleanup(test_utils.call_and_ignore_notfound_exc,
224 waiters.wait_for_server_termination,
225 self.servers_client, body['id'])
lkuchlan5fc69362016-09-05 08:42:34 +0300226 self.addCleanup(test_utils.call_and_ignore_notfound_exc,
227 self.servers_client.delete_server, body['id'])
Joseph Lanouxa074c012015-08-04 15:44:07 +0000228 return body
Rohan Kanade9ce97df2013-12-10 18:59:35 +0530229
James E. Blaire6d8ee12013-01-18 21:33:45 +0000230
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000231class BaseVolumeAdminTest(BaseVolumeTest):
Attila Fazekas3dcdae12013-02-14 12:50:04 +0100232 """Base test case class for all Volume Admin API tests."""
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000233
Andrea Frittolib21de6c2015-02-06 20:12:38 +0000234 credentials = ['primary', 'admin']
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000235
Rohan Kanade05749152015-01-30 17:15:18 +0530236 @classmethod
237 def setup_clients(cls):
238 super(BaseVolumeAdminTest, cls).setup_clients()
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000239
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000240 if cls._api_version == 1:
bkopilov62d21752016-06-08 10:16:11 +0300241 cls.admin_volume_qos_client = cls.os_adm.volume_qos_client
jun xie9f123822014-11-20 14:21:23 +0800242 cls.admin_volume_services_client = \
243 cls.os_adm.volume_services_client
bkopilov62d21752016-06-08 10:16:11 +0300244 cls.admin_volume_types_client = cls.os_adm.volume_types_client
Chandan Kumaree3f4bd2014-10-29 23:09:29 +0530245 cls.admin_volume_client = cls.os_adm.volumes_client
bkopilov62d21752016-06-08 10:16:11 +0300246 cls.admin_hosts_client = cls.os_adm.volume_hosts_client
Chandan Kumar457d1632014-11-18 13:46:08 +0530247 cls.admin_snapshots_client = cls.os_adm.snapshots_client
bkopilov62d21752016-06-08 10:16:11 +0300248 cls.admin_backups_client = cls.os_adm.backups_client
Ken'ichi Ohmichia6ebf622016-08-25 11:52:27 -0700249 cls.admin_encryption_types_client = \
250 cls.os_adm.encryption_types_client
bkopilov62d21752016-06-08 10:16:11 +0300251 cls.admin_quotas_client = cls.os_adm.volume_quotas_client
bkopilov14193082016-05-31 10:01:28 +0300252 cls.admin_volume_limits_client = cls.os_adm.volume_limits_client
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000253 elif cls._api_version == 2:
bkopilov62d21752016-06-08 10:16:11 +0300254 cls.admin_volume_qos_client = cls.os_adm.volume_qos_v2_client
jun xie9f123822014-11-20 14:21:23 +0800255 cls.admin_volume_services_client = \
256 cls.os_adm.volume_services_v2_client
bkopilov62d21752016-06-08 10:16:11 +0300257 cls.admin_volume_types_client = cls.os_adm.volume_types_v2_client
Chandan Kumaree3f4bd2014-10-29 23:09:29 +0530258 cls.admin_volume_client = cls.os_adm.volumes_v2_client
bkopilov62d21752016-06-08 10:16:11 +0300259 cls.admin_hosts_client = cls.os_adm.volume_hosts_v2_client
Chandan Kumar457d1632014-11-18 13:46:08 +0530260 cls.admin_snapshots_client = cls.os_adm.snapshots_v2_client
bkopilov62d21752016-06-08 10:16:11 +0300261 cls.admin_backups_client = cls.os_adm.backups_v2_client
Ken'ichi Ohmichia6ebf622016-08-25 11:52:27 -0700262 cls.admin_encryption_types_client = \
263 cls.os_adm.encryption_types_v2_client
bkopilov62d21752016-06-08 10:16:11 +0300264 cls.admin_quotas_client = cls.os_adm.volume_quotas_v2_client
bkopilov14193082016-05-31 10:01:28 +0300265 cls.admin_volume_limits_client = cls.os_adm.volume_v2_limits_client
lkuchlan7bba16c2016-09-04 12:36:04 +0300266 cls.admin_capabilities_client = \
267 cls.os_adm.volume_capabilities_v2_client
268 cls.admin_scheduler_stats_client = \
269 cls.os_adm.volume_scheduler_stats_v2_client
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000270
271 @classmethod
Rohan Kanade05749152015-01-30 17:15:18 +0530272 def resource_setup(cls):
273 super(BaseVolumeAdminTest, cls).resource_setup()
274
275 cls.qos_specs = []
lkuchlan76650572016-05-23 12:30:10 +0300276 cls.volume_types = []
Rohan Kanade05749152015-01-30 17:15:18 +0530277
278 @classmethod
Andrea Frittoli61a12e22014-09-15 13:14:54 +0100279 def resource_cleanup(cls):
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000280 cls.clear_qos_specs()
Andrea Frittoli61a12e22014-09-15 13:14:54 +0100281 super(BaseVolumeAdminTest, cls).resource_cleanup()
lkuchlan76650572016-05-23 12:30:10 +0300282 cls.clear_volume_types()
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000283
284 @classmethod
285 def create_test_qos_specs(cls, name=None, consumer=None, **kwargs):
286 """create a test Qos-Specs."""
287 name = name or data_utils.rand_name(cls.__name__ + '-QoS')
288 consumer = consumer or 'front-end'
bkopilov62d21752016-06-08 10:16:11 +0300289 qos_specs = cls.admin_volume_qos_client.create_qos(
Jordan Pittier0359c4d2015-12-09 14:34:58 +0100290 name=name, consumer=consumer, **kwargs)['qos_specs']
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000291 cls.qos_specs.append(qos_specs['id'])
292 return qos_specs
293
294 @classmethod
lkuchlan76650572016-05-23 12:30:10 +0300295 def create_volume_type(cls, name=None, **kwargs):
296 """Create a test volume-type"""
zhuflc6ce5392016-08-17 14:34:37 +0800297 name = name or data_utils.rand_name(cls.__name__ + '-volume-type')
lkuchlan76650572016-05-23 12:30:10 +0300298 volume_type = cls.admin_volume_types_client.create_volume_type(
299 name=name, **kwargs)['volume_type']
300 cls.volume_types.append(volume_type['id'])
301 return volume_type
302
303 @classmethod
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000304 def clear_qos_specs(cls):
305 for qos_id in cls.qos_specs:
Jordan Pittier9e227c52016-02-09 14:35:18 +0100306 test_utils.call_and_ignore_notfound_exc(
bkopilov62d21752016-06-08 10:16:11 +0300307 cls.admin_volume_qos_client.delete_qos, qos_id)
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000308
309 for qos_id in cls.qos_specs:
Jordan Pittier9e227c52016-02-09 14:35:18 +0100310 test_utils.call_and_ignore_notfound_exc(
bkopilov62d21752016-06-08 10:16:11 +0300311 cls.admin_volume_qos_client.wait_for_resource_deletion, qos_id)
lkuchlan76650572016-05-23 12:30:10 +0300312
313 @classmethod
314 def clear_volume_types(cls):
315 for vol_type in cls.volume_types:
316 test_utils.call_and_ignore_notfound_exc(
317 cls.admin_volume_types_client.delete_volume_type, vol_type)
318
319 for vol_type in cls.volume_types:
lkuchlan76650572016-05-23 12:30:10 +0300320 test_utils.call_and_ignore_notfound_exc(
321 cls.admin_volume_types_client.wait_for_resource_deletion,
Ken'ichi Ohmichia6ebf622016-08-25 11:52:27 -0700322 vol_type)