Rohit Karajgi | dd47d7e | 2012-07-31 04:11:01 -0700 | [diff] [blame] | 1 | # vim: tabstop=4 shiftwidth=4 softtabstop=4 |
| 2 | |
ZhiQiang Fan | 39f9722 | 2013-09-20 04:49:44 +0800 | [diff] [blame] | 3 | # Copyright 2012 OpenStack Foundation |
Rohit Karajgi | dd47d7e | 2012-07-31 04:11:01 -0700 | [diff] [blame] | 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 | f4a9b0f | 2013-07-26 16:58:26 -0400 | [diff] [blame] | 21 | from tempest.openstack.common import log as logging |
Attila Fazekas | dc21642 | 2013-01-29 15:12:14 +0100 | [diff] [blame] | 22 | import tempest.test |
Rohit Karajgi | dd47d7e | 2012-07-31 04:11:01 -0700 | [diff] [blame] | 23 | |
| 24 | LOG = logging.getLogger(__name__) |
| 25 | |
| 26 | |
Attila Fazekas | dc21642 | 2013-01-29 15:12:14 +0100 | [diff] [blame] | 27 | class BaseVolumeTest(tempest.test.BaseTestCase): |
Rohit Karajgi | dd47d7e | 2012-07-31 04:11:01 -0700 | [diff] [blame] | 28 | |
Sean Dague | f237ccb | 2013-01-04 15:19:14 -0500 | [diff] [blame] | 29 | """Base test case class for all Cinder API tests.""" |
Rohit Karajgi | dd47d7e | 2012-07-31 04:11:01 -0700 | [diff] [blame] | 30 | |
| 31 | @classmethod |
| 32 | def setUpClass(cls): |
Attila Fazekas | f86fa31 | 2013-07-30 19:56:39 +0200 | [diff] [blame] | 33 | super(BaseVolumeTest, cls).setUpClass() |
Rohit Karajgi | dd47d7e | 2012-07-31 04:11:01 -0700 | [diff] [blame] | 34 | |
Matthew Treinish | 4c41292 | 2013-07-16 15:27:42 -0400 | [diff] [blame] | 35 | if not cls.config.service_available.cinder: |
| 36 | skip_msg = ("%s skipped as Cinder is not available" % cls.__name__) |
| 37 | raise cls.skipException(skip_msg) |
| 38 | |
Ryan Hsu | 6c4bb3d | 2013-10-21 21:22:50 -0700 | [diff] [blame] | 39 | os = cls.get_client_manager() |
Rohit Karajgi | dd47d7e | 2012-07-31 04:11:01 -0700 | [diff] [blame] | 40 | |
| 41 | cls.os = os |
| 42 | cls.volumes_client = os.volumes_client |
Attila Fazekas | 36b1fcf | 2013-01-31 16:41:04 +0100 | [diff] [blame] | 43 | cls.snapshots_client = os.snapshots_client |
Rohit Karajgi | a42fe44 | 2012-09-21 03:08:33 -0700 | [diff] [blame] | 44 | cls.servers_client = os.servers_client |
| 45 | cls.image_ref = cls.config.compute.image_ref |
| 46 | cls.flavor_ref = cls.config.compute.flavor_ref |
Rohit Karajgi | dd47d7e | 2012-07-31 04:11:01 -0700 | [diff] [blame] | 47 | cls.build_interval = cls.config.volume.build_interval |
| 48 | cls.build_timeout = cls.config.volume.build_timeout |
Attila Fazekas | 36b1fcf | 2013-01-31 16:41:04 +0100 | [diff] [blame] | 49 | cls.snapshots = [] |
| 50 | cls.volumes = [] |
Rohit Karajgi | dd47d7e | 2012-07-31 04:11:01 -0700 | [diff] [blame] | 51 | |
Matthew Treinish | 4c41292 | 2013-07-16 15:27:42 -0400 | [diff] [blame] | 52 | cls.volumes_client.keystone_auth(cls.os.username, |
| 53 | cls.os.password, |
| 54 | cls.os.auth_url, |
| 55 | cls.volumes_client.service, |
| 56 | cls.os.tenant_name) |
Rohit Karajgi | dd47d7e | 2012-07-31 04:11:01 -0700 | [diff] [blame] | 57 | |
| 58 | @classmethod |
Rohit Karajgi | dd47d7e | 2012-07-31 04:11:01 -0700 | [diff] [blame] | 59 | def tearDownClass(cls): |
Attila Fazekas | 36b1fcf | 2013-01-31 16:41:04 +0100 | [diff] [blame] | 60 | cls.clear_snapshots() |
| 61 | cls.clear_volumes() |
Ryan Hsu | 6c4bb3d | 2013-10-21 21:22:50 -0700 | [diff] [blame] | 62 | cls.clear_isolated_creds() |
Matthew Treinish | b86cda9 | 2013-07-29 11:22:23 -0400 | [diff] [blame] | 63 | super(BaseVolumeTest, cls).tearDownClass() |
Rohit Karajgi | dd47d7e | 2012-07-31 04:11:01 -0700 | [diff] [blame] | 64 | |
Attila Fazekas | 36b1fcf | 2013-01-31 16:41:04 +0100 | [diff] [blame] | 65 | @classmethod |
| 66 | def create_snapshot(cls, volume_id=1, **kwargs): |
| 67 | """Wrapper utility that returns a test snapshot.""" |
| 68 | resp, snapshot = cls.snapshots_client.create_snapshot(volume_id, |
| 69 | **kwargs) |
| 70 | assert 200 == resp.status |
Giulio Fidente | 02f4298 | 2013-06-17 16:25:56 +0200 | [diff] [blame] | 71 | cls.snapshots.append(snapshot) |
Attila Fazekas | 36b1fcf | 2013-01-31 16:41:04 +0100 | [diff] [blame] | 72 | cls.snapshots_client.wait_for_snapshot_status(snapshot['id'], |
| 73 | 'available') |
Attila Fazekas | 36b1fcf | 2013-01-31 16:41:04 +0100 | [diff] [blame] | 74 | return snapshot |
| 75 | |
Attila Fazekas | f7f34f9 | 2013-08-01 17:01:44 +0200 | [diff] [blame] | 76 | # NOTE(afazekas): these create_* and clean_* could be defined |
Attila Fazekas | 36b1fcf | 2013-01-31 16:41:04 +0100 | [diff] [blame] | 77 | # only in a single location in the source, and could be more general. |
| 78 | |
| 79 | @classmethod |
| 80 | def create_volume(cls, size=1, **kwargs): |
Sean Dague | f237ccb | 2013-01-04 15:19:14 -0500 | [diff] [blame] | 81 | """Wrapper utility that returns a test volume.""" |
Attila Fazekas | 36b1fcf | 2013-01-31 16:41:04 +0100 | [diff] [blame] | 82 | resp, volume = cls.volumes_client.create_volume(size, **kwargs) |
| 83 | assert 200 == resp.status |
Attila Fazekas | 36b1fcf | 2013-01-31 16:41:04 +0100 | [diff] [blame] | 84 | cls.volumes.append(volume) |
Giulio Fidente | 02f4298 | 2013-06-17 16:25:56 +0200 | [diff] [blame] | 85 | cls.volumes_client.wait_for_volume_status(volume['id'], 'available') |
Rohit Karajgi | dd47d7e | 2012-07-31 04:11:01 -0700 | [diff] [blame] | 86 | return volume |
| 87 | |
Attila Fazekas | 36b1fcf | 2013-01-31 16:41:04 +0100 | [diff] [blame] | 88 | @classmethod |
| 89 | def clear_volumes(cls): |
| 90 | for volume in cls.volumes: |
| 91 | try: |
Giulio Fidente | 26d16ed | 2013-04-30 12:05:56 +0200 | [diff] [blame] | 92 | cls.volumes_client.delete_volume(volume['id']) |
Attila Fazekas | 36b1fcf | 2013-01-31 16:41:04 +0100 | [diff] [blame] | 93 | except Exception: |
| 94 | pass |
| 95 | |
| 96 | for volume in cls.volumes: |
| 97 | try: |
Giulio Fidente | 26d16ed | 2013-04-30 12:05:56 +0200 | [diff] [blame] | 98 | cls.volumes_client.wait_for_resource_deletion(volume['id']) |
Attila Fazekas | 36b1fcf | 2013-01-31 16:41:04 +0100 | [diff] [blame] | 99 | except Exception: |
| 100 | pass |
| 101 | |
| 102 | @classmethod |
| 103 | def clear_snapshots(cls): |
| 104 | for snapshot in cls.snapshots: |
| 105 | try: |
| 106 | cls.snapshots_client.delete_snapshot(snapshot['id']) |
| 107 | except Exception: |
| 108 | pass |
| 109 | |
| 110 | for snapshot in cls.snapshots: |
| 111 | try: |
| 112 | cls.snapshots_client.wait_for_resource_deletion(snapshot['id']) |
| 113 | except Exception: |
| 114 | pass |
| 115 | |
Rohit Karajgi | dd47d7e | 2012-07-31 04:11:01 -0700 | [diff] [blame] | 116 | def wait_for(self, condition): |
Sean Dague | f237ccb | 2013-01-04 15:19:14 -0500 | [diff] [blame] | 117 | """Repeatedly calls condition() until a timeout.""" |
Rohit Karajgi | dd47d7e | 2012-07-31 04:11:01 -0700 | [diff] [blame] | 118 | start_time = int(time.time()) |
| 119 | while True: |
| 120 | try: |
| 121 | condition() |
Matthew Treinish | 05d9fb9 | 2012-12-07 16:14:05 -0500 | [diff] [blame] | 122 | except Exception: |
Rohit Karajgi | dd47d7e | 2012-07-31 04:11:01 -0700 | [diff] [blame] | 123 | pass |
| 124 | else: |
| 125 | return |
| 126 | if int(time.time()) - start_time >= self.build_timeout: |
| 127 | condition() |
| 128 | return |
| 129 | time.sleep(self.build_interval) |
James E. Blair | e6d8ee1 | 2013-01-18 21:33:45 +0000 | [diff] [blame] | 130 | |
| 131 | |
Attila Fazekas | 3dcdae1 | 2013-02-14 12:50:04 +0100 | [diff] [blame] | 132 | class BaseVolumeAdminTest(BaseVolumeTest): |
| 133 | """Base test case class for all Volume Admin API tests.""" |
James E. Blair | e6d8ee1 | 2013-01-18 21:33:45 +0000 | [diff] [blame] | 134 | @classmethod |
| 135 | def setUpClass(cls): |
Attila Fazekas | 3dcdae1 | 2013-02-14 12:50:04 +0100 | [diff] [blame] | 136 | super(BaseVolumeAdminTest, cls).setUpClass() |
| 137 | cls.adm_user = cls.config.identity.admin_username |
| 138 | cls.adm_pass = cls.config.identity.admin_password |
| 139 | cls.adm_tenant = cls.config.identity.admin_tenant_name |
| 140 | if not all((cls.adm_user, cls.adm_pass, cls.adm_tenant)): |
| 141 | msg = ("Missing Volume Admin API credentials " |
| 142 | "in configuration.") |
| 143 | raise cls.skipException(msg) |
Matthew Treinish | 3e04685 | 2013-07-23 16:00:24 -0400 | [diff] [blame] | 144 | if cls.config.compute.allow_tenant_isolation: |
Matthew Treinish | b86cda9 | 2013-07-29 11:22:23 -0400 | [diff] [blame] | 145 | creds = cls.isolated_creds.get_admin_creds() |
Matthew Treinish | 3e04685 | 2013-07-23 16:00:24 -0400 | [diff] [blame] | 146 | admin_username, admin_tenant_name, admin_password = creds |
| 147 | cls.os_adm = clients.Manager(username=admin_username, |
| 148 | password=admin_password, |
| 149 | tenant_name=admin_tenant_name, |
| 150 | interface=cls._interface) |
| 151 | else: |
| 152 | cls.os_adm = clients.AdminManager(interface=cls._interface) |
Attila Fazekas | 3dcdae1 | 2013-02-14 12:50:04 +0100 | [diff] [blame] | 153 | cls.client = cls.os_adm.volume_types_client |
Nayna Patel | 4a5024c | 2013-11-18 07:08:23 +0000 | [diff] [blame] | 154 | cls.hosts_client = cls.os_adm.volume_hosts_client |