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 | |
Doug Hellmann | 583ce2c | 2015-03-11 14:55:46 +0000 | [diff] [blame] | 18 | from oslo_log import log as logging |
Matthew Treinish | 01472ff | 2015-02-20 17:26:52 -0500 | [diff] [blame] | 19 | from tempest_lib import exceptions as lib_exc |
| 20 | |
Ken'ichi Ohmichi | 4d237e7 | 2015-11-05 06:32:33 +0000 | [diff] [blame] | 21 | from tempest.common import api_version_utils |
Joseph Lanoux | b3e1f87 | 2015-01-30 11:13:07 +0000 | [diff] [blame] | 22 | from tempest.common import compute |
Fei Long Wang | d39431f | 2015-05-14 11:30:48 +1200 | [diff] [blame] | 23 | from tempest.common.utils import data_utils |
Ken'ichi Ohmichi | 8b9c780 | 2015-07-08 05:57:37 +0000 | [diff] [blame] | 24 | from tempest.common import waiters |
Matthew Treinish | b0a78fc | 2014-01-29 16:49:12 +0000 | [diff] [blame] | 25 | from tempest import config |
Attila Fazekas | dc21642 | 2013-01-29 15:12:14 +0100 | [diff] [blame] | 26 | import tempest.test |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 27 | |
Matthew Treinish | b0a78fc | 2014-01-29 16:49:12 +0000 | [diff] [blame] | 28 | CONF = config.CONF |
Tiago Mello | eda03b5 | 2012-08-22 23:47:29 -0300 | [diff] [blame] | 29 | |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 30 | LOG = logging.getLogger(__name__) |
Daryl Walleck | c725196 | 2012-03-12 17:26:54 -0500 | [diff] [blame] | 31 | |
| 32 | |
Ken'ichi Ohmichi | 4d237e7 | 2015-11-05 06:32:33 +0000 | [diff] [blame] | 33 | class BaseV2ComputeTest(api_version_utils.BaseMicroversionTest, |
| 34 | tempest.test.BaseTestCase): |
Sean Dague | f237ccb | 2013-01-04 15:19:14 -0500 | [diff] [blame] | 35 | """Base test case class for all Compute API tests.""" |
Daryl Walleck | c725196 | 2012-03-12 17:26:54 -0500 | [diff] [blame] | 36 | |
Attila Fazekas | 430dae3 | 2013-10-17 15:19:32 +0200 | [diff] [blame] | 37 | force_tenant_isolation = False |
Chris Yeoh | 8a79b9d | 2013-01-18 19:32:47 +1030 | [diff] [blame] | 38 | |
Andrea Frittoli | b21de6c | 2015-02-06 20:12:38 +0000 | [diff] [blame] | 39 | # TODO(andreaf) We should care also for the alt_manager here |
| 40 | # but only once client lazy load in the manager is done |
| 41 | credentials = ['primary'] |
| 42 | |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 43 | @classmethod |
Emily Hugenbruch | e7991d9 | 2014-12-12 16:53:36 +0000 | [diff] [blame] | 44 | def skip_checks(cls): |
Ken'ichi Ohmichi | 02a8ccd | 2015-11-05 06:05:29 +0000 | [diff] [blame] | 45 | super(BaseV2ComputeTest, cls).skip_checks() |
Matthew Treinish | f8ff358 | 2015-08-25 12:41:56 -0400 | [diff] [blame] | 46 | if not CONF.service_available.nova: |
| 47 | raise cls.skipException("Nova is not available") |
Ken'ichi Ohmichi | 4d237e7 | 2015-11-05 06:32:33 +0000 | [diff] [blame] | 48 | cfg_min_version = CONF.compute_feature_enabled.min_microversion |
| 49 | cfg_max_version = CONF.compute_feature_enabled.max_microversion |
| 50 | api_version_utils.check_skip_with_microversion(cls.min_microversion, |
| 51 | cls.max_microversion, |
| 52 | cfg_min_version, |
| 53 | cfg_max_version) |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 54 | |
Emily Hugenbruch | e7991d9 | 2014-12-12 16:53:36 +0000 | [diff] [blame] | 55 | @classmethod |
| 56 | def setup_credentials(cls): |
| 57 | cls.set_network_resources() |
Ken'ichi Ohmichi | 02a8ccd | 2015-11-05 06:05:29 +0000 | [diff] [blame] | 58 | super(BaseV2ComputeTest, cls).setup_credentials() |
Daryl Walleck | c725196 | 2012-03-12 17:26:54 -0500 | [diff] [blame] | 59 | |
Emily Hugenbruch | e7991d9 | 2014-12-12 16:53:36 +0000 | [diff] [blame] | 60 | @classmethod |
| 61 | def setup_clients(cls): |
Ken'ichi Ohmichi | 02a8ccd | 2015-11-05 06:05:29 +0000 | [diff] [blame] | 62 | super(BaseV2ComputeTest, cls).setup_clients() |
Emily Hugenbruch | e7991d9 | 2014-12-12 16:53:36 +0000 | [diff] [blame] | 63 | cls.servers_client = cls.os.servers_client |
Ken'ichi Ohmichi | 7ca54b8 | 2015-07-07 01:10:26 +0000 | [diff] [blame] | 64 | cls.server_groups_client = cls.os.server_groups_client |
Emily Hugenbruch | e7991d9 | 2014-12-12 16:53:36 +0000 | [diff] [blame] | 65 | cls.flavors_client = cls.os.flavors_client |
| 66 | cls.images_client = cls.os.images_client |
| 67 | cls.extensions_client = cls.os.extensions_client |
Ken'ichi Ohmichi | 03af1c5 | 2015-07-13 00:28:05 +0000 | [diff] [blame] | 68 | cls.floating_ip_pools_client = cls.os.floating_ip_pools_client |
John Warren | e74890a | 2015-11-11 15:18:01 -0500 | [diff] [blame] | 69 | cls.floating_ips_client = cls.os.compute_floating_ips_client |
Emily Hugenbruch | e7991d9 | 2014-12-12 16:53:36 +0000 | [diff] [blame] | 70 | cls.keypairs_client = cls.os.keypairs_client |
Ken'ichi Ohmichi | 685cd17 | 2015-07-13 01:29:57 +0000 | [diff] [blame] | 71 | cls.security_group_rules_client = cls.os.security_group_rules_client |
John Warren | f234551 | 2015-12-10 13:39:30 -0500 | [diff] [blame^] | 72 | cls.security_groups_client = cls.os.compute_security_groups_client |
Emily Hugenbruch | e7991d9 | 2014-12-12 16:53:36 +0000 | [diff] [blame] | 73 | cls.quotas_client = cls.os.quotas_client |
Emily Hugenbruch | e7991d9 | 2014-12-12 16:53:36 +0000 | [diff] [blame] | 74 | cls.quota_classes_client = cls.os.quota_classes_client |
John Warren | 9487a18 | 2015-09-14 18:12:56 -0400 | [diff] [blame] | 75 | cls.compute_networks_client = cls.os.compute_networks_client |
Emily Hugenbruch | e7991d9 | 2014-12-12 16:53:36 +0000 | [diff] [blame] | 76 | cls.limits_client = cls.os.limits_client |
| 77 | cls.volumes_extensions_client = cls.os.volumes_extensions_client |
Gaozexu | b9c9d6e | 2015-09-10 17:08:04 +0800 | [diff] [blame] | 78 | cls.snapshots_extensions_client = cls.os.snapshots_extensions_client |
Emily Hugenbruch | e7991d9 | 2014-12-12 16:53:36 +0000 | [diff] [blame] | 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 |
| 90 | cls.security_group_default_rules_client = ( |
| 91 | cls.os.security_group_default_rules_client) |
Ken'ichi Ohmichi | 2b6012b | 2015-09-03 01:56:19 +0000 | [diff] [blame] | 92 | cls.versions_client = cls.os.compute_versions_client |
Emily Hugenbruch | e7991d9 | 2014-12-12 16:53:36 +0000 | [diff] [blame] | 93 | |
Ivan Kolodyazhny | bcfc32e | 2015-08-06 13:31:36 +0300 | [diff] [blame] | 94 | if CONF.volume_feature_enabled.api_v1: |
| 95 | cls.volumes_client = cls.os.volumes_client |
| 96 | else: |
| 97 | cls.volumes_client = cls.os.volumes_v2_client |
| 98 | |
Emily Hugenbruch | e7991d9 | 2014-12-12 16:53:36 +0000 | [diff] [blame] | 99 | @classmethod |
| 100 | def resource_setup(cls): |
Ken'ichi Ohmichi | 02a8ccd | 2015-11-05 06:05:29 +0000 | [diff] [blame] | 101 | super(BaseV2ComputeTest, cls).resource_setup() |
Matthew Treinish | b0a78fc | 2014-01-29 16:49:12 +0000 | [diff] [blame] | 102 | cls.build_interval = CONF.compute.build_interval |
| 103 | cls.build_timeout = CONF.compute.build_timeout |
| 104 | cls.ssh_user = CONF.compute.ssh_user |
| 105 | cls.image_ref = CONF.compute.image_ref |
| 106 | cls.image_ref_alt = CONF.compute.image_ref_alt |
| 107 | cls.flavor_ref = CONF.compute.flavor_ref |
| 108 | cls.flavor_ref_alt = CONF.compute.flavor_ref_alt |
| 109 | cls.image_ssh_user = CONF.compute.image_ssh_user |
| 110 | cls.image_ssh_password = CONF.compute.image_ssh_password |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 111 | cls.servers = [] |
Sean Dague | d62bf1c | 2013-06-05 14:36:25 -0400 | [diff] [blame] | 112 | cls.images = [] |
Zhi Kun Liu | 02e7a7b | 2014-01-08 16:08:32 +0800 | [diff] [blame] | 113 | cls.security_groups = [] |
Abhijeet.Jain | 87dd445 | 2014-04-23 15:51:23 +0530 | [diff] [blame] | 114 | cls.server_groups = [] |
Matthew Treinish | f7fca6a | 2013-12-09 16:27:23 +0000 | [diff] [blame] | 115 | |
Emily Hugenbruch | e7991d9 | 2014-12-12 16:53:36 +0000 | [diff] [blame] | 116 | @classmethod |
| 117 | def resource_cleanup(cls): |
| 118 | cls.clear_images() |
| 119 | cls.clear_servers() |
| 120 | cls.clear_security_groups() |
| 121 | cls.clear_server_groups() |
Ken'ichi Ohmichi | 02a8ccd | 2015-11-05 06:05:29 +0000 | [diff] [blame] | 122 | super(BaseV2ComputeTest, cls).resource_cleanup() |
Ken'ichi Ohmichi | 543a5d4 | 2014-05-02 08:44:15 +0900 | [diff] [blame] | 123 | |
Matthew Treinish | f7fca6a | 2013-12-09 16:27:23 +0000 | [diff] [blame] | 124 | @classmethod |
Jay Pipes | 444c3e6 | 2012-10-04 19:26:35 -0400 | [diff] [blame] | 125 | def clear_servers(cls): |
Salvatore | 1422a9a | 2014-10-08 15:53:25 +0200 | [diff] [blame] | 126 | LOG.debug('Clearing servers: %s', ','.join( |
| 127 | server['id'] for server in cls.servers)) |
Jay Pipes | 444c3e6 | 2012-10-04 19:26:35 -0400 | [diff] [blame] | 128 | for server in cls.servers: |
Dan Smith | 74e7bcb | 2012-08-21 09:18:26 -0700 | [diff] [blame] | 129 | try: |
| 130 | cls.servers_client.delete_server(server['id']) |
Masayuki Igawa | bfa0760 | 2015-01-20 18:47:17 +0900 | [diff] [blame] | 131 | except lib_exc.NotFound: |
Joe Gordon | 0c33579 | 2014-09-23 12:36:11 -0700 | [diff] [blame] | 132 | # Something else already cleaned up the server, nothing to be |
| 133 | # worried about |
Dan Smith | 74e7bcb | 2012-08-21 09:18:26 -0700 | [diff] [blame] | 134 | pass |
Joe Gordon | 0c33579 | 2014-09-23 12:36:11 -0700 | [diff] [blame] | 135 | except Exception: |
| 136 | LOG.exception('Deleting server %s failed' % server['id']) |
Dan Smith | 74e7bcb | 2012-08-21 09:18:26 -0700 | [diff] [blame] | 137 | |
Jay Pipes | 444c3e6 | 2012-10-04 19:26:35 -0400 | [diff] [blame] | 138 | for server in cls.servers: |
Dan Smith | 74e7bcb | 2012-08-21 09:18:26 -0700 | [diff] [blame] | 139 | try: |
Ken'ichi Ohmichi | e91a0c6 | 2015-08-13 02:09:16 +0000 | [diff] [blame] | 140 | waiters.wait_for_server_termination(cls.servers_client, |
| 141 | server['id']) |
Dan Smith | 74e7bcb | 2012-08-21 09:18:26 -0700 | [diff] [blame] | 142 | except Exception: |
Joe Gordon | 0c33579 | 2014-09-23 12:36:11 -0700 | [diff] [blame] | 143 | LOG.exception('Waiting for deletion of server %s failed' |
| 144 | % server['id']) |
Dan Smith | 74e7bcb | 2012-08-21 09:18:26 -0700 | [diff] [blame] | 145 | |
| 146 | @classmethod |
Attila Fazekas | 305e65b | 2013-10-29 13:23:07 +0100 | [diff] [blame] | 147 | def server_check_teardown(cls): |
| 148 | """Checks is the shared server clean enough for subsequent test. |
Ken'ichi Ohmichi | 88363cb | 2015-11-19 08:00:54 +0000 | [diff] [blame] | 149 | |
Attila Fazekas | 305e65b | 2013-10-29 13:23:07 +0100 | [diff] [blame] | 150 | Method will delete the server when it's dirty. |
| 151 | The setUp method is responsible for creating a new server. |
| 152 | Exceptions raised in tearDown class are fails the test case, |
Marian Horban | 6afb023 | 2015-11-10 22:47:12 -0500 | [diff] [blame] | 153 | This method supposed to use only by tearDown methods, when |
Attila Fazekas | 305e65b | 2013-10-29 13:23:07 +0100 | [diff] [blame] | 154 | the shared server_id is stored in the server_id of the class. |
| 155 | """ |
| 156 | if getattr(cls, 'server_id', None) is not None: |
| 157 | try: |
Ken'ichi Ohmichi | 0eb153c | 2015-07-13 02:18:25 +0000 | [diff] [blame] | 158 | waiters.wait_for_server_status(cls.servers_client, |
| 159 | cls.server_id, 'ACTIVE') |
Attila Fazekas | 305e65b | 2013-10-29 13:23:07 +0100 | [diff] [blame] | 160 | except Exception as exc: |
| 161 | LOG.exception(exc) |
| 162 | cls.servers_client.delete_server(cls.server_id) |
Ken'ichi Ohmichi | e91a0c6 | 2015-08-13 02:09:16 +0000 | [diff] [blame] | 163 | waiters.wait_for_server_termination(cls.servers_client, |
| 164 | cls.server_id) |
Attila Fazekas | 305e65b | 2013-10-29 13:23:07 +0100 | [diff] [blame] | 165 | cls.server_id = None |
| 166 | raise |
| 167 | |
| 168 | @classmethod |
Sean Dague | d62bf1c | 2013-06-05 14:36:25 -0400 | [diff] [blame] | 169 | def clear_images(cls): |
Salvatore | 1422a9a | 2014-10-08 15:53:25 +0200 | [diff] [blame] | 170 | LOG.debug('Clearing images: %s', ','.join(cls.images)) |
Sean Dague | d62bf1c | 2013-06-05 14:36:25 -0400 | [diff] [blame] | 171 | for image_id in cls.images: |
| 172 | try: |
| 173 | cls.images_client.delete_image(image_id) |
Masayuki Igawa | bfa0760 | 2015-01-20 18:47:17 +0900 | [diff] [blame] | 174 | except lib_exc.NotFound: |
David Kranz | 3313831 | 2013-09-24 17:09:32 -0400 | [diff] [blame] | 175 | # The image may have already been deleted which is OK. |
| 176 | pass |
Yair Fried | a039f87 | 2014-01-02 12:11:10 +0200 | [diff] [blame] | 177 | except Exception: |
| 178 | LOG.exception('Exception raised deleting image %s' % image_id) |
Sean Dague | d62bf1c | 2013-06-05 14:36:25 -0400 | [diff] [blame] | 179 | |
| 180 | @classmethod |
Zhi Kun Liu | 02e7a7b | 2014-01-08 16:08:32 +0800 | [diff] [blame] | 181 | def clear_security_groups(cls): |
Salvatore | 1422a9a | 2014-10-08 15:53:25 +0200 | [diff] [blame] | 182 | LOG.debug('Clearing security groups: %s', ','.join( |
| 183 | str(sg['id']) for sg in cls.security_groups)) |
Zhi Kun Liu | 02e7a7b | 2014-01-08 16:08:32 +0800 | [diff] [blame] | 184 | for sg in cls.security_groups: |
| 185 | try: |
David Kranz | 9964b4e | 2015-02-06 15:45:29 -0500 | [diff] [blame] | 186 | cls.security_groups_client.delete_security_group(sg['id']) |
Masayuki Igawa | bfa0760 | 2015-01-20 18:47:17 +0900 | [diff] [blame] | 187 | except lib_exc.NotFound: |
Zhi Kun Liu | 02e7a7b | 2014-01-08 16:08:32 +0800 | [diff] [blame] | 188 | # The security group may have already been deleted which is OK. |
| 189 | pass |
| 190 | except Exception as exc: |
| 191 | LOG.info('Exception raised deleting security group %s', |
| 192 | sg['id']) |
| 193 | LOG.exception(exc) |
Zhi Kun Liu | 02e7a7b | 2014-01-08 16:08:32 +0800 | [diff] [blame] | 194 | |
| 195 | @classmethod |
Abhijeet.Jain | 87dd445 | 2014-04-23 15:51:23 +0530 | [diff] [blame] | 196 | def clear_server_groups(cls): |
Salvatore | 1422a9a | 2014-10-08 15:53:25 +0200 | [diff] [blame] | 197 | LOG.debug('Clearing server groups: %s', ','.join(cls.server_groups)) |
Abhijeet.Jain | 87dd445 | 2014-04-23 15:51:23 +0530 | [diff] [blame] | 198 | for server_group_id in cls.server_groups: |
| 199 | try: |
Ken'ichi Ohmichi | 7ca54b8 | 2015-07-07 01:10:26 +0000 | [diff] [blame] | 200 | cls.server_groups_client.delete_server_group(server_group_id) |
Masayuki Igawa | bfa0760 | 2015-01-20 18:47:17 +0900 | [diff] [blame] | 201 | except lib_exc.NotFound: |
Abhijeet.Jain | 87dd445 | 2014-04-23 15:51:23 +0530 | [diff] [blame] | 202 | # The server-group may have already been deleted which is OK. |
| 203 | pass |
| 204 | except Exception: |
| 205 | LOG.exception('Exception raised deleting server-group %s', |
| 206 | server_group_id) |
| 207 | |
| 208 | @classmethod |
Joe Gordon | 8843f0f | 2015-03-17 15:07:34 -0700 | [diff] [blame] | 209 | def create_test_server(cls, validatable=False, volume_backed=False, |
| 210 | **kwargs): |
Joseph Lanoux | b3e1f87 | 2015-01-30 11:13:07 +0000 | [diff] [blame] | 211 | """Wrapper utility that returns a test server. |
Rohit Karajgi | dc300b2 | 2012-05-04 08:11:00 -0700 | [diff] [blame] | 212 | |
Joseph Lanoux | b3e1f87 | 2015-01-30 11:13:07 +0000 | [diff] [blame] | 213 | This wrapper utility calls the common create test server and |
| 214 | returns a test server. The purpose of this wrapper is to minimize |
| 215 | the impact on the code of the tests already using this |
| 216 | function. |
Joe Gordon | 8843f0f | 2015-03-17 15:07:34 -0700 | [diff] [blame] | 217 | |
| 218 | :param validatable: Whether the server will be pingable or sshable. |
| 219 | :param volume_backed: Whether the instance is volume backed or not. |
Joseph Lanoux | b3e1f87 | 2015-01-30 11:13:07 +0000 | [diff] [blame] | 220 | """ |
| 221 | tenant_network = cls.get_tenant_network() |
| 222 | body, servers = compute.create_test_server( |
| 223 | cls.os, |
| 224 | validatable, |
| 225 | validation_resources=cls.validation_resources, |
| 226 | tenant_network=tenant_network, |
Joe Gordon | 8843f0f | 2015-03-17 15:07:34 -0700 | [diff] [blame] | 227 | volume_backed=volume_backed, |
Joseph Lanoux | b3e1f87 | 2015-01-30 11:13:07 +0000 | [diff] [blame] | 228 | **kwargs) |
Ken'ichi Ohmichi | 51c8c26 | 2013-12-21 03:30:37 +0900 | [diff] [blame] | 229 | |
| 230 | cls.servers.extend(servers) |
Sean Dague | 9b669e3 | 2012-12-13 18:40:08 -0500 | [diff] [blame] | 231 | |
David Kranz | 0fb1429 | 2015-02-11 15:55:20 -0500 | [diff] [blame] | 232 | return body |
Sean Dague | 9b669e3 | 2012-12-13 18:40:08 -0500 | [diff] [blame] | 233 | |
Zhi Kun Liu | 02e7a7b | 2014-01-08 16:08:32 +0800 | [diff] [blame] | 234 | @classmethod |
| 235 | def create_security_group(cls, name=None, description=None): |
| 236 | if name is None: |
| 237 | name = data_utils.rand_name(cls.__name__ + "-securitygroup") |
| 238 | if description is None: |
Ken'ichi Ohmichi | 4937f56 | 2015-03-23 00:15:01 +0000 | [diff] [blame] | 239 | description = data_utils.rand_name('description') |
ghanshyam | b610b77 | 2015-08-24 17:29:38 +0900 | [diff] [blame] | 240 | body = cls.security_groups_client.create_security_group( |
| 241 | name=name, description=description)['security_group'] |
Zhi Kun Liu | 02e7a7b | 2014-01-08 16:08:32 +0800 | [diff] [blame] | 242 | cls.security_groups.append(body) |
| 243 | |
David Kranz | 9964b4e | 2015-02-06 15:45:29 -0500 | [diff] [blame] | 244 | return body |
Zhi Kun Liu | 02e7a7b | 2014-01-08 16:08:32 +0800 | [diff] [blame] | 245 | |
Abhijeet.Jain | 87dd445 | 2014-04-23 15:51:23 +0530 | [diff] [blame] | 246 | @classmethod |
Ghanshyam | 2a180b8 | 2014-06-16 13:54:22 +0900 | [diff] [blame] | 247 | def create_test_server_group(cls, name="", policy=None): |
Abhijeet.Jain | 87dd445 | 2014-04-23 15:51:23 +0530 | [diff] [blame] | 248 | if not name: |
| 249 | name = data_utils.rand_name(cls.__name__ + "-Server-Group") |
Ghanshyam | 2a180b8 | 2014-06-16 13:54:22 +0900 | [diff] [blame] | 250 | if policy is None: |
Abhijeet.Jain | 87dd445 | 2014-04-23 15:51:23 +0530 | [diff] [blame] | 251 | policy = ['affinity'] |
Ken'ichi Ohmichi | 1f36daa | 2015-09-30 01:41:34 +0000 | [diff] [blame] | 252 | body = cls.server_groups_client.create_server_group( |
| 253 | name=name, policies=policy)['server_group'] |
David Kranz | da5d4ec | 2014-06-24 16:04:57 -0400 | [diff] [blame] | 254 | cls.server_groups.append(body['id']) |
David Kranz | ae99b9a | 2015-02-16 13:37:01 -0500 | [diff] [blame] | 255 | return body |
Abhijeet.Jain | 87dd445 | 2014-04-23 15:51:23 +0530 | [diff] [blame] | 256 | |
David Kranz | cf0040c | 2012-06-26 09:46:56 -0400 | [diff] [blame] | 257 | def wait_for(self, condition): |
Sean Dague | f237ccb | 2013-01-04 15:19:14 -0500 | [diff] [blame] | 258 | """Repeatedly calls condition() until a timeout.""" |
David Kranz | cf0040c | 2012-06-26 09:46:56 -0400 | [diff] [blame] | 259 | start_time = int(time.time()) |
| 260 | while True: |
| 261 | try: |
| 262 | condition() |
Matthew Treinish | 05d9fb9 | 2012-12-07 16:14:05 -0500 | [diff] [blame] | 263 | except Exception: |
David Kranz | cf0040c | 2012-06-26 09:46:56 -0400 | [diff] [blame] | 264 | pass |
| 265 | else: |
| 266 | return |
| 267 | if int(time.time()) - start_time >= self.build_timeout: |
| 268 | condition() |
| 269 | return |
| 270 | time.sleep(self.build_interval) |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 271 | |
Matt Riedemann | 807d056 | 2014-01-27 12:03:10 -0800 | [diff] [blame] | 272 | @staticmethod |
| 273 | def _delete_volume(volumes_client, volume_id): |
| 274 | """Deletes the given volume and waits for it to be gone.""" |
| 275 | try: |
Joseph Lanoux | 6809bab | 2014-12-18 14:57:18 +0000 | [diff] [blame] | 276 | volumes_client.delete_volume(volume_id) |
Matt Riedemann | 807d056 | 2014-01-27 12:03:10 -0800 | [diff] [blame] | 277 | # TODO(mriedem): We should move the wait_for_resource_deletion |
| 278 | # into the delete_volume method as a convenience to the caller. |
| 279 | volumes_client.wait_for_resource_deletion(volume_id) |
Masayuki Igawa | bfa0760 | 2015-01-20 18:47:17 +0900 | [diff] [blame] | 280 | except lib_exc.NotFound: |
Matt Riedemann | 807d056 | 2014-01-27 12:03:10 -0800 | [diff] [blame] | 281 | LOG.warn("Unable to delete volume '%s' since it was not found. " |
| 282 | "Maybe it was already deleted?" % volume_id) |
| 283 | |
Attila Fazekas | 423834d | 2014-03-14 17:33:13 +0100 | [diff] [blame] | 284 | @classmethod |
| 285 | def prepare_instance_network(cls): |
Joseph Lanoux | ffe09dd | 2015-03-18 16:45:33 +0000 | [diff] [blame] | 286 | if (CONF.validation.auth_method != 'disabled' and |
| 287 | CONF.validation.connect_method == 'floating'): |
Attila Fazekas | 423834d | 2014-03-14 17:33:13 +0100 | [diff] [blame] | 288 | cls.set_network_resources(network=True, subnet=True, router=True, |
| 289 | dhcp=True) |
| 290 | |
ivan-zhu | 8f992be | 2013-07-31 14:56:58 +0800 | [diff] [blame] | 291 | @classmethod |
| 292 | def create_image_from_server(cls, server_id, **kwargs): |
| 293 | """Wrapper utility that returns an image created from the server.""" |
Masayuki Igawa | 259c113 | 2013-10-31 17:48:44 +0900 | [diff] [blame] | 294 | name = data_utils.rand_name(cls.__name__ + "-image") |
ivan-zhu | 8f992be | 2013-07-31 14:56:58 +0800 | [diff] [blame] | 295 | if 'name' in kwargs: |
| 296 | name = kwargs.pop('name') |
| 297 | |
Ken'ichi Ohmichi | 28f1867 | 2015-07-17 10:00:38 +0000 | [diff] [blame] | 298 | image = cls.images_client.create_image(server_id, name=name) |
David Kranz | a5299eb | 2015-01-15 17:24:05 -0500 | [diff] [blame] | 299 | image_id = data_utils.parse_image_id(image.response['location']) |
ivan-zhu | 8f992be | 2013-07-31 14:56:58 +0800 | [diff] [blame] | 300 | cls.images.append(image_id) |
| 301 | |
| 302 | if 'wait_until' in kwargs: |
Ken'ichi Ohmichi | 8b9c780 | 2015-07-08 05:57:37 +0000 | [diff] [blame] | 303 | waiters.wait_for_image_status(cls.images_client, |
| 304 | image_id, kwargs['wait_until']) |
ghanshyam | 1756e0b | 2015-08-18 19:19:05 +0900 | [diff] [blame] | 305 | image = cls.images_client.show_image(image_id)['image'] |
ivan-zhu | 8f992be | 2013-07-31 14:56:58 +0800 | [diff] [blame] | 306 | |
Bob Ball | 621e460 | 2013-12-06 19:53:43 +0000 | [diff] [blame] | 307 | if kwargs['wait_until'] == 'ACTIVE': |
| 308 | if kwargs.get('wait_for_server', True): |
Ken'ichi Ohmichi | 0eb153c | 2015-07-13 02:18:25 +0000 | [diff] [blame] | 309 | waiters.wait_for_server_status(cls.servers_client, |
| 310 | server_id, 'ACTIVE') |
David Kranz | a5299eb | 2015-01-15 17:24:05 -0500 | [diff] [blame] | 311 | return image |
ivan-zhu | 8f992be | 2013-07-31 14:56:58 +0800 | [diff] [blame] | 312 | |
| 313 | @classmethod |
Joseph Lanoux | ffe09dd | 2015-03-18 16:45:33 +0000 | [diff] [blame] | 314 | def rebuild_server(cls, server_id, validatable=False, **kwargs): |
ivan-zhu | 8f992be | 2013-07-31 14:56:58 +0800 | [diff] [blame] | 315 | # Destroy an existing server and creates a new one |
Matthew Treinish | 2cd19a4 | 2013-12-02 21:54:42 +0000 | [diff] [blame] | 316 | if server_id: |
| 317 | try: |
| 318 | cls.servers_client.delete_server(server_id) |
Ken'ichi Ohmichi | e91a0c6 | 2015-08-13 02:09:16 +0000 | [diff] [blame] | 319 | waiters.wait_for_server_termination(cls.servers_client, |
| 320 | server_id) |
Yair Fried | a039f87 | 2014-01-02 12:11:10 +0200 | [diff] [blame] | 321 | except Exception: |
| 322 | LOG.exception('Failed to delete server %s' % server_id) |
Joseph Lanoux | ffe09dd | 2015-03-18 16:45:33 +0000 | [diff] [blame] | 323 | |
| 324 | server = cls.create_test_server( |
| 325 | validatable, |
| 326 | wait_until='ACTIVE', |
| 327 | **kwargs) |
Ken'ichi Ohmichi | 9f5adf8 | 2014-12-12 04:01:32 +0000 | [diff] [blame] | 328 | cls.password = server['adminPass'] |
Matthew Treinish | 2cd19a4 | 2013-12-02 21:54:42 +0000 | [diff] [blame] | 329 | return server['id'] |
ivan-zhu | 8f992be | 2013-07-31 14:56:58 +0800 | [diff] [blame] | 330 | |
Matt Riedemann | 5dc594c | 2014-01-27 11:40:28 -0800 | [diff] [blame] | 331 | @classmethod |
Jesse Keating | 613b498 | 2015-05-04 15:05:19 -0700 | [diff] [blame] | 332 | def delete_server(cls, server_id): |
| 333 | """Deletes an existing server and waits for it to be gone.""" |
| 334 | try: |
| 335 | cls.servers_client.delete_server(server_id) |
Ken'ichi Ohmichi | e91a0c6 | 2015-08-13 02:09:16 +0000 | [diff] [blame] | 336 | waiters.wait_for_server_termination(cls.servers_client, |
| 337 | server_id) |
Jesse Keating | 613b498 | 2015-05-04 15:05:19 -0700 | [diff] [blame] | 338 | except Exception: |
| 339 | LOG.exception('Failed to delete server %s' % server_id) |
| 340 | |
| 341 | @classmethod |
Matt Riedemann | 5dc594c | 2014-01-27 11:40:28 -0800 | [diff] [blame] | 342 | def delete_volume(cls, volume_id): |
| 343 | """Deletes the given volume and waits for it to be gone.""" |
Ken'ichi Ohmichi | 9f5adf8 | 2014-12-12 04:01:32 +0000 | [diff] [blame] | 344 | cls._delete_volume(cls.volumes_extensions_client, volume_id) |
Ken'ichi Ohmichi | 543a5d4 | 2014-05-02 08:44:15 +0900 | [diff] [blame] | 345 | |
Joseph Lanoux | ffe09dd | 2015-03-18 16:45:33 +0000 | [diff] [blame] | 346 | @classmethod |
| 347 | def get_server_ip(cls, server): |
| 348 | """Get the server fixed or floating IP. |
| 349 | |
| 350 | For the floating IP, the address created by the validation resources |
| 351 | is returned. |
| 352 | For the fixed IP, the server is returned and the current mechanism of |
| 353 | address extraction in the remote_client is followed. |
| 354 | """ |
| 355 | if CONF.validation.connect_method == 'floating': |
| 356 | ip_or_server = cls.validation_resources['floating_ip']['ip'] |
| 357 | elif CONF.validation.connect_method == 'fixed': |
| 358 | ip_or_server = server |
| 359 | return ip_or_server |
| 360 | |
Ken'ichi Ohmichi | 543a5d4 | 2014-05-02 08:44:15 +0900 | [diff] [blame] | 361 | |
Ken'ichi Ohmichi | 02a8ccd | 2015-11-05 06:05:29 +0000 | [diff] [blame] | 362 | class BaseV2ComputeAdminTest(BaseV2ComputeTest): |
Ken'ichi Ohmichi | bcefa3d | 2014-05-09 08:14:05 +0900 | [diff] [blame] | 363 | """Base test case class for Compute Admin API tests.""" |
ivan-zhu | f2b0050 | 2013-10-18 10:06:52 +0800 | [diff] [blame] | 364 | |
Andrea Frittoli | b21de6c | 2015-02-06 20:12:38 +0000 | [diff] [blame] | 365 | credentials = ['primary', 'admin'] |
Emily Hugenbruch | e7991d9 | 2014-12-12 16:53:36 +0000 | [diff] [blame] | 366 | |
| 367 | @classmethod |
| 368 | def setup_clients(cls): |
Ken'ichi Ohmichi | 02a8ccd | 2015-11-05 06:05:29 +0000 | [diff] [blame] | 369 | super(BaseV2ComputeAdminTest, cls).setup_clients() |
Ken'ichi Ohmichi | 9f5adf8 | 2014-12-12 04:01:32 +0000 | [diff] [blame] | 370 | cls.availability_zone_admin_client = ( |
| 371 | cls.os_adm.availability_zone_client) |