blob: c5be1f3aa3f0b82774e95f2d184a71d2b16496a7 [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
35 def setUpClass(cls):
Sylvain Afchain11b99d02014-01-16 00:42:33 +010036 cls.set_network_resources()
Attila Fazekasf86fa312013-07-30 19:56:39 +020037 super(BaseVolumeTest, cls).setUpClass()
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)
64
65 elif cls._api_version == 2:
66 if not CONF.volume_feature_enabled.api_v2:
67 msg = "Volume API v2 is disabled"
68 raise cls.skipException(msg)
69 cls.volumes_client = cls.os.volumes_v2_client
70
71 else:
72 msg = ("Invalid Cinder API version (%s)" % cls._api_version)
73 raise exceptions.InvalidConfiguration(message=msg)
74
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070075 @classmethod
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070076 def tearDownClass(cls):
Attila Fazekas36b1fcf2013-01-31 16:41:04 +010077 cls.clear_snapshots()
78 cls.clear_volumes()
Ryan Hsu6c4bb3d2013-10-21 21:22:50 -070079 cls.clear_isolated_creds()
Matthew Treinishb86cda92013-07-29 11:22:23 -040080 super(BaseVolumeTest, cls).tearDownClass()
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070081
Attila Fazekas36b1fcf2013-01-31 16:41:04 +010082 @classmethod
Zhi Kun Liu6e6cf832014-05-08 17:25:22 +080083 def create_volume(cls, size=1, **kwargs):
84 """Wrapper utility that returns a test volume."""
85 vol_name = data_utils.rand_name('Volume')
86 if cls._api_version == 1:
87 resp, volume = cls.volumes_client.create_volume(
88 size, display_name=vol_name, **kwargs)
89 assert 200 == resp.status
90 elif cls._api_version == 2:
91 resp, volume = cls.volumes_client.create_volume(
92 size, name=vol_name, **kwargs)
93 assert 202 == resp.status
94 cls.volumes.append(volume)
95 cls.volumes_client.wait_for_volume_status(volume['id'], 'available')
96 return volume
97
98 @classmethod
Attila Fazekas36b1fcf2013-01-31 16:41:04 +010099 def create_snapshot(cls, volume_id=1, **kwargs):
100 """Wrapper utility that returns a test snapshot."""
101 resp, snapshot = cls.snapshots_client.create_snapshot(volume_id,
102 **kwargs)
103 assert 200 == resp.status
Giulio Fidente02f42982013-06-17 16:25:56 +0200104 cls.snapshots.append(snapshot)
Attila Fazekas36b1fcf2013-01-31 16:41:04 +0100105 cls.snapshots_client.wait_for_snapshot_status(snapshot['id'],
106 'available')
Attila Fazekas36b1fcf2013-01-31 16:41:04 +0100107 return snapshot
108
Attila Fazekasf7f34f92013-08-01 17:01:44 +0200109 # NOTE(afazekas): these create_* and clean_* could be defined
Attila Fazekas36b1fcf2013-01-31 16:41:04 +0100110 # only in a single location in the source, and could be more general.
111
112 @classmethod
Attila Fazekas36b1fcf2013-01-31 16:41:04 +0100113 def clear_volumes(cls):
114 for volume in cls.volumes:
115 try:
Giulio Fidente26d16ed2013-04-30 12:05:56 +0200116 cls.volumes_client.delete_volume(volume['id'])
Attila Fazekas36b1fcf2013-01-31 16:41:04 +0100117 except Exception:
118 pass
119
120 for volume in cls.volumes:
121 try:
Giulio Fidente26d16ed2013-04-30 12:05:56 +0200122 cls.volumes_client.wait_for_resource_deletion(volume['id'])
Attila Fazekas36b1fcf2013-01-31 16:41:04 +0100123 except Exception:
124 pass
125
126 @classmethod
127 def clear_snapshots(cls):
128 for snapshot in cls.snapshots:
129 try:
130 cls.snapshots_client.delete_snapshot(snapshot['id'])
131 except Exception:
132 pass
133
134 for snapshot in cls.snapshots:
135 try:
136 cls.snapshots_client.wait_for_resource_deletion(snapshot['id'])
137 except Exception:
138 pass
139
James E. Blaire6d8ee12013-01-18 21:33:45 +0000140
Zhi Kun Liubb363a22013-11-28 18:47:39 +0800141class BaseVolumeV1Test(BaseVolumeTest):
Zhi Kun Liu6e6cf832014-05-08 17:25:22 +0800142 _api_version = 1
Zhi Kun Liubb363a22013-11-28 18:47:39 +0800143
Zhi Kun Liu6e6cf832014-05-08 17:25:22 +0800144
Zhi Kun Liubb363a22013-11-28 18:47:39 +0800145class BaseVolumeV1AdminTest(BaseVolumeV1Test):
Attila Fazekas3dcdae12013-02-14 12:50:04 +0100146 """Base test case class for all Volume Admin API tests."""
James E. Blaire6d8ee12013-01-18 21:33:45 +0000147 @classmethod
148 def setUpClass(cls):
Zhi Kun Liubb363a22013-11-28 18:47:39 +0800149 super(BaseVolumeV1AdminTest, cls).setUpClass()
Matthew Treinish4d352bc2014-01-29 18:29:18 +0000150 cls.adm_user = CONF.identity.admin_username
151 cls.adm_pass = CONF.identity.admin_password
152 cls.adm_tenant = CONF.identity.admin_tenant_name
Attila Fazekas3dcdae12013-02-14 12:50:04 +0100153 if not all((cls.adm_user, cls.adm_pass, cls.adm_tenant)):
154 msg = ("Missing Volume Admin API credentials "
155 "in configuration.")
156 raise cls.skipException(msg)
Matthew Treinish4d352bc2014-01-29 18:29:18 +0000157 if CONF.compute.allow_tenant_isolation:
Andrea Frittoli422fbdf2014-03-20 10:05:18 +0000158 cls.os_adm = clients.Manager(cls.isolated_creds.get_admin_creds(),
Matthew Treinish3e046852013-07-23 16:00:24 -0400159 interface=cls._interface)
160 else:
161 cls.os_adm = clients.AdminManager(interface=cls._interface)
Attila Fazekas3dcdae12013-02-14 12:50:04 +0100162 cls.client = cls.os_adm.volume_types_client
Nayna Patel4a5024c2013-11-18 07:08:23 +0000163 cls.hosts_client = cls.os_adm.volume_hosts_client
Sylvain Baubeaufdd34592014-02-20 18:40:10 +0100164 cls.quotas_client = cls.os_adm.volume_quotas_client