blob: b67a6d23367858ae10f2f53a7a7fb692c5430908 [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
Masayuki Igawabfa07602015-01-20 18:47:17 +090017from tempest_lib import exceptions as lib_exc
18
Rohan Kanade9ce97df2013-12-10 18:59:35 +053019from tempest.common import fixed_network
Fei Long Wangd39431f2015-05-14 11:30:48 +120020from tempest.common.utils import data_utils
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
Daryl Walleck586b2cc2015-07-17 14:14:44 -050065 cls.images_client = cls.os.images_client
Rohan Kanade05749152015-01-30 17:15:18 +053066
67 if cls._api_version == 1:
Zhi Kun Liu6e6cf832014-05-08 17:25:22 +080068 cls.snapshots_client = cls.os.snapshots_client
69 cls.volumes_client = cls.os.volumes_client
70 cls.backups_client = cls.os.backups_client
71 cls.volume_services_client = cls.os.volume_services_client
72 cls.volumes_extension_client = cls.os.volumes_extension_client
73 cls.availability_zone_client = (
74 cls.os.volume_availability_zone_client)
Rohan Kanade05749152015-01-30 17:15:18 +053075 else:
Zhi Kun Liu38641c62014-07-10 20:12:48 +080076 cls.snapshots_client = cls.os.snapshots_v2_client
Zhi Kun Liu6e6cf832014-05-08 17:25:22 +080077 cls.volumes_client = cls.os.volumes_v2_client
Zhi Kun Liu53395522014-07-18 16:05:52 +080078 cls.volumes_extension_client = cls.os.volumes_v2_extension_client
79 cls.availability_zone_client = (
80 cls.os.volume_v2_availability_zone_client)
Rohan Kanade05749152015-01-30 17:15:18 +053081
82 @classmethod
83 def resource_setup(cls):
84 super(BaseVolumeTest, cls).resource_setup()
85
86 cls.snapshots = []
87 cls.volumes = []
88 cls.image_ref = CONF.compute.image_ref
89 cls.flavor_ref = CONF.compute.flavor_ref
90 cls.build_interval = CONF.volume.build_interval
91 cls.build_timeout = CONF.volume.build_timeout
92
93 if cls._api_version == 1:
94 # Special fields and resp code for cinder v1
95 cls.special_fields = {'name_field': 'display_name',
96 'descrip_field': 'display_description'}
97 else:
Zhi Kun Liu3d6d9862014-06-16 16:43:59 +080098 # Special fields and resp code for cinder v2
99 cls.special_fields = {'name_field': 'name',
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000100 'descrip_field': 'description'}
Zhi Kun Liu6e6cf832014-05-08 17:25:22 +0800101
Rohit Karajgidd47d7e2012-07-31 04:11:01 -0700102 @classmethod
Andrea Frittoli61a12e22014-09-15 13:14:54 +0100103 def resource_cleanup(cls):
Attila Fazekas36b1fcf2013-01-31 16:41:04 +0100104 cls.clear_snapshots()
105 cls.clear_volumes()
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
Rohan Kanade9ce97df2013-12-10 18:59:35 +0530163 @classmethod
164 def create_server(cls, name, **kwargs):
165 network = cls.get_tenant_network()
166 network_kwargs = fixed_network.set_networks_kwarg(network, kwargs)
167 return cls.servers_client.create_server(name,
168 cls.image_ref,
169 cls.flavor_ref,
170 **network_kwargs)
171
James E. Blaire6d8ee12013-01-18 21:33:45 +0000172
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000173class BaseVolumeAdminTest(BaseVolumeTest):
Attila Fazekas3dcdae12013-02-14 12:50:04 +0100174 """Base test case class for all Volume Admin API tests."""
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000175
Andrea Frittolib21de6c2015-02-06 20:12:38 +0000176 credentials = ['primary', 'admin']
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000177
Rohan Kanade05749152015-01-30 17:15:18 +0530178 @classmethod
179 def setup_clients(cls):
180 super(BaseVolumeAdminTest, cls).setup_clients()
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000181
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000182 if cls._api_version == 1:
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000183 cls.volume_qos_client = cls.os_adm.volume_qos_client
jun xie9f123822014-11-20 14:21:23 +0800184 cls.admin_volume_services_client = \
185 cls.os_adm.volume_services_client
Chandan Kumar449e4c02014-09-12 07:26:19 -0400186 cls.volume_types_client = cls.os_adm.volume_types_client
Chandan Kumaree3f4bd2014-10-29 23:09:29 +0530187 cls.admin_volume_client = cls.os_adm.volumes_client
Chandan Kumar65eb8592014-11-12 18:32:32 +0530188 cls.hosts_client = cls.os_adm.volume_hosts_client
Chandan Kumar457d1632014-11-18 13:46:08 +0530189 cls.admin_snapshots_client = cls.os_adm.snapshots_client
jun xieebc3da32014-11-18 14:34:56 +0800190 cls.backups_adm_client = cls.os_adm.backups_client
Chandan Kumardd23f632014-11-17 15:27:48 +0530191 cls.quotas_client = cls.os_adm.volume_quotas_client
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000192 elif cls._api_version == 2:
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000193 cls.volume_qos_client = cls.os_adm.volume_qos_v2_client
jun xie9f123822014-11-20 14:21:23 +0800194 cls.admin_volume_services_client = \
195 cls.os_adm.volume_services_v2_client
Chandan Kumar449e4c02014-09-12 07:26:19 -0400196 cls.volume_types_client = cls.os_adm.volume_types_v2_client
Chandan Kumaree3f4bd2014-10-29 23:09:29 +0530197 cls.admin_volume_client = cls.os_adm.volumes_v2_client
Chandan Kumar65eb8592014-11-12 18:32:32 +0530198 cls.hosts_client = cls.os_adm.volume_hosts_v2_client
Chandan Kumar457d1632014-11-18 13:46:08 +0530199 cls.admin_snapshots_client = cls.os_adm.snapshots_v2_client
jun xieebc3da32014-11-18 14:34:56 +0800200 cls.backups_adm_client = cls.os_adm.backups_v2_client
Chandan Kumardd23f632014-11-17 15:27:48 +0530201 cls.quotas_client = cls.os_adm.volume_quotas_v2_client
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000202
203 @classmethod
Rohan Kanade05749152015-01-30 17:15:18 +0530204 def resource_setup(cls):
205 super(BaseVolumeAdminTest, cls).resource_setup()
206
207 cls.qos_specs = []
208
209 @classmethod
Andrea Frittoli61a12e22014-09-15 13:14:54 +0100210 def resource_cleanup(cls):
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000211 cls.clear_qos_specs()
Andrea Frittoli61a12e22014-09-15 13:14:54 +0100212 super(BaseVolumeAdminTest, cls).resource_cleanup()
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000213
214 @classmethod
215 def create_test_qos_specs(cls, name=None, consumer=None, **kwargs):
216 """create a test Qos-Specs."""
217 name = name or data_utils.rand_name(cls.__name__ + '-QoS')
218 consumer = consumer or 'front-end'
Joseph Lanoux6809bab2014-12-18 14:57:18 +0000219 qos_specs = cls.volume_qos_client.create_qos(name, consumer,
220 **kwargs)
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000221 cls.qos_specs.append(qos_specs['id'])
222 return qos_specs
223
224 @classmethod
225 def clear_qos_specs(cls):
226 for qos_id in cls.qos_specs:
227 try:
228 cls.volume_qos_client.delete_qos(qos_id)
Masayuki Igawabfa07602015-01-20 18:47:17 +0900229 except lib_exc.NotFound:
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000230 # The qos_specs may have already been deleted which is OK.
231 pass
232
233 for qos_id in cls.qos_specs:
234 try:
235 cls.volume_qos_client.wait_for_resource_deletion(qos_id)
Masayuki Igawabfa07602015-01-20 18:47:17 +0900236 except lib_exc.NotFound:
Swapnil Kulkarni7dba3e62014-08-14 09:05:07 +0000237 # The qos_specs may have already been deleted which is OK.
238 pass