blob: e5cff23e0ee0cd9aec988baa2fd4d40bb671bc6d [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 Treinish01472ff2015-02-20 17:26:52 -050016from tempest_lib.common.utils import data_utils
Masayuki Igawabfa07602015-01-20 18:47:17 +090017from tempest_lib import exceptions as lib_exc
18
Matthew Treinish481466b2012-12-20 17:16:01 -050019from tempest import clients
Matthew Treinish4d352bc2014-01-29 18:29:18 +000020from tempest import config
Zhi Kun Liu6e6cf832014-05-08 17:25:22 +080021from tempest import exceptions
Matthew Treinishf4a9b0f2013-07-26 16:58:26 -040022from tempest.openstack.common import log as logging
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
Zhi Kun Liu6e6cf832014-05-08 17:25:22 +080034
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070035 @classmethod
Rohan Kanade05749152015-01-30 17:15:18 +053036 def skip_checks(cls):
37 super(BaseVolumeTest, cls).skip_checks()
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)
Zhi Kun Liu6e6cf832014-05-08 17:25:22 +080042 if cls._api_version == 1:
43 if not CONF.volume_feature_enabled.api_v1:
44 msg = "Volume API v1 is disabled"
45 raise cls.skipException(msg)
Rohan Kanade05749152015-01-30 17:15:18 +053046 elif cls._api_version == 2:
47 if not CONF.volume_feature_enabled.api_v2:
48 msg = "Volume API v2 is disabled"
49 raise cls.skipException(msg)
50 else:
51 msg = ("Invalid Cinder API version (%s)" % cls._api_version)
52 raise exceptions.InvalidConfiguration(message=msg)
53
54 @classmethod
55 def setup_credentials(cls):
56 cls.set_network_resources()
57 super(BaseVolumeTest, cls).setup_credentials()
58 cls.os = cls.get_client_manager()
59
60 @classmethod
61 def setup_clients(cls):
62 super(BaseVolumeTest, cls).setup_clients()
63
64 cls.servers_client = cls.os.servers_client
65
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()
Ryan Hsu6c4bb3d2013-10-21 21:22:50 -0700105 cls.clear_isolated_creds()
Andrea Frittoli61a12e22014-09-15 13:14:54 +0100106 super(BaseVolumeTest, cls).resource_cleanup()
Rohit Karajgidd47d7e2012-07-31 04:11:01 -0700107
Attila Fazekas36b1fcf2013-01-31 16:41:04 +0100108 @classmethod
Markus Zoeller3d2a21c2015-02-27 12:04:22 +0100109 def create_volume(cls, size=None, **kwargs):
Zhi Kun Liu6e6cf832014-05-08 17:25:22 +0800110 """Wrapper utility that returns a test volume."""
Zhi Kun Liu3d6d9862014-06-16 16:43:59 +0800111 name = data_utils.rand_name('Volume')
112
113 name_field = cls.special_fields['name_field']
Zhi Kun Liu3d6d9862014-06-16 16:43:59 +0800114
115 kwargs[name_field] = name
Joseph Lanoux6809bab2014-12-18 14:57:18 +0000116 volume = cls.volumes_client.create_volume(size, **kwargs)
Zhi Kun Liu3d6d9862014-06-16 16:43:59 +0800117
Zhi Kun Liu6e6cf832014-05-08 17:25:22 +0800118 cls.volumes.append(volume)
119 cls.volumes_client.wait_for_volume_status(volume['id'], 'available')
120 return volume
121
122 @classmethod
Attila Fazekas36b1fcf2013-01-31 16:41:04 +0100123 def create_snapshot(cls, volume_id=1, **kwargs):
124 """Wrapper utility that returns a test snapshot."""
Joseph Lanoux6809bab2014-12-18 14:57:18 +0000125 snapshot = cls.snapshots_client.create_snapshot(volume_id,
126 **kwargs)
Giulio Fidente02f42982013-06-17 16:25:56 +0200127 cls.snapshots.append(snapshot)
Attila Fazekas36b1fcf2013-01-31 16:41:04 +0100128 cls.snapshots_client.wait_for_snapshot_status(snapshot['id'],
129 'available')
Attila Fazekas36b1fcf2013-01-31 16:41:04 +0100130 return snapshot
131
Attila Fazekasf7f34f92013-08-01 17:01:44 +0200132 # NOTE(afazekas): these create_* and clean_* could be defined
Attila Fazekas36b1fcf2013-01-31 16:41:04 +0100133 # only in a single location in the source, and could be more general.
134
135 @classmethod
Attila Fazekas36b1fcf2013-01-31 16:41:04 +0100136 def clear_volumes(cls):
137 for volume in cls.volumes:
138 try:
Giulio Fidente26d16ed2013-04-30 12:05:56 +0200139 cls.volumes_client.delete_volume(volume['id'])
Attila Fazekas36b1fcf2013-01-31 16:41:04 +0100140 except Exception:
141 pass
142
143 for volume in cls.volumes:
144 try:
Giulio Fidente26d16ed2013-04-30 12:05:56 +0200145 cls.volumes_client.wait_for_resource_deletion(volume['id'])
Attila Fazekas36b1fcf2013-01-31 16:41:04 +0100146 except Exception:
147 pass
148
149 @classmethod
150 def clear_snapshots(cls):
151 for snapshot in cls.snapshots:
152 try:
153 cls.snapshots_client.delete_snapshot(snapshot['id'])
154 except Exception:
155 pass
156
157 for snapshot in cls.snapshots:
158 try:
159 cls.snapshots_client.wait_for_resource_deletion(snapshot['id'])
160 except Exception:
161 pass
162
James E. Blaire6d8ee12013-01-18 21:33:45 +0000163
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000164class BaseVolumeAdminTest(BaseVolumeTest):
Attila Fazekas3dcdae12013-02-14 12:50:04 +0100165 """Base test case class for all Volume Admin API tests."""
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000166
Rohan Kanade05749152015-01-30 17:15:18 +0530167 @classmethod
168 def setup_credentials(cls):
169 super(BaseVolumeAdminTest, cls).setup_credentials()
Andrea Frittoli8283b4e2014-07-17 13:28:58 +0100170 try:
171 cls.adm_creds = cls.isolated_creds.get_admin_creds()
Andrea Frittolic0978352015-02-06 15:57:40 +0000172 cls.os_adm = clients.Manager(credentials=cls.adm_creds)
Andrea Frittoli8283b4e2014-07-17 13:28:58 +0100173 except NotImplementedError:
174 msg = "Missing Volume Admin API credentials in configuration."
175 raise cls.skipException(msg)
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