Rohit Karajgi | dd47d7e | 2012-07-31 04:11:01 -0700 | [diff] [blame] | 1 | # 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 Karajgi | dd47d7e | 2012-07-31 04:11:01 -0700 | [diff] [blame] | 18 | import time |
Rohit Karajgi | dd47d7e | 2012-07-31 04:11:01 -0700 | [diff] [blame] | 19 | |
Matthew Treinish | 481466b | 2012-12-20 17:16:01 -0500 | [diff] [blame] | 20 | from tempest import clients |
Mitsuhiko Yamazaki | 46818aa | 2013-04-18 17:49:17 +0900 | [diff] [blame] | 21 | from tempest.common import log as logging |
Rohit Karajgi | dd47d7e | 2012-07-31 04:11:01 -0700 | [diff] [blame] | 22 | from tempest.common.utils.data_utils import rand_name |
Rohit Karajgi | dd47d7e | 2012-07-31 04:11:01 -0700 | [diff] [blame] | 23 | from tempest import exceptions |
Attila Fazekas | dc21642 | 2013-01-29 15:12:14 +0100 | [diff] [blame] | 24 | import tempest.test |
Rohit Karajgi | dd47d7e | 2012-07-31 04:11:01 -0700 | [diff] [blame] | 25 | |
| 26 | LOG = logging.getLogger(__name__) |
| 27 | |
| 28 | |
Attila Fazekas | dc21642 | 2013-01-29 15:12:14 +0100 | [diff] [blame] | 29 | class BaseVolumeTest(tempest.test.BaseTestCase): |
Rohit Karajgi | dd47d7e | 2012-07-31 04:11:01 -0700 | [diff] [blame] | 30 | |
Sean Dague | f237ccb | 2013-01-04 15:19:14 -0500 | [diff] [blame] | 31 | """Base test case class for all Cinder API tests.""" |
Rohit Karajgi | dd47d7e | 2012-07-31 04:11:01 -0700 | [diff] [blame] | 32 | |
| 33 | @classmethod |
| 34 | def setUpClass(cls): |
Rohit Karajgi | dd47d7e | 2012-07-31 04:11:01 -0700 | [diff] [blame] | 35 | cls.isolated_creds = [] |
| 36 | |
| 37 | if cls.config.compute.allow_tenant_isolation: |
| 38 | creds = cls._get_isolated_creds() |
| 39 | username, tenant_name, password = creds |
Matthew Treinish | 481466b | 2012-12-20 17:16:01 -0500 | [diff] [blame] | 40 | os = clients.Manager(username=username, |
| 41 | password=password, |
Attila Fazekas | 786236c | 2013-01-31 16:06:51 +0100 | [diff] [blame] | 42 | tenant_name=tenant_name, |
| 43 | interface=cls._interface) |
Rohit Karajgi | dd47d7e | 2012-07-31 04:11:01 -0700 | [diff] [blame] | 44 | else: |
Attila Fazekas | 786236c | 2013-01-31 16:06:51 +0100 | [diff] [blame] | 45 | os = clients.Manager(interface=cls._interface) |
Rohit Karajgi | dd47d7e | 2012-07-31 04:11:01 -0700 | [diff] [blame] | 46 | |
| 47 | cls.os = os |
| 48 | cls.volumes_client = os.volumes_client |
Attila Fazekas | 36b1fcf | 2013-01-31 16:41:04 +0100 | [diff] [blame] | 49 | cls.snapshots_client = os.snapshots_client |
Rohit Karajgi | a42fe44 | 2012-09-21 03:08:33 -0700 | [diff] [blame] | 50 | cls.servers_client = os.servers_client |
| 51 | cls.image_ref = cls.config.compute.image_ref |
| 52 | cls.flavor_ref = cls.config.compute.flavor_ref |
Rohit Karajgi | dd47d7e | 2012-07-31 04:11:01 -0700 | [diff] [blame] | 53 | cls.build_interval = cls.config.volume.build_interval |
| 54 | cls.build_timeout = cls.config.volume.build_timeout |
Attila Fazekas | 36b1fcf | 2013-01-31 16:41:04 +0100 | [diff] [blame] | 55 | cls.snapshots = [] |
| 56 | cls.volumes = [] |
Rohit Karajgi | dd47d7e | 2012-07-31 04:11:01 -0700 | [diff] [blame] | 57 | |
| 58 | skip_msg = ("%s skipped as Cinder endpoint is not available" % |
Zhongyue Luo | e0884a3 | 2012-09-25 17:24:17 +0800 | [diff] [blame] | 59 | cls.__name__) |
Rohit Karajgi | dd47d7e | 2012-07-31 04:11:01 -0700 | [diff] [blame] | 60 | try: |
| 61 | 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) |
| 66 | except exceptions.EndpointNotFound: |
Rohit Karajgi | a42fe44 | 2012-09-21 03:08:33 -0700 | [diff] [blame] | 67 | cls.clear_isolated_creds() |
ivan-zhu | 1feeb38 | 2013-01-24 10:14:39 +0800 | [diff] [blame] | 68 | raise cls.skipException(skip_msg) |
Rohit Karajgi | dd47d7e | 2012-07-31 04:11:01 -0700 | [diff] [blame] | 69 | |
| 70 | @classmethod |
| 71 | def _get_identity_admin_client(cls): |
| 72 | """ |
| 73 | Returns an instance of the Identity Admin API client |
| 74 | """ |
Attila Fazekas | cadcb1f | 2013-01-21 23:10:53 +0100 | [diff] [blame] | 75 | os = clients.ComputeAdminManager() |
Attila Fazekas | 407b6db | 2013-01-19 12:48:36 +0100 | [diff] [blame] | 76 | return os.identity_client |
Rohit Karajgi | dd47d7e | 2012-07-31 04:11:01 -0700 | [diff] [blame] | 77 | |
| 78 | @classmethod |
| 79 | def _get_isolated_creds(cls): |
| 80 | """ |
| 81 | Creates a new set of user/tenant/password credentials for a |
| 82 | **regular** user of the Volume API so that a test case can |
| 83 | operate in an isolated tenant container. |
| 84 | """ |
| 85 | admin_client = cls._get_identity_admin_client() |
Chris Yeoh | 5b89eb4 | 2013-02-04 15:33:29 +1030 | [diff] [blame] | 86 | rand_name_root = rand_name(cls.__name__) |
Rohit Karajgi | dd47d7e | 2012-07-31 04:11:01 -0700 | [diff] [blame] | 87 | if cls.isolated_creds: |
| 88 | # Main user already created. Create the alt one... |
| 89 | rand_name_root += '-alt' |
| 90 | username = rand_name_root + "-user" |
| 91 | email = rand_name_root + "@example.com" |
| 92 | tenant_name = rand_name_root + "-tenant" |
| 93 | tenant_desc = tenant_name + "-desc" |
| 94 | password = "pass" |
| 95 | |
| 96 | resp, tenant = admin_client.create_tenant(name=tenant_name, |
| 97 | description=tenant_desc) |
| 98 | resp, user = admin_client.create_user(username, |
| 99 | password, |
| 100 | tenant['id'], |
| 101 | email) |
| 102 | # Store the complete creds (including UUID ids...) for later |
| 103 | # but return just the username, tenant_name, password tuple |
| 104 | # that the various clients will use. |
| 105 | cls.isolated_creds.append((user, tenant)) |
| 106 | |
| 107 | return username, tenant_name, password |
| 108 | |
| 109 | @classmethod |
| 110 | def clear_isolated_creds(cls): |
| 111 | if not cls.isolated_creds: |
Attila Fazekas | 6c4cce2 | 2013-02-14 14:01:13 +0100 | [diff] [blame] | 112 | return |
Rohit Karajgi | dd47d7e | 2012-07-31 04:11:01 -0700 | [diff] [blame] | 113 | admin_client = cls._get_identity_admin_client() |
| 114 | |
| 115 | for user, tenant in cls.isolated_creds: |
| 116 | admin_client.delete_user(user['id']) |
| 117 | admin_client.delete_tenant(tenant['id']) |
| 118 | |
| 119 | @classmethod |
| 120 | def tearDownClass(cls): |
Attila Fazekas | 36b1fcf | 2013-01-31 16:41:04 +0100 | [diff] [blame] | 121 | cls.clear_snapshots() |
| 122 | cls.clear_volumes() |
Rohit Karajgi | dd47d7e | 2012-07-31 04:11:01 -0700 | [diff] [blame] | 123 | cls.clear_isolated_creds() |
| 124 | |
Attila Fazekas | 36b1fcf | 2013-01-31 16:41:04 +0100 | [diff] [blame] | 125 | @classmethod |
| 126 | def create_snapshot(cls, volume_id=1, **kwargs): |
| 127 | """Wrapper utility that returns a test snapshot.""" |
| 128 | resp, snapshot = cls.snapshots_client.create_snapshot(volume_id, |
| 129 | **kwargs) |
| 130 | assert 200 == resp.status |
Giulio Fidente | 02f4298 | 2013-06-17 16:25:56 +0200 | [diff] [blame] | 131 | cls.snapshots.append(snapshot) |
Attila Fazekas | 36b1fcf | 2013-01-31 16:41:04 +0100 | [diff] [blame] | 132 | cls.snapshots_client.wait_for_snapshot_status(snapshot['id'], |
| 133 | 'available') |
Attila Fazekas | 36b1fcf | 2013-01-31 16:41:04 +0100 | [diff] [blame] | 134 | return snapshot |
| 135 | |
| 136 | #NOTE(afazekas): these create_* and clean_* could be defined |
| 137 | # only in a single location in the source, and could be more general. |
| 138 | |
| 139 | @classmethod |
| 140 | def create_volume(cls, size=1, **kwargs): |
Sean Dague | f237ccb | 2013-01-04 15:19:14 -0500 | [diff] [blame] | 141 | """Wrapper utility that returns a test volume.""" |
Attila Fazekas | 36b1fcf | 2013-01-31 16:41:04 +0100 | [diff] [blame] | 142 | resp, volume = cls.volumes_client.create_volume(size, **kwargs) |
| 143 | assert 200 == resp.status |
Attila Fazekas | 36b1fcf | 2013-01-31 16:41:04 +0100 | [diff] [blame] | 144 | cls.volumes.append(volume) |
Giulio Fidente | 02f4298 | 2013-06-17 16:25:56 +0200 | [diff] [blame] | 145 | cls.volumes_client.wait_for_volume_status(volume['id'], 'available') |
Rohit Karajgi | dd47d7e | 2012-07-31 04:11:01 -0700 | [diff] [blame] | 146 | return volume |
| 147 | |
Attila Fazekas | 36b1fcf | 2013-01-31 16:41:04 +0100 | [diff] [blame] | 148 | @classmethod |
| 149 | def clear_volumes(cls): |
| 150 | for volume in cls.volumes: |
| 151 | try: |
Giulio Fidente | 26d16ed | 2013-04-30 12:05:56 +0200 | [diff] [blame] | 152 | cls.volumes_client.delete_volume(volume['id']) |
Attila Fazekas | 36b1fcf | 2013-01-31 16:41:04 +0100 | [diff] [blame] | 153 | except Exception: |
| 154 | pass |
| 155 | |
| 156 | for volume in cls.volumes: |
| 157 | try: |
Giulio Fidente | 26d16ed | 2013-04-30 12:05:56 +0200 | [diff] [blame] | 158 | cls.volumes_client.wait_for_resource_deletion(volume['id']) |
Attila Fazekas | 36b1fcf | 2013-01-31 16:41:04 +0100 | [diff] [blame] | 159 | except Exception: |
| 160 | pass |
| 161 | |
| 162 | @classmethod |
| 163 | def clear_snapshots(cls): |
| 164 | for snapshot in cls.snapshots: |
| 165 | try: |
| 166 | cls.snapshots_client.delete_snapshot(snapshot['id']) |
| 167 | except Exception: |
| 168 | pass |
| 169 | |
| 170 | for snapshot in cls.snapshots: |
| 171 | try: |
| 172 | cls.snapshots_client.wait_for_resource_deletion(snapshot['id']) |
| 173 | except Exception: |
| 174 | pass |
| 175 | |
Rohit Karajgi | dd47d7e | 2012-07-31 04:11:01 -0700 | [diff] [blame] | 176 | def wait_for(self, condition): |
Sean Dague | f237ccb | 2013-01-04 15:19:14 -0500 | [diff] [blame] | 177 | """Repeatedly calls condition() until a timeout.""" |
Rohit Karajgi | dd47d7e | 2012-07-31 04:11:01 -0700 | [diff] [blame] | 178 | start_time = int(time.time()) |
| 179 | while True: |
| 180 | try: |
| 181 | condition() |
Matthew Treinish | 05d9fb9 | 2012-12-07 16:14:05 -0500 | [diff] [blame] | 182 | except Exception: |
Rohit Karajgi | dd47d7e | 2012-07-31 04:11:01 -0700 | [diff] [blame] | 183 | pass |
| 184 | else: |
| 185 | return |
| 186 | if int(time.time()) - start_time >= self.build_timeout: |
| 187 | condition() |
| 188 | return |
| 189 | time.sleep(self.build_interval) |
James E. Blair | e6d8ee1 | 2013-01-18 21:33:45 +0000 | [diff] [blame] | 190 | |
| 191 | |
Attila Fazekas | 3dcdae1 | 2013-02-14 12:50:04 +0100 | [diff] [blame] | 192 | class BaseVolumeAdminTest(BaseVolumeTest): |
| 193 | """Base test case class for all Volume Admin API tests.""" |
James E. Blair | e6d8ee1 | 2013-01-18 21:33:45 +0000 | [diff] [blame] | 194 | @classmethod |
| 195 | def setUpClass(cls): |
Attila Fazekas | 3dcdae1 | 2013-02-14 12:50:04 +0100 | [diff] [blame] | 196 | super(BaseVolumeAdminTest, cls).setUpClass() |
| 197 | cls.adm_user = cls.config.identity.admin_username |
| 198 | cls.adm_pass = cls.config.identity.admin_password |
| 199 | cls.adm_tenant = cls.config.identity.admin_tenant_name |
| 200 | if not all((cls.adm_user, cls.adm_pass, cls.adm_tenant)): |
| 201 | msg = ("Missing Volume Admin API credentials " |
| 202 | "in configuration.") |
| 203 | raise cls.skipException(msg) |
James E. Blair | e6d8ee1 | 2013-01-18 21:33:45 +0000 | [diff] [blame] | 204 | |
Attila Fazekas | 3dcdae1 | 2013-02-14 12:50:04 +0100 | [diff] [blame] | 205 | cls.os_adm = clients.AdminManager(interface=cls._interface) |
| 206 | cls.client = cls.os_adm.volume_types_client |