blob: 7781647a24659ca36b6a42b95d22e925d61ac523 [file] [log] [blame]
Rohit Karajgidd47d7e2012-07-31 04:11:01 -07001# vim: tabstop=4 shiftwidth=4 softtabstop=4
2
3# Copyright 2012 OpenStack, LLC
4# 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 Treinishb86cda92013-07-29 11:22:23 -040021from tempest.common import isolated_creds
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
25LOG = logging.getLogger(__name__)
26
27
Attila Fazekasdc216422013-01-29 15:12:14 +010028class BaseVolumeTest(tempest.test.BaseTestCase):
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070029
Sean Daguef237ccb2013-01-04 15:19:14 -050030 """Base test case class for all Cinder API tests."""
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070031
32 @classmethod
33 def setUpClass(cls):
Attila Fazekasf86fa312013-07-30 19:56:39 +020034 super(BaseVolumeTest, cls).setUpClass()
Matthew Treinishb86cda92013-07-29 11:22:23 -040035 cls.isolated_creds = isolated_creds.IsolatedCreds(cls.__name__)
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070036
Matthew Treinish4c412922013-07-16 15:27:42 -040037 if not cls.config.service_available.cinder:
38 skip_msg = ("%s skipped as Cinder is not available" % cls.__name__)
39 raise cls.skipException(skip_msg)
40
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070041 if cls.config.compute.allow_tenant_isolation:
Matthew Treinishb86cda92013-07-29 11:22:23 -040042 creds = cls.isolated_creds.get_primary_creds()
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070043 username, tenant_name, password = creds
Matthew Treinish481466b2012-12-20 17:16:01 -050044 os = clients.Manager(username=username,
45 password=password,
Attila Fazekas786236c2013-01-31 16:06:51 +010046 tenant_name=tenant_name,
47 interface=cls._interface)
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070048 else:
Attila Fazekas786236c2013-01-31 16:06:51 +010049 os = clients.Manager(interface=cls._interface)
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070050
51 cls.os = os
52 cls.volumes_client = os.volumes_client
Attila Fazekas36b1fcf2013-01-31 16:41:04 +010053 cls.snapshots_client = os.snapshots_client
Rohit Karajgia42fe442012-09-21 03:08:33 -070054 cls.servers_client = os.servers_client
55 cls.image_ref = cls.config.compute.image_ref
56 cls.flavor_ref = cls.config.compute.flavor_ref
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070057 cls.build_interval = cls.config.volume.build_interval
58 cls.build_timeout = cls.config.volume.build_timeout
Attila Fazekas36b1fcf2013-01-31 16:41:04 +010059 cls.snapshots = []
60 cls.volumes = []
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070061
Matthew Treinish4c412922013-07-16 15:27:42 -040062 cls.volumes_client.keystone_auth(cls.os.username,
63 cls.os.password,
64 cls.os.auth_url,
65 cls.volumes_client.service,
66 cls.os.tenant_name)
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070067
68 @classmethod
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070069 def tearDownClass(cls):
Attila Fazekas36b1fcf2013-01-31 16:41:04 +010070 cls.clear_snapshots()
71 cls.clear_volumes()
Matthew Treinishb86cda92013-07-29 11:22:23 -040072 cls.isolated_creds.clear_isolated_creds()
73 super(BaseVolumeTest, cls).tearDownClass()
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070074
Attila Fazekas36b1fcf2013-01-31 16:41:04 +010075 @classmethod
76 def create_snapshot(cls, volume_id=1, **kwargs):
77 """Wrapper utility that returns a test snapshot."""
78 resp, snapshot = cls.snapshots_client.create_snapshot(volume_id,
79 **kwargs)
80 assert 200 == resp.status
Giulio Fidente02f42982013-06-17 16:25:56 +020081 cls.snapshots.append(snapshot)
Attila Fazekas36b1fcf2013-01-31 16:41:04 +010082 cls.snapshots_client.wait_for_snapshot_status(snapshot['id'],
83 'available')
Attila Fazekas36b1fcf2013-01-31 16:41:04 +010084 return snapshot
85
Attila Fazekasf7f34f92013-08-01 17:01:44 +020086 # NOTE(afazekas): these create_* and clean_* could be defined
Attila Fazekas36b1fcf2013-01-31 16:41:04 +010087 # only in a single location in the source, and could be more general.
88
89 @classmethod
90 def create_volume(cls, size=1, **kwargs):
Sean Daguef237ccb2013-01-04 15:19:14 -050091 """Wrapper utility that returns a test volume."""
Attila Fazekas36b1fcf2013-01-31 16:41:04 +010092 resp, volume = cls.volumes_client.create_volume(size, **kwargs)
93 assert 200 == resp.status
Attila Fazekas36b1fcf2013-01-31 16:41:04 +010094 cls.volumes.append(volume)
Giulio Fidente02f42982013-06-17 16:25:56 +020095 cls.volumes_client.wait_for_volume_status(volume['id'], 'available')
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070096 return volume
97
Attila Fazekas36b1fcf2013-01-31 16:41:04 +010098 @classmethod
99 def clear_volumes(cls):
100 for volume in cls.volumes:
101 try:
Giulio Fidente26d16ed2013-04-30 12:05:56 +0200102 cls.volumes_client.delete_volume(volume['id'])
Attila Fazekas36b1fcf2013-01-31 16:41:04 +0100103 except Exception:
104 pass
105
106 for volume in cls.volumes:
107 try:
Giulio Fidente26d16ed2013-04-30 12:05:56 +0200108 cls.volumes_client.wait_for_resource_deletion(volume['id'])
Attila Fazekas36b1fcf2013-01-31 16:41:04 +0100109 except Exception:
110 pass
111
112 @classmethod
113 def clear_snapshots(cls):
114 for snapshot in cls.snapshots:
115 try:
116 cls.snapshots_client.delete_snapshot(snapshot['id'])
117 except Exception:
118 pass
119
120 for snapshot in cls.snapshots:
121 try:
122 cls.snapshots_client.wait_for_resource_deletion(snapshot['id'])
123 except Exception:
124 pass
125
Rohit Karajgidd47d7e2012-07-31 04:11:01 -0700126 def wait_for(self, condition):
Sean Daguef237ccb2013-01-04 15:19:14 -0500127 """Repeatedly calls condition() until a timeout."""
Rohit Karajgidd47d7e2012-07-31 04:11:01 -0700128 start_time = int(time.time())
129 while True:
130 try:
131 condition()
Matthew Treinish05d9fb92012-12-07 16:14:05 -0500132 except Exception:
Rohit Karajgidd47d7e2012-07-31 04:11:01 -0700133 pass
134 else:
135 return
136 if int(time.time()) - start_time >= self.build_timeout:
137 condition()
138 return
139 time.sleep(self.build_interval)
James E. Blaire6d8ee12013-01-18 21:33:45 +0000140
141
Attila Fazekas3dcdae12013-02-14 12:50:04 +0100142class BaseVolumeAdminTest(BaseVolumeTest):
143 """Base test case class for all Volume Admin API tests."""
James E. Blaire6d8ee12013-01-18 21:33:45 +0000144 @classmethod
145 def setUpClass(cls):
Attila Fazekas3dcdae12013-02-14 12:50:04 +0100146 super(BaseVolumeAdminTest, cls).setUpClass()
147 cls.adm_user = cls.config.identity.admin_username
148 cls.adm_pass = cls.config.identity.admin_password
149 cls.adm_tenant = cls.config.identity.admin_tenant_name
150 if not all((cls.adm_user, cls.adm_pass, cls.adm_tenant)):
151 msg = ("Missing Volume Admin API credentials "
152 "in configuration.")
153 raise cls.skipException(msg)
Matthew Treinish3e046852013-07-23 16:00:24 -0400154 if cls.config.compute.allow_tenant_isolation:
Matthew Treinishb86cda92013-07-29 11:22:23 -0400155 creds = cls.isolated_creds.get_admin_creds()
Matthew Treinish3e046852013-07-23 16:00:24 -0400156 admin_username, admin_tenant_name, admin_password = creds
157 cls.os_adm = clients.Manager(username=admin_username,
158 password=admin_password,
159 tenant_name=admin_tenant_name,
160 interface=cls._interface)
161 else:
162 cls.os_adm = clients.AdminManager(interface=cls._interface)
Attila Fazekas3dcdae12013-02-14 12:50:04 +0100163 cls.client = cls.os_adm.volume_types_client