blob: 8170cbf93bf13bd9cb3e9e1894c5bca15c1288d5 [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
Matthew Treinish481466b2012-12-20 17:16:01 -050016from tempest import clients
Ken'ichi Ohmichi5687d552013-12-26 19:00:12 +090017from 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
Matthew Treinishf4a9b0f2013-07-26 16:58:26 -040020from tempest.openstack.common import log as logging
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 -070025LOG = logging.getLogger(__name__)
26
27
Attila Fazekasdc216422013-01-29 15:12:14 +010028class BaseVolumeTest(tempest.test.BaseTestCase):
Sean Daguef237ccb2013-01-04 15:19:14 -050029 """Base test case class for all Cinder API tests."""
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070030
Zhi Kun Liu6e6cf832014-05-08 17:25:22 +080031 _api_version = 2
32 _interface = 'json'
33
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070034 @classmethod
Andrea Frittoli61a12e22014-09-15 13:14:54 +010035 def resource_setup(cls):
Sylvain Afchain11b99d02014-01-16 00:42:33 +010036 cls.set_network_resources()
Andrea Frittoli61a12e22014-09-15 13:14:54 +010037 super(BaseVolumeTest, cls).resource_setup()
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070038
Matthew Treinish4d352bc2014-01-29 18:29:18 +000039 if not CONF.service_available.cinder:
Matthew Treinish4c412922013-07-16 15:27:42 -040040 skip_msg = ("%s skipped as Cinder is not available" % cls.__name__)
41 raise cls.skipException(skip_msg)
42
Zhi Kun Liubb363a22013-11-28 18:47:39 +080043 cls.os = cls.get_client_manager()
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070044
Zhi Kun Liubb363a22013-11-28 18:47:39 +080045 cls.servers_client = cls.os.servers_client
Matthew Treinish4d352bc2014-01-29 18:29:18 +000046 cls.image_ref = CONF.compute.image_ref
47 cls.flavor_ref = CONF.compute.flavor_ref
48 cls.build_interval = CONF.volume.build_interval
49 cls.build_timeout = CONF.volume.build_timeout
Attila Fazekas36b1fcf2013-01-31 16:41:04 +010050 cls.snapshots = []
51 cls.volumes = []
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070052
Zhi Kun Liu6e6cf832014-05-08 17:25:22 +080053 if cls._api_version == 1:
54 if not CONF.volume_feature_enabled.api_v1:
55 msg = "Volume API v1 is disabled"
56 raise cls.skipException(msg)
57 cls.snapshots_client = cls.os.snapshots_client
58 cls.volumes_client = cls.os.volumes_client
59 cls.backups_client = cls.os.backups_client
60 cls.volume_services_client = cls.os.volume_services_client
61 cls.volumes_extension_client = cls.os.volumes_extension_client
62 cls.availability_zone_client = (
63 cls.os.volume_availability_zone_client)
Zhi Kun Liu3d6d9862014-06-16 16:43:59 +080064 # Special fields and resp code for cinder v1
65 cls.special_fields = {'name_field': 'display_name',
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +000066 'descrip_field': 'display_description'}
Zhi Kun Liu6e6cf832014-05-08 17:25:22 +080067
68 elif cls._api_version == 2:
69 if not CONF.volume_feature_enabled.api_v2:
70 msg = "Volume API v2 is disabled"
71 raise cls.skipException(msg)
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)
Zhi Kun Liu3d6d9862014-06-16 16:43:59 +080077 # Special fields and resp code for cinder v2
78 cls.special_fields = {'name_field': 'name',
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +000079 'descrip_field': 'description'}
Zhi Kun Liu6e6cf832014-05-08 17:25:22 +080080
81 else:
82 msg = ("Invalid Cinder API version (%s)" % cls._api_version)
83 raise exceptions.InvalidConfiguration(message=msg)
84
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070085 @classmethod
Andrea Frittoli61a12e22014-09-15 13:14:54 +010086 def resource_cleanup(cls):
Attila Fazekas36b1fcf2013-01-31 16:41:04 +010087 cls.clear_snapshots()
88 cls.clear_volumes()
Ryan Hsu6c4bb3d2013-10-21 21:22:50 -070089 cls.clear_isolated_creds()
Andrea Frittoli61a12e22014-09-15 13:14:54 +010090 super(BaseVolumeTest, cls).resource_cleanup()
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070091
Attila Fazekas36b1fcf2013-01-31 16:41:04 +010092 @classmethod
Zhi Kun Liu6e6cf832014-05-08 17:25:22 +080093 def create_volume(cls, size=1, **kwargs):
94 """Wrapper utility that returns a test volume."""
Zhi Kun Liu3d6d9862014-06-16 16:43:59 +080095 name = data_utils.rand_name('Volume')
96
97 name_field = cls.special_fields['name_field']
Zhi Kun Liu3d6d9862014-06-16 16:43:59 +080098
99 kwargs[name_field] = name
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000100 _, volume = cls.volumes_client.create_volume(size, **kwargs)
Zhi Kun Liu3d6d9862014-06-16 16:43:59 +0800101
Zhi Kun Liu6e6cf832014-05-08 17:25:22 +0800102 cls.volumes.append(volume)
103 cls.volumes_client.wait_for_volume_status(volume['id'], 'available')
104 return volume
105
106 @classmethod
Attila Fazekas36b1fcf2013-01-31 16:41:04 +0100107 def create_snapshot(cls, volume_id=1, **kwargs):
108 """Wrapper utility that returns a test snapshot."""
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000109 _, snapshot = cls.snapshots_client.create_snapshot(volume_id,
110 **kwargs)
Giulio Fidente02f42982013-06-17 16:25:56 +0200111 cls.snapshots.append(snapshot)
Attila Fazekas36b1fcf2013-01-31 16:41:04 +0100112 cls.snapshots_client.wait_for_snapshot_status(snapshot['id'],
113 'available')
Attila Fazekas36b1fcf2013-01-31 16:41:04 +0100114 return snapshot
115
Attila Fazekasf7f34f92013-08-01 17:01:44 +0200116 # NOTE(afazekas): these create_* and clean_* could be defined
Attila Fazekas36b1fcf2013-01-31 16:41:04 +0100117 # only in a single location in the source, and could be more general.
118
119 @classmethod
Attila Fazekas36b1fcf2013-01-31 16:41:04 +0100120 def clear_volumes(cls):
121 for volume in cls.volumes:
122 try:
Giulio Fidente26d16ed2013-04-30 12:05:56 +0200123 cls.volumes_client.delete_volume(volume['id'])
Attila Fazekas36b1fcf2013-01-31 16:41:04 +0100124 except Exception:
125 pass
126
127 for volume in cls.volumes:
128 try:
Giulio Fidente26d16ed2013-04-30 12:05:56 +0200129 cls.volumes_client.wait_for_resource_deletion(volume['id'])
Attila Fazekas36b1fcf2013-01-31 16:41:04 +0100130 except Exception:
131 pass
132
133 @classmethod
134 def clear_snapshots(cls):
135 for snapshot in cls.snapshots:
136 try:
137 cls.snapshots_client.delete_snapshot(snapshot['id'])
138 except Exception:
139 pass
140
141 for snapshot in cls.snapshots:
142 try:
143 cls.snapshots_client.wait_for_resource_deletion(snapshot['id'])
144 except Exception:
145 pass
146
James E. Blaire6d8ee12013-01-18 21:33:45 +0000147
Zhi Kun Liubb363a22013-11-28 18:47:39 +0800148class BaseVolumeV1Test(BaseVolumeTest):
Zhi Kun Liu6e6cf832014-05-08 17:25:22 +0800149 _api_version = 1
Zhi Kun Liubb363a22013-11-28 18:47:39 +0800150
Zhi Kun Liu6e6cf832014-05-08 17:25:22 +0800151
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000152class BaseVolumeAdminTest(BaseVolumeTest):
Attila Fazekas3dcdae12013-02-14 12:50:04 +0100153 """Base test case class for all Volume Admin API tests."""
James E. Blaire6d8ee12013-01-18 21:33:45 +0000154 @classmethod
Andrea Frittoli61a12e22014-09-15 13:14:54 +0100155 def resource_setup(cls):
156 super(BaseVolumeAdminTest, cls).resource_setup()
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000157
Andrea Frittoli8283b4e2014-07-17 13:28:58 +0100158 try:
159 cls.adm_creds = cls.isolated_creds.get_admin_creds()
160 cls.os_adm = clients.Manager(
161 credentials=cls.adm_creds, interface=cls._interface)
162 except NotImplementedError:
163 msg = "Missing Volume Admin API credentials in configuration."
164 raise cls.skipException(msg)
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000165
166 cls.qos_specs = []
167
Nayna Patel4a5024c2013-11-18 07:08:23 +0000168 cls.hosts_client = cls.os_adm.volume_hosts_client
Sylvain Baubeaufdd34592014-02-20 18:40:10 +0100169 cls.quotas_client = cls.os_adm.volume_quotas_client
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000170
171 if cls._api_version == 1:
172 if not CONF.volume_feature_enabled.api_v1:
173 msg = "Volume API v1 is disabled"
174 raise cls.skipException(msg)
175 cls.volume_qos_client = cls.os_adm.volume_qos_client
Chandan Kumar449e4c02014-09-12 07:26:19 -0400176 cls.volume_types_client = cls.os_adm.volume_types_client
Chandan Kumaree3f4bd2014-10-29 23:09:29 +0530177 cls.admin_volume_client = cls.os_adm.volumes_client
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000178 elif cls._api_version == 2:
179 if not CONF.volume_feature_enabled.api_v2:
180 msg = "Volume API v2 is disabled"
181 raise cls.skipException(msg)
182 cls.volume_qos_client = cls.os_adm.volume_qos_v2_client
Chandan Kumar449e4c02014-09-12 07:26:19 -0400183 cls.volume_types_client = cls.os_adm.volume_types_v2_client
Chandan Kumaree3f4bd2014-10-29 23:09:29 +0530184 cls.admin_volume_client = cls.os_adm.volumes_v2_client
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000185
186 @classmethod
Andrea Frittoli61a12e22014-09-15 13:14:54 +0100187 def resource_cleanup(cls):
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000188 cls.clear_qos_specs()
Andrea Frittoli61a12e22014-09-15 13:14:54 +0100189 super(BaseVolumeAdminTest, cls).resource_cleanup()
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000190
191 @classmethod
192 def create_test_qos_specs(cls, name=None, consumer=None, **kwargs):
193 """create a test Qos-Specs."""
194 name = name or data_utils.rand_name(cls.__name__ + '-QoS')
195 consumer = consumer or 'front-end'
196 _, qos_specs = cls.volume_qos_client.create_qos(name, consumer,
197 **kwargs)
198 cls.qos_specs.append(qos_specs['id'])
199 return qos_specs
200
201 @classmethod
202 def clear_qos_specs(cls):
203 for qos_id in cls.qos_specs:
204 try:
205 cls.volume_qos_client.delete_qos(qos_id)
206 except exceptions.NotFound:
207 # The qos_specs may have already been deleted which is OK.
208 pass
209
210 for qos_id in cls.qos_specs:
211 try:
212 cls.volume_qos_client.wait_for_resource_deletion(qos_id)
213 except exceptions.NotFound:
214 # The qos_specs may have already been deleted which is OK.
215 pass
216
217
218class BaseVolumeV1AdminTest(BaseVolumeAdminTest):
219 _api_version = 1