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