blob: 7f56b18701dc4ee3dab6f98a338d371ec3abb011 [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
Doug Hellmann583ce2c2015-03-11 14:55:46 +000016from oslo_log import log as logging
Matthew Treinish01472ff2015-02-20 17:26:52 -050017from tempest_lib.common.utils import data_utils
Masayuki Igawabfa07602015-01-20 18:47:17 +090018from tempest_lib import exceptions as lib_exc
19
Rohan Kanade9ce97df2013-12-10 18:59:35 +053020from tempest.common import fixed_network
Matthew Treinish4d352bc2014-01-29 18:29:18 +000021from tempest import config
Zhi Kun Liu6e6cf832014-05-08 17:25:22 +080022from tempest import exceptions
Attila Fazekasdc216422013-01-29 15:12:14 +010023import tempest.test
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070024
Matthew Treinish4d352bc2014-01-29 18:29:18 +000025CONF = config.CONF
26
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070027LOG = logging.getLogger(__name__)
28
29
Attila Fazekasdc216422013-01-29 15:12:14 +010030class BaseVolumeTest(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
Andrea Frittolib21de6c2015-02-06 20:12:38 +000034 credentials = ['primary']
Zhi Kun Liu6e6cf832014-05-08 17:25:22 +080035
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070036 @classmethod
Rohan Kanade05749152015-01-30 17:15:18 +053037 def skip_checks(cls):
38 super(BaseVolumeTest, cls).skip_checks()
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070039
Matthew Treinish4d352bc2014-01-29 18:29:18 +000040 if not CONF.service_available.cinder:
Matthew Treinish4c412922013-07-16 15:27:42 -040041 skip_msg = ("%s skipped as Cinder is not available" % cls.__name__)
42 raise cls.skipException(skip_msg)
Zhi Kun Liu6e6cf832014-05-08 17:25:22 +080043 if cls._api_version == 1:
44 if not CONF.volume_feature_enabled.api_v1:
45 msg = "Volume API v1 is disabled"
46 raise cls.skipException(msg)
Rohan Kanade05749152015-01-30 17:15:18 +053047 elif cls._api_version == 2:
48 if not CONF.volume_feature_enabled.api_v2:
49 msg = "Volume API v2 is disabled"
50 raise cls.skipException(msg)
51 else:
52 msg = ("Invalid Cinder API version (%s)" % cls._api_version)
53 raise exceptions.InvalidConfiguration(message=msg)
54
55 @classmethod
56 def setup_credentials(cls):
57 cls.set_network_resources()
58 super(BaseVolumeTest, cls).setup_credentials()
Rohan Kanade05749152015-01-30 17:15:18 +053059
60 @classmethod
61 def setup_clients(cls):
62 super(BaseVolumeTest, cls).setup_clients()
Rohan Kanade05749152015-01-30 17:15:18 +053063 cls.servers_client = cls.os.servers_client
Rohan Kanade9ce97df2013-12-10 18:59:35 +053064 cls.networks_client = cls.os.networks_client
Rohan Kanade05749152015-01-30 17:15:18 +053065
66 if cls._api_version == 1:
Zhi Kun Liu6e6cf832014-05-08 17:25:22 +080067 cls.snapshots_client = cls.os.snapshots_client
68 cls.volumes_client = cls.os.volumes_client
69 cls.backups_client = cls.os.backups_client
70 cls.volume_services_client = cls.os.volume_services_client
71 cls.volumes_extension_client = cls.os.volumes_extension_client
72 cls.availability_zone_client = (
73 cls.os.volume_availability_zone_client)
Rohan Kanade05749152015-01-30 17:15:18 +053074 else:
Zhi Kun Liu38641c62014-07-10 20:12:48 +080075 cls.snapshots_client = cls.os.snapshots_v2_client
Zhi Kun Liu6e6cf832014-05-08 17:25:22 +080076 cls.volumes_client = cls.os.volumes_v2_client
Zhi Kun Liu53395522014-07-18 16:05:52 +080077 cls.volumes_extension_client = cls.os.volumes_v2_extension_client
78 cls.availability_zone_client = (
79 cls.os.volume_v2_availability_zone_client)
Rohan Kanade05749152015-01-30 17:15:18 +053080
81 @classmethod
82 def resource_setup(cls):
83 super(BaseVolumeTest, cls).resource_setup()
84
85 cls.snapshots = []
86 cls.volumes = []
87 cls.image_ref = CONF.compute.image_ref
88 cls.flavor_ref = CONF.compute.flavor_ref
89 cls.build_interval = CONF.volume.build_interval
90 cls.build_timeout = CONF.volume.build_timeout
91
92 if cls._api_version == 1:
93 # Special fields and resp code for cinder v1
94 cls.special_fields = {'name_field': 'display_name',
95 'descrip_field': 'display_description'}
96 else:
Zhi Kun Liu3d6d9862014-06-16 16:43:59 +080097 # Special fields and resp code for cinder v2
98 cls.special_fields = {'name_field': 'name',
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +000099 'descrip_field': 'description'}
Zhi Kun Liu6e6cf832014-05-08 17:25:22 +0800100
Rohit Karajgidd47d7e2012-07-31 04:11:01 -0700101 @classmethod
Andrea Frittoli61a12e22014-09-15 13:14:54 +0100102 def resource_cleanup(cls):
Attila Fazekas36b1fcf2013-01-31 16:41:04 +0100103 cls.clear_snapshots()
104 cls.clear_volumes()
Andrea Frittoli61a12e22014-09-15 13:14:54 +0100105 super(BaseVolumeTest, cls).resource_cleanup()
Rohit Karajgidd47d7e2012-07-31 04:11:01 -0700106
Attila Fazekas36b1fcf2013-01-31 16:41:04 +0100107 @classmethod
Markus Zoeller3d2a21c2015-02-27 12:04:22 +0100108 def create_volume(cls, size=None, **kwargs):
Zhi Kun Liu6e6cf832014-05-08 17:25:22 +0800109 """Wrapper utility that returns a test volume."""
Zhi Kun Liu3d6d9862014-06-16 16:43:59 +0800110 name = data_utils.rand_name('Volume')
111
112 name_field = cls.special_fields['name_field']
Zhi Kun Liu3d6d9862014-06-16 16:43:59 +0800113
114 kwargs[name_field] = name
Joseph Lanoux6809bab2014-12-18 14:57:18 +0000115 volume = cls.volumes_client.create_volume(size, **kwargs)
Zhi Kun Liu3d6d9862014-06-16 16:43:59 +0800116
Zhi Kun Liu6e6cf832014-05-08 17:25:22 +0800117 cls.volumes.append(volume)
118 cls.volumes_client.wait_for_volume_status(volume['id'], 'available')
119 return volume
120
121 @classmethod
Attila Fazekas36b1fcf2013-01-31 16:41:04 +0100122 def create_snapshot(cls, volume_id=1, **kwargs):
123 """Wrapper utility that returns a test snapshot."""
Joseph Lanoux6809bab2014-12-18 14:57:18 +0000124 snapshot = cls.snapshots_client.create_snapshot(volume_id,
125 **kwargs)
Giulio Fidente02f42982013-06-17 16:25:56 +0200126 cls.snapshots.append(snapshot)
Attila Fazekas36b1fcf2013-01-31 16:41:04 +0100127 cls.snapshots_client.wait_for_snapshot_status(snapshot['id'],
128 'available')
Attila Fazekas36b1fcf2013-01-31 16:41:04 +0100129 return snapshot
130
Attila Fazekasf7f34f92013-08-01 17:01:44 +0200131 # NOTE(afazekas): these create_* and clean_* could be defined
Attila Fazekas36b1fcf2013-01-31 16:41:04 +0100132 # only in a single location in the source, and could be more general.
133
134 @classmethod
Attila Fazekas36b1fcf2013-01-31 16:41:04 +0100135 def clear_volumes(cls):
136 for volume in cls.volumes:
137 try:
Giulio Fidente26d16ed2013-04-30 12:05:56 +0200138 cls.volumes_client.delete_volume(volume['id'])
Attila Fazekas36b1fcf2013-01-31 16:41:04 +0100139 except Exception:
140 pass
141
142 for volume in cls.volumes:
143 try:
Giulio Fidente26d16ed2013-04-30 12:05:56 +0200144 cls.volumes_client.wait_for_resource_deletion(volume['id'])
Attila Fazekas36b1fcf2013-01-31 16:41:04 +0100145 except Exception:
146 pass
147
148 @classmethod
149 def clear_snapshots(cls):
150 for snapshot in cls.snapshots:
151 try:
152 cls.snapshots_client.delete_snapshot(snapshot['id'])
153 except Exception:
154 pass
155
156 for snapshot in cls.snapshots:
157 try:
158 cls.snapshots_client.wait_for_resource_deletion(snapshot['id'])
159 except Exception:
160 pass
161
Rohan Kanade9ce97df2013-12-10 18:59:35 +0530162 @classmethod
163 def create_server(cls, name, **kwargs):
164 network = cls.get_tenant_network()
165 network_kwargs = fixed_network.set_networks_kwarg(network, kwargs)
166 return cls.servers_client.create_server(name,
167 cls.image_ref,
168 cls.flavor_ref,
169 **network_kwargs)
170
James E. Blaire6d8ee12013-01-18 21:33:45 +0000171
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000172class BaseVolumeAdminTest(BaseVolumeTest):
Attila Fazekas3dcdae12013-02-14 12:50:04 +0100173 """Base test case class for all Volume Admin API tests."""
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000174
Andrea Frittolib21de6c2015-02-06 20:12:38 +0000175 credentials = ['primary', 'admin']
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000176
Rohan Kanade05749152015-01-30 17:15:18 +0530177 @classmethod
178 def setup_clients(cls):
179 super(BaseVolumeAdminTest, cls).setup_clients()
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000180
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000181 if cls._api_version == 1:
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000182 cls.volume_qos_client = cls.os_adm.volume_qos_client
jun xie9f123822014-11-20 14:21:23 +0800183 cls.admin_volume_services_client = \
184 cls.os_adm.volume_services_client
Chandan Kumar449e4c02014-09-12 07:26:19 -0400185 cls.volume_types_client = cls.os_adm.volume_types_client
Chandan Kumaree3f4bd2014-10-29 23:09:29 +0530186 cls.admin_volume_client = cls.os_adm.volumes_client
Chandan Kumar65eb8592014-11-12 18:32:32 +0530187 cls.hosts_client = cls.os_adm.volume_hosts_client
Chandan Kumar457d1632014-11-18 13:46:08 +0530188 cls.admin_snapshots_client = cls.os_adm.snapshots_client
jun xieebc3da32014-11-18 14:34:56 +0800189 cls.backups_adm_client = cls.os_adm.backups_client
Chandan Kumardd23f632014-11-17 15:27:48 +0530190 cls.quotas_client = cls.os_adm.volume_quotas_client
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000191 elif cls._api_version == 2:
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000192 cls.volume_qos_client = cls.os_adm.volume_qos_v2_client
jun xie9f123822014-11-20 14:21:23 +0800193 cls.admin_volume_services_client = \
194 cls.os_adm.volume_services_v2_client
Chandan Kumar449e4c02014-09-12 07:26:19 -0400195 cls.volume_types_client = cls.os_adm.volume_types_v2_client
Chandan Kumaree3f4bd2014-10-29 23:09:29 +0530196 cls.admin_volume_client = cls.os_adm.volumes_v2_client
Chandan Kumar65eb8592014-11-12 18:32:32 +0530197 cls.hosts_client = cls.os_adm.volume_hosts_v2_client
Chandan Kumar457d1632014-11-18 13:46:08 +0530198 cls.admin_snapshots_client = cls.os_adm.snapshots_v2_client
jun xieebc3da32014-11-18 14:34:56 +0800199 cls.backups_adm_client = cls.os_adm.backups_v2_client
Chandan Kumardd23f632014-11-17 15:27:48 +0530200 cls.quotas_client = cls.os_adm.volume_quotas_v2_client
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000201
202 @classmethod
Rohan Kanade05749152015-01-30 17:15:18 +0530203 def resource_setup(cls):
204 super(BaseVolumeAdminTest, cls).resource_setup()
205
206 cls.qos_specs = []
207
208 @classmethod
Andrea Frittoli61a12e22014-09-15 13:14:54 +0100209 def resource_cleanup(cls):
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000210 cls.clear_qos_specs()
Andrea Frittoli61a12e22014-09-15 13:14:54 +0100211 super(BaseVolumeAdminTest, cls).resource_cleanup()
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000212
213 @classmethod
214 def create_test_qos_specs(cls, name=None, consumer=None, **kwargs):
215 """create a test Qos-Specs."""
216 name = name or data_utils.rand_name(cls.__name__ + '-QoS')
217 consumer = consumer or 'front-end'
Joseph Lanoux6809bab2014-12-18 14:57:18 +0000218 qos_specs = cls.volume_qos_client.create_qos(name, consumer,
219 **kwargs)
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000220 cls.qos_specs.append(qos_specs['id'])
221 return qos_specs
222
223 @classmethod
224 def clear_qos_specs(cls):
225 for qos_id in cls.qos_specs:
226 try:
227 cls.volume_qos_client.delete_qos(qos_id)
Masayuki Igawabfa07602015-01-20 18:47:17 +0900228 except lib_exc.NotFound:
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000229 # The qos_specs may have already been deleted which is OK.
230 pass
231
232 for qos_id in cls.qos_specs:
233 try:
234 cls.volume_qos_client.wait_for_resource_deletion(qos_id)
Masayuki Igawabfa07602015-01-20 18:47:17 +0900235 except lib_exc.NotFound:
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000236 # The qos_specs may have already been deleted which is OK.
237 pass