blob: 1ba9b1662fab2e3dcc334eedeb6e14c6b0aba106 [file] [log] [blame]
Jay Pipes13b479b2012-06-11 14:52:27 -04001# vim: tabstop=4 shiftwidth=4 softtabstop=4
2
ZhiQiang Fan39f97222013-09-20 04:49:44 +08003# Copyright 2012 OpenStack Foundation
Jay Pipes13b479b2012-06-11 14:52:27 -04004# All Rights Reserved.
5#
6# Licensed under the Apache License, Version 2.0 (the "License"); you may
7# not use this file except in compliance with the License. You may obtain
8# a copy of the License at
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15# License for the specific language governing permissions and limitations
16# under the License.
17
David Kranzcf0040c2012-06-26 09:46:56 -040018import time
Jay Pipesf38eaac2012-06-21 13:37:35 -040019
Sean Dague1937d092013-05-17 16:36:38 -040020from tempest.api import compute
Matthew Treinish481466b2012-12-20 17:16:01 -050021from tempest import clients
Masayuki Igawa259c1132013-10-31 17:48:44 +090022from tempest.common.utils import data_utils
David Kranz33138312013-09-24 17:09:32 -040023from tempest import exceptions
Matthew Treinishf4a9b0f2013-07-26 16:58:26 -040024from tempest.openstack.common import log as logging
Attila Fazekasdc216422013-01-29 15:12:14 +010025import tempest.test
Jay Pipesf38eaac2012-06-21 13:37:35 -040026
Tiago Melloeda03b52012-08-22 23:47:29 -030027
Jay Pipesf38eaac2012-06-21 13:37:35 -040028LOG = logging.getLogger(__name__)
Daryl Walleckc7251962012-03-12 17:26:54 -050029
30
Attila Fazekasdc216422013-01-29 15:12:14 +010031class BaseComputeTest(tempest.test.BaseTestCase):
Sean Daguef237ccb2013-01-04 15:19:14 -050032 """Base test case class for all Compute API tests."""
Daryl Walleckc7251962012-03-12 17:26:54 -050033
Attila Fazekas9a63c942013-01-29 21:46:02 +010034 conclusion = compute.generic_setup_package()
Attila Fazekas430dae32013-10-17 15:19:32 +020035 force_tenant_isolation = False
Chris Yeoh8a79b9d2013-01-18 19:32:47 +103036
Jay Pipesf38eaac2012-06-21 13:37:35 -040037 @classmethod
38 def setUpClass(cls):
Attila Fazekasf86fa312013-07-30 19:56:39 +020039 super(BaseComputeTest, cls).setUpClass()
Matthew Treinish6b41e242013-07-19 16:49:28 -040040 if not cls.config.service_available.nova:
41 skip_msg = ("%s skipped as nova is not available" % cls.__name__)
42 raise cls.skipException(skip_msg)
Jay Pipesf38eaac2012-06-21 13:37:35 -040043
Ryan Hsu6c4bb3d2013-10-21 21:22:50 -070044 os = cls.get_client_manager()
Daryl Walleckc7251962012-03-12 17:26:54 -050045
Jay Pipesf38eaac2012-06-21 13:37:35 -040046 cls.os = os
Jay Pipesf38eaac2012-06-21 13:37:35 -040047 cls.build_interval = cls.config.compute.build_interval
48 cls.build_timeout = cls.config.compute.build_timeout
49 cls.ssh_user = cls.config.compute.ssh_user
50 cls.image_ref = cls.config.compute.image_ref
51 cls.image_ref_alt = cls.config.compute.image_ref_alt
52 cls.flavor_ref = cls.config.compute.flavor_ref
53 cls.flavor_ref_alt = cls.config.compute.flavor_ref_alt
ivan-zhuf2b00502013-10-18 10:06:52 +080054 cls.image_ssh_user = cls.config.compute.image_ssh_user
55 cls.image_ssh_password = cls.config.compute.image_ssh_password
Jay Pipesf38eaac2012-06-21 13:37:35 -040056 cls.servers = []
Sean Dagued62bf1c2013-06-05 14:36:25 -040057 cls.images = []
Daryl Walleckc7251962012-03-12 17:26:54 -050058
Jay Pipesf38eaac2012-06-21 13:37:35 -040059 @classmethod
Jay Pipes444c3e62012-10-04 19:26:35 -040060 def clear_servers(cls):
61 for server in cls.servers:
Dan Smith74e7bcb2012-08-21 09:18:26 -070062 try:
63 cls.servers_client.delete_server(server['id'])
64 except Exception:
65 pass
66
Jay Pipes444c3e62012-10-04 19:26:35 -040067 for server in cls.servers:
Dan Smith74e7bcb2012-08-21 09:18:26 -070068 try:
69 cls.servers_client.wait_for_server_termination(server['id'])
70 except Exception:
71 pass
72
73 @classmethod
Sean Dagued62bf1c2013-06-05 14:36:25 -040074 def clear_images(cls):
75 for image_id in cls.images:
76 try:
77 cls.images_client.delete_image(image_id)
David Kranz33138312013-09-24 17:09:32 -040078 except exceptions.NotFound:
79 # The image may have already been deleted which is OK.
80 pass
Sean Dagued62bf1c2013-06-05 14:36:25 -040081 except Exception as exc:
82 LOG.info('Exception raised deleting image %s', image_id)
83 LOG.exception(exc)
84 pass
85
86 @classmethod
Jay Pipesf38eaac2012-06-21 13:37:35 -040087 def tearDownClass(cls):
Sean Dagued62bf1c2013-06-05 14:36:25 -040088 cls.clear_images()
Jay Pipes444c3e62012-10-04 19:26:35 -040089 cls.clear_servers()
Ryan Hsu6c4bb3d2013-10-21 21:22:50 -070090 cls.clear_isolated_creds()
Matthew Treinishb86cda92013-07-29 11:22:23 -040091 super(BaseComputeTest, cls).tearDownClass()
Rohit Karajgidc300b22012-05-04 08:11:00 -070092
Jay Pipes444c3e62012-10-04 19:26:35 -040093 @classmethod
Ken'ichi Ohmichicfc052e2013-10-23 11:50:04 +090094 def create_test_server(cls, **kwargs):
Sean Daguef237ccb2013-01-04 15:19:14 -050095 """Wrapper utility that returns a test server."""
Masayuki Igawa259c1132013-10-31 17:48:44 +090096 name = data_utils.rand_name(cls.__name__ + "-instance")
Sean Dague22897e12013-02-25 17:54:09 -050097 if 'name' in kwargs:
98 name = kwargs.pop('name')
99 flavor = kwargs.get('flavor', cls.flavor_ref)
100 image_id = kwargs.get('image_id', cls.image_ref)
Rohit Karajgidc300b22012-05-04 08:11:00 -0700101
Andrea Frittoli938d1512013-05-16 15:42:27 +0100102 resp, body = cls.servers_client.create_server(
Sean Dague22897e12013-02-25 17:54:09 -0500103 name, image_id, flavor, **kwargs)
Andrea Frittoli938d1512013-05-16 15:42:27 +0100104
105 # handle the case of multiple servers
106 servers = [body]
107 if 'min_count' in kwargs or 'max_count' in kwargs:
108 # Get servers created which name match with name param.
109 r, b = cls.servers_client.list_servers()
110 servers = [s for s in b['servers'] if s['name'].startswith(name)]
111
112 cls.servers.extend(servers)
David Kranzcf0040c2012-06-26 09:46:56 -0400113
Sean Dague22897e12013-02-25 17:54:09 -0500114 if 'wait_until' in kwargs:
Andrea Frittoli938d1512013-05-16 15:42:27 +0100115 for server in servers:
116 cls.servers_client.wait_for_server_status(
117 server['id'], kwargs['wait_until'])
Sean Dague9b669e32012-12-13 18:40:08 -0500118
Andrea Frittoli938d1512013-05-16 15:42:27 +0100119 return resp, body
Sean Dague9b669e32012-12-13 18:40:08 -0500120
David Kranzcf0040c2012-06-26 09:46:56 -0400121 def wait_for(self, condition):
Sean Daguef237ccb2013-01-04 15:19:14 -0500122 """Repeatedly calls condition() until a timeout."""
David Kranzcf0040c2012-06-26 09:46:56 -0400123 start_time = int(time.time())
124 while True:
125 try:
126 condition()
Matthew Treinish05d9fb92012-12-07 16:14:05 -0500127 except Exception:
David Kranzcf0040c2012-06-26 09:46:56 -0400128 pass
129 else:
130 return
131 if int(time.time()) - start_time >= self.build_timeout:
132 condition()
133 return
134 time.sleep(self.build_interval)
Jay Pipesf38eaac2012-06-21 13:37:35 -0400135
136
ivan-zhuf2b00502013-10-18 10:06:52 +0800137class BaseV2ComputeTest(BaseComputeTest):
Jay Pipesf38eaac2012-06-21 13:37:35 -0400138
139 @classmethod
140 def setUpClass(cls):
ivan-zhuf2b00502013-10-18 10:06:52 +0800141 super(BaseV2ComputeTest, cls).setUpClass()
142 cls.servers_client = cls.os.servers_client
143 cls.flavors_client = cls.os.flavors_client
144 cls.images_client = cls.os.images_client
145 cls.extensions_client = cls.os.extensions_client
146 cls.floating_ips_client = cls.os.floating_ips_client
147 cls.keypairs_client = cls.os.keypairs_client
148 cls.security_groups_client = cls.os.security_groups_client
149 cls.quotas_client = cls.os.quotas_client
150 cls.limits_client = cls.os.limits_client
151 cls.volumes_extensions_client = cls.os.volumes_extensions_client
152 cls.volumes_client = cls.os.volumes_client
153 cls.interfaces_client = cls.os.interfaces_client
154 cls.fixed_ips_client = cls.os.fixed_ips_client
155 cls.availability_zone_client = cls.os.availability_zone_client
156 cls.aggregates_client = cls.os.aggregates_client
157 cls.services_client = cls.os.services_client
ivan-zhuef7a1bd2013-10-22 17:56:46 +0800158 cls.instance_usages_audit_log_client = \
159 cls.os.instance_usages_audit_log_client
ivan-zhuf2b00502013-10-18 10:06:52 +0800160 cls.hypervisor_client = cls.os.hypervisor_client
161 cls.servers_client_v3_auth = cls.os.servers_client_v3_auth
ivan-zhud57f3cf2013-11-06 16:59:52 +0800162 cls.certificates_client = cls.os.certificates_client
ivan-zhuf2b00502013-10-18 10:06:52 +0800163
ivan-zhu8f992be2013-07-31 14:56:58 +0800164 @classmethod
165 def create_image_from_server(cls, server_id, **kwargs):
166 """Wrapper utility that returns an image created from the server."""
Masayuki Igawa259c1132013-10-31 17:48:44 +0900167 name = data_utils.rand_name(cls.__name__ + "-image")
ivan-zhu8f992be2013-07-31 14:56:58 +0800168 if 'name' in kwargs:
169 name = kwargs.pop('name')
170
171 resp, image = cls.images_client.create_image(
172 server_id, name)
Masayuki Igawa259c1132013-10-31 17:48:44 +0900173 image_id = data_utils.parse_image_id(resp['location'])
ivan-zhu8f992be2013-07-31 14:56:58 +0800174 cls.images.append(image_id)
175
176 if 'wait_until' in kwargs:
177 cls.images_client.wait_for_image_status(image_id,
178 kwargs['wait_until'])
179 resp, image = cls.images_client.get_image(image_id)
180
181 return resp, image
182
183 @classmethod
Matthew Treinish2cd19a42013-12-02 21:54:42 +0000184 def rebuild_server(cls, server_id, **kwargs):
ivan-zhu8f992be2013-07-31 14:56:58 +0800185 # Destroy an existing server and creates a new one
Matthew Treinish2cd19a42013-12-02 21:54:42 +0000186 if server_id:
187 try:
188 cls.servers_client.delete_server(server_id)
189 cls.servers_client.wait_for_server_termination(server_id)
190 except Exception as exc:
191 LOG.exception(exc)
192 pass
Ken'ichi Ohmichicfc052e2013-10-23 11:50:04 +0900193 resp, server = cls.create_test_server(wait_until='ACTIVE', **kwargs)
ivan-zhu8f992be2013-07-31 14:56:58 +0800194 cls.password = server['adminPass']
Matthew Treinish2cd19a42013-12-02 21:54:42 +0000195 return server['id']
ivan-zhu8f992be2013-07-31 14:56:58 +0800196
ivan-zhuf2b00502013-10-18 10:06:52 +0800197
198class BaseV2ComputeAdminTest(BaseV2ComputeTest):
199 """Base test case class for Compute Admin V2 API tests."""
200
201 @classmethod
202 def setUpClass(cls):
203 super(BaseV2ComputeAdminTest, cls).setUpClass()
Attila Fazekas4ba36582013-02-12 08:26:17 +0100204 admin_username = cls.config.compute_admin.username
205 admin_password = cls.config.compute_admin.password
206 admin_tenant = cls.config.compute_admin.tenant_name
Attila Fazekas4ba36582013-02-12 08:26:17 +0100207 if not (admin_username and admin_password and admin_tenant):
Jay Pipesf38eaac2012-06-21 13:37:35 -0400208 msg = ("Missing Compute Admin API credentials "
209 "in configuration.")
ivan-zhu1feeb382013-01-24 10:14:39 +0800210 raise cls.skipException(msg)
Attila Fazekas430dae32013-10-17 15:19:32 +0200211 if (cls.config.compute.allow_tenant_isolation or
212 cls.force_tenant_isolation is True):
Matthew Treinishb86cda92013-07-29 11:22:23 -0400213 creds = cls.isolated_creds.get_admin_creds()
Matthew Treinish47ff7912013-07-22 17:09:55 -0400214 admin_username, admin_tenant_name, admin_password = creds
215 cls.os_adm = clients.Manager(username=admin_username,
216 password=admin_password,
217 tenant_name=admin_tenant_name,
218 interface=cls._interface)
219 else:
220 cls.os_adm = clients.ComputeAdminManager(interface=cls._interface)
ivan-zhu8f992be2013-07-31 14:56:58 +0800221
222
223class BaseV3ComputeTest(BaseComputeTest):
224
225 @classmethod
226 def setUpClass(cls):
227 super(BaseV3ComputeTest, cls).setUpClass()
228 if not cls.config.compute_feature_enabled.api_v3:
armando-migliaccio3e2a0282013-11-22 14:47:16 -0800229 cls.tearDownClass()
ivan-zhu8f992be2013-07-31 14:56:58 +0800230 skip_msg = ("%s skipped as nova v3 api is not available" %
231 cls.__name__)
232 raise cls.skipException(skip_msg)
233
234 cls.servers_client = cls.os.servers_v3_client
235 cls.images_client = cls.os.image_client
ivan-zhu5c86ae62013-08-20 21:09:01 +0800236 cls.services_client = cls.os.services_v3_client
ivan-zhu31d98482013-08-22 10:51:48 +0800237 cls.extensions_client = cls.os.extensions_v3_client
ivan-zhuac7b3802013-08-21 16:03:53 +0800238 cls.availability_zone_client = cls.os.availability_zone_v3_client
ivan-zhu91feab92013-08-15 18:25:33 +0800239 cls.interfaces_client = cls.os.interfaces_v3_client
ivan-zhu6f5f9e92013-08-21 22:16:37 +0800240 cls.hypervisor_client = cls.os.hypervisor_v3_client
ivan-zhubec84a32013-08-21 15:32:05 +0800241 cls.tenant_usages_client = cls.os.tenant_usages_v3_client
ivan-zhu8f992be2013-07-31 14:56:58 +0800242
243 @classmethod
244 def create_image_from_server(cls, server_id, **kwargs):
245 """Wrapper utility that returns an image created from the server."""
Masayuki Igawa259c1132013-10-31 17:48:44 +0900246 name = data_utils.rand_name(cls.__name__ + "-image")
ivan-zhu8f992be2013-07-31 14:56:58 +0800247 if 'name' in kwargs:
248 name = kwargs.pop('name')
249
250 resp, image = cls.servers_client.create_image(
251 server_id, name)
Masayuki Igawa259c1132013-10-31 17:48:44 +0900252 image_id = data_utils.parse_image_id(resp['location'])
ivan-zhu8f992be2013-07-31 14:56:58 +0800253 cls.images.append(image_id)
254
255 if 'wait_until' in kwargs:
256 cls.images_client.wait_for_image_status(image_id,
257 kwargs['wait_until'])
258 resp, image = cls.images_client.get_image_meta(image_id)
259
260 return resp, image
261
262 @classmethod
Matthew Treinish2cd19a42013-12-02 21:54:42 +0000263 def rebuild_server(cls, server_id, **kwargs):
ivan-zhu8f992be2013-07-31 14:56:58 +0800264 # Destroy an existing server and creates a new one
265 try:
Matthew Treinish2cd19a42013-12-02 21:54:42 +0000266 cls.servers_client.delete_server(server_id)
267 cls.servers_client.wait_for_server_termination(server_id)
ivan-zhu8f992be2013-07-31 14:56:58 +0800268 except Exception as exc:
269 LOG.exception(exc)
270 pass
Ken'ichi Ohmichicfc052e2013-10-23 11:50:04 +0900271 resp, server = cls.create_test_server(wait_until='ACTIVE', **kwargs)
Ken'ichi Ohmichie985ca82013-11-12 15:10:35 +0900272 cls.password = server['admin_password']
Matthew Treinish2cd19a42013-12-02 21:54:42 +0000273 return server['id']
ivan-zhu8f992be2013-07-31 14:56:58 +0800274
275
276class BaseV3ComputeAdminTest(BaseV3ComputeTest):
277 """Base test case class for all Compute Admin API V3 tests."""
278
279 @classmethod
280 def setUpClass(cls):
281 super(BaseV3ComputeAdminTest, cls).setUpClass()
282 admin_username = cls.config.compute_admin.username
283 admin_password = cls.config.compute_admin.password
284 admin_tenant = cls.config.compute_admin.tenant_name
285 if not (admin_username and admin_password and admin_tenant):
286 msg = ("Missing Compute Admin API credentials "
287 "in configuration.")
288 raise cls.skipException(msg)
289 if cls.config.compute.allow_tenant_isolation:
290 creds = cls.isolated_creds.get_admin_creds()
291 admin_username, admin_tenant_name, admin_password = creds
292 os_adm = clients.Manager(username=admin_username,
293 password=admin_password,
294 tenant_name=admin_tenant_name,
295 interface=cls._interface)
296 else:
297 os_adm = clients.ComputeAdminManager(interface=cls._interface)
298
299 cls.os_adm = os_adm
300 cls.severs_admin_client = cls.os_adm.servers_v3_client
ivan-zhu5c86ae62013-08-20 21:09:01 +0800301 cls.services_admin_client = cls.os_adm.services_v3_client
ivan-zhuac7b3802013-08-21 16:03:53 +0800302 cls.availability_zone_admin_client = \
303 cls.os_adm.availability_zone_v3_client
ivan-zhu6f5f9e92013-08-21 22:16:37 +0800304 cls.hypervisor_admin_client = cls.os_adm.hypervisor_v3_client
ivan-zhubec84a32013-08-21 15:32:05 +0800305 cls.tenant_usages_admin_client = cls.os_adm.tenant_usages_v3_client