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 | |
Ghanshyam | 05049dd | 2016-02-12 17:44:48 +0900 | [diff] [blame] | 20 | from tempest.api.compute import api_microversion_fixture |
Joseph Lanoux | b3e1f87 | 2015-01-30 11:13:07 +0000 | [diff] [blame] | 21 | from tempest.common import compute |
Fei Long Wang | d39431f | 2015-05-14 11:30:48 +1200 | [diff] [blame] | 22 | from tempest.common.utils import data_utils |
Ken'ichi Ohmichi | 8b9c780 | 2015-07-08 05:57:37 +0000 | [diff] [blame] | 23 | from tempest.common import waiters |
Matthew Treinish | b0a78fc | 2014-01-29 16:49:12 +0000 | [diff] [blame] | 24 | from tempest import config |
Sean Dague | 20e9861 | 2016-01-06 14:33:28 -0500 | [diff] [blame] | 25 | from tempest import exceptions |
Ghanshyam | 1f47cf9 | 2016-02-25 04:57:18 +0900 | [diff] [blame] | 26 | from tempest.lib.common import api_version_utils |
Jordan Pittier | 9e227c5 | 2016-02-09 14:35:18 +0100 | [diff] [blame] | 27 | from tempest.lib.common.utils import test_utils |
Andrea Frittoli (andreaf) | db9672e | 2016-02-23 14:07:24 -0500 | [diff] [blame] | 28 | from tempest.lib import exceptions as lib_exc |
Attila Fazekas | dc21642 | 2013-01-29 15:12:14 +0100 | [diff] [blame] | 29 | import tempest.test |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 30 | |
Matthew Treinish | b0a78fc | 2014-01-29 16:49:12 +0000 | [diff] [blame] | 31 | CONF = config.CONF |
Tiago Mello | eda03b5 | 2012-08-22 23:47:29 -0300 | [diff] [blame] | 32 | |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 33 | LOG = logging.getLogger(__name__) |
Daryl Walleck | c725196 | 2012-03-12 17:26:54 -0500 | [diff] [blame] | 34 | |
| 35 | |
Ken'ichi Ohmichi | 4d237e7 | 2015-11-05 06:32:33 +0000 | [diff] [blame] | 36 | class BaseV2ComputeTest(api_version_utils.BaseMicroversionTest, |
| 37 | tempest.test.BaseTestCase): |
Sean Dague | f237ccb | 2013-01-04 15:19:14 -0500 | [diff] [blame] | 38 | """Base test case class for all Compute API tests.""" |
Daryl Walleck | c725196 | 2012-03-12 17:26:54 -0500 | [diff] [blame] | 39 | |
Attila Fazekas | 430dae3 | 2013-10-17 15:19:32 +0200 | [diff] [blame] | 40 | force_tenant_isolation = False |
Chris Yeoh | 8a79b9d | 2013-01-18 19:32:47 +1030 | [diff] [blame] | 41 | |
Andrea Frittoli | b21de6c | 2015-02-06 20:12:38 +0000 | [diff] [blame] | 42 | # TODO(andreaf) We should care also for the alt_manager here |
| 43 | # but only once client lazy load in the manager is done |
| 44 | credentials = ['primary'] |
| 45 | |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 46 | @classmethod |
Emily Hugenbruch | e7991d9 | 2014-12-12 16:53:36 +0000 | [diff] [blame] | 47 | def skip_checks(cls): |
Ken'ichi Ohmichi | 02a8ccd | 2015-11-05 06:05:29 +0000 | [diff] [blame] | 48 | super(BaseV2ComputeTest, cls).skip_checks() |
Matthew Treinish | f8ff358 | 2015-08-25 12:41:56 -0400 | [diff] [blame] | 49 | if not CONF.service_available.nova: |
| 50 | raise cls.skipException("Nova is not available") |
ghanshyam | 2959153 | 2016-03-11 17:12:43 +0900 | [diff] [blame] | 51 | cfg_min_version = CONF.compute.min_microversion |
| 52 | cfg_max_version = CONF.compute.max_microversion |
Ken'ichi Ohmichi | 4d237e7 | 2015-11-05 06:32:33 +0000 | [diff] [blame] | 53 | api_version_utils.check_skip_with_microversion(cls.min_microversion, |
| 54 | cls.max_microversion, |
| 55 | cfg_min_version, |
| 56 | cfg_max_version) |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 57 | |
Emily Hugenbruch | e7991d9 | 2014-12-12 16:53:36 +0000 | [diff] [blame] | 58 | @classmethod |
| 59 | def setup_credentials(cls): |
| 60 | cls.set_network_resources() |
Ken'ichi Ohmichi | 02a8ccd | 2015-11-05 06:05:29 +0000 | [diff] [blame] | 61 | super(BaseV2ComputeTest, cls).setup_credentials() |
Daryl Walleck | c725196 | 2012-03-12 17:26:54 -0500 | [diff] [blame] | 62 | |
Emily Hugenbruch | e7991d9 | 2014-12-12 16:53:36 +0000 | [diff] [blame] | 63 | @classmethod |
| 64 | def setup_clients(cls): |
Ken'ichi Ohmichi | 02a8ccd | 2015-11-05 06:05:29 +0000 | [diff] [blame] | 65 | super(BaseV2ComputeTest, cls).setup_clients() |
Emily Hugenbruch | e7991d9 | 2014-12-12 16:53:36 +0000 | [diff] [blame] | 66 | cls.servers_client = cls.os.servers_client |
Ken'ichi Ohmichi | 7ca54b8 | 2015-07-07 01:10:26 +0000 | [diff] [blame] | 67 | cls.server_groups_client = cls.os.server_groups_client |
Emily Hugenbruch | e7991d9 | 2014-12-12 16:53:36 +0000 | [diff] [blame] | 68 | cls.flavors_client = cls.os.flavors_client |
Ghanshyam | ae76c12 | 2015-12-22 13:41:35 +0900 | [diff] [blame] | 69 | cls.compute_images_client = cls.os.compute_images_client |
Emily Hugenbruch | e7991d9 | 2014-12-12 16:53:36 +0000 | [diff] [blame] | 70 | cls.extensions_client = cls.os.extensions_client |
Ken'ichi Ohmichi | 03af1c5 | 2015-07-13 00:28:05 +0000 | [diff] [blame] | 71 | cls.floating_ip_pools_client = cls.os.floating_ip_pools_client |
John Warren | e74890a | 2015-11-11 15:18:01 -0500 | [diff] [blame] | 72 | cls.floating_ips_client = cls.os.compute_floating_ips_client |
Emily Hugenbruch | e7991d9 | 2014-12-12 16:53:36 +0000 | [diff] [blame] | 73 | cls.keypairs_client = cls.os.keypairs_client |
John Warren | 5cdbf42 | 2016-01-05 12:42:43 -0500 | [diff] [blame] | 74 | cls.security_group_rules_client = ( |
| 75 | cls.os.compute_security_group_rules_client) |
John Warren | f234551 | 2015-12-10 13:39:30 -0500 | [diff] [blame] | 76 | cls.security_groups_client = cls.os.compute_security_groups_client |
Emily Hugenbruch | e7991d9 | 2014-12-12 16:53:36 +0000 | [diff] [blame] | 77 | cls.quotas_client = cls.os.quotas_client |
John Warren | 9487a18 | 2015-09-14 18:12:56 -0400 | [diff] [blame] | 78 | cls.compute_networks_client = cls.os.compute_networks_client |
Emily Hugenbruch | e7991d9 | 2014-12-12 16:53:36 +0000 | [diff] [blame] | 79 | cls.limits_client = cls.os.limits_client |
| 80 | cls.volumes_extensions_client = cls.os.volumes_extensions_client |
Gaozexu | b9c9d6e | 2015-09-10 17:08:04 +0800 | [diff] [blame] | 81 | cls.snapshots_extensions_client = cls.os.snapshots_extensions_client |
Emily Hugenbruch | e7991d9 | 2014-12-12 16:53:36 +0000 | [diff] [blame] | 82 | cls.interfaces_client = cls.os.interfaces_client |
| 83 | cls.fixed_ips_client = cls.os.fixed_ips_client |
| 84 | cls.availability_zone_client = cls.os.availability_zone_client |
| 85 | cls.agents_client = cls.os.agents_client |
| 86 | cls.aggregates_client = cls.os.aggregates_client |
| 87 | cls.services_client = cls.os.services_client |
| 88 | cls.instance_usages_audit_log_client = ( |
| 89 | cls.os.instance_usages_audit_log_client) |
| 90 | cls.hypervisor_client = cls.os.hypervisor_client |
| 91 | cls.certificates_client = cls.os.certificates_client |
| 92 | cls.migrations_client = cls.os.migrations_client |
| 93 | cls.security_group_default_rules_client = ( |
| 94 | cls.os.security_group_default_rules_client) |
Ken'ichi Ohmichi | 2b6012b | 2015-09-03 01:56:19 +0000 | [diff] [blame] | 95 | cls.versions_client = cls.os.compute_versions_client |
Emily Hugenbruch | e7991d9 | 2014-12-12 16:53:36 +0000 | [diff] [blame] | 96 | |
Ivan Kolodyazhny | bcfc32e | 2015-08-06 13:31:36 +0300 | [diff] [blame] | 97 | if CONF.volume_feature_enabled.api_v1: |
| 98 | cls.volumes_client = cls.os.volumes_client |
| 99 | else: |
| 100 | cls.volumes_client = cls.os.volumes_v2_client |
| 101 | |
Emily Hugenbruch | e7991d9 | 2014-12-12 16:53:36 +0000 | [diff] [blame] | 102 | @classmethod |
| 103 | def resource_setup(cls): |
Ken'ichi Ohmichi | 02a8ccd | 2015-11-05 06:05:29 +0000 | [diff] [blame] | 104 | super(BaseV2ComputeTest, cls).resource_setup() |
Ghanshyam | 05049dd | 2016-02-12 17:44:48 +0900 | [diff] [blame] | 105 | cls.request_microversion = ( |
| 106 | api_version_utils.select_request_microversion( |
| 107 | cls.min_microversion, |
ghanshyam | 2959153 | 2016-03-11 17:12:43 +0900 | [diff] [blame] | 108 | CONF.compute.min_microversion)) |
Matthew Treinish | b0a78fc | 2014-01-29 16:49:12 +0000 | [diff] [blame] | 109 | cls.build_interval = CONF.compute.build_interval |
| 110 | cls.build_timeout = CONF.compute.build_timeout |
Matthew Treinish | b0a78fc | 2014-01-29 16:49:12 +0000 | [diff] [blame] | 111 | cls.image_ref = CONF.compute.image_ref |
| 112 | cls.image_ref_alt = CONF.compute.image_ref_alt |
| 113 | cls.flavor_ref = CONF.compute.flavor_ref |
| 114 | cls.flavor_ref_alt = CONF.compute.flavor_ref_alt |
lanoux | 283273b | 2015-12-04 03:01:54 -0800 | [diff] [blame] | 115 | cls.ssh_user = CONF.validation.image_ssh_user |
| 116 | cls.image_ssh_user = CONF.validation.image_ssh_user |
| 117 | cls.image_ssh_password = CONF.validation.image_ssh_password |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 118 | cls.servers = [] |
Sean Dague | d62bf1c | 2013-06-05 14:36:25 -0400 | [diff] [blame] | 119 | cls.images = [] |
Zhi Kun Liu | 02e7a7b | 2014-01-08 16:08:32 +0800 | [diff] [blame] | 120 | cls.security_groups = [] |
Abhijeet.Jain | 87dd445 | 2014-04-23 15:51:23 +0530 | [diff] [blame] | 121 | cls.server_groups = [] |
Matt Riedemann | 342b37c | 2016-09-21 15:38:12 -0400 | [diff] [blame] | 122 | cls.volumes = [] |
Matthew Treinish | f7fca6a | 2013-12-09 16:27:23 +0000 | [diff] [blame] | 123 | |
Emily Hugenbruch | e7991d9 | 2014-12-12 16:53:36 +0000 | [diff] [blame] | 124 | @classmethod |
| 125 | def resource_cleanup(cls): |
| 126 | cls.clear_images() |
| 127 | cls.clear_servers() |
| 128 | cls.clear_security_groups() |
| 129 | cls.clear_server_groups() |
Matt Riedemann | 342b37c | 2016-09-21 15:38:12 -0400 | [diff] [blame] | 130 | cls.clear_volumes() |
Ken'ichi Ohmichi | 02a8ccd | 2015-11-05 06:05:29 +0000 | [diff] [blame] | 131 | super(BaseV2ComputeTest, cls).resource_cleanup() |
Ken'ichi Ohmichi | 543a5d4 | 2014-05-02 08:44:15 +0900 | [diff] [blame] | 132 | |
Matthew Treinish | f7fca6a | 2013-12-09 16:27:23 +0000 | [diff] [blame] | 133 | @classmethod |
Jay Pipes | 444c3e6 | 2012-10-04 19:26:35 -0400 | [diff] [blame] | 134 | def clear_servers(cls): |
Salvatore | 1422a9a | 2014-10-08 15:53:25 +0200 | [diff] [blame] | 135 | LOG.debug('Clearing servers: %s', ','.join( |
| 136 | server['id'] for server in cls.servers)) |
Jay Pipes | 444c3e6 | 2012-10-04 19:26:35 -0400 | [diff] [blame] | 137 | for server in cls.servers: |
Dan Smith | 74e7bcb | 2012-08-21 09:18:26 -0700 | [diff] [blame] | 138 | try: |
Jordan Pittier | 9e227c5 | 2016-02-09 14:35:18 +0100 | [diff] [blame] | 139 | test_utils.call_and_ignore_notfound_exc( |
| 140 | cls.servers_client.delete_server, server['id']) |
Joe Gordon | 0c33579 | 2014-09-23 12:36:11 -0700 | [diff] [blame] | 141 | except Exception: |
Jordan Pittier | 525ec71 | 2016-12-07 17:51:26 +0100 | [diff] [blame] | 142 | LOG.exception('Deleting server %s failed', server['id']) |
Dan Smith | 74e7bcb | 2012-08-21 09:18:26 -0700 | [diff] [blame] | 143 | |
Jay Pipes | 444c3e6 | 2012-10-04 19:26:35 -0400 | [diff] [blame] | 144 | for server in cls.servers: |
Dan Smith | 74e7bcb | 2012-08-21 09:18:26 -0700 | [diff] [blame] | 145 | try: |
Ken'ichi Ohmichi | e91a0c6 | 2015-08-13 02:09:16 +0000 | [diff] [blame] | 146 | waiters.wait_for_server_termination(cls.servers_client, |
| 147 | server['id']) |
Dan Smith | 74e7bcb | 2012-08-21 09:18:26 -0700 | [diff] [blame] | 148 | except Exception: |
Jordan Pittier | 525ec71 | 2016-12-07 17:51:26 +0100 | [diff] [blame] | 149 | LOG.exception('Waiting for deletion of server %s failed', |
| 150 | server['id']) |
Dan Smith | 74e7bcb | 2012-08-21 09:18:26 -0700 | [diff] [blame] | 151 | |
| 152 | @classmethod |
Attila Fazekas | 305e65b | 2013-10-29 13:23:07 +0100 | [diff] [blame] | 153 | def server_check_teardown(cls): |
| 154 | """Checks is the shared server clean enough for subsequent test. |
Ken'ichi Ohmichi | 88363cb | 2015-11-19 08:00:54 +0000 | [diff] [blame] | 155 | |
Attila Fazekas | 305e65b | 2013-10-29 13:23:07 +0100 | [diff] [blame] | 156 | Method will delete the server when it's dirty. |
| 157 | The setUp method is responsible for creating a new server. |
| 158 | Exceptions raised in tearDown class are fails the test case, |
Marian Horban | 6afb023 | 2015-11-10 22:47:12 -0500 | [diff] [blame] | 159 | This method supposed to use only by tearDown methods, when |
Attila Fazekas | 305e65b | 2013-10-29 13:23:07 +0100 | [diff] [blame] | 160 | the shared server_id is stored in the server_id of the class. |
| 161 | """ |
| 162 | if getattr(cls, 'server_id', None) is not None: |
| 163 | try: |
Ken'ichi Ohmichi | 0eb153c | 2015-07-13 02:18:25 +0000 | [diff] [blame] | 164 | waiters.wait_for_server_status(cls.servers_client, |
| 165 | cls.server_id, 'ACTIVE') |
Attila Fazekas | 305e65b | 2013-10-29 13:23:07 +0100 | [diff] [blame] | 166 | except Exception as exc: |
| 167 | LOG.exception(exc) |
| 168 | cls.servers_client.delete_server(cls.server_id) |
Ken'ichi Ohmichi | e91a0c6 | 2015-08-13 02:09:16 +0000 | [diff] [blame] | 169 | waiters.wait_for_server_termination(cls.servers_client, |
| 170 | cls.server_id) |
Attila Fazekas | 305e65b | 2013-10-29 13:23:07 +0100 | [diff] [blame] | 171 | cls.server_id = None |
| 172 | raise |
| 173 | |
| 174 | @classmethod |
Sean Dague | d62bf1c | 2013-06-05 14:36:25 -0400 | [diff] [blame] | 175 | def clear_images(cls): |
Salvatore | 1422a9a | 2014-10-08 15:53:25 +0200 | [diff] [blame] | 176 | LOG.debug('Clearing images: %s', ','.join(cls.images)) |
Sean Dague | d62bf1c | 2013-06-05 14:36:25 -0400 | [diff] [blame] | 177 | for image_id in cls.images: |
| 178 | try: |
Jordan Pittier | 9e227c5 | 2016-02-09 14:35:18 +0100 | [diff] [blame] | 179 | test_utils.call_and_ignore_notfound_exc( |
| 180 | cls.compute_images_client.delete_image, image_id) |
Yair Fried | a039f87 | 2014-01-02 12:11:10 +0200 | [diff] [blame] | 181 | except Exception: |
Jordan Pittier | 525ec71 | 2016-12-07 17:51:26 +0100 | [diff] [blame] | 182 | LOG.exception('Exception raised deleting image %s', image_id) |
Sean Dague | d62bf1c | 2013-06-05 14:36:25 -0400 | [diff] [blame] | 183 | |
| 184 | @classmethod |
Zhi Kun Liu | 02e7a7b | 2014-01-08 16:08:32 +0800 | [diff] [blame] | 185 | def clear_security_groups(cls): |
Salvatore | 1422a9a | 2014-10-08 15:53:25 +0200 | [diff] [blame] | 186 | LOG.debug('Clearing security groups: %s', ','.join( |
| 187 | str(sg['id']) for sg in cls.security_groups)) |
Zhi Kun Liu | 02e7a7b | 2014-01-08 16:08:32 +0800 | [diff] [blame] | 188 | for sg in cls.security_groups: |
| 189 | try: |
Jordan Pittier | 9e227c5 | 2016-02-09 14:35:18 +0100 | [diff] [blame] | 190 | test_utils.call_and_ignore_notfound_exc( |
| 191 | cls.security_groups_client.delete_security_group, sg['id']) |
Zhi Kun Liu | 02e7a7b | 2014-01-08 16:08:32 +0800 | [diff] [blame] | 192 | except Exception as exc: |
| 193 | LOG.info('Exception raised deleting security group %s', |
| 194 | sg['id']) |
| 195 | LOG.exception(exc) |
Zhi Kun Liu | 02e7a7b | 2014-01-08 16:08:32 +0800 | [diff] [blame] | 196 | |
| 197 | @classmethod |
Abhijeet.Jain | 87dd445 | 2014-04-23 15:51:23 +0530 | [diff] [blame] | 198 | def clear_server_groups(cls): |
Salvatore | 1422a9a | 2014-10-08 15:53:25 +0200 | [diff] [blame] | 199 | LOG.debug('Clearing server groups: %s', ','.join(cls.server_groups)) |
Abhijeet.Jain | 87dd445 | 2014-04-23 15:51:23 +0530 | [diff] [blame] | 200 | for server_group_id in cls.server_groups: |
| 201 | try: |
Jordan Pittier | 9e227c5 | 2016-02-09 14:35:18 +0100 | [diff] [blame] | 202 | test_utils.call_and_ignore_notfound_exc( |
| 203 | cls.server_groups_client.delete_server_group, |
| 204 | server_group_id |
| 205 | ) |
Abhijeet.Jain | 87dd445 | 2014-04-23 15:51:23 +0530 | [diff] [blame] | 206 | except Exception: |
| 207 | LOG.exception('Exception raised deleting server-group %s', |
| 208 | server_group_id) |
| 209 | |
| 210 | @classmethod |
Joe Gordon | 8843f0f | 2015-03-17 15:07:34 -0700 | [diff] [blame] | 211 | def create_test_server(cls, validatable=False, volume_backed=False, |
| 212 | **kwargs): |
Joseph Lanoux | b3e1f87 | 2015-01-30 11:13:07 +0000 | [diff] [blame] | 213 | """Wrapper utility that returns a test server. |
Rohit Karajgi | dc300b2 | 2012-05-04 08:11:00 -0700 | [diff] [blame] | 214 | |
Joseph Lanoux | b3e1f87 | 2015-01-30 11:13:07 +0000 | [diff] [blame] | 215 | This wrapper utility calls the common create test server and |
| 216 | returns a test server. The purpose of this wrapper is to minimize |
| 217 | the impact on the code of the tests already using this |
| 218 | function. |
Joe Gordon | 8843f0f | 2015-03-17 15:07:34 -0700 | [diff] [blame] | 219 | |
| 220 | :param validatable: Whether the server will be pingable or sshable. |
| 221 | :param volume_backed: Whether the instance is volume backed or not. |
Joseph Lanoux | b3e1f87 | 2015-01-30 11:13:07 +0000 | [diff] [blame] | 222 | """ |
zhufl | 7ae2268 | 2016-09-18 15:22:33 +0800 | [diff] [blame] | 223 | if 'name' not in kwargs: |
| 224 | kwargs['name'] = data_utils.rand_name(cls.__name__ + "-server") |
Joseph Lanoux | b3e1f87 | 2015-01-30 11:13:07 +0000 | [diff] [blame] | 225 | tenant_network = cls.get_tenant_network() |
| 226 | body, servers = compute.create_test_server( |
| 227 | cls.os, |
| 228 | validatable, |
| 229 | validation_resources=cls.validation_resources, |
| 230 | tenant_network=tenant_network, |
Joe Gordon | 8843f0f | 2015-03-17 15:07:34 -0700 | [diff] [blame] | 231 | volume_backed=volume_backed, |
Joseph Lanoux | b3e1f87 | 2015-01-30 11:13:07 +0000 | [diff] [blame] | 232 | **kwargs) |
Ken'ichi Ohmichi | 51c8c26 | 2013-12-21 03:30:37 +0900 | [diff] [blame] | 233 | |
| 234 | cls.servers.extend(servers) |
Sean Dague | 9b669e3 | 2012-12-13 18:40:08 -0500 | [diff] [blame] | 235 | |
David Kranz | 0fb1429 | 2015-02-11 15:55:20 -0500 | [diff] [blame] | 236 | return body |
Sean Dague | 9b669e3 | 2012-12-13 18:40:08 -0500 | [diff] [blame] | 237 | |
Zhi Kun Liu | 02e7a7b | 2014-01-08 16:08:32 +0800 | [diff] [blame] | 238 | @classmethod |
| 239 | def create_security_group(cls, name=None, description=None): |
| 240 | if name is None: |
| 241 | name = data_utils.rand_name(cls.__name__ + "-securitygroup") |
| 242 | if description is None: |
Ken'ichi Ohmichi | 4937f56 | 2015-03-23 00:15:01 +0000 | [diff] [blame] | 243 | description = data_utils.rand_name('description') |
ghanshyam | b610b77 | 2015-08-24 17:29:38 +0900 | [diff] [blame] | 244 | body = cls.security_groups_client.create_security_group( |
| 245 | name=name, description=description)['security_group'] |
Zhi Kun Liu | 02e7a7b | 2014-01-08 16:08:32 +0800 | [diff] [blame] | 246 | cls.security_groups.append(body) |
| 247 | |
David Kranz | 9964b4e | 2015-02-06 15:45:29 -0500 | [diff] [blame] | 248 | return body |
Zhi Kun Liu | 02e7a7b | 2014-01-08 16:08:32 +0800 | [diff] [blame] | 249 | |
Abhijeet.Jain | 87dd445 | 2014-04-23 15:51:23 +0530 | [diff] [blame] | 250 | @classmethod |
Ghanshyam | 2a180b8 | 2014-06-16 13:54:22 +0900 | [diff] [blame] | 251 | def create_test_server_group(cls, name="", policy=None): |
Abhijeet.Jain | 87dd445 | 2014-04-23 15:51:23 +0530 | [diff] [blame] | 252 | if not name: |
| 253 | name = data_utils.rand_name(cls.__name__ + "-Server-Group") |
Ghanshyam | 2a180b8 | 2014-06-16 13:54:22 +0900 | [diff] [blame] | 254 | if policy is None: |
Abhijeet.Jain | 87dd445 | 2014-04-23 15:51:23 +0530 | [diff] [blame] | 255 | policy = ['affinity'] |
Ken'ichi Ohmichi | 1f36daa | 2015-09-30 01:41:34 +0000 | [diff] [blame] | 256 | body = cls.server_groups_client.create_server_group( |
| 257 | name=name, policies=policy)['server_group'] |
David Kranz | da5d4ec | 2014-06-24 16:04:57 -0400 | [diff] [blame] | 258 | cls.server_groups.append(body['id']) |
David Kranz | ae99b9a | 2015-02-16 13:37:01 -0500 | [diff] [blame] | 259 | return body |
Abhijeet.Jain | 87dd445 | 2014-04-23 15:51:23 +0530 | [diff] [blame] | 260 | |
David Kranz | cf0040c | 2012-06-26 09:46:56 -0400 | [diff] [blame] | 261 | def wait_for(self, condition): |
Sean Dague | f237ccb | 2013-01-04 15:19:14 -0500 | [diff] [blame] | 262 | """Repeatedly calls condition() until a timeout.""" |
David Kranz | cf0040c | 2012-06-26 09:46:56 -0400 | [diff] [blame] | 263 | start_time = int(time.time()) |
| 264 | while True: |
| 265 | try: |
| 266 | condition() |
Matthew Treinish | 05d9fb9 | 2012-12-07 16:14:05 -0500 | [diff] [blame] | 267 | except Exception: |
David Kranz | cf0040c | 2012-06-26 09:46:56 -0400 | [diff] [blame] | 268 | pass |
| 269 | else: |
| 270 | return |
| 271 | if int(time.time()) - start_time >= self.build_timeout: |
| 272 | condition() |
| 273 | return |
| 274 | time.sleep(self.build_interval) |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 275 | |
Matt Riedemann | 807d056 | 2014-01-27 12:03:10 -0800 | [diff] [blame] | 276 | @staticmethod |
| 277 | def _delete_volume(volumes_client, volume_id): |
| 278 | """Deletes the given volume and waits for it to be gone.""" |
| 279 | try: |
Joseph Lanoux | 6809bab | 2014-12-18 14:57:18 +0000 | [diff] [blame] | 280 | volumes_client.delete_volume(volume_id) |
Matt Riedemann | 807d056 | 2014-01-27 12:03:10 -0800 | [diff] [blame] | 281 | # TODO(mriedem): We should move the wait_for_resource_deletion |
| 282 | # into the delete_volume method as a convenience to the caller. |
| 283 | volumes_client.wait_for_resource_deletion(volume_id) |
Masayuki Igawa | bfa0760 | 2015-01-20 18:47:17 +0900 | [diff] [blame] | 284 | except lib_exc.NotFound: |
zhangguoqing | 6c09664 | 2016-01-04 06:17:21 +0000 | [diff] [blame] | 285 | LOG.warning("Unable to delete volume '%s' since it was not found. " |
Jordan Pittier | 525ec71 | 2016-12-07 17:51:26 +0100 | [diff] [blame] | 286 | "Maybe it was already deleted?", volume_id) |
Matt Riedemann | 807d056 | 2014-01-27 12:03:10 -0800 | [diff] [blame] | 287 | |
Attila Fazekas | 423834d | 2014-03-14 17:33:13 +0100 | [diff] [blame] | 288 | @classmethod |
| 289 | def prepare_instance_network(cls): |
Joseph Lanoux | ffe09dd | 2015-03-18 16:45:33 +0000 | [diff] [blame] | 290 | if (CONF.validation.auth_method != 'disabled' and |
| 291 | CONF.validation.connect_method == 'floating'): |
Attila Fazekas | 423834d | 2014-03-14 17:33:13 +0100 | [diff] [blame] | 292 | cls.set_network_resources(network=True, subnet=True, router=True, |
| 293 | dhcp=True) |
| 294 | |
ivan-zhu | 8f992be | 2013-07-31 14:56:58 +0800 | [diff] [blame] | 295 | @classmethod |
| 296 | def create_image_from_server(cls, server_id, **kwargs): |
| 297 | """Wrapper utility that returns an image created from the server.""" |
Masayuki Igawa | 259c113 | 2013-10-31 17:48:44 +0900 | [diff] [blame] | 298 | name = data_utils.rand_name(cls.__name__ + "-image") |
ivan-zhu | 8f992be | 2013-07-31 14:56:58 +0800 | [diff] [blame] | 299 | if 'name' in kwargs: |
| 300 | name = kwargs.pop('name') |
| 301 | |
Ghanshyam | ae76c12 | 2015-12-22 13:41:35 +0900 | [diff] [blame] | 302 | image = cls.compute_images_client.create_image(server_id, name=name) |
David Kranz | a5299eb | 2015-01-15 17:24:05 -0500 | [diff] [blame] | 303 | image_id = data_utils.parse_image_id(image.response['location']) |
ivan-zhu | 8f992be | 2013-07-31 14:56:58 +0800 | [diff] [blame] | 304 | cls.images.append(image_id) |
| 305 | |
| 306 | if 'wait_until' in kwargs: |
Matt Riedemann | 1395435 | 2017-02-07 14:03:54 -0500 | [diff] [blame] | 307 | try: |
| 308 | waiters.wait_for_image_status(cls.compute_images_client, |
| 309 | image_id, kwargs['wait_until']) |
| 310 | except lib_exc.NotFound: |
| 311 | if kwargs['wait_until'].upper() == 'ACTIVE': |
| 312 | # If the image is not found after create_image returned |
| 313 | # that means the snapshot failed in nova-compute and nova |
| 314 | # deleted the image. There should be a compute fault |
| 315 | # recorded with the server in that case, so get the server |
| 316 | # and dump some details. |
| 317 | server = ( |
| 318 | cls.servers_client.show_server(server_id)['server']) |
| 319 | if 'fault' in server: |
| 320 | raise exceptions.SnapshotNotFoundException( |
| 321 | server['fault'], image_id=image_id) |
| 322 | else: |
| 323 | raise exceptions.SnapshotNotFoundException( |
| 324 | image_id=image_id) |
| 325 | else: |
| 326 | raise |
Ghanshyam | ae76c12 | 2015-12-22 13:41:35 +0900 | [diff] [blame] | 327 | image = cls.compute_images_client.show_image(image_id)['image'] |
ivan-zhu | 8f992be | 2013-07-31 14:56:58 +0800 | [diff] [blame] | 328 | |
David Kranz | a5299eb | 2015-01-15 17:24:05 -0500 | [diff] [blame] | 329 | return image |
ivan-zhu | 8f992be | 2013-07-31 14:56:58 +0800 | [diff] [blame] | 330 | |
| 331 | @classmethod |
Joseph Lanoux | ffe09dd | 2015-03-18 16:45:33 +0000 | [diff] [blame] | 332 | def rebuild_server(cls, server_id, validatable=False, **kwargs): |
ivan-zhu | 8f992be | 2013-07-31 14:56:58 +0800 | [diff] [blame] | 333 | # Destroy an existing server and creates a new one |
Matthew Treinish | 2cd19a4 | 2013-12-02 21:54:42 +0000 | [diff] [blame] | 334 | if server_id: |
zhufl | 9b68290 | 2016-12-15 09:16:34 +0800 | [diff] [blame] | 335 | cls.delete_server(server_id) |
Joseph Lanoux | ffe09dd | 2015-03-18 16:45:33 +0000 | [diff] [blame] | 336 | |
Ghanshyam | 3390d9f | 2015-12-25 12:48:02 +0900 | [diff] [blame] | 337 | cls.password = data_utils.rand_password() |
Joseph Lanoux | ffe09dd | 2015-03-18 16:45:33 +0000 | [diff] [blame] | 338 | server = cls.create_test_server( |
| 339 | validatable, |
| 340 | wait_until='ACTIVE', |
Ghanshyam | 3390d9f | 2015-12-25 12:48:02 +0900 | [diff] [blame] | 341 | adminPass=cls.password, |
Joseph Lanoux | ffe09dd | 2015-03-18 16:45:33 +0000 | [diff] [blame] | 342 | **kwargs) |
Matthew Treinish | 2cd19a4 | 2013-12-02 21:54:42 +0000 | [diff] [blame] | 343 | return server['id'] |
ivan-zhu | 8f992be | 2013-07-31 14:56:58 +0800 | [diff] [blame] | 344 | |
Matt Riedemann | 5dc594c | 2014-01-27 11:40:28 -0800 | [diff] [blame] | 345 | @classmethod |
Jesse Keating | 613b498 | 2015-05-04 15:05:19 -0700 | [diff] [blame] | 346 | def delete_server(cls, server_id): |
| 347 | """Deletes an existing server and waits for it to be gone.""" |
| 348 | try: |
| 349 | cls.servers_client.delete_server(server_id) |
Ken'ichi Ohmichi | e91a0c6 | 2015-08-13 02:09:16 +0000 | [diff] [blame] | 350 | waiters.wait_for_server_termination(cls.servers_client, |
| 351 | server_id) |
Jesse Keating | 613b498 | 2015-05-04 15:05:19 -0700 | [diff] [blame] | 352 | except Exception: |
Jordan Pittier | 525ec71 | 2016-12-07 17:51:26 +0100 | [diff] [blame] | 353 | LOG.exception('Failed to delete server %s', server_id) |
Jesse Keating | 613b498 | 2015-05-04 15:05:19 -0700 | [diff] [blame] | 354 | |
| 355 | @classmethod |
zhufl | 3d018b0 | 2016-11-25 16:43:04 +0800 | [diff] [blame] | 356 | def resize_server(cls, server_id, new_flavor_id, **kwargs): |
| 357 | """resize and confirm_resize an server, waits for it to be ACTIVE.""" |
| 358 | cls.servers_client.resize_server(server_id, new_flavor_id, **kwargs) |
| 359 | waiters.wait_for_server_status(cls.servers_client, server_id, |
| 360 | 'VERIFY_RESIZE') |
| 361 | cls.servers_client.confirm_resize_server(server_id) |
| 362 | waiters.wait_for_server_status(cls.servers_client, server_id, 'ACTIVE') |
| 363 | |
| 364 | @classmethod |
Matt Riedemann | 5dc594c | 2014-01-27 11:40:28 -0800 | [diff] [blame] | 365 | def delete_volume(cls, volume_id): |
| 366 | """Deletes the given volume and waits for it to be gone.""" |
Ken'ichi Ohmichi | 9f5adf8 | 2014-12-12 04:01:32 +0000 | [diff] [blame] | 367 | cls._delete_volume(cls.volumes_extensions_client, volume_id) |
Ken'ichi Ohmichi | 543a5d4 | 2014-05-02 08:44:15 +0900 | [diff] [blame] | 368 | |
Joseph Lanoux | ffe09dd | 2015-03-18 16:45:33 +0000 | [diff] [blame] | 369 | @classmethod |
| 370 | def get_server_ip(cls, server): |
| 371 | """Get the server fixed or floating IP. |
| 372 | |
Sean Dague | 20e9861 | 2016-01-06 14:33:28 -0500 | [diff] [blame] | 373 | Based on the configuration we're in, return a correct ip |
| 374 | address for validating that a guest is up. |
Joseph Lanoux | ffe09dd | 2015-03-18 16:45:33 +0000 | [diff] [blame] | 375 | """ |
| 376 | if CONF.validation.connect_method == 'floating': |
Sean Dague | 20e9861 | 2016-01-06 14:33:28 -0500 | [diff] [blame] | 377 | return cls.validation_resources['floating_ip']['ip'] |
Joseph Lanoux | ffe09dd | 2015-03-18 16:45:33 +0000 | [diff] [blame] | 378 | elif CONF.validation.connect_method == 'fixed': |
Sean Dague | 20e9861 | 2016-01-06 14:33:28 -0500 | [diff] [blame] | 379 | addresses = server['addresses'][CONF.validation.network_for_ssh] |
| 380 | for address in addresses: |
| 381 | if address['version'] == CONF.validation.ip_version_for_ssh: |
| 382 | return address['addr'] |
zhufl | 955f82b | 2016-07-22 11:14:34 +0800 | [diff] [blame] | 383 | raise exceptions.ServerUnreachable(server_id=server['id']) |
Sean Dague | 20e9861 | 2016-01-06 14:33:28 -0500 | [diff] [blame] | 384 | else: |
guo yunxian | ffc4fc0 | 2016-11-15 09:56:08 +0800 | [diff] [blame] | 385 | raise lib_exc.InvalidConfiguration() |
Joseph Lanoux | ffe09dd | 2015-03-18 16:45:33 +0000 | [diff] [blame] | 386 | |
Ghanshyam | 05049dd | 2016-02-12 17:44:48 +0900 | [diff] [blame] | 387 | def setUp(self): |
| 388 | super(BaseV2ComputeTest, self).setUp() |
| 389 | self.useFixture(api_microversion_fixture.APIMicroversionFixture( |
| 390 | self.request_microversion)) |
| 391 | |
Matt Riedemann | 342b37c | 2016-09-21 15:38:12 -0400 | [diff] [blame] | 392 | @classmethod |
zhufl | 8d23f92 | 2016-12-12 17:29:42 +0800 | [diff] [blame] | 393 | def create_volume(cls, image_ref=None, **kwargs): |
Matt Riedemann | 342b37c | 2016-09-21 15:38:12 -0400 | [diff] [blame] | 394 | """Create a volume and wait for it to become 'available'. |
| 395 | |
Artom Lifshitz | fc8f8e6 | 2016-04-13 11:08:32 +0000 | [diff] [blame] | 396 | :param image_ref: Specify an image id to create a bootable volume. |
zhufl | 8d23f92 | 2016-12-12 17:29:42 +0800 | [diff] [blame] | 397 | :**kwargs: other parameters to create volume. |
Matt Riedemann | 342b37c | 2016-09-21 15:38:12 -0400 | [diff] [blame] | 398 | :returns: The available volume. |
| 399 | """ |
zhufl | 8d23f92 | 2016-12-12 17:29:42 +0800 | [diff] [blame] | 400 | if 'size' not in kwargs: |
| 401 | kwargs['size'] = CONF.volume.volume_size |
| 402 | if 'display_name' not in kwargs: |
| 403 | vol_name = data_utils.rand_name(cls.__name__ + '-volume') |
| 404 | kwargs['display_name'] = vol_name |
Artom Lifshitz | fc8f8e6 | 2016-04-13 11:08:32 +0000 | [diff] [blame] | 405 | if image_ref is not None: |
zhufl | 8d23f92 | 2016-12-12 17:29:42 +0800 | [diff] [blame] | 406 | kwargs['imageRef'] = image_ref |
| 407 | volume = cls.volumes_client.create_volume(**kwargs)['volume'] |
Matt Riedemann | 342b37c | 2016-09-21 15:38:12 -0400 | [diff] [blame] | 408 | cls.volumes.append(volume) |
lkuchlan | 52d7b0d | 2016-11-07 20:53:19 +0200 | [diff] [blame^] | 409 | waiters.wait_for_volume_resource_status(cls.volumes_client, |
| 410 | volume['id'], 'available') |
Matt Riedemann | 342b37c | 2016-09-21 15:38:12 -0400 | [diff] [blame] | 411 | return volume |
| 412 | |
| 413 | @classmethod |
| 414 | def clear_volumes(cls): |
| 415 | LOG.debug('Clearing volumes: %s', ','.join( |
| 416 | volume['id'] for volume in cls.volumes)) |
| 417 | for volume in cls.volumes: |
| 418 | try: |
| 419 | test_utils.call_and_ignore_notfound_exc( |
| 420 | cls.volumes_client.delete_volume, volume['id']) |
| 421 | except Exception: |
| 422 | LOG.exception('Deleting volume %s failed', volume['id']) |
| 423 | |
| 424 | for volume in cls.volumes: |
| 425 | try: |
| 426 | cls.volumes_client.wait_for_resource_deletion(volume['id']) |
| 427 | except Exception: |
| 428 | LOG.exception('Waiting for deletion of volume %s failed', |
| 429 | volume['id']) |
| 430 | |
Matt Riedemann | cb16a66 | 2016-10-01 18:30:05 -0400 | [diff] [blame] | 431 | def attach_volume(self, server, volume, device=None): |
| 432 | """Attaches volume to server and waits for 'in-use' volume status. |
| 433 | |
| 434 | The volume will be detached when the test tears down. |
| 435 | |
| 436 | :param server: The server to which the volume will be attached. |
| 437 | :param volume: The volume to attach. |
| 438 | :param device: Optional mountpoint for the attached volume. Note that |
| 439 | this is not guaranteed for all hypervisors and is not recommended. |
| 440 | """ |
| 441 | attach_kwargs = dict(volumeId=volume['id']) |
| 442 | if device: |
| 443 | attach_kwargs['device'] = device |
Matt Riedemann | 342b37c | 2016-09-21 15:38:12 -0400 | [diff] [blame] | 444 | self.servers_client.attach_volume( |
Matt Riedemann | cb16a66 | 2016-10-01 18:30:05 -0400 | [diff] [blame] | 445 | server['id'], **attach_kwargs) |
Matt Riedemann | 342b37c | 2016-09-21 15:38:12 -0400 | [diff] [blame] | 446 | # On teardown detach the volume and wait for it to be available. This |
| 447 | # is so we don't error out when trying to delete the volume during |
| 448 | # teardown. |
lkuchlan | 52d7b0d | 2016-11-07 20:53:19 +0200 | [diff] [blame^] | 449 | self.addCleanup(waiters.wait_for_volume_resource_status, |
Matt Riedemann | 342b37c | 2016-09-21 15:38:12 -0400 | [diff] [blame] | 450 | self.volumes_client, volume['id'], 'available') |
| 451 | # Ignore 404s on detach in case the server is deleted or the volume |
| 452 | # is already detached. |
| 453 | self.addCleanup(test_utils.call_and_ignore_notfound_exc, |
| 454 | self.servers_client.detach_volume, |
| 455 | server['id'], volume['id']) |
lkuchlan | 52d7b0d | 2016-11-07 20:53:19 +0200 | [diff] [blame^] | 456 | waiters.wait_for_volume_resource_status(self.volumes_client, |
| 457 | volume['id'], 'in-use') |
Matt Riedemann | 342b37c | 2016-09-21 15:38:12 -0400 | [diff] [blame] | 458 | |
Ken'ichi Ohmichi | 543a5d4 | 2014-05-02 08:44:15 +0900 | [diff] [blame] | 459 | |
Ken'ichi Ohmichi | 02a8ccd | 2015-11-05 06:05:29 +0000 | [diff] [blame] | 460 | class BaseV2ComputeAdminTest(BaseV2ComputeTest): |
Ken'ichi Ohmichi | bcefa3d | 2014-05-09 08:14:05 +0900 | [diff] [blame] | 461 | """Base test case class for Compute Admin API tests.""" |
ivan-zhu | f2b0050 | 2013-10-18 10:06:52 +0800 | [diff] [blame] | 462 | |
Andrea Frittoli | b21de6c | 2015-02-06 20:12:38 +0000 | [diff] [blame] | 463 | credentials = ['primary', 'admin'] |
Emily Hugenbruch | e7991d9 | 2014-12-12 16:53:36 +0000 | [diff] [blame] | 464 | |
| 465 | @classmethod |
| 466 | def setup_clients(cls): |
Ken'ichi Ohmichi | 02a8ccd | 2015-11-05 06:05:29 +0000 | [diff] [blame] | 467 | super(BaseV2ComputeAdminTest, cls).setup_clients() |
Ken'ichi Ohmichi | 9f5adf8 | 2014-12-12 04:01:32 +0000 | [diff] [blame] | 468 | cls.availability_zone_admin_client = ( |
| 469 | cls.os_adm.availability_zone_client) |
zhufl | 36eeab0 | 2017-01-18 11:49:04 +0800 | [diff] [blame] | 470 | cls.admin_flavors_client = cls.os_adm.flavors_client |
| 471 | |
| 472 | def create_flavor(self, ram, vcpus, disk, name=None, |
| 473 | is_public='True', **kwargs): |
| 474 | if name is None: |
| 475 | name = data_utils.rand_name(self.__class__.__name__ + "-flavor") |
| 476 | id = kwargs.pop('id', data_utils.rand_int_id(start=1000)) |
| 477 | client = self.admin_flavors_client |
| 478 | flavor = client.create_flavor( |
| 479 | ram=ram, vcpus=vcpus, disk=disk, name=name, |
| 480 | id=id, is_public=is_public, **kwargs)['flavor'] |
| 481 | self.addCleanup(client.wait_for_resource_deletion, flavor['id']) |
| 482 | self.addCleanup(client.delete_flavor, flavor['id']) |
| 483 | return flavor |