blob: 52ab5b7eead8011ef3114f284b338141a111bbae [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):
Matthew Treinishb86cda92013-07-29 11:22:23 -040034 cls.isolated_creds = isolated_creds.IsolatedCreds(cls.__name__)
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070035
Matthew Treinish4c412922013-07-16 15:27:42 -040036 if not cls.config.service_available.cinder:
37 skip_msg = ("%s skipped as Cinder is not available" % cls.__name__)
38 raise cls.skipException(skip_msg)
39
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070040 if cls.config.compute.allow_tenant_isolation:
Matthew Treinishb86cda92013-07-29 11:22:23 -040041 creds = cls.isolated_creds.get_primary_creds()
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070042 username, tenant_name, password = creds
Matthew Treinish481466b2012-12-20 17:16:01 -050043 os = clients.Manager(username=username,
44 password=password,
Attila Fazekas786236c2013-01-31 16:06:51 +010045 tenant_name=tenant_name,
46 interface=cls._interface)
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070047 else:
Attila Fazekas786236c2013-01-31 16:06:51 +010048 os = clients.Manager(interface=cls._interface)
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070049
50 cls.os = os
51 cls.volumes_client = os.volumes_client
Attila Fazekas36b1fcf2013-01-31 16:41:04 +010052 cls.snapshots_client = os.snapshots_client
Rohit Karajgia42fe442012-09-21 03:08:33 -070053 cls.servers_client = os.servers_client
54 cls.image_ref = cls.config.compute.image_ref
55 cls.flavor_ref = cls.config.compute.flavor_ref
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070056 cls.build_interval = cls.config.volume.build_interval
57 cls.build_timeout = cls.config.volume.build_timeout
Attila Fazekas36b1fcf2013-01-31 16:41:04 +010058 cls.snapshots = []
59 cls.volumes = []
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070060
Matthew Treinish4c412922013-07-16 15:27:42 -040061 cls.volumes_client.keystone_auth(cls.os.username,
62 cls.os.password,
63 cls.os.auth_url,
64 cls.volumes_client.service,
65 cls.os.tenant_name)
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070066
67 @classmethod
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070068 def tearDownClass(cls):
Attila Fazekas36b1fcf2013-01-31 16:41:04 +010069 cls.clear_snapshots()
70 cls.clear_volumes()
Matthew Treinishb86cda92013-07-29 11:22:23 -040071 cls.isolated_creds.clear_isolated_creds()
72 super(BaseVolumeTest, cls).tearDownClass()
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070073
Attila Fazekas36b1fcf2013-01-31 16:41:04 +010074 @classmethod
75 def create_snapshot(cls, volume_id=1, **kwargs):
76 """Wrapper utility that returns a test snapshot."""
77 resp, snapshot = cls.snapshots_client.create_snapshot(volume_id,
78 **kwargs)
79 assert 200 == resp.status
Giulio Fidente02f42982013-06-17 16:25:56 +020080 cls.snapshots.append(snapshot)
Attila Fazekas36b1fcf2013-01-31 16:41:04 +010081 cls.snapshots_client.wait_for_snapshot_status(snapshot['id'],
82 'available')
Attila Fazekas36b1fcf2013-01-31 16:41:04 +010083 return snapshot
84
Attila Fazekasf7f34f92013-08-01 17:01:44 +020085 # NOTE(afazekas): these create_* and clean_* could be defined
Attila Fazekas36b1fcf2013-01-31 16:41:04 +010086 # only in a single location in the source, and could be more general.
87
88 @classmethod
89 def create_volume(cls, size=1, **kwargs):
Sean Daguef237ccb2013-01-04 15:19:14 -050090 """Wrapper utility that returns a test volume."""
Attila Fazekas36b1fcf2013-01-31 16:41:04 +010091 resp, volume = cls.volumes_client.create_volume(size, **kwargs)
92 assert 200 == resp.status
Attila Fazekas36b1fcf2013-01-31 16:41:04 +010093 cls.volumes.append(volume)
Giulio Fidente02f42982013-06-17 16:25:56 +020094 cls.volumes_client.wait_for_volume_status(volume['id'], 'available')
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070095 return volume
96
Attila Fazekas36b1fcf2013-01-31 16:41:04 +010097 @classmethod
98 def clear_volumes(cls):
99 for volume in cls.volumes:
100 try:
Giulio Fidente26d16ed2013-04-30 12:05:56 +0200101 cls.volumes_client.delete_volume(volume['id'])
Attila Fazekas36b1fcf2013-01-31 16:41:04 +0100102 except Exception:
103 pass
104
105 for volume in cls.volumes:
106 try:
Giulio Fidente26d16ed2013-04-30 12:05:56 +0200107 cls.volumes_client.wait_for_resource_deletion(volume['id'])
Attila Fazekas36b1fcf2013-01-31 16:41:04 +0100108 except Exception:
109 pass
110
111 @classmethod
112 def clear_snapshots(cls):
113 for snapshot in cls.snapshots:
114 try:
115 cls.snapshots_client.delete_snapshot(snapshot['id'])
116 except Exception:
117 pass
118
119 for snapshot in cls.snapshots:
120 try:
121 cls.snapshots_client.wait_for_resource_deletion(snapshot['id'])
122 except Exception:
123 pass
124
Rohit Karajgidd47d7e2012-07-31 04:11:01 -0700125 def wait_for(self, condition):
Sean Daguef237ccb2013-01-04 15:19:14 -0500126 """Repeatedly calls condition() until a timeout."""
Rohit Karajgidd47d7e2012-07-31 04:11:01 -0700127 start_time = int(time.time())
128 while True:
129 try:
130 condition()
Matthew Treinish05d9fb92012-12-07 16:14:05 -0500131 except Exception:
Rohit Karajgidd47d7e2012-07-31 04:11:01 -0700132 pass
133 else:
134 return
135 if int(time.time()) - start_time >= self.build_timeout:
136 condition()
137 return
138 time.sleep(self.build_interval)
James E. Blaire6d8ee12013-01-18 21:33:45 +0000139
140
Attila Fazekas3dcdae12013-02-14 12:50:04 +0100141class BaseVolumeAdminTest(BaseVolumeTest):
142 """Base test case class for all Volume Admin API tests."""
James E. Blaire6d8ee12013-01-18 21:33:45 +0000143 @classmethod
144 def setUpClass(cls):
Attila Fazekas3dcdae12013-02-14 12:50:04 +0100145 super(BaseVolumeAdminTest, cls).setUpClass()
146 cls.adm_user = cls.config.identity.admin_username
147 cls.adm_pass = cls.config.identity.admin_password
148 cls.adm_tenant = cls.config.identity.admin_tenant_name
149 if not all((cls.adm_user, cls.adm_pass, cls.adm_tenant)):
150 msg = ("Missing Volume Admin API credentials "
151 "in configuration.")
152 raise cls.skipException(msg)
Matthew Treinish3e046852013-07-23 16:00:24 -0400153 if cls.config.compute.allow_tenant_isolation:
Matthew Treinishb86cda92013-07-29 11:22:23 -0400154 creds = cls.isolated_creds.get_admin_creds()
Matthew Treinish3e046852013-07-23 16:00:24 -0400155 admin_username, admin_tenant_name, admin_password = creds
156 cls.os_adm = clients.Manager(username=admin_username,
157 password=admin_password,
158 tenant_name=admin_tenant_name,
159 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