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