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 |
Matthew Treinish | b86cda9 | 2013-07-29 11:22:23 -0400 | [diff] [blame] | 21 | from tempest.common import isolated_creds |
Matthew Treinish | f4a9b0f | 2013-07-26 16:58:26 -0400 | [diff] [blame] | 22 | from tempest.openstack.common import log as logging |
Attila Fazekas | dc21642 | 2013-01-29 15:12:14 +0100 | [diff] [blame] | 23 | import tempest.test |
Rohit Karajgi | dd47d7e | 2012-07-31 04:11:01 -0700 | [diff] [blame] | 24 | |
| 25 | LOG = logging.getLogger(__name__) |
| 26 | |
| 27 | |
Attila Fazekas | dc21642 | 2013-01-29 15:12:14 +0100 | [diff] [blame] | 28 | class BaseVolumeTest(tempest.test.BaseTestCase): |
Rohit Karajgi | dd47d7e | 2012-07-31 04:11:01 -0700 | [diff] [blame] | 29 | |
Sean Dague | f237ccb | 2013-01-04 15:19:14 -0500 | [diff] [blame] | 30 | """Base test case class for all Cinder API tests.""" |
Rohit Karajgi | dd47d7e | 2012-07-31 04:11:01 -0700 | [diff] [blame] | 31 | |
| 32 | @classmethod |
| 33 | def setUpClass(cls): |
Matthew Treinish | b86cda9 | 2013-07-29 11:22:23 -0400 | [diff] [blame] | 34 | cls.isolated_creds = isolated_creds.IsolatedCreds(cls.__name__) |
Rohit Karajgi | dd47d7e | 2012-07-31 04:11:01 -0700 | [diff] [blame] | 35 | |
Matthew Treinish | 4c41292 | 2013-07-16 15:27:42 -0400 | [diff] [blame] | 36 | 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 Karajgi | dd47d7e | 2012-07-31 04:11:01 -0700 | [diff] [blame] | 40 | if cls.config.compute.allow_tenant_isolation: |
Matthew Treinish | b86cda9 | 2013-07-29 11:22:23 -0400 | [diff] [blame] | 41 | creds = cls.isolated_creds.get_primary_creds() |
Rohit Karajgi | dd47d7e | 2012-07-31 04:11:01 -0700 | [diff] [blame] | 42 | username, tenant_name, password = creds |
Matthew Treinish | 481466b | 2012-12-20 17:16:01 -0500 | [diff] [blame] | 43 | os = clients.Manager(username=username, |
| 44 | password=password, |
Attila Fazekas | 786236c | 2013-01-31 16:06:51 +0100 | [diff] [blame] | 45 | tenant_name=tenant_name, |
| 46 | interface=cls._interface) |
Rohit Karajgi | dd47d7e | 2012-07-31 04:11:01 -0700 | [diff] [blame] | 47 | else: |
Attila Fazekas | 786236c | 2013-01-31 16:06:51 +0100 | [diff] [blame] | 48 | os = clients.Manager(interface=cls._interface) |
Rohit Karajgi | dd47d7e | 2012-07-31 04:11:01 -0700 | [diff] [blame] | 49 | |
| 50 | cls.os = os |
| 51 | cls.volumes_client = os.volumes_client |
Attila Fazekas | 36b1fcf | 2013-01-31 16:41:04 +0100 | [diff] [blame] | 52 | cls.snapshots_client = os.snapshots_client |
Rohit Karajgi | a42fe44 | 2012-09-21 03:08:33 -0700 | [diff] [blame] | 53 | 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 Karajgi | dd47d7e | 2012-07-31 04:11:01 -0700 | [diff] [blame] | 56 | cls.build_interval = cls.config.volume.build_interval |
| 57 | cls.build_timeout = cls.config.volume.build_timeout |
Attila Fazekas | 36b1fcf | 2013-01-31 16:41:04 +0100 | [diff] [blame] | 58 | cls.snapshots = [] |
| 59 | cls.volumes = [] |
Rohit Karajgi | dd47d7e | 2012-07-31 04:11:01 -0700 | [diff] [blame] | 60 | |
Matthew Treinish | 4c41292 | 2013-07-16 15:27:42 -0400 | [diff] [blame] | 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) |
Rohit Karajgi | dd47d7e | 2012-07-31 04:11:01 -0700 | [diff] [blame] | 66 | |
| 67 | @classmethod |
Rohit Karajgi | dd47d7e | 2012-07-31 04:11:01 -0700 | [diff] [blame] | 68 | def tearDownClass(cls): |
Attila Fazekas | 36b1fcf | 2013-01-31 16:41:04 +0100 | [diff] [blame] | 69 | cls.clear_snapshots() |
| 70 | cls.clear_volumes() |
Matthew Treinish | b86cda9 | 2013-07-29 11:22:23 -0400 | [diff] [blame] | 71 | cls.isolated_creds.clear_isolated_creds() |
| 72 | super(BaseVolumeTest, cls).tearDownClass() |
Rohit Karajgi | dd47d7e | 2012-07-31 04:11:01 -0700 | [diff] [blame] | 73 | |
Attila Fazekas | 36b1fcf | 2013-01-31 16:41:04 +0100 | [diff] [blame] | 74 | @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 Fidente | 02f4298 | 2013-06-17 16:25:56 +0200 | [diff] [blame] | 80 | cls.snapshots.append(snapshot) |
Attila Fazekas | 36b1fcf | 2013-01-31 16:41:04 +0100 | [diff] [blame] | 81 | cls.snapshots_client.wait_for_snapshot_status(snapshot['id'], |
| 82 | 'available') |
Attila Fazekas | 36b1fcf | 2013-01-31 16:41:04 +0100 | [diff] [blame] | 83 | return snapshot |
| 84 | |
Attila Fazekas | f7f34f9 | 2013-08-01 17:01:44 +0200 | [diff] [blame] | 85 | # NOTE(afazekas): these create_* and clean_* could be defined |
Attila Fazekas | 36b1fcf | 2013-01-31 16:41:04 +0100 | [diff] [blame] | 86 | # 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 Dague | f237ccb | 2013-01-04 15:19:14 -0500 | [diff] [blame] | 90 | """Wrapper utility that returns a test volume.""" |
Attila Fazekas | 36b1fcf | 2013-01-31 16:41:04 +0100 | [diff] [blame] | 91 | resp, volume = cls.volumes_client.create_volume(size, **kwargs) |
| 92 | assert 200 == resp.status |
Attila Fazekas | 36b1fcf | 2013-01-31 16:41:04 +0100 | [diff] [blame] | 93 | cls.volumes.append(volume) |
Giulio Fidente | 02f4298 | 2013-06-17 16:25:56 +0200 | [diff] [blame] | 94 | cls.volumes_client.wait_for_volume_status(volume['id'], 'available') |
Rohit Karajgi | dd47d7e | 2012-07-31 04:11:01 -0700 | [diff] [blame] | 95 | return volume |
| 96 | |
Attila Fazekas | 36b1fcf | 2013-01-31 16:41:04 +0100 | [diff] [blame] | 97 | @classmethod |
| 98 | def clear_volumes(cls): |
| 99 | for volume in cls.volumes: |
| 100 | try: |
Giulio Fidente | 26d16ed | 2013-04-30 12:05:56 +0200 | [diff] [blame] | 101 | cls.volumes_client.delete_volume(volume['id']) |
Attila Fazekas | 36b1fcf | 2013-01-31 16:41:04 +0100 | [diff] [blame] | 102 | except Exception: |
| 103 | pass |
| 104 | |
| 105 | for volume in cls.volumes: |
| 106 | try: |
Giulio Fidente | 26d16ed | 2013-04-30 12:05:56 +0200 | [diff] [blame] | 107 | cls.volumes_client.wait_for_resource_deletion(volume['id']) |
Attila Fazekas | 36b1fcf | 2013-01-31 16:41:04 +0100 | [diff] [blame] | 108 | 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 Karajgi | dd47d7e | 2012-07-31 04:11:01 -0700 | [diff] [blame] | 125 | def wait_for(self, condition): |
Sean Dague | f237ccb | 2013-01-04 15:19:14 -0500 | [diff] [blame] | 126 | """Repeatedly calls condition() until a timeout.""" |
Rohit Karajgi | dd47d7e | 2012-07-31 04:11:01 -0700 | [diff] [blame] | 127 | start_time = int(time.time()) |
| 128 | while True: |
| 129 | try: |
| 130 | condition() |
Matthew Treinish | 05d9fb9 | 2012-12-07 16:14:05 -0500 | [diff] [blame] | 131 | except Exception: |
Rohit Karajgi | dd47d7e | 2012-07-31 04:11:01 -0700 | [diff] [blame] | 132 | 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. Blair | e6d8ee1 | 2013-01-18 21:33:45 +0000 | [diff] [blame] | 139 | |
| 140 | |
Attila Fazekas | 3dcdae1 | 2013-02-14 12:50:04 +0100 | [diff] [blame] | 141 | class BaseVolumeAdminTest(BaseVolumeTest): |
| 142 | """Base test case class for all Volume Admin API tests.""" |
James E. Blair | e6d8ee1 | 2013-01-18 21:33:45 +0000 | [diff] [blame] | 143 | @classmethod |
| 144 | def setUpClass(cls): |
Attila Fazekas | 3dcdae1 | 2013-02-14 12:50:04 +0100 | [diff] [blame] | 145 | 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 Treinish | 3e04685 | 2013-07-23 16:00:24 -0400 | [diff] [blame] | 153 | if cls.config.compute.allow_tenant_isolation: |
Matthew Treinish | b86cda9 | 2013-07-29 11:22:23 -0400 | [diff] [blame] | 154 | creds = cls.isolated_creds.get_admin_creds() |
Matthew Treinish | 3e04685 | 2013-07-23 16:00:24 -0400 | [diff] [blame] | 155 | 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 Fazekas | 3dcdae1 | 2013-02-14 12:50:04 +0100 | [diff] [blame] | 162 | cls.client = cls.os_adm.volume_types_client |