blob: 9c841ccb89ca7dd4f076a43a9d59e975119767db [file] [log] [blame]
Rohit Karajgidd47d7e2012-07-31 04:11:01 -07001# vim: tabstop=4 shiftwidth=4 softtabstop=4
2
ZhiQiang Fan39f97222013-09-20 04:49:44 +08003# Copyright 2012 OpenStack Foundation
Rohit Karajgidd47d7e2012-07-31 04:11:01 -07004# All Rights Reserved.
5#
6# Licensed under the Apache License, Version 2.0 (the "License"); you may
7# not use this file except in compliance with the License. You may obtain
8# a copy of the License at
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15# License for the specific language governing permissions and limitations
16# under the License.
17
Matthew Treinish481466b2012-12-20 17:16:01 -050018from tempest import clients
Ken'ichi Ohmichi5687d552013-12-26 19:00:12 +090019from tempest.common.utils import data_utils
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
23LOG = logging.getLogger(__name__)
24
25
Attila Fazekasdc216422013-01-29 15:12:14 +010026class BaseVolumeTest(tempest.test.BaseTestCase):
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070027
Sean Daguef237ccb2013-01-04 15:19:14 -050028 """Base test case class for all Cinder API tests."""
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070029
30 @classmethod
31 def setUpClass(cls):
Attila Fazekasf86fa312013-07-30 19:56:39 +020032 super(BaseVolumeTest, cls).setUpClass()
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070033
Matthew Treinish4c412922013-07-16 15:27:42 -040034 if not cls.config.service_available.cinder:
35 skip_msg = ("%s skipped as Cinder is not available" % cls.__name__)
36 raise cls.skipException(skip_msg)
37
Zhi Kun Liubb363a22013-11-28 18:47:39 +080038 cls.os = cls.get_client_manager()
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070039
Zhi Kun Liubb363a22013-11-28 18:47:39 +080040 cls.volumes_client = cls.os.volumes_client
41 cls.snapshots_client = cls.os.snapshots_client
42 cls.servers_client = cls.os.servers_client
43 cls.volumes_extension_client = cls.os.volumes_extension_client
Rohit Karajgia42fe442012-09-21 03:08:33 -070044 cls.image_ref = cls.config.compute.image_ref
45 cls.flavor_ref = cls.config.compute.flavor_ref
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070046 cls.build_interval = cls.config.volume.build_interval
47 cls.build_timeout = cls.config.volume.build_timeout
Attila Fazekas36b1fcf2013-01-31 16:41:04 +010048 cls.snapshots = []
49 cls.volumes = []
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070050
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070051 @classmethod
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070052 def tearDownClass(cls):
Attila Fazekas36b1fcf2013-01-31 16:41:04 +010053 cls.clear_snapshots()
54 cls.clear_volumes()
Ryan Hsu6c4bb3d2013-10-21 21:22:50 -070055 cls.clear_isolated_creds()
Matthew Treinishb86cda92013-07-29 11:22:23 -040056 super(BaseVolumeTest, cls).tearDownClass()
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070057
Attila Fazekas36b1fcf2013-01-31 16:41:04 +010058 @classmethod
59 def create_snapshot(cls, volume_id=1, **kwargs):
60 """Wrapper utility that returns a test snapshot."""
61 resp, snapshot = cls.snapshots_client.create_snapshot(volume_id,
62 **kwargs)
63 assert 200 == resp.status
Giulio Fidente02f42982013-06-17 16:25:56 +020064 cls.snapshots.append(snapshot)
Attila Fazekas36b1fcf2013-01-31 16:41:04 +010065 cls.snapshots_client.wait_for_snapshot_status(snapshot['id'],
66 'available')
Attila Fazekas36b1fcf2013-01-31 16:41:04 +010067 return snapshot
68
Attila Fazekasf7f34f92013-08-01 17:01:44 +020069 # NOTE(afazekas): these create_* and clean_* could be defined
Attila Fazekas36b1fcf2013-01-31 16:41:04 +010070 # only in a single location in the source, and could be more general.
71
72 @classmethod
73 def create_volume(cls, size=1, **kwargs):
Sean Daguef237ccb2013-01-04 15:19:14 -050074 """Wrapper utility that returns a test volume."""
Ken'ichi Ohmichi5687d552013-12-26 19:00:12 +090075 vol_name = data_utils.rand_name('Volume')
76 resp, volume = cls.volumes_client.create_volume(size,
77 display_name=vol_name,
78 **kwargs)
Attila Fazekas36b1fcf2013-01-31 16:41:04 +010079 assert 200 == resp.status
Attila Fazekas36b1fcf2013-01-31 16:41:04 +010080 cls.volumes.append(volume)
Giulio Fidente02f42982013-06-17 16:25:56 +020081 cls.volumes_client.wait_for_volume_status(volume['id'], 'available')
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070082 return volume
83
Attila Fazekas36b1fcf2013-01-31 16:41:04 +010084 @classmethod
85 def clear_volumes(cls):
86 for volume in cls.volumes:
87 try:
Giulio Fidente26d16ed2013-04-30 12:05:56 +020088 cls.volumes_client.delete_volume(volume['id'])
Attila Fazekas36b1fcf2013-01-31 16:41:04 +010089 except Exception:
90 pass
91
92 for volume in cls.volumes:
93 try:
Giulio Fidente26d16ed2013-04-30 12:05:56 +020094 cls.volumes_client.wait_for_resource_deletion(volume['id'])
Attila Fazekas36b1fcf2013-01-31 16:41:04 +010095 except Exception:
96 pass
97
98 @classmethod
99 def clear_snapshots(cls):
100 for snapshot in cls.snapshots:
101 try:
102 cls.snapshots_client.delete_snapshot(snapshot['id'])
103 except Exception:
104 pass
105
106 for snapshot in cls.snapshots:
107 try:
108 cls.snapshots_client.wait_for_resource_deletion(snapshot['id'])
109 except Exception:
110 pass
111
James E. Blaire6d8ee12013-01-18 21:33:45 +0000112
Zhi Kun Liubb363a22013-11-28 18:47:39 +0800113class BaseVolumeV1Test(BaseVolumeTest):
114 @classmethod
115 def setUpClass(cls):
116 if not cls.config.volume_feature_enabled.api_v1:
117 msg = "Volume API v1 not supported"
118 raise cls.skipException(msg)
119 super(BaseVolumeV1Test, cls).setUpClass()
120 cls.volumes_client = cls.os.volumes_client
121 cls.volumes_client.keystone_auth(cls.os.username,
122 cls.os.password,
123 cls.os.auth_url,
124 cls.volumes_client.service,
125 cls.os.tenant_name)
126
127
128class BaseVolumeV1AdminTest(BaseVolumeV1Test):
Attila Fazekas3dcdae12013-02-14 12:50:04 +0100129 """Base test case class for all Volume Admin API tests."""
James E. Blaire6d8ee12013-01-18 21:33:45 +0000130 @classmethod
131 def setUpClass(cls):
Zhi Kun Liubb363a22013-11-28 18:47:39 +0800132 super(BaseVolumeV1AdminTest, cls).setUpClass()
Attila Fazekas3dcdae12013-02-14 12:50:04 +0100133 cls.adm_user = cls.config.identity.admin_username
134 cls.adm_pass = cls.config.identity.admin_password
135 cls.adm_tenant = cls.config.identity.admin_tenant_name
136 if not all((cls.adm_user, cls.adm_pass, cls.adm_tenant)):
137 msg = ("Missing Volume Admin API credentials "
138 "in configuration.")
139 raise cls.skipException(msg)
Matthew Treinish3e046852013-07-23 16:00:24 -0400140 if cls.config.compute.allow_tenant_isolation:
Matthew Treinishb86cda92013-07-29 11:22:23 -0400141 creds = cls.isolated_creds.get_admin_creds()
Matthew Treinish3e046852013-07-23 16:00:24 -0400142 admin_username, admin_tenant_name, admin_password = creds
143 cls.os_adm = clients.Manager(username=admin_username,
144 password=admin_password,
145 tenant_name=admin_tenant_name,
146 interface=cls._interface)
147 else:
148 cls.os_adm = clients.AdminManager(interface=cls._interface)
Attila Fazekas3dcdae12013-02-14 12:50:04 +0100149 cls.client = cls.os_adm.volume_types_client
Nayna Patel4a5024c2013-11-18 07:08:23 +0000150 cls.hosts_client = cls.os_adm.volume_hosts_client