blob: 465f5708b9f395e5b55926ef0a96169ecdfaf430 [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
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070018import time
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070019
Matthew Treinish481466b2012-12-20 17:16:01 -050020from tempest import clients
Matthew Treinishf4a9b0f2013-07-26 16:58:26 -040021from tempest.openstack.common import log as logging
Attila Fazekasdc216422013-01-29 15:12:14 +010022import tempest.test
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070023
24LOG = logging.getLogger(__name__)
25
26
Attila Fazekasdc216422013-01-29 15:12:14 +010027class BaseVolumeTest(tempest.test.BaseTestCase):
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070028
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
31 @classmethod
32 def setUpClass(cls):
Attila Fazekasf86fa312013-07-30 19:56:39 +020033 super(BaseVolumeTest, cls).setUpClass()
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070034
Matthew Treinish4c412922013-07-16 15:27:42 -040035 if not cls.config.service_available.cinder:
36 skip_msg = ("%s skipped as Cinder is not available" % cls.__name__)
37 raise cls.skipException(skip_msg)
38
Ryan Hsu6c4bb3d2013-10-21 21:22:50 -070039 os = cls.get_client_manager()
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070040
41 cls.os = os
42 cls.volumes_client = os.volumes_client
Attila Fazekas36b1fcf2013-01-31 16:41:04 +010043 cls.snapshots_client = os.snapshots_client
Rohit Karajgia42fe442012-09-21 03:08:33 -070044 cls.servers_client = os.servers_client
45 cls.image_ref = cls.config.compute.image_ref
46 cls.flavor_ref = cls.config.compute.flavor_ref
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070047 cls.build_interval = cls.config.volume.build_interval
48 cls.build_timeout = cls.config.volume.build_timeout
Attila Fazekas36b1fcf2013-01-31 16:41:04 +010049 cls.snapshots = []
50 cls.volumes = []
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070051
Matthew Treinish4c412922013-07-16 15:27:42 -040052 cls.volumes_client.keystone_auth(cls.os.username,
53 cls.os.password,
54 cls.os.auth_url,
55 cls.volumes_client.service,
56 cls.os.tenant_name)
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070057
58 @classmethod
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070059 def tearDownClass(cls):
Attila Fazekas36b1fcf2013-01-31 16:41:04 +010060 cls.clear_snapshots()
61 cls.clear_volumes()
Ryan Hsu6c4bb3d2013-10-21 21:22:50 -070062 cls.clear_isolated_creds()
Matthew Treinishb86cda92013-07-29 11:22:23 -040063 super(BaseVolumeTest, cls).tearDownClass()
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070064
Attila Fazekas36b1fcf2013-01-31 16:41:04 +010065 @classmethod
66 def create_snapshot(cls, volume_id=1, **kwargs):
67 """Wrapper utility that returns a test snapshot."""
68 resp, snapshot = cls.snapshots_client.create_snapshot(volume_id,
69 **kwargs)
70 assert 200 == resp.status
Giulio Fidente02f42982013-06-17 16:25:56 +020071 cls.snapshots.append(snapshot)
Attila Fazekas36b1fcf2013-01-31 16:41:04 +010072 cls.snapshots_client.wait_for_snapshot_status(snapshot['id'],
73 'available')
Attila Fazekas36b1fcf2013-01-31 16:41:04 +010074 return snapshot
75
Attila Fazekasf7f34f92013-08-01 17:01:44 +020076 # NOTE(afazekas): these create_* and clean_* could be defined
Attila Fazekas36b1fcf2013-01-31 16:41:04 +010077 # only in a single location in the source, and could be more general.
78
79 @classmethod
80 def create_volume(cls, size=1, **kwargs):
Sean Daguef237ccb2013-01-04 15:19:14 -050081 """Wrapper utility that returns a test volume."""
Attila Fazekas36b1fcf2013-01-31 16:41:04 +010082 resp, volume = cls.volumes_client.create_volume(size, **kwargs)
83 assert 200 == resp.status
Attila Fazekas36b1fcf2013-01-31 16:41:04 +010084 cls.volumes.append(volume)
Giulio Fidente02f42982013-06-17 16:25:56 +020085 cls.volumes_client.wait_for_volume_status(volume['id'], 'available')
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070086 return volume
87
Attila Fazekas36b1fcf2013-01-31 16:41:04 +010088 @classmethod
89 def clear_volumes(cls):
90 for volume in cls.volumes:
91 try:
Giulio Fidente26d16ed2013-04-30 12:05:56 +020092 cls.volumes_client.delete_volume(volume['id'])
Attila Fazekas36b1fcf2013-01-31 16:41:04 +010093 except Exception:
94 pass
95
96 for volume in cls.volumes:
97 try:
Giulio Fidente26d16ed2013-04-30 12:05:56 +020098 cls.volumes_client.wait_for_resource_deletion(volume['id'])
Attila Fazekas36b1fcf2013-01-31 16:41:04 +010099 except Exception:
100 pass
101
102 @classmethod
103 def clear_snapshots(cls):
104 for snapshot in cls.snapshots:
105 try:
106 cls.snapshots_client.delete_snapshot(snapshot['id'])
107 except Exception:
108 pass
109
110 for snapshot in cls.snapshots:
111 try:
112 cls.snapshots_client.wait_for_resource_deletion(snapshot['id'])
113 except Exception:
114 pass
115
Rohit Karajgidd47d7e2012-07-31 04:11:01 -0700116 def wait_for(self, condition):
Sean Daguef237ccb2013-01-04 15:19:14 -0500117 """Repeatedly calls condition() until a timeout."""
Rohit Karajgidd47d7e2012-07-31 04:11:01 -0700118 start_time = int(time.time())
119 while True:
120 try:
121 condition()
Matthew Treinish05d9fb92012-12-07 16:14:05 -0500122 except Exception:
Rohit Karajgidd47d7e2012-07-31 04:11:01 -0700123 pass
124 else:
125 return
126 if int(time.time()) - start_time >= self.build_timeout:
127 condition()
128 return
129 time.sleep(self.build_interval)
James E. Blaire6d8ee12013-01-18 21:33:45 +0000130
131
Attila Fazekas3dcdae12013-02-14 12:50:04 +0100132class BaseVolumeAdminTest(BaseVolumeTest):
133 """Base test case class for all Volume Admin API tests."""
James E. Blaire6d8ee12013-01-18 21:33:45 +0000134 @classmethod
135 def setUpClass(cls):
Attila Fazekas3dcdae12013-02-14 12:50:04 +0100136 super(BaseVolumeAdminTest, cls).setUpClass()
137 cls.adm_user = cls.config.identity.admin_username
138 cls.adm_pass = cls.config.identity.admin_password
139 cls.adm_tenant = cls.config.identity.admin_tenant_name
140 if not all((cls.adm_user, cls.adm_pass, cls.adm_tenant)):
141 msg = ("Missing Volume Admin API credentials "
142 "in configuration.")
143 raise cls.skipException(msg)
Matthew Treinish3e046852013-07-23 16:00:24 -0400144 if cls.config.compute.allow_tenant_isolation:
Matthew Treinishb86cda92013-07-29 11:22:23 -0400145 creds = cls.isolated_creds.get_admin_creds()
Matthew Treinish3e046852013-07-23 16:00:24 -0400146 admin_username, admin_tenant_name, admin_password = creds
147 cls.os_adm = clients.Manager(username=admin_username,
148 password=admin_password,
149 tenant_name=admin_tenant_name,
150 interface=cls._interface)
151 else:
152 cls.os_adm = clients.AdminManager(interface=cls._interface)
Attila Fazekas3dcdae12013-02-14 12:50:04 +0100153 cls.client = cls.os_adm.volume_types_client
Nayna Patel4a5024c2013-11-18 07:08:23 +0000154 cls.hosts_client = cls.os_adm.volume_hosts_client