blob: 82dc2c9687b58dd41ed482ee6a8b80d40e5674c9 [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
Matthew Treinish4d352bc2014-01-29 18:29:18 +000018from tempest import config
Zhi Kun Liu6e6cf832014-05-08 17:25:22 +080019from tempest import exceptions
Andrea Frittoli (andreaf)db9672e2016-02-23 14:07:24 -050020from tempest.lib import exceptions as lib_exc
Attila Fazekasdc216422013-01-29 15:12:14 +010021import tempest.test
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070022
Matthew Treinish4d352bc2014-01-29 18:29:18 +000023CONF = config.CONF
24
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070025
Attila Fazekasdc216422013-01-29 15:12:14 +010026class BaseVolumeTest(tempest.test.BaseTestCase):
Sean Daguef237ccb2013-01-04 15:19:14 -050027 """Base test case class for all Cinder API tests."""
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070028
Zhi Kun Liu6e6cf832014-05-08 17:25:22 +080029 _api_version = 2
Andrea Frittolib21de6c2015-02-06 20:12:38 +000030 credentials = ['primary']
Zhi Kun Liu6e6cf832014-05-08 17:25:22 +080031
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070032 @classmethod
Rohan Kanade05749152015-01-30 17:15:18 +053033 def skip_checks(cls):
34 super(BaseVolumeTest, cls).skip_checks()
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070035
Matthew Treinish4d352bc2014-01-29 18:29:18 +000036 if not CONF.service_available.cinder:
Matthew Treinish4c412922013-07-16 15:27:42 -040037 skip_msg = ("%s skipped as Cinder is not available" % cls.__name__)
38 raise cls.skipException(skip_msg)
Zhi Kun Liu6e6cf832014-05-08 17:25:22 +080039 if cls._api_version == 1:
40 if not CONF.volume_feature_enabled.api_v1:
41 msg = "Volume API v1 is disabled"
42 raise cls.skipException(msg)
Rohan Kanade05749152015-01-30 17:15:18 +053043 elif cls._api_version == 2:
44 if not CONF.volume_feature_enabled.api_v2:
45 msg = "Volume API v2 is disabled"
46 raise cls.skipException(msg)
47 else:
48 msg = ("Invalid Cinder API version (%s)" % cls._api_version)
49 raise exceptions.InvalidConfiguration(message=msg)
50
51 @classmethod
52 def setup_credentials(cls):
53 cls.set_network_resources()
54 super(BaseVolumeTest, cls).setup_credentials()
Rohan Kanade05749152015-01-30 17:15:18 +053055
56 @classmethod
57 def setup_clients(cls):
58 super(BaseVolumeTest, cls).setup_clients()
Rohan Kanade05749152015-01-30 17:15:18 +053059 cls.servers_client = cls.os.servers_client
John Warren9487a182015-09-14 18:12:56 -040060 cls.compute_networks_client = cls.os.compute_networks_client
Ghanshyamae76c122015-12-22 13:41:35 +090061 cls.compute_images_client = cls.os.compute_images_client
Rohan Kanade05749152015-01-30 17:15:18 +053062
63 if cls._api_version == 1:
Zhi Kun Liu6e6cf832014-05-08 17:25:22 +080064 cls.snapshots_client = cls.os.snapshots_client
65 cls.volumes_client = cls.os.volumes_client
66 cls.backups_client = cls.os.backups_client
67 cls.volume_services_client = cls.os.volume_services_client
68 cls.volumes_extension_client = cls.os.volumes_extension_client
69 cls.availability_zone_client = (
70 cls.os.volume_availability_zone_client)
Rohan Kanade05749152015-01-30 17:15:18 +053071 else:
Zhi Kun Liu38641c62014-07-10 20:12:48 +080072 cls.snapshots_client = cls.os.snapshots_v2_client
Zhi Kun Liu6e6cf832014-05-08 17:25:22 +080073 cls.volumes_client = cls.os.volumes_v2_client
Zhi Kun Liu53395522014-07-18 16:05:52 +080074 cls.volumes_extension_client = cls.os.volumes_v2_extension_client
75 cls.availability_zone_client = (
76 cls.os.volume_v2_availability_zone_client)
Rohan Kanade05749152015-01-30 17:15:18 +053077
78 @classmethod
79 def resource_setup(cls):
80 super(BaseVolumeTest, cls).resource_setup()
81
82 cls.snapshots = []
83 cls.volumes = []
84 cls.image_ref = CONF.compute.image_ref
85 cls.flavor_ref = CONF.compute.flavor_ref
86 cls.build_interval = CONF.volume.build_interval
87 cls.build_timeout = CONF.volume.build_timeout
88
89 if cls._api_version == 1:
90 # Special fields and resp code for cinder v1
91 cls.special_fields = {'name_field': 'display_name',
92 'descrip_field': 'display_description'}
93 else:
Zhi Kun Liu3d6d9862014-06-16 16:43:59 +080094 # Special fields and resp code for cinder v2
95 cls.special_fields = {'name_field': 'name',
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +000096 'descrip_field': 'description'}
Zhi Kun Liu6e6cf832014-05-08 17:25:22 +080097
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070098 @classmethod
Andrea Frittoli61a12e22014-09-15 13:14:54 +010099 def resource_cleanup(cls):
Attila Fazekas36b1fcf2013-01-31 16:41:04 +0100100 cls.clear_snapshots()
101 cls.clear_volumes()
Andrea Frittoli61a12e22014-09-15 13:14:54 +0100102 super(BaseVolumeTest, cls).resource_cleanup()
Rohit Karajgidd47d7e2012-07-31 04:11:01 -0700103
Attila Fazekas36b1fcf2013-01-31 16:41:04 +0100104 @classmethod
Ghanshyam8fc0ed22015-12-18 10:25:14 +0900105 def create_volume(cls, **kwargs):
Zhi Kun Liu6e6cf832014-05-08 17:25:22 +0800106 """Wrapper utility that returns a test volume."""
Zhi Kun Liu3d6d9862014-06-16 16:43:59 +0800107 name = data_utils.rand_name('Volume')
108
109 name_field = cls.special_fields['name_field']
Zhi Kun Liu3d6d9862014-06-16 16:43:59 +0800110
111 kwargs[name_field] = name
Ghanshyam8fc0ed22015-12-18 10:25:14 +0900112 volume = cls.volumes_client.create_volume(**kwargs)['volume']
Zhi Kun Liu3d6d9862014-06-16 16:43:59 +0800113
Zhi Kun Liu6e6cf832014-05-08 17:25:22 +0800114 cls.volumes.append(volume)
115 cls.volumes_client.wait_for_volume_status(volume['id'], 'available')
116 return volume
117
118 @classmethod
Attila Fazekas36b1fcf2013-01-31 16:41:04 +0100119 def create_snapshot(cls, volume_id=1, **kwargs):
120 """Wrapper utility that returns a test snapshot."""
John Warrenff7faf62015-08-17 16:59:06 +0000121 snapshot = cls.snapshots_client.create_snapshot(
Ghanshyam0b75b632015-12-11 15:08:28 +0900122 volume_id=volume_id, **kwargs)['snapshot']
Giulio Fidente02f42982013-06-17 16:25:56 +0200123 cls.snapshots.append(snapshot)
Attila Fazekas36b1fcf2013-01-31 16:41:04 +0100124 cls.snapshots_client.wait_for_snapshot_status(snapshot['id'],
125 'available')
Attila Fazekas36b1fcf2013-01-31 16:41:04 +0100126 return snapshot
127
Attila Fazekasf7f34f92013-08-01 17:01:44 +0200128 # NOTE(afazekas): these create_* and clean_* could be defined
Attila Fazekas36b1fcf2013-01-31 16:41:04 +0100129 # only in a single location in the source, and could be more general.
130
131 @classmethod
Attila Fazekas36b1fcf2013-01-31 16:41:04 +0100132 def clear_volumes(cls):
133 for volume in cls.volumes:
134 try:
Giulio Fidente26d16ed2013-04-30 12:05:56 +0200135 cls.volumes_client.delete_volume(volume['id'])
Attila Fazekas36b1fcf2013-01-31 16:41:04 +0100136 except Exception:
137 pass
138
139 for volume in cls.volumes:
140 try:
Giulio Fidente26d16ed2013-04-30 12:05:56 +0200141 cls.volumes_client.wait_for_resource_deletion(volume['id'])
Attila Fazekas36b1fcf2013-01-31 16:41:04 +0100142 except Exception:
143 pass
144
145 @classmethod
146 def clear_snapshots(cls):
147 for snapshot in cls.snapshots:
148 try:
149 cls.snapshots_client.delete_snapshot(snapshot['id'])
150 except Exception:
151 pass
152
153 for snapshot in cls.snapshots:
154 try:
155 cls.snapshots_client.wait_for_resource_deletion(snapshot['id'])
156 except Exception:
157 pass
158
Rohan Kanade9ce97df2013-12-10 18:59:35 +0530159 @classmethod
160 def create_server(cls, name, **kwargs):
Joseph Lanouxa074c012015-08-04 15:44:07 +0000161 tenant_network = cls.get_tenant_network()
162 body, _ = compute.create_test_server(
163 cls.os,
164 tenant_network=tenant_network,
165 name=name,
166 **kwargs)
167 return body
Rohan Kanade9ce97df2013-12-10 18:59:35 +0530168
James E. Blaire6d8ee12013-01-18 21:33:45 +0000169
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000170class BaseVolumeAdminTest(BaseVolumeTest):
Attila Fazekas3dcdae12013-02-14 12:50:04 +0100171 """Base test case class for all Volume Admin API tests."""
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000172
Andrea Frittolib21de6c2015-02-06 20:12:38 +0000173 credentials = ['primary', 'admin']
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000174
Rohan Kanade05749152015-01-30 17:15:18 +0530175 @classmethod
176 def setup_clients(cls):
177 super(BaseVolumeAdminTest, cls).setup_clients()
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000178
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000179 if cls._api_version == 1:
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000180 cls.volume_qos_client = cls.os_adm.volume_qos_client
jun xie9f123822014-11-20 14:21:23 +0800181 cls.admin_volume_services_client = \
182 cls.os_adm.volume_services_client
Chandan Kumar449e4c02014-09-12 07:26:19 -0400183 cls.volume_types_client = cls.os_adm.volume_types_client
Chandan Kumaree3f4bd2014-10-29 23:09:29 +0530184 cls.admin_volume_client = cls.os_adm.volumes_client
Chandan Kumar65eb8592014-11-12 18:32:32 +0530185 cls.hosts_client = cls.os_adm.volume_hosts_client
Chandan Kumar457d1632014-11-18 13:46:08 +0530186 cls.admin_snapshots_client = cls.os_adm.snapshots_client
jun xieebc3da32014-11-18 14:34:56 +0800187 cls.backups_adm_client = cls.os_adm.backups_client
Chandan Kumardd23f632014-11-17 15:27:48 +0530188 cls.quotas_client = cls.os_adm.volume_quotas_client
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000189 elif cls._api_version == 2:
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000190 cls.volume_qos_client = cls.os_adm.volume_qos_v2_client
jun xie9f123822014-11-20 14:21:23 +0800191 cls.admin_volume_services_client = \
192 cls.os_adm.volume_services_v2_client
Chandan Kumar449e4c02014-09-12 07:26:19 -0400193 cls.volume_types_client = cls.os_adm.volume_types_v2_client
Chandan Kumaree3f4bd2014-10-29 23:09:29 +0530194 cls.admin_volume_client = cls.os_adm.volumes_v2_client
Chandan Kumar65eb8592014-11-12 18:32:32 +0530195 cls.hosts_client = cls.os_adm.volume_hosts_v2_client
Chandan Kumar457d1632014-11-18 13:46:08 +0530196 cls.admin_snapshots_client = cls.os_adm.snapshots_v2_client
jun xieebc3da32014-11-18 14:34:56 +0800197 cls.backups_adm_client = cls.os_adm.backups_v2_client
Chandan Kumardd23f632014-11-17 15:27:48 +0530198 cls.quotas_client = cls.os_adm.volume_quotas_v2_client
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000199
200 @classmethod
Rohan Kanade05749152015-01-30 17:15:18 +0530201 def resource_setup(cls):
202 super(BaseVolumeAdminTest, cls).resource_setup()
203
204 cls.qos_specs = []
205
206 @classmethod
Andrea Frittoli61a12e22014-09-15 13:14:54 +0100207 def resource_cleanup(cls):
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000208 cls.clear_qos_specs()
Andrea Frittoli61a12e22014-09-15 13:14:54 +0100209 super(BaseVolumeAdminTest, cls).resource_cleanup()
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000210
211 @classmethod
212 def create_test_qos_specs(cls, name=None, consumer=None, **kwargs):
213 """create a test Qos-Specs."""
214 name = name or data_utils.rand_name(cls.__name__ + '-QoS')
215 consumer = consumer or 'front-end'
Jordan Pittier0359c4d2015-12-09 14:34:58 +0100216 qos_specs = cls.volume_qos_client.create_qos(
217 name=name, consumer=consumer, **kwargs)['qos_specs']
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000218 cls.qos_specs.append(qos_specs['id'])
219 return qos_specs
220
221 @classmethod
222 def clear_qos_specs(cls):
223 for qos_id in cls.qos_specs:
224 try:
225 cls.volume_qos_client.delete_qos(qos_id)
Masayuki Igawabfa07602015-01-20 18:47:17 +0900226 except lib_exc.NotFound:
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000227 # The qos_specs may have already been deleted which is OK.
228 pass
229
230 for qos_id in cls.qos_specs:
231 try:
232 cls.volume_qos_client.wait_for_resource_deletion(qos_id)
Masayuki Igawabfa07602015-01-20 18:47:17 +0900233 except lib_exc.NotFound:
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000234 # The qos_specs may have already been deleted which is OK.
235 pass