blob: 7104f8349fef170b4b4a347623f4e4c309aa14b0 [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
158 cls.hypervisor_client = cls.os.hypervisor_client
159 cls.servers_client_v3_auth = cls.os.servers_client_v3_auth
ivan-zhud57f3cf2013-11-06 16:59:52 +0800160 cls.certificates_client = cls.os.certificates_client
ivan-zhuf2b00502013-10-18 10:06:52 +0800161
ivan-zhu8f992be2013-07-31 14:56:58 +0800162 @classmethod
163 def create_image_from_server(cls, server_id, **kwargs):
164 """Wrapper utility that returns an image created from the server."""
Masayuki Igawa259c1132013-10-31 17:48:44 +0900165 name = data_utils.rand_name(cls.__name__ + "-image")
ivan-zhu8f992be2013-07-31 14:56:58 +0800166 if 'name' in kwargs:
167 name = kwargs.pop('name')
168
169 resp, image = cls.images_client.create_image(
170 server_id, name)
Masayuki Igawa259c1132013-10-31 17:48:44 +0900171 image_id = data_utils.parse_image_id(resp['location'])
ivan-zhu8f992be2013-07-31 14:56:58 +0800172 cls.images.append(image_id)
173
174 if 'wait_until' in kwargs:
175 cls.images_client.wait_for_image_status(image_id,
176 kwargs['wait_until'])
177 resp, image = cls.images_client.get_image(image_id)
178
179 return resp, image
180
181 @classmethod
182 def rebuild_server(cls, **kwargs):
183 # Destroy an existing server and creates a new one
184 try:
185 cls.servers_client.delete_server(cls.server_id)
186 cls.servers_client.wait_for_server_termination(cls.server_id)
187 except Exception as exc:
188 LOG.exception(exc)
189 pass
Ken'ichi Ohmichicfc052e2013-10-23 11:50:04 +0900190 resp, server = cls.create_test_server(wait_until='ACTIVE', **kwargs)
ivan-zhu8f992be2013-07-31 14:56:58 +0800191 cls.server_id = server['id']
192 cls.password = server['adminPass']
193
ivan-zhuf2b00502013-10-18 10:06:52 +0800194
195class BaseV2ComputeAdminTest(BaseV2ComputeTest):
196 """Base test case class for Compute Admin V2 API tests."""
197
198 @classmethod
199 def setUpClass(cls):
200 super(BaseV2ComputeAdminTest, cls).setUpClass()
Attila Fazekas4ba36582013-02-12 08:26:17 +0100201 admin_username = cls.config.compute_admin.username
202 admin_password = cls.config.compute_admin.password
203 admin_tenant = cls.config.compute_admin.tenant_name
Attila Fazekas4ba36582013-02-12 08:26:17 +0100204 if not (admin_username and admin_password and admin_tenant):
Jay Pipesf38eaac2012-06-21 13:37:35 -0400205 msg = ("Missing Compute Admin API credentials "
206 "in configuration.")
ivan-zhu1feeb382013-01-24 10:14:39 +0800207 raise cls.skipException(msg)
Attila Fazekas430dae32013-10-17 15:19:32 +0200208 if (cls.config.compute.allow_tenant_isolation or
209 cls.force_tenant_isolation is True):
Matthew Treinishb86cda92013-07-29 11:22:23 -0400210 creds = cls.isolated_creds.get_admin_creds()
Matthew Treinish47ff7912013-07-22 17:09:55 -0400211 admin_username, admin_tenant_name, admin_password = creds
212 cls.os_adm = clients.Manager(username=admin_username,
213 password=admin_password,
214 tenant_name=admin_tenant_name,
215 interface=cls._interface)
216 else:
217 cls.os_adm = clients.ComputeAdminManager(interface=cls._interface)
ivan-zhu8f992be2013-07-31 14:56:58 +0800218
219
220class BaseV3ComputeTest(BaseComputeTest):
221
222 @classmethod
223 def setUpClass(cls):
224 super(BaseV3ComputeTest, cls).setUpClass()
225 if not cls.config.compute_feature_enabled.api_v3:
226 skip_msg = ("%s skipped as nova v3 api is not available" %
227 cls.__name__)
228 raise cls.skipException(skip_msg)
229
230 cls.servers_client = cls.os.servers_v3_client
231 cls.images_client = cls.os.image_client
ivan-zhu5c86ae62013-08-20 21:09:01 +0800232 cls.services_client = cls.os.services_v3_client
ivan-zhu31d98482013-08-22 10:51:48 +0800233 cls.extensions_client = cls.os.extensions_v3_client
ivan-zhuac7b3802013-08-21 16:03:53 +0800234 cls.availability_zone_client = cls.os.availability_zone_v3_client
ivan-zhu8f992be2013-07-31 14:56:58 +0800235
236 @classmethod
237 def create_image_from_server(cls, server_id, **kwargs):
238 """Wrapper utility that returns an image created from the server."""
Masayuki Igawa259c1132013-10-31 17:48:44 +0900239 name = data_utils.rand_name(cls.__name__ + "-image")
ivan-zhu8f992be2013-07-31 14:56:58 +0800240 if 'name' in kwargs:
241 name = kwargs.pop('name')
242
243 resp, image = cls.servers_client.create_image(
244 server_id, name)
Masayuki Igawa259c1132013-10-31 17:48:44 +0900245 image_id = data_utils.parse_image_id(resp['location'])
ivan-zhu8f992be2013-07-31 14:56:58 +0800246 cls.images.append(image_id)
247
248 if 'wait_until' in kwargs:
249 cls.images_client.wait_for_image_status(image_id,
250 kwargs['wait_until'])
251 resp, image = cls.images_client.get_image_meta(image_id)
252
253 return resp, image
254
255 @classmethod
256 def rebuild_server(cls, **kwargs):
257 # Destroy an existing server and creates a new one
258 try:
259 cls.servers_client.delete_server(cls.server_id)
260 cls.servers_client.wait_for_server_termination(cls.server_id)
261 except Exception as exc:
262 LOG.exception(exc)
263 pass
Ken'ichi Ohmichicfc052e2013-10-23 11:50:04 +0900264 resp, server = cls.create_test_server(wait_until='ACTIVE', **kwargs)
ivan-zhu8f992be2013-07-31 14:56:58 +0800265 cls.server_id = server['id']
Ken'ichi Ohmichie985ca82013-11-12 15:10:35 +0900266 cls.password = server['admin_password']
ivan-zhu8f992be2013-07-31 14:56:58 +0800267
268
269class BaseV3ComputeAdminTest(BaseV3ComputeTest):
270 """Base test case class for all Compute Admin API V3 tests."""
271
272 @classmethod
273 def setUpClass(cls):
274 super(BaseV3ComputeAdminTest, cls).setUpClass()
275 admin_username = cls.config.compute_admin.username
276 admin_password = cls.config.compute_admin.password
277 admin_tenant = cls.config.compute_admin.tenant_name
278 if not (admin_username and admin_password and admin_tenant):
279 msg = ("Missing Compute Admin API credentials "
280 "in configuration.")
281 raise cls.skipException(msg)
282 if cls.config.compute.allow_tenant_isolation:
283 creds = cls.isolated_creds.get_admin_creds()
284 admin_username, admin_tenant_name, admin_password = creds
285 os_adm = clients.Manager(username=admin_username,
286 password=admin_password,
287 tenant_name=admin_tenant_name,
288 interface=cls._interface)
289 else:
290 os_adm = clients.ComputeAdminManager(interface=cls._interface)
291
292 cls.os_adm = os_adm
293 cls.severs_admin_client = cls.os_adm.servers_v3_client
ivan-zhu5c86ae62013-08-20 21:09:01 +0800294 cls.services_admin_client = cls.os_adm.services_v3_client
ivan-zhuac7b3802013-08-21 16:03:53 +0800295 cls.availability_zone_admin_client = \
296 cls.os_adm.availability_zone_v3_client