ZhiQiang Fan | 39f9722 | 2013-09-20 04:49:44 +0800 | [diff] [blame] | 1 | # Copyright 2012 OpenStack Foundation |
Rohit Karajgi | dd47d7e | 2012-07-31 04:11:01 -0700 | [diff] [blame] | 2 | # All Rights Reserved. |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 5 | # not use this file except in compliance with the License. You may obtain |
| 6 | # a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 12 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 13 | # License for the specific language governing permissions and limitations |
| 14 | # under the License. |
| 15 | |
Matthew Treinish | 481466b | 2012-12-20 17:16:01 -0500 | [diff] [blame] | 16 | from tempest import clients |
Ken'ichi Ohmichi | 5687d55 | 2013-12-26 19:00:12 +0900 | [diff] [blame] | 17 | from tempest.common.utils import data_utils |
Matthew Treinish | 4d352bc | 2014-01-29 18:29:18 +0000 | [diff] [blame] | 18 | from tempest import config |
Matthew Treinish | f4a9b0f | 2013-07-26 16:58:26 -0400 | [diff] [blame] | 19 | from tempest.openstack.common import log as logging |
Attila Fazekas | dc21642 | 2013-01-29 15:12:14 +0100 | [diff] [blame] | 20 | import tempest.test |
Rohit Karajgi | dd47d7e | 2012-07-31 04:11:01 -0700 | [diff] [blame] | 21 | |
Matthew Treinish | 4d352bc | 2014-01-29 18:29:18 +0000 | [diff] [blame] | 22 | CONF = config.CONF |
| 23 | |
Rohit Karajgi | dd47d7e | 2012-07-31 04:11:01 -0700 | [diff] [blame] | 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): |
Sylvain Afchain | 11b99d0 | 2014-01-16 00:42:33 +0100 | [diff] [blame] | 33 | cls.set_network_resources() |
Attila Fazekas | f86fa31 | 2013-07-30 19:56:39 +0200 | [diff] [blame] | 34 | super(BaseVolumeTest, cls).setUpClass() |
Rohit Karajgi | dd47d7e | 2012-07-31 04:11:01 -0700 | [diff] [blame] | 35 | |
Matthew Treinish | 4d352bc | 2014-01-29 18:29:18 +0000 | [diff] [blame] | 36 | if not CONF.service_available.cinder: |
Matthew Treinish | 4c41292 | 2013-07-16 15:27:42 -0400 | [diff] [blame] | 37 | skip_msg = ("%s skipped as Cinder is not available" % cls.__name__) |
| 38 | raise cls.skipException(skip_msg) |
| 39 | |
Zhi Kun Liu | bb363a2 | 2013-11-28 18:47:39 +0800 | [diff] [blame] | 40 | cls.os = cls.get_client_manager() |
Rohit Karajgi | dd47d7e | 2012-07-31 04:11:01 -0700 | [diff] [blame] | 41 | |
Zhi Kun Liu | bb363a2 | 2013-11-28 18:47:39 +0800 | [diff] [blame] | 42 | cls.servers_client = cls.os.servers_client |
Matthew Treinish | 4d352bc | 2014-01-29 18:29:18 +0000 | [diff] [blame] | 43 | cls.image_ref = CONF.compute.image_ref |
| 44 | cls.flavor_ref = CONF.compute.flavor_ref |
| 45 | cls.build_interval = CONF.volume.build_interval |
| 46 | cls.build_timeout = CONF.volume.build_timeout |
Attila Fazekas | 36b1fcf | 2013-01-31 16:41:04 +0100 | [diff] [blame] | 47 | cls.snapshots = [] |
| 48 | cls.volumes = [] |
Rohit Karajgi | dd47d7e | 2012-07-31 04:11:01 -0700 | [diff] [blame] | 49 | |
Rohit Karajgi | dd47d7e | 2012-07-31 04:11:01 -0700 | [diff] [blame] | 50 | @classmethod |
Rohit Karajgi | dd47d7e | 2012-07-31 04:11:01 -0700 | [diff] [blame] | 51 | def tearDownClass(cls): |
Attila Fazekas | 36b1fcf | 2013-01-31 16:41:04 +0100 | [diff] [blame] | 52 | cls.clear_snapshots() |
| 53 | cls.clear_volumes() |
Ryan Hsu | 6c4bb3d | 2013-10-21 21:22:50 -0700 | [diff] [blame] | 54 | cls.clear_isolated_creds() |
Matthew Treinish | b86cda9 | 2013-07-29 11:22:23 -0400 | [diff] [blame] | 55 | super(BaseVolumeTest, cls).tearDownClass() |
Rohit Karajgi | dd47d7e | 2012-07-31 04:11:01 -0700 | [diff] [blame] | 56 | |
Attila Fazekas | 36b1fcf | 2013-01-31 16:41:04 +0100 | [diff] [blame] | 57 | @classmethod |
| 58 | def create_snapshot(cls, volume_id=1, **kwargs): |
| 59 | """Wrapper utility that returns a test snapshot.""" |
| 60 | resp, snapshot = cls.snapshots_client.create_snapshot(volume_id, |
| 61 | **kwargs) |
| 62 | assert 200 == resp.status |
Giulio Fidente | 02f4298 | 2013-06-17 16:25:56 +0200 | [diff] [blame] | 63 | cls.snapshots.append(snapshot) |
Attila Fazekas | 36b1fcf | 2013-01-31 16:41:04 +0100 | [diff] [blame] | 64 | cls.snapshots_client.wait_for_snapshot_status(snapshot['id'], |
| 65 | 'available') |
Attila Fazekas | 36b1fcf | 2013-01-31 16:41:04 +0100 | [diff] [blame] | 66 | return snapshot |
| 67 | |
Attila Fazekas | f7f34f9 | 2013-08-01 17:01:44 +0200 | [diff] [blame] | 68 | # NOTE(afazekas): these create_* and clean_* could be defined |
Attila Fazekas | 36b1fcf | 2013-01-31 16:41:04 +0100 | [diff] [blame] | 69 | # only in a single location in the source, and could be more general. |
| 70 | |
| 71 | @classmethod |
Attila Fazekas | 36b1fcf | 2013-01-31 16:41:04 +0100 | [diff] [blame] | 72 | def clear_volumes(cls): |
| 73 | for volume in cls.volumes: |
| 74 | try: |
Giulio Fidente | 26d16ed | 2013-04-30 12:05:56 +0200 | [diff] [blame] | 75 | cls.volumes_client.delete_volume(volume['id']) |
Attila Fazekas | 36b1fcf | 2013-01-31 16:41:04 +0100 | [diff] [blame] | 76 | except Exception: |
| 77 | pass |
| 78 | |
| 79 | for volume in cls.volumes: |
| 80 | try: |
Giulio Fidente | 26d16ed | 2013-04-30 12:05:56 +0200 | [diff] [blame] | 81 | cls.volumes_client.wait_for_resource_deletion(volume['id']) |
Attila Fazekas | 36b1fcf | 2013-01-31 16:41:04 +0100 | [diff] [blame] | 82 | except Exception: |
| 83 | pass |
| 84 | |
| 85 | @classmethod |
| 86 | def clear_snapshots(cls): |
| 87 | for snapshot in cls.snapshots: |
| 88 | try: |
| 89 | cls.snapshots_client.delete_snapshot(snapshot['id']) |
| 90 | except Exception: |
| 91 | pass |
| 92 | |
| 93 | for snapshot in cls.snapshots: |
| 94 | try: |
| 95 | cls.snapshots_client.wait_for_resource_deletion(snapshot['id']) |
| 96 | except Exception: |
| 97 | pass |
| 98 | |
James E. Blair | e6d8ee1 | 2013-01-18 21:33:45 +0000 | [diff] [blame] | 99 | |
Zhi Kun Liu | bb363a2 | 2013-11-28 18:47:39 +0800 | [diff] [blame] | 100 | class BaseVolumeV1Test(BaseVolumeTest): |
| 101 | @classmethod |
| 102 | def setUpClass(cls): |
Matthew Treinish | 4d352bc | 2014-01-29 18:29:18 +0000 | [diff] [blame] | 103 | if not CONF.volume_feature_enabled.api_v1: |
Zhi Kun Liu | bb363a2 | 2013-11-28 18:47:39 +0800 | [diff] [blame] | 104 | msg = "Volume API v1 not supported" |
| 105 | raise cls.skipException(msg) |
| 106 | super(BaseVolumeV1Test, cls).setUpClass() |
Zhi Kun Liu | 02a9906 | 2014-01-02 19:00:08 +0800 | [diff] [blame] | 107 | cls.snapshots_client = cls.os.snapshots_client |
Zhi Kun Liu | bb363a2 | 2013-11-28 18:47:39 +0800 | [diff] [blame] | 108 | cls.volumes_client = cls.os.volumes_client |
Giulio Fidente | 74b08ad | 2014-01-18 04:02:51 +0100 | [diff] [blame] | 109 | cls.backups_client = cls.os.backups_client |
Zhi Kun Liu | 02a9906 | 2014-01-02 19:00:08 +0800 | [diff] [blame] | 110 | cls.volumes_extension_client = cls.os.volumes_extension_client |
Zhi Kun Liu | bb363a2 | 2013-11-28 18:47:39 +0800 | [diff] [blame] | 111 | |
Zhi Kun Liu | 8cc3c84 | 2014-01-07 10:44:34 +0800 | [diff] [blame] | 112 | @classmethod |
| 113 | def create_volume(cls, size=1, **kwargs): |
| 114 | """Wrapper utility that returns a test volume.""" |
| 115 | vol_name = data_utils.rand_name('Volume') |
| 116 | resp, volume = cls.volumes_client.create_volume(size, |
| 117 | display_name=vol_name, |
| 118 | **kwargs) |
| 119 | assert 200 == resp.status |
| 120 | cls.volumes.append(volume) |
| 121 | cls.volumes_client.wait_for_volume_status(volume['id'], 'available') |
| 122 | return volume |
| 123 | |
Zhi Kun Liu | bb363a2 | 2013-11-28 18:47:39 +0800 | [diff] [blame] | 124 | |
| 125 | class BaseVolumeV1AdminTest(BaseVolumeV1Test): |
Attila Fazekas | 3dcdae1 | 2013-02-14 12:50:04 +0100 | [diff] [blame] | 126 | """Base test case class for all Volume Admin API tests.""" |
James E. Blair | e6d8ee1 | 2013-01-18 21:33:45 +0000 | [diff] [blame] | 127 | @classmethod |
| 128 | def setUpClass(cls): |
Zhi Kun Liu | bb363a2 | 2013-11-28 18:47:39 +0800 | [diff] [blame] | 129 | super(BaseVolumeV1AdminTest, cls).setUpClass() |
Matthew Treinish | 4d352bc | 2014-01-29 18:29:18 +0000 | [diff] [blame] | 130 | cls.adm_user = CONF.identity.admin_username |
| 131 | cls.adm_pass = CONF.identity.admin_password |
| 132 | cls.adm_tenant = CONF.identity.admin_tenant_name |
Attila Fazekas | 3dcdae1 | 2013-02-14 12:50:04 +0100 | [diff] [blame] | 133 | if not all((cls.adm_user, cls.adm_pass, cls.adm_tenant)): |
| 134 | msg = ("Missing Volume Admin API credentials " |
| 135 | "in configuration.") |
| 136 | raise cls.skipException(msg) |
Matthew Treinish | 4d352bc | 2014-01-29 18:29:18 +0000 | [diff] [blame] | 137 | if CONF.compute.allow_tenant_isolation: |
Matthew Treinish | b86cda9 | 2013-07-29 11:22:23 -0400 | [diff] [blame] | 138 | creds = cls.isolated_creds.get_admin_creds() |
Matthew Treinish | 3e04685 | 2013-07-23 16:00:24 -0400 | [diff] [blame] | 139 | admin_username, admin_tenant_name, admin_password = creds |
| 140 | cls.os_adm = clients.Manager(username=admin_username, |
| 141 | password=admin_password, |
| 142 | tenant_name=admin_tenant_name, |
| 143 | interface=cls._interface) |
| 144 | else: |
| 145 | cls.os_adm = clients.AdminManager(interface=cls._interface) |
Attila Fazekas | 3dcdae1 | 2013-02-14 12:50:04 +0100 | [diff] [blame] | 146 | cls.client = cls.os_adm.volume_types_client |
Nayna Patel | 4a5024c | 2013-11-18 07:08:23 +0000 | [diff] [blame] | 147 | cls.hosts_client = cls.os_adm.volume_hosts_client |
Sylvain Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 148 | cls.quotas_client = cls.os_adm.volume_quotas_client |
Zhi Kun Liu | 8cc3c84 | 2014-01-07 10:44:34 +0800 | [diff] [blame] | 149 | |
| 150 | |
| 151 | class BaseVolumeV2Test(BaseVolumeTest): |
| 152 | @classmethod |
| 153 | def setUpClass(cls): |
| 154 | if not CONF.volume_feature_enabled.api_v2: |
| 155 | msg = "Volume API v2 not supported" |
| 156 | raise cls.skipException(msg) |
| 157 | super(BaseVolumeV2Test, cls).setUpClass() |
| 158 | cls.volumes_client = cls.os.volumes_v2_client |
| 159 | |
| 160 | @classmethod |
| 161 | def create_volume(cls, size=1, **kwargs): |
| 162 | """Wrapper utility that returns a test volume.""" |
| 163 | vol_name = data_utils.rand_name('Volume') |
| 164 | resp, volume = cls.volumes_client.create_volume(size, |
| 165 | name=vol_name, |
| 166 | **kwargs) |
| 167 | assert 202 == resp.status |
| 168 | cls.volumes.append(volume) |
| 169 | cls.volumes_client.wait_for_volume_status(volume['id'], 'available') |
| 170 | return volume |