ZhiQiang Fan | 39f9722 | 2013-09-20 04:49:44 +0800 | [diff] [blame] | 1 | # Copyright 2012 OpenStack Foundation |
Jay Pipes | 13b479b | 2012-06-11 14:52:27 -0400 | [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 | |
David Kranz | cf0040c | 2012-06-26 09:46:56 -0400 | [diff] [blame] | 16 | import time |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 17 | |
Matthew Treinish | 481466b | 2012-12-20 17:16:01 -0500 | [diff] [blame] | 18 | from tempest import clients |
Masayuki Igawa | 259c113 | 2013-10-31 17:48:44 +0900 | [diff] [blame] | 19 | from tempest.common.utils import data_utils |
Matthew Treinish | b0a78fc | 2014-01-29 16:49:12 +0000 | [diff] [blame] | 20 | from tempest import config |
David Kranz | 3313831 | 2013-09-24 17:09:32 -0400 | [diff] [blame] | 21 | from tempest import exceptions |
Matthew Treinish | 83d97be | 2014-09-19 16:34:54 -0400 | [diff] [blame] | 22 | from tempest.openstack.common import excutils |
Matthew Treinish | f4a9b0f | 2013-07-26 16:58:26 -0400 | [diff] [blame] | 23 | from tempest.openstack.common import log as logging |
Attila Fazekas | dc21642 | 2013-01-29 15:12:14 +0100 | [diff] [blame] | 24 | import tempest.test |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 25 | |
Matthew Treinish | b0a78fc | 2014-01-29 16:49:12 +0000 | [diff] [blame] | 26 | CONF = config.CONF |
Tiago Mello | eda03b5 | 2012-08-22 23:47:29 -0300 | [diff] [blame] | 27 | |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 28 | LOG = logging.getLogger(__name__) |
Daryl Walleck | c725196 | 2012-03-12 17:26:54 -0500 | [diff] [blame] | 29 | |
| 30 | |
Attila Fazekas | dc21642 | 2013-01-29 15:12:14 +0100 | [diff] [blame] | 31 | class BaseComputeTest(tempest.test.BaseTestCase): |
Sean Dague | f237ccb | 2013-01-04 15:19:14 -0500 | [diff] [blame] | 32 | """Base test case class for all Compute API tests.""" |
Daryl Walleck | c725196 | 2012-03-12 17:26:54 -0500 | [diff] [blame] | 33 | |
Ken'ichi Ohmichi | 543a5d4 | 2014-05-02 08:44:15 +0900 | [diff] [blame] | 34 | _api_version = 3 |
Attila Fazekas | 430dae3 | 2013-10-17 15:19:32 +0200 | [diff] [blame] | 35 | force_tenant_isolation = False |
Chris Yeoh | 8a79b9d | 2013-01-18 19:32:47 +1030 | [diff] [blame] | 36 | |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 37 | @classmethod |
Andrea Frittoli | 50bb80d | 2014-09-15 12:34:27 +0100 | [diff] [blame] | 38 | def resource_setup(cls): |
Ken'ichi Ohmichi | 5fd4ecf | 2014-04-25 13:38:15 +0900 | [diff] [blame] | 39 | cls.set_network_resources() |
Andrea Frittoli | 50bb80d | 2014-09-15 12:34:27 +0100 | [diff] [blame] | 40 | super(BaseComputeTest, cls).resource_setup() |
Matthew Treinish | 20866a2 | 2014-06-12 14:58:36 -0400 | [diff] [blame] | 41 | if getattr(cls, '_interface', None) == 'xml' and cls._api_version == 2: |
| 42 | if not CONF.compute_feature_enabled.xml_api_v2: |
| 43 | raise cls.skipException('XML API is not enabled') |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 44 | |
Andrea Frittoli | 422fbdf | 2014-03-20 10:05:18 +0000 | [diff] [blame] | 45 | # TODO(andreaf) WE should care also for the alt_manager here |
| 46 | # but only once client lazy load in the manager is done |
Ryan Hsu | 6c4bb3d | 2013-10-21 21:22:50 -0700 | [diff] [blame] | 47 | os = cls.get_client_manager() |
Daryl Walleck | c725196 | 2012-03-12 17:26:54 -0500 | [diff] [blame] | 48 | |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 49 | cls.os = os |
Matthew Treinish | b0a78fc | 2014-01-29 16:49:12 +0000 | [diff] [blame] | 50 | cls.build_interval = CONF.compute.build_interval |
| 51 | cls.build_timeout = CONF.compute.build_timeout |
| 52 | cls.ssh_user = CONF.compute.ssh_user |
| 53 | cls.image_ref = CONF.compute.image_ref |
| 54 | cls.image_ref_alt = CONF.compute.image_ref_alt |
| 55 | cls.flavor_ref = CONF.compute.flavor_ref |
| 56 | cls.flavor_ref_alt = CONF.compute.flavor_ref_alt |
| 57 | cls.image_ssh_user = CONF.compute.image_ssh_user |
| 58 | cls.image_ssh_password = CONF.compute.image_ssh_password |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 59 | cls.servers = [] |
Sean Dague | d62bf1c | 2013-06-05 14:36:25 -0400 | [diff] [blame] | 60 | cls.images = [] |
Matthew Treinish | f7fca6a | 2013-12-09 16:27:23 +0000 | [diff] [blame] | 61 | cls.multi_user = cls.get_multi_user() |
Zhi Kun Liu | 02e7a7b | 2014-01-08 16:08:32 +0800 | [diff] [blame] | 62 | cls.security_groups = [] |
Abhijeet.Jain | 87dd445 | 2014-04-23 15:51:23 +0530 | [diff] [blame] | 63 | cls.server_groups = [] |
Matthew Treinish | f7fca6a | 2013-12-09 16:27:23 +0000 | [diff] [blame] | 64 | |
Ken'ichi Ohmichi | 543a5d4 | 2014-05-02 08:44:15 +0900 | [diff] [blame] | 65 | if cls._api_version == 2: |
| 66 | cls.servers_client = cls.os.servers_client |
| 67 | cls.flavors_client = cls.os.flavors_client |
| 68 | cls.images_client = cls.os.images_client |
| 69 | cls.extensions_client = cls.os.extensions_client |
| 70 | cls.floating_ips_client = cls.os.floating_ips_client |
| 71 | cls.keypairs_client = cls.os.keypairs_client |
| 72 | cls.security_groups_client = cls.os.security_groups_client |
| 73 | cls.quotas_client = cls.os.quotas_client |
Matt Riedemann | 848805f | 2014-06-16 13:23:51 -0700 | [diff] [blame] | 74 | # NOTE(mriedem): os-quota-class-sets is v2 API only |
| 75 | cls.quota_classes_client = cls.os.quota_classes_client |
Ken'ichi Ohmichi | 543a5d4 | 2014-05-02 08:44:15 +0900 | [diff] [blame] | 76 | cls.limits_client = cls.os.limits_client |
| 77 | cls.volumes_extensions_client = cls.os.volumes_extensions_client |
| 78 | cls.volumes_client = cls.os.volumes_client |
| 79 | cls.interfaces_client = cls.os.interfaces_client |
| 80 | cls.fixed_ips_client = cls.os.fixed_ips_client |
| 81 | cls.availability_zone_client = cls.os.availability_zone_client |
| 82 | cls.agents_client = cls.os.agents_client |
| 83 | cls.aggregates_client = cls.os.aggregates_client |
| 84 | cls.services_client = cls.os.services_client |
| 85 | cls.instance_usages_audit_log_client = \ |
| 86 | cls.os.instance_usages_audit_log_client |
| 87 | cls.hypervisor_client = cls.os.hypervisor_client |
| 88 | cls.certificates_client = cls.os.certificates_client |
| 89 | cls.migrations_client = cls.os.migrations_client |
Ghanshyam | 9d9201d | 2014-04-16 19:28:09 +0900 | [diff] [blame] | 90 | cls.security_group_default_rules_client = ( |
| 91 | cls.os.security_group_default_rules_client) |
Ken'ichi Ohmichi | 543a5d4 | 2014-05-02 08:44:15 +0900 | [diff] [blame] | 92 | |
| 93 | elif cls._api_version == 3: |
| 94 | if not CONF.compute_feature_enabled.api_v3: |
| 95 | skip_msg = ("%s skipped as nova v3 api is not available" % |
| 96 | cls.__name__) |
| 97 | raise cls.skipException(skip_msg) |
| 98 | cls.servers_client = cls.os.servers_v3_client |
| 99 | cls.images_client = cls.os.image_client |
| 100 | cls.flavors_client = cls.os.flavors_v3_client |
| 101 | cls.services_client = cls.os.services_v3_client |
| 102 | cls.extensions_client = cls.os.extensions_v3_client |
| 103 | cls.availability_zone_client = cls.os.availability_zone_v3_client |
| 104 | cls.interfaces_client = cls.os.interfaces_v3_client |
| 105 | cls.hypervisor_client = cls.os.hypervisor_v3_client |
| 106 | cls.keypairs_client = cls.os.keypairs_v3_client |
| 107 | cls.volumes_client = cls.os.volumes_client |
| 108 | cls.certificates_client = cls.os.certificates_v3_client |
| 109 | cls.keypairs_client = cls.os.keypairs_v3_client |
| 110 | cls.aggregates_client = cls.os.aggregates_v3_client |
| 111 | cls.hosts_client = cls.os.hosts_v3_client |
| 112 | cls.quotas_client = cls.os.quotas_v3_client |
| 113 | cls.version_client = cls.os.version_v3_client |
| 114 | cls.migrations_client = cls.os.migrations_v3_client |
| 115 | else: |
| 116 | msg = ("Unexpected API version is specified (%s)" % |
| 117 | cls._api_version) |
| 118 | raise exceptions.InvalidConfiguration(message=msg) |
| 119 | |
Matthew Treinish | f7fca6a | 2013-12-09 16:27:23 +0000 | [diff] [blame] | 120 | @classmethod |
| 121 | def get_multi_user(cls): |
| 122 | multi_user = True |
| 123 | # Determine if there are two regular users that can be |
| 124 | # used in testing. If the test cases are allowed to create |
| 125 | # users (config.compute.allow_tenant_isolation is true, |
| 126 | # then we allow multi-user. |
Matthew Treinish | b0a78fc | 2014-01-29 16:49:12 +0000 | [diff] [blame] | 127 | if not CONF.compute.allow_tenant_isolation: |
| 128 | user1 = CONF.identity.username |
| 129 | user2 = CONF.identity.alt_username |
Matthew Treinish | f7fca6a | 2013-12-09 16:27:23 +0000 | [diff] [blame] | 130 | if not user2 or user1 == user2: |
| 131 | multi_user = False |
| 132 | else: |
Matthew Treinish | b0a78fc | 2014-01-29 16:49:12 +0000 | [diff] [blame] | 133 | user2_password = CONF.identity.alt_password |
| 134 | user2_tenant_name = CONF.identity.alt_tenant_name |
Matthew Treinish | f7fca6a | 2013-12-09 16:27:23 +0000 | [diff] [blame] | 135 | if not user2_password or not user2_tenant_name: |
| 136 | msg = ("Alternate user specified but not alternate " |
| 137 | "tenant or password: alt_tenant_name=%s " |
| 138 | "alt_password=%s" |
| 139 | % (user2_tenant_name, user2_password)) |
| 140 | raise exceptions.InvalidConfiguration(msg) |
| 141 | return multi_user |
Daryl Walleck | c725196 | 2012-03-12 17:26:54 -0500 | [diff] [blame] | 142 | |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 143 | @classmethod |
Jay Pipes | 444c3e6 | 2012-10-04 19:26:35 -0400 | [diff] [blame] | 144 | def clear_servers(cls): |
Salvatore | 1422a9a | 2014-10-08 15:53:25 +0200 | [diff] [blame^] | 145 | LOG.debug('Clearing servers: %s', ','.join( |
| 146 | server['id'] for server in cls.servers)) |
Jay Pipes | 444c3e6 | 2012-10-04 19:26:35 -0400 | [diff] [blame] | 147 | for server in cls.servers: |
Dan Smith | 74e7bcb | 2012-08-21 09:18:26 -0700 | [diff] [blame] | 148 | try: |
| 149 | cls.servers_client.delete_server(server['id']) |
Joe Gordon | 0c33579 | 2014-09-23 12:36:11 -0700 | [diff] [blame] | 150 | except exceptions.NotFound: |
| 151 | # Something else already cleaned up the server, nothing to be |
| 152 | # worried about |
Dan Smith | 74e7bcb | 2012-08-21 09:18:26 -0700 | [diff] [blame] | 153 | pass |
Joe Gordon | 0c33579 | 2014-09-23 12:36:11 -0700 | [diff] [blame] | 154 | except Exception: |
| 155 | LOG.exception('Deleting server %s failed' % server['id']) |
Dan Smith | 74e7bcb | 2012-08-21 09:18:26 -0700 | [diff] [blame] | 156 | |
Jay Pipes | 444c3e6 | 2012-10-04 19:26:35 -0400 | [diff] [blame] | 157 | for server in cls.servers: |
Dan Smith | 74e7bcb | 2012-08-21 09:18:26 -0700 | [diff] [blame] | 158 | try: |
| 159 | cls.servers_client.wait_for_server_termination(server['id']) |
| 160 | except Exception: |
Joe Gordon | 0c33579 | 2014-09-23 12:36:11 -0700 | [diff] [blame] | 161 | LOG.exception('Waiting for deletion of server %s failed' |
| 162 | % server['id']) |
Dan Smith | 74e7bcb | 2012-08-21 09:18:26 -0700 | [diff] [blame] | 163 | |
| 164 | @classmethod |
Attila Fazekas | 305e65b | 2013-10-29 13:23:07 +0100 | [diff] [blame] | 165 | def server_check_teardown(cls): |
| 166 | """Checks is the shared server clean enough for subsequent test. |
| 167 | Method will delete the server when it's dirty. |
| 168 | The setUp method is responsible for creating a new server. |
| 169 | Exceptions raised in tearDown class are fails the test case, |
| 170 | This method supposed to use only by tierDown methods, when |
| 171 | the shared server_id is stored in the server_id of the class. |
| 172 | """ |
| 173 | if getattr(cls, 'server_id', None) is not None: |
| 174 | try: |
| 175 | cls.servers_client.wait_for_server_status(cls.server_id, |
| 176 | 'ACTIVE') |
| 177 | except Exception as exc: |
| 178 | LOG.exception(exc) |
| 179 | cls.servers_client.delete_server(cls.server_id) |
| 180 | cls.servers_client.wait_for_server_termination(cls.server_id) |
| 181 | cls.server_id = None |
| 182 | raise |
| 183 | |
| 184 | @classmethod |
Sean Dague | d62bf1c | 2013-06-05 14:36:25 -0400 | [diff] [blame] | 185 | def clear_images(cls): |
Salvatore | 1422a9a | 2014-10-08 15:53:25 +0200 | [diff] [blame^] | 186 | LOG.debug('Clearing images: %s', ','.join(cls.images)) |
Sean Dague | d62bf1c | 2013-06-05 14:36:25 -0400 | [diff] [blame] | 187 | for image_id in cls.images: |
| 188 | try: |
| 189 | cls.images_client.delete_image(image_id) |
David Kranz | 3313831 | 2013-09-24 17:09:32 -0400 | [diff] [blame] | 190 | except exceptions.NotFound: |
| 191 | # The image may have already been deleted which is OK. |
| 192 | pass |
Yair Fried | a039f87 | 2014-01-02 12:11:10 +0200 | [diff] [blame] | 193 | except Exception: |
| 194 | LOG.exception('Exception raised deleting image %s' % image_id) |
Sean Dague | d62bf1c | 2013-06-05 14:36:25 -0400 | [diff] [blame] | 195 | |
| 196 | @classmethod |
Zhi Kun Liu | 02e7a7b | 2014-01-08 16:08:32 +0800 | [diff] [blame] | 197 | def clear_security_groups(cls): |
Salvatore | 1422a9a | 2014-10-08 15:53:25 +0200 | [diff] [blame^] | 198 | LOG.debug('Clearing security groups: %s', ','.join( |
| 199 | str(sg['id']) for sg in cls.security_groups)) |
Zhi Kun Liu | 02e7a7b | 2014-01-08 16:08:32 +0800 | [diff] [blame] | 200 | for sg in cls.security_groups: |
| 201 | try: |
| 202 | resp, body =\ |
| 203 | cls.security_groups_client.delete_security_group(sg['id']) |
| 204 | except exceptions.NotFound: |
| 205 | # The security group may have already been deleted which is OK. |
| 206 | pass |
| 207 | except Exception as exc: |
| 208 | LOG.info('Exception raised deleting security group %s', |
| 209 | sg['id']) |
| 210 | LOG.exception(exc) |
Zhi Kun Liu | 02e7a7b | 2014-01-08 16:08:32 +0800 | [diff] [blame] | 211 | |
| 212 | @classmethod |
Abhijeet.Jain | 87dd445 | 2014-04-23 15:51:23 +0530 | [diff] [blame] | 213 | def clear_server_groups(cls): |
Salvatore | 1422a9a | 2014-10-08 15:53:25 +0200 | [diff] [blame^] | 214 | LOG.debug('Clearing server groups: %s', ','.join(cls.server_groups)) |
Abhijeet.Jain | 87dd445 | 2014-04-23 15:51:23 +0530 | [diff] [blame] | 215 | for server_group_id in cls.server_groups: |
| 216 | try: |
| 217 | cls.client.delete_server_group(server_group_id) |
| 218 | except exceptions.NotFound: |
| 219 | # The server-group may have already been deleted which is OK. |
| 220 | pass |
| 221 | except Exception: |
| 222 | LOG.exception('Exception raised deleting server-group %s', |
| 223 | server_group_id) |
| 224 | |
| 225 | @classmethod |
Andrea Frittoli | 50bb80d | 2014-09-15 12:34:27 +0100 | [diff] [blame] | 226 | def resource_cleanup(cls): |
Sean Dague | d62bf1c | 2013-06-05 14:36:25 -0400 | [diff] [blame] | 227 | cls.clear_images() |
Jay Pipes | 444c3e6 | 2012-10-04 19:26:35 -0400 | [diff] [blame] | 228 | cls.clear_servers() |
Zhi Kun Liu | 02e7a7b | 2014-01-08 16:08:32 +0800 | [diff] [blame] | 229 | cls.clear_security_groups() |
Abhijeet.Jain | 87dd445 | 2014-04-23 15:51:23 +0530 | [diff] [blame] | 230 | cls.clear_server_groups() |
Andrea Frittoli | 50bb80d | 2014-09-15 12:34:27 +0100 | [diff] [blame] | 231 | super(BaseComputeTest, cls).resource_cleanup() |
Rohit Karajgi | dc300b2 | 2012-05-04 08:11:00 -0700 | [diff] [blame] | 232 | |
Jay Pipes | 444c3e6 | 2012-10-04 19:26:35 -0400 | [diff] [blame] | 233 | @classmethod |
Ken'ichi Ohmichi | cfc052e | 2013-10-23 11:50:04 +0900 | [diff] [blame] | 234 | def create_test_server(cls, **kwargs): |
Sean Dague | f237ccb | 2013-01-04 15:19:14 -0500 | [diff] [blame] | 235 | """Wrapper utility that returns a test server.""" |
Masayuki Igawa | 259c113 | 2013-10-31 17:48:44 +0900 | [diff] [blame] | 236 | name = data_utils.rand_name(cls.__name__ + "-instance") |
Sean Dague | 22897e1 | 2013-02-25 17:54:09 -0500 | [diff] [blame] | 237 | if 'name' in kwargs: |
| 238 | name = kwargs.pop('name') |
| 239 | flavor = kwargs.get('flavor', cls.flavor_ref) |
| 240 | image_id = kwargs.get('image_id', cls.image_ref) |
Rohit Karajgi | dc300b2 | 2012-05-04 08:11:00 -0700 | [diff] [blame] | 241 | |
Andrea Frittoli | 938d151 | 2013-05-16 15:42:27 +0100 | [diff] [blame] | 242 | resp, body = cls.servers_client.create_server( |
Sean Dague | 22897e1 | 2013-02-25 17:54:09 -0500 | [diff] [blame] | 243 | name, image_id, flavor, **kwargs) |
Andrea Frittoli | 938d151 | 2013-05-16 15:42:27 +0100 | [diff] [blame] | 244 | |
| 245 | # handle the case of multiple servers |
| 246 | servers = [body] |
| 247 | if 'min_count' in kwargs or 'max_count' in kwargs: |
| 248 | # Get servers created which name match with name param. |
| 249 | r, b = cls.servers_client.list_servers() |
| 250 | servers = [s for s in b['servers'] if s['name'].startswith(name)] |
| 251 | |
Sean Dague | 22897e1 | 2013-02-25 17:54:09 -0500 | [diff] [blame] | 252 | if 'wait_until' in kwargs: |
Andrea Frittoli | 938d151 | 2013-05-16 15:42:27 +0100 | [diff] [blame] | 253 | for server in servers: |
Ken'ichi Ohmichi | 51c8c26 | 2013-12-21 03:30:37 +0900 | [diff] [blame] | 254 | try: |
| 255 | cls.servers_client.wait_for_server_status( |
| 256 | server['id'], kwargs['wait_until']) |
Matthew Treinish | 83d97be | 2014-09-19 16:34:54 -0400 | [diff] [blame] | 257 | except Exception: |
| 258 | with excutils.save_and_reraise_exception(): |
| 259 | if ('preserve_server_on_error' not in kwargs |
| 260 | or kwargs['preserve_server_on_error'] is False): |
| 261 | for server in servers: |
| 262 | try: |
| 263 | cls.servers_client.delete_server( |
| 264 | server['id']) |
| 265 | except Exception: |
| 266 | pass |
Ken'ichi Ohmichi | 51c8c26 | 2013-12-21 03:30:37 +0900 | [diff] [blame] | 267 | |
| 268 | cls.servers.extend(servers) |
Sean Dague | 9b669e3 | 2012-12-13 18:40:08 -0500 | [diff] [blame] | 269 | |
Andrea Frittoli | 938d151 | 2013-05-16 15:42:27 +0100 | [diff] [blame] | 270 | return resp, body |
Sean Dague | 9b669e3 | 2012-12-13 18:40:08 -0500 | [diff] [blame] | 271 | |
Zhi Kun Liu | 02e7a7b | 2014-01-08 16:08:32 +0800 | [diff] [blame] | 272 | @classmethod |
| 273 | def create_security_group(cls, name=None, description=None): |
| 274 | if name is None: |
| 275 | name = data_utils.rand_name(cls.__name__ + "-securitygroup") |
| 276 | if description is None: |
| 277 | description = data_utils.rand_name('description-') |
| 278 | resp, body = \ |
| 279 | cls.security_groups_client.create_security_group(name, |
| 280 | description) |
| 281 | cls.security_groups.append(body) |
| 282 | |
| 283 | return resp, body |
| 284 | |
Abhijeet.Jain | 87dd445 | 2014-04-23 15:51:23 +0530 | [diff] [blame] | 285 | @classmethod |
Ghanshyam | 2a180b8 | 2014-06-16 13:54:22 +0900 | [diff] [blame] | 286 | def create_test_server_group(cls, name="", policy=None): |
Abhijeet.Jain | 87dd445 | 2014-04-23 15:51:23 +0530 | [diff] [blame] | 287 | if not name: |
| 288 | name = data_utils.rand_name(cls.__name__ + "-Server-Group") |
Ghanshyam | 2a180b8 | 2014-06-16 13:54:22 +0900 | [diff] [blame] | 289 | if policy is None: |
Abhijeet.Jain | 87dd445 | 2014-04-23 15:51:23 +0530 | [diff] [blame] | 290 | policy = ['affinity'] |
| 291 | resp, body = cls.servers_client.create_server_group(name, policy) |
David Kranz | da5d4ec | 2014-06-24 16:04:57 -0400 | [diff] [blame] | 292 | cls.server_groups.append(body['id']) |
Abhijeet.Jain | 87dd445 | 2014-04-23 15:51:23 +0530 | [diff] [blame] | 293 | return resp, body |
| 294 | |
David Kranz | cf0040c | 2012-06-26 09:46:56 -0400 | [diff] [blame] | 295 | def wait_for(self, condition): |
Sean Dague | f237ccb | 2013-01-04 15:19:14 -0500 | [diff] [blame] | 296 | """Repeatedly calls condition() until a timeout.""" |
David Kranz | cf0040c | 2012-06-26 09:46:56 -0400 | [diff] [blame] | 297 | start_time = int(time.time()) |
| 298 | while True: |
| 299 | try: |
| 300 | condition() |
Matthew Treinish | 05d9fb9 | 2012-12-07 16:14:05 -0500 | [diff] [blame] | 301 | except Exception: |
David Kranz | cf0040c | 2012-06-26 09:46:56 -0400 | [diff] [blame] | 302 | pass |
| 303 | else: |
| 304 | return |
| 305 | if int(time.time()) - start_time >= self.build_timeout: |
| 306 | condition() |
| 307 | return |
| 308 | time.sleep(self.build_interval) |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 309 | |
Matt Riedemann | 807d056 | 2014-01-27 12:03:10 -0800 | [diff] [blame] | 310 | @staticmethod |
| 311 | def _delete_volume(volumes_client, volume_id): |
| 312 | """Deletes the given volume and waits for it to be gone.""" |
| 313 | try: |
| 314 | resp, _ = volumes_client.delete_volume(volume_id) |
| 315 | # TODO(mriedem): We should move the wait_for_resource_deletion |
| 316 | # into the delete_volume method as a convenience to the caller. |
| 317 | volumes_client.wait_for_resource_deletion(volume_id) |
| 318 | except exceptions.NotFound: |
| 319 | LOG.warn("Unable to delete volume '%s' since it was not found. " |
| 320 | "Maybe it was already deleted?" % volume_id) |
| 321 | |
Attila Fazekas | 423834d | 2014-03-14 17:33:13 +0100 | [diff] [blame] | 322 | @classmethod |
| 323 | def prepare_instance_network(cls): |
| 324 | if (CONF.compute.ssh_auth_method != 'disabled' and |
| 325 | CONF.compute.ssh_connect_method == 'floating'): |
| 326 | cls.set_network_resources(network=True, subnet=True, router=True, |
| 327 | dhcp=True) |
| 328 | |
ivan-zhu | 8f992be | 2013-07-31 14:56:58 +0800 | [diff] [blame] | 329 | @classmethod |
| 330 | def create_image_from_server(cls, server_id, **kwargs): |
| 331 | """Wrapper utility that returns an image created from the server.""" |
Masayuki Igawa | 259c113 | 2013-10-31 17:48:44 +0900 | [diff] [blame] | 332 | name = data_utils.rand_name(cls.__name__ + "-image") |
ivan-zhu | 8f992be | 2013-07-31 14:56:58 +0800 | [diff] [blame] | 333 | if 'name' in kwargs: |
| 334 | name = kwargs.pop('name') |
| 335 | |
Ken'ichi Ohmichi | 543a5d4 | 2014-05-02 08:44:15 +0900 | [diff] [blame] | 336 | if cls._api_version == 2: |
| 337 | resp, image = cls.images_client.create_image(server_id, name) |
| 338 | elif cls._api_version == 3: |
| 339 | resp, image = cls.servers_client.create_image(server_id, name) |
Masayuki Igawa | 259c113 | 2013-10-31 17:48:44 +0900 | [diff] [blame] | 340 | image_id = data_utils.parse_image_id(resp['location']) |
ivan-zhu | 8f992be | 2013-07-31 14:56:58 +0800 | [diff] [blame] | 341 | cls.images.append(image_id) |
| 342 | |
| 343 | if 'wait_until' in kwargs: |
| 344 | cls.images_client.wait_for_image_status(image_id, |
| 345 | kwargs['wait_until']) |
Ken'ichi Ohmichi | 543a5d4 | 2014-05-02 08:44:15 +0900 | [diff] [blame] | 346 | if cls._api_version == 2: |
| 347 | resp, image = cls.images_client.get_image(image_id) |
| 348 | elif cls._api_version == 3: |
| 349 | resp, image = cls.images_client.get_image_meta(image_id) |
ivan-zhu | 8f992be | 2013-07-31 14:56:58 +0800 | [diff] [blame] | 350 | |
Bob Ball | 621e460 | 2013-12-06 19:53:43 +0000 | [diff] [blame] | 351 | if kwargs['wait_until'] == 'ACTIVE': |
| 352 | if kwargs.get('wait_for_server', True): |
| 353 | cls.servers_client.wait_for_server_status(server_id, |
| 354 | 'ACTIVE') |
ivan-zhu | 8f992be | 2013-07-31 14:56:58 +0800 | [diff] [blame] | 355 | return resp, image |
| 356 | |
| 357 | @classmethod |
Matthew Treinish | 2cd19a4 | 2013-12-02 21:54:42 +0000 | [diff] [blame] | 358 | def rebuild_server(cls, server_id, **kwargs): |
ivan-zhu | 8f992be | 2013-07-31 14:56:58 +0800 | [diff] [blame] | 359 | # Destroy an existing server and creates a new one |
Matthew Treinish | 2cd19a4 | 2013-12-02 21:54:42 +0000 | [diff] [blame] | 360 | if server_id: |
| 361 | try: |
| 362 | cls.servers_client.delete_server(server_id) |
| 363 | cls.servers_client.wait_for_server_termination(server_id) |
Yair Fried | a039f87 | 2014-01-02 12:11:10 +0200 | [diff] [blame] | 364 | except Exception: |
| 365 | LOG.exception('Failed to delete server %s' % server_id) |
Ken'ichi Ohmichi | cfc052e | 2013-10-23 11:50:04 +0900 | [diff] [blame] | 366 | resp, server = cls.create_test_server(wait_until='ACTIVE', **kwargs) |
Ken'ichi Ohmichi | 543a5d4 | 2014-05-02 08:44:15 +0900 | [diff] [blame] | 367 | if cls._api_version == 2: |
| 368 | cls.password = server['adminPass'] |
| 369 | elif cls._api_version == 3: |
| 370 | cls.password = server['admin_password'] |
Matthew Treinish | 2cd19a4 | 2013-12-02 21:54:42 +0000 | [diff] [blame] | 371 | return server['id'] |
ivan-zhu | 8f992be | 2013-07-31 14:56:58 +0800 | [diff] [blame] | 372 | |
Matt Riedemann | 5dc594c | 2014-01-27 11:40:28 -0800 | [diff] [blame] | 373 | @classmethod |
| 374 | def delete_volume(cls, volume_id): |
| 375 | """Deletes the given volume and waits for it to be gone.""" |
Ken'ichi Ohmichi | 543a5d4 | 2014-05-02 08:44:15 +0900 | [diff] [blame] | 376 | if cls._api_version == 2: |
| 377 | cls._delete_volume(cls.volumes_extensions_client, volume_id) |
| 378 | elif cls._api_version == 3: |
| 379 | cls._delete_volume(cls.volumes_client, volume_id) |
| 380 | |
| 381 | |
| 382 | class BaseV2ComputeTest(BaseComputeTest): |
| 383 | _api_version = 2 |
| 384 | _interface = "json" |
Matt Riedemann | 5dc594c | 2014-01-27 11:40:28 -0800 | [diff] [blame] | 385 | |
ivan-zhu | f2b0050 | 2013-10-18 10:06:52 +0800 | [diff] [blame] | 386 | |
Ken'ichi Ohmichi | bcefa3d | 2014-05-09 08:14:05 +0900 | [diff] [blame] | 387 | class BaseV3ComputeTest(BaseComputeTest): |
| 388 | _api_version = 3 |
| 389 | _interface = "json" |
| 390 | |
| 391 | |
| 392 | class BaseComputeAdminTest(BaseComputeTest): |
| 393 | """Base test case class for Compute Admin API tests.""" |
| 394 | _interface = "json" |
ivan-zhu | f2b0050 | 2013-10-18 10:06:52 +0800 | [diff] [blame] | 395 | |
| 396 | @classmethod |
Andrea Frittoli | 50bb80d | 2014-09-15 12:34:27 +0100 | [diff] [blame] | 397 | def resource_setup(cls): |
| 398 | super(BaseComputeAdminTest, cls).resource_setup() |
Matthew Treinish | b0a78fc | 2014-01-29 16:49:12 +0000 | [diff] [blame] | 399 | if (CONF.compute.allow_tenant_isolation or |
Attila Fazekas | 430dae3 | 2013-10-17 15:19:32 +0200 | [diff] [blame] | 400 | cls.force_tenant_isolation is True): |
Matthew Treinish | b86cda9 | 2013-07-29 11:22:23 -0400 | [diff] [blame] | 401 | creds = cls.isolated_creds.get_admin_creds() |
Andrea Frittoli | 422fbdf | 2014-03-20 10:05:18 +0000 | [diff] [blame] | 402 | cls.os_adm = clients.Manager(credentials=creds, |
Matthew Treinish | 47ff791 | 2013-07-22 17:09:55 -0400 | [diff] [blame] | 403 | interface=cls._interface) |
| 404 | else: |
Andrea Frittoli | 422fbdf | 2014-03-20 10:05:18 +0000 | [diff] [blame] | 405 | try: |
| 406 | cls.os_adm = clients.ComputeAdminManager( |
| 407 | interface=cls._interface) |
| 408 | except exceptions.InvalidCredentials: |
| 409 | msg = ("Missing Compute Admin API credentials " |
| 410 | "in configuration.") |
| 411 | raise cls.skipException(msg) |
Ghanshyam | 3150111 | 2014-06-23 13:56:42 +0900 | [diff] [blame] | 412 | if cls._api_version == 2: |
| 413 | cls.availability_zone_admin_client = ( |
| 414 | cls.os_adm.availability_zone_client) |
ivan-zhu | 8f992be | 2013-07-31 14:56:58 +0800 | [diff] [blame] | 415 | |
Ghanshyam | 3150111 | 2014-06-23 13:56:42 +0900 | [diff] [blame] | 416 | else: |
Ken'ichi Ohmichi | bcefa3d | 2014-05-09 08:14:05 +0900 | [diff] [blame] | 417 | cls.servers_admin_client = cls.os_adm.servers_v3_client |
| 418 | cls.services_admin_client = cls.os_adm.services_v3_client |
| 419 | cls.availability_zone_admin_client = \ |
| 420 | cls.os_adm.availability_zone_v3_client |
| 421 | cls.hypervisor_admin_client = cls.os_adm.hypervisor_v3_client |
| 422 | cls.flavors_admin_client = cls.os_adm.flavors_v3_client |
| 423 | cls.aggregates_admin_client = cls.os_adm.aggregates_v3_client |
| 424 | cls.hosts_admin_client = cls.os_adm.hosts_v3_client |
| 425 | cls.quotas_admin_client = cls.os_adm.quotas_v3_client |
| 426 | cls.agents_admin_client = cls.os_adm.agents_v3_client |
| 427 | cls.migrations_admin_client = cls.os_adm.migrations_v3_client |
ivan-zhu | 8f992be | 2013-07-31 14:56:58 +0800 | [diff] [blame] | 428 | |
Ken'ichi Ohmichi | bcefa3d | 2014-05-09 08:14:05 +0900 | [diff] [blame] | 429 | |
| 430 | class BaseV2ComputeAdminTest(BaseComputeAdminTest): |
| 431 | """Base test case class for Compute Admin V2 API tests.""" |
| 432 | _api_version = 2 |
| 433 | |
| 434 | |
| 435 | class BaseV3ComputeAdminTest(BaseComputeAdminTest): |
| 436 | """Base test case class for Compute Admin V3 API tests.""" |
Ken'ichi Ohmichi | 543a5d4 | 2014-05-02 08:44:15 +0900 | [diff] [blame] | 437 | _api_version = 3 |