blob: 3a4428a441a2b807f9c32a87f18af9b7ac83ae24 [file] [log] [blame]
ZhiQiang Fan39f97222013-09-20 04:49:44 +08001# Copyright 2012 OpenStack Foundation
Jay Pipes13b479b2012-06-11 14:52:27 -04002# 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
Ryan Hsu38231092014-06-08 23:12:10 -070016import logging
Brian Waldon738cd632011-12-12 18:45:09 -050017
Matthew Treinishf077dd22015-04-23 09:37:41 -040018from six.moves.urllib import parse as urlparse
ivan-zhu1feeb382013-01-24 10:14:39 +080019import testtools
Jay Pipes13b479b2012-06-11 14:52:27 -040020
Sean Dague1937d092013-05-17 16:36:38 -040021from tempest.api.compute import base
ghanshyam017b5fe2016-04-15 18:49:26 +090022from tempest.common import compute
Fei Long Wangd39431f2015-05-14 11:30:48 +120023from tempest.common.utils import data_utils
Masayuki Igawa209fd502014-02-17 14:46:43 +090024from tempest.common.utils.linux import remote_client
Ken'ichi Ohmichi0eb153c2015-07-13 02:18:25 +000025from tempest.common import waiters
Sean Dague86bd8422013-12-20 09:56:44 -050026from tempest import config
Matt Riedemann2aa19d42016-06-06 17:45:41 -040027from tempest import exceptions
Andrea Frittoli (andreaf)db9672e2016-02-23 14:07:24 -050028from tempest.lib import decorators
29from tempest.lib import exceptions as lib_exc
Masayuki Igawa209fd502014-02-17 14:46:43 +090030from tempest import test
Daryl Wallecked8bef32011-12-05 23:02:08 -060031
Sean Dague86bd8422013-12-20 09:56:44 -050032CONF = config.CONF
33
Ryan Hsu38231092014-06-08 23:12:10 -070034LOG = logging.getLogger(__name__)
35
Daryl Walleckc7251962012-03-12 17:26:54 -050036
ivan-zhuf2b00502013-10-18 10:06:52 +080037class ServerActionsTestJSON(base.BaseV2ComputeTest):
Matthew Treinishe5cca002015-05-11 15:36:50 -040038 run_ssh = CONF.validation.run_validation
Daryl Wallecked8bef32011-12-05 23:02:08 -060039
Attila Fazekas19044d52013-02-16 07:35:06 +010040 def setUp(self):
Matt Riedemann2da58592014-06-08 12:46:02 +000041 # NOTE(afazekas): Normally we use the same server with all test cases,
42 # but if it has an issue, we build a new one
Attila Fazekas19044d52013-02-16 07:35:06 +010043 super(ServerActionsTestJSON, self).setUp()
Matt Riedemann2da58592014-06-08 12:46:02 +000044 # Check if the server is in a clean state after test
45 try:
Ken'ichi Ohmichi0eb153c2015-07-13 02:18:25 +000046 waiters.wait_for_server_status(self.client,
47 self.server_id, 'ACTIVE')
Viktor Tikkanen1b0ce232015-05-28 10:21:27 +030048 except lib_exc.NotFound:
49 # The server was deleted by previous test, create a new one
Joseph Lanouxffe09dd2015-03-18 16:45:33 +000050 server = self.create_test_server(
51 validatable=True,
52 wait_until='ACTIVE')
Viktor Tikkanen1b0ce232015-05-28 10:21:27 +030053 self.__class__.server_id = server['id']
Matt Riedemann2da58592014-06-08 12:46:02 +000054 except Exception:
55 # Rebuild server if something happened to it during a test
ghanshyam0f825252015-08-25 16:02:50 +090056 self.__class__.server_id = self.rebuild_server(
ghanshyam52d22352015-11-10 13:35:27 +090057 self.server_id, validatable=True)
Matt Riedemann2da58592014-06-08 12:46:02 +000058
59 def tearDown(self):
Matt Riedemann2da58592014-06-08 12:46:02 +000060 self.server_check_teardown()
61 super(ServerActionsTestJSON, self).tearDown()
Attila Fazekas305e65b2013-10-29 13:23:07 +010062
Attila Fazekas19044d52013-02-16 07:35:06 +010063 @classmethod
Joseph Lanouxffe09dd2015-03-18 16:45:33 +000064 def setup_credentials(cls):
65 cls.prepare_instance_network()
66 super(ServerActionsTestJSON, cls).setup_credentials()
67
68 @classmethod
Rohan Kanade60b73092015-02-04 17:58:19 +053069 def setup_clients(cls):
70 super(ServerActionsTestJSON, cls).setup_clients()
71 cls.client = cls.servers_client
72
73 @classmethod
Andrea Frittoli50bb80d2014-09-15 12:34:27 +010074 def resource_setup(cls):
Joseph Lanouxffe09dd2015-03-18 16:45:33 +000075 cls.set_validation_resources()
76
Andrea Frittoli50bb80d2014-09-15 12:34:27 +010077 super(ServerActionsTestJSON, cls).resource_setup()
Joseph Lanouxffe09dd2015-03-18 16:45:33 +000078 cls.server_id = cls.rebuild_server(None, validatable=True)
Attila Fazekas19044d52013-02-16 07:35:06 +010079
Chris Hoge7579c1a2015-02-26 14:12:15 -080080 @test.idempotent_id('6158df09-4b82-4ab3-af6d-29cf36af858d')
Sean Dague86bd8422013-12-20 09:56:44 -050081 @testtools.skipUnless(CONF.compute_feature_enabled.change_password,
ivan-zhu1feeb382013-01-24 10:14:39 +080082 'Change password not available.')
Daryl Wallecked8bef32011-12-05 23:02:08 -060083 def test_change_server_password(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -050084 # The server's password should be set to the provided password
Daryl Walleck98e66dd2012-06-21 04:58:39 -050085 new_password = 'Newpass1234'
Ken'ichi Ohmichie6349f32015-12-09 06:47:54 +000086 self.client.change_password(self.server_id, adminPass=new_password)
Ken'ichi Ohmichi0eb153c2015-07-13 02:18:25 +000087 waiters.wait_for_server_status(self.client, self.server_id, 'ACTIVE')
Daryl Wallecked8bef32011-12-05 23:02:08 -060088
Joseph Lanouxffe09dd2015-03-18 16:45:33 +000089 if CONF.validation.run_validation:
Daryl Walleck98e66dd2012-06-21 04:58:39 -050090 # Verify that the user can authenticate with the new password
ghanshyam0f825252015-08-25 16:02:50 +090091 server = self.client.show_server(self.server_id)['server']
Joseph Lanouxffe09dd2015-03-18 16:45:33 +000092 linux_client = remote_client.RemoteClient(
93 self.get_server_ip(server),
94 self.ssh_user,
Andrea Frittoli (andreaf)2a70a612016-04-29 16:09:13 -050095 new_password,
96 server=server,
97 servers_client=self.client)
Attila Fazekasad7ef7d2013-11-20 10:12:53 +010098 linux_client.validate_authentication()
Daryl Walleck98e66dd2012-06-21 04:58:39 -050099
Ken'ichi Ohmichi84d7fbc2014-09-30 01:42:33 +0000100 def _test_reboot_server(self, reboot_type):
Joseph Lanouxffe09dd2015-03-18 16:45:33 +0000101 if CONF.validation.run_validation:
Daryl Walleck98e66dd2012-06-21 04:58:39 -0500102 # Get the time the server was last rebooted,
ghanshyam0f825252015-08-25 16:02:50 +0900103 server = self.client.show_server(self.server_id)['server']
Joseph Lanouxffe09dd2015-03-18 16:45:33 +0000104 linux_client = remote_client.RemoteClient(
105 self.get_server_ip(server),
106 self.ssh_user,
107 self.password,
Andrea Frittoli (andreaf)2a70a612016-04-29 16:09:13 -0500108 self.validation_resources['keypair']['private_key'],
109 server=server,
110 servers_client=self.client)
Daryl Walleck98e66dd2012-06-21 04:58:39 -0500111 boot_time = linux_client.get_boot_time()
Daryl Walleck98e66dd2012-06-21 04:58:39 -0500112
Ken'ichi Ohmichi36b714c2015-12-09 08:12:47 +0000113 self.client.reboot_server(self.server_id, type=reboot_type)
Ken'ichi Ohmichi0eb153c2015-07-13 02:18:25 +0000114 waiters.wait_for_server_status(self.client, self.server_id, 'ACTIVE')
Daryl Wallecked8bef32011-12-05 23:02:08 -0600115
Joseph Lanouxffe09dd2015-03-18 16:45:33 +0000116 if CONF.validation.run_validation:
Daryl Walleck98e66dd2012-06-21 04:58:39 -0500117 # Log in and verify the boot time has changed
Joseph Lanouxffe09dd2015-03-18 16:45:33 +0000118 linux_client = remote_client.RemoteClient(
119 self.get_server_ip(server),
120 self.ssh_user,
121 self.password,
Andrea Frittoli (andreaf)2a70a612016-04-29 16:09:13 -0500122 self.validation_resources['keypair']['private_key'],
123 server=server,
124 servers_client=self.client)
Daryl Walleck98e66dd2012-06-21 04:58:39 -0500125 new_boot_time = linux_client.get_boot_time()
Vincent Untz32173d12014-01-19 20:34:47 +0100126 self.assertTrue(new_boot_time > boot_time,
127 '%s > %s' % (new_boot_time, boot_time))
Daryl Walleck98e66dd2012-06-21 04:58:39 -0500128
Ken'ichi Ohmichi84d7fbc2014-09-30 01:42:33 +0000129 @test.attr(type='smoke')
Chris Hoge7579c1a2015-02-26 14:12:15 -0800130 @test.idempotent_id('2cb1baf6-ac8d-4429-bf0d-ba8a0ba53e32')
Ken'ichi Ohmichi84d7fbc2014-09-30 01:42:33 +0000131 def test_reboot_server_hard(self):
132 # The server should be power cycled
133 self._test_reboot_server('HARD')
134
Matthew Treinishc49fcbe2015-02-05 23:37:34 -0500135 @decorators.skip_because(bug="1014647")
Chris Hoge7579c1a2015-02-26 14:12:15 -0800136 @test.idempotent_id('4640e3ef-a5df-482e-95a1-ceeeb0faa84d')
Daryl Wallecked8bef32011-12-05 23:02:08 -0600137 def test_reboot_server_soft(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500138 # The server should be signaled to reboot gracefully
Ken'ichi Ohmichi84d7fbc2014-09-30 01:42:33 +0000139 self._test_reboot_server('SOFT')
Daryl Walleck98e66dd2012-06-21 04:58:39 -0500140
Yaroslav Lobankovfb1c3642015-05-13 18:38:47 +0300141 def _rebuild_server_and_check(self, image_ref):
ghanshyam0f825252015-08-25 16:02:50 +0900142 rebuilt_server = (self.client.rebuild_server(self.server_id, image_ref)
143 ['server'])
Ken'ichi Ohmichi0eb153c2015-07-13 02:18:25 +0000144 waiters.wait_for_server_status(self.client, self.server_id, 'ACTIVE')
Yaroslav Lobankovfb1c3642015-05-13 18:38:47 +0300145 msg = ('Server was not rebuilt to the original image. '
146 'The original image: {0}. The current image: {1}'
147 .format(image_ref, rebuilt_server['image']['id']))
148 self.assertEqual(image_ref, rebuilt_server['image']['id'], msg)
149
Chris Hoge7579c1a2015-02-26 14:12:15 -0800150 @test.idempotent_id('aaa6cdf3-55a7-461a-add9-1c8596b9a07c')
Daryl Wallecked8bef32011-12-05 23:02:08 -0600151 def test_rebuild_server(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500152 # The server should be rebuilt using the provided image and data
Daryl Wallecked8bef32011-12-05 23:02:08 -0600153 meta = {'rebuild': 'server'}
Masayuki Igawa259c1132013-10-31 17:48:44 +0900154 new_name = data_utils.rand_name('server')
Daryl Walleck98e66dd2012-06-21 04:58:39 -0500155 password = 'rebuildPassw0rd'
ghanshyam0f825252015-08-25 16:02:50 +0900156 rebuilt_server = self.client.rebuild_server(
157 self.server_id,
158 self.image_ref_alt,
159 name=new_name,
160 metadata=meta,
ghanshyam0f825252015-08-25 16:02:50 +0900161 adminPass=password)['server']
Daryl Wallecked8bef32011-12-05 23:02:08 -0600162
Andrea Frittolie8040812015-04-28 14:26:35 +0100163 # If the server was rebuilt on a different image, restore it to the
164 # original image once the test ends
165 if self.image_ref_alt != self.image_ref:
Yaroslav Lobankovfb1c3642015-05-13 18:38:47 +0300166 self.addCleanup(self._rebuild_server_and_check, self.image_ref)
Andrea Frittolie8040812015-04-28 14:26:35 +0100167
Attila Fazekasf7f34f92013-08-01 17:01:44 +0200168 # Verify the properties in the initial response are correct
Brian Waldon3bde07f2011-12-13 15:11:22 -0500169 self.assertEqual(self.server_id, rebuilt_server['id'])
Eoghan Glynn57c1a3d2012-03-01 16:50:29 -0500170 rebuilt_image_id = rebuilt_server['image']['id']
171 self.assertTrue(self.image_ref_alt.endswith(rebuilt_image_id))
Ken'ichi Ohmichi35772602013-11-14 15:03:27 +0900172 self.assertEqual(self.flavor_ref, rebuilt_server['flavor']['id'])
Daryl Wallecked8bef32011-12-05 23:02:08 -0600173
Attila Fazekasf7f34f92013-08-01 17:01:44 +0200174 # Verify the server properties after the rebuild completes
Ken'ichi Ohmichi0eb153c2015-07-13 02:18:25 +0000175 waiters.wait_for_server_status(self.client,
176 rebuilt_server['id'], 'ACTIVE')
ghanshyam0f825252015-08-25 16:02:50 +0900177 server = self.client.show_server(rebuilt_server['id'])['server']
Zhi Kun Liue5401762013-09-11 20:45:48 +0800178 rebuilt_image_id = server['image']['id']
Eoghan Glynn57c1a3d2012-03-01 16:50:29 -0500179 self.assertTrue(self.image_ref_alt.endswith(rebuilt_image_id))
Zhi Kun Liue5401762013-09-11 20:45:48 +0800180 self.assertEqual(new_name, server['name'])
Daryl Wallecked8bef32011-12-05 23:02:08 -0600181
Joseph Lanouxffe09dd2015-03-18 16:45:33 +0000182 if CONF.validation.run_validation:
wangxiyuan878c50e2016-01-04 19:24:17 +0800183 # Authentication is attempted in the following order of priority:
184 # 1.The key passed in, if one was passed in.
185 # 2.Any key we can find through an SSH agent (if allowed).
186 # 3.Any "id_rsa", "id_dsa" or "id_ecdsa" key discoverable in
187 # ~/.ssh/ (if allowed).
188 # 4.Plain username/password auth, if a password was given.
Joseph Lanouxffe09dd2015-03-18 16:45:33 +0000189 linux_client = remote_client.RemoteClient(
190 self.get_server_ip(rebuilt_server),
191 self.ssh_user,
wangxiyuan878c50e2016-01-04 19:24:17 +0800192 password,
Andrea Frittoli (andreaf)2a70a612016-04-29 16:09:13 -0500193 self.validation_resources['keypair']['private_key'],
194 server=rebuilt_server,
195 servers_client=self.client)
Attila Fazekasad7ef7d2013-11-20 10:12:53 +0100196 linux_client.validate_authentication()
Daryl Walleck98e66dd2012-06-21 04:58:39 -0500197
Chris Hoge7579c1a2015-02-26 14:12:15 -0800198 @test.idempotent_id('30449a88-5aff-4f9b-9866-6ee9b17f906d')
Zhi Kun Liue5401762013-09-11 20:45:48 +0800199 def test_rebuild_server_in_stop_state(self):
200 # The server in stop state should be rebuilt using the provided
201 # image and remain in SHUTOFF state
ghanshyam0f825252015-08-25 16:02:50 +0900202 server = self.client.show_server(self.server_id)['server']
Zhi Kun Liue5401762013-09-11 20:45:48 +0800203 old_image = server['image']['id']
Yaroslav Lobankovfb1c3642015-05-13 18:38:47 +0300204 new_image = (self.image_ref_alt
205 if old_image == self.image_ref else self.image_ref)
Ken'ichi Ohmichib2631082015-08-27 01:31:00 +0000206 self.client.stop_server(self.server_id)
Ken'ichi Ohmichi0eb153c2015-07-13 02:18:25 +0000207 waiters.wait_for_server_status(self.client, self.server_id, 'SHUTOFF')
ghanshyam0f825252015-08-25 16:02:50 +0900208 rebuilt_server = (self.client.rebuild_server(self.server_id, new_image)
209 ['server'])
Yaroslav Lobankovfb1c3642015-05-13 18:38:47 +0300210 # If the server was rebuilt on a different image, restore it to the
211 # original image once the test ends
212 if self.image_ref_alt != self.image_ref:
213 self.addCleanup(self._rebuild_server_and_check, old_image)
Zhi Kun Liue5401762013-09-11 20:45:48 +0800214
215 # Verify the properties in the initial response are correct
216 self.assertEqual(self.server_id, rebuilt_server['id'])
217 rebuilt_image_id = rebuilt_server['image']['id']
218 self.assertEqual(new_image, rebuilt_image_id)
219 self.assertEqual(self.flavor_ref, rebuilt_server['flavor']['id'])
220
221 # Verify the server properties after the rebuild completes
Ken'ichi Ohmichi0eb153c2015-07-13 02:18:25 +0000222 waiters.wait_for_server_status(self.client,
223 rebuilt_server['id'], 'SHUTOFF')
ghanshyam0f825252015-08-25 16:02:50 +0900224 server = self.client.show_server(rebuilt_server['id'])['server']
Zhi Kun Liue5401762013-09-11 20:45:48 +0800225 rebuilt_image_id = server['image']['id']
226 self.assertEqual(new_image, rebuilt_image_id)
227
Ken'ichi Ohmichib2631082015-08-27 01:31:00 +0000228 self.client.start_server(self.server_id)
Attila Fazekas305e65b2013-10-29 13:23:07 +0100229
Roman Podoliaka908f9062015-04-21 16:52:20 +0300230 @test.idempotent_id('b68bd8d6-855d-4212-b59b-2e704044dace')
231 @test.services('volume')
232 def test_rebuild_server_with_volume_attached(self):
233 # create a new volume and attach it to the server
234 volume = self.volumes_client.create_volume(
235 size=CONF.volume.volume_size)
236 volume = volume['volume']
237 self.addCleanup(self.volumes_client.delete_volume, volume['id'])
238 waiters.wait_for_volume_status(self.volumes_client, volume['id'],
239 'available')
240
241 self.client.attach_volume(self.server_id, volumeId=volume['id'])
242 self.addCleanup(waiters.wait_for_volume_status, self.volumes_client,
243 volume['id'], 'available')
244 self.addCleanup(self.client.detach_volume,
245 self.server_id, volume['id'])
246 waiters.wait_for_volume_status(self.volumes_client, volume['id'],
247 'in-use')
248
249 # run general rebuild test
250 self.test_rebuild_server()
251
252 # make sure the volume is attached to the instance after rebuild
253 vol_after_rebuild = self.volumes_client.show_volume(volume['id'])
254 vol_after_rebuild = vol_after_rebuild['volume']
255 self.assertEqual('in-use', vol_after_rebuild['status'])
256 self.assertEqual(self.server_id,
257 vol_after_rebuild['attachments'][0]['server_id'])
258
Matt Riedemann9fd63b82014-04-14 09:33:05 -0700259 def _test_resize_server_confirm(self, stop=False):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500260 # The server's RAM and disk space should be modified to that of
261 # the provided flavor
Daryl Wallecked8bef32011-12-05 23:02:08 -0600262
Matt Riedemann9fd63b82014-04-14 09:33:05 -0700263 if stop:
Ken'ichi Ohmichib2631082015-08-27 01:31:00 +0000264 self.client.stop_server(self.server_id)
Ken'ichi Ohmichi32752ff2015-07-13 04:33:23 +0000265 waiters.wait_for_server_status(self.client, self.server_id,
Ken'ichi Ohmichi0eb153c2015-07-13 02:18:25 +0000266 'SHUTOFF')
Matt Riedemann9fd63b82014-04-14 09:33:05 -0700267
Ken'ichi Ohmichi5271b0f2015-08-10 07:53:27 +0000268 self.client.resize_server(self.server_id, self.flavor_ref_alt)
Ken'ichi Ohmichi0eb153c2015-07-13 02:18:25 +0000269 waiters.wait_for_server_status(self.client, self.server_id,
270 'VERIFY_RESIZE')
Daryl Wallecked8bef32011-12-05 23:02:08 -0600271
Ken'ichi Ohmichib2631082015-08-27 01:31:00 +0000272 self.client.confirm_resize_server(self.server_id)
Matt Riedemann9fd63b82014-04-14 09:33:05 -0700273 expected_status = 'SHUTOFF' if stop else 'ACTIVE'
Ken'ichi Ohmichi0eb153c2015-07-13 02:18:25 +0000274 waiters.wait_for_server_status(self.client, self.server_id,
275 expected_status)
Daryl Wallecked8bef32011-12-05 23:02:08 -0600276
ghanshyam0f825252015-08-25 16:02:50 +0900277 server = self.client.show_server(self.server_id)['server']
Jesse Keating613b4982015-05-04 15:05:19 -0700278 self.assertEqual(self.flavor_ref_alt, server['flavor']['id'])
Daryl Wallecked8bef32011-12-05 23:02:08 -0600279
Matt Riedemann9fd63b82014-04-14 09:33:05 -0700280 if stop:
281 # NOTE(mriedem): tearDown requires the server to be started.
Ken'ichi Ohmichib2631082015-08-27 01:31:00 +0000282 self.client.start_server(self.server_id)
Matt Riedemann9fd63b82014-04-14 09:33:05 -0700283
Jesse Keating613b4982015-05-04 15:05:19 -0700284 # NOTE(jlk): Explicitly delete the server to get a new one for later
285 # tests. Avoids resize down race issues.
286 self.addCleanup(self.delete_server, self.server_id)
287
Chris Hoge7579c1a2015-02-26 14:12:15 -0800288 @test.idempotent_id('1499262a-9328-4eda-9068-db1ac57498d2')
Matt Riedemann9fd63b82014-04-14 09:33:05 -0700289 @testtools.skipUnless(CONF.compute_feature_enabled.resize,
290 'Resize not available.')
Matt Riedemann9fd63b82014-04-14 09:33:05 -0700291 def test_resize_server_confirm(self):
292 self._test_resize_server_confirm(stop=False)
293
Chris Hoge7579c1a2015-02-26 14:12:15 -0800294 @test.idempotent_id('138b131d-66df-48c9-a171-64f45eb92962')
Matt Riedemann9fd63b82014-04-14 09:33:05 -0700295 @testtools.skipUnless(CONF.compute_feature_enabled.resize,
296 'Resize not available.')
Matt Riedemann9fd63b82014-04-14 09:33:05 -0700297 def test_resize_server_confirm_from_stopped(self):
298 self._test_resize_server_confirm(stop=True)
299
Chris Hoge7579c1a2015-02-26 14:12:15 -0800300 @test.idempotent_id('c03aab19-adb1-44f5-917d-c419577e9e68')
Matt Riedemann5d1f8b12014-03-24 09:12:53 -0700301 @testtools.skipUnless(CONF.compute_feature_enabled.resize,
302 'Resize not available.')
Daryl Wallecked8bef32011-12-05 23:02:08 -0600303 def test_resize_server_revert(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500304 # The server's RAM and disk space should return to its original
305 # values after a resize is reverted
Daryl Wallecked8bef32011-12-05 23:02:08 -0600306
Ken'ichi Ohmichi5271b0f2015-08-10 07:53:27 +0000307 self.client.resize_server(self.server_id, self.flavor_ref_alt)
Ken'ichi Ohmichi0eb153c2015-07-13 02:18:25 +0000308 waiters.wait_for_server_status(self.client, self.server_id,
309 'VERIFY_RESIZE')
Daryl Wallecked8bef32011-12-05 23:02:08 -0600310
Ken'ichi Ohmichib2631082015-08-27 01:31:00 +0000311 self.client.revert_resize_server(self.server_id)
Ken'ichi Ohmichi0eb153c2015-07-13 02:18:25 +0000312 waiters.wait_for_server_status(self.client, self.server_id, 'ACTIVE')
Daryl Wallecked8bef32011-12-05 23:02:08 -0600313
ghanshyam0f825252015-08-25 16:02:50 +0900314 server = self.client.show_server(self.server_id)['server']
Jesse Keating613b4982015-05-04 15:05:19 -0700315 self.assertEqual(self.flavor_ref, server['flavor']['id'])
sapan-konaf1e3f002011-12-22 23:18:44 +0530316
Chris Hoge7579c1a2015-02-26 14:12:15 -0800317 @test.idempotent_id('b963d4f1-94b3-4c40-9e97-7b583f46e470')
Adam Gandelmanfbc95ac2014-06-19 17:33:43 -0700318 @testtools.skipUnless(CONF.compute_feature_enabled.snapshot,
319 'Snapshotting not available, backup not possible.')
ekhugen0b3bc522014-08-04 20:58:21 +0000320 @test.services('image')
ivan-zhuccc89462013-10-31 16:53:12 +0800321 def test_create_backup(self):
322 # Positive test:create backup successfully and rotate backups correctly
323 # create the first and the second backup
Matt Riedemann2aa19d42016-06-06 17:45:41 -0400324
325 # Check if glance v1 is available to determine which client to use. We
326 # prefer glance v1 for the compute API tests since the compute image
327 # API proxy was written for glance v1.
328 if CONF.image_feature_enabled.api_v1:
329 glance_client = self.os.image_client
330 elif CONF.image_feature_enabled.api_v2:
331 glance_client = self.os.image_client_v2
332 else:
333 raise exceptions.InvalidConfiguration(
334 'Either api_v1 or api_v2 must be True in '
335 '[image-feature-enabled].')
336
Matt Riedemanne699f822014-01-24 08:11:42 -0800337 backup1 = data_utils.rand_name('backup-1')
Ken'ichi Ohmichi32752ff2015-07-13 04:33:23 +0000338 resp = self.client.create_backup(self.server_id,
Ken'ichi Ohmichie6349f32015-12-09 06:47:54 +0000339 backup_type='daily',
340 rotation=2,
341 name=backup1).response
ivan-zhuccc89462013-10-31 16:53:12 +0800342 oldest_backup_exist = True
343
344 # the oldest one should be deleted automatically in this test
345 def _clean_oldest_backup(oldest_backup):
346 if oldest_backup_exist:
Ryan Hsu38231092014-06-08 23:12:10 -0700347 try:
Matt Riedemann2aa19d42016-06-06 17:45:41 -0400348 glance_client.delete_image(oldest_backup)
Masayuki Igawabfa07602015-01-20 18:47:17 +0900349 except lib_exc.NotFound:
Ryan Hsu38231092014-06-08 23:12:10 -0700350 pass
351 else:
352 LOG.warning("Deletion of oldest backup %s should not have "
353 "been successful as it should have been "
354 "deleted during rotation." % oldest_backup)
ivan-zhuccc89462013-10-31 16:53:12 +0800355
Masayuki Igawa259c1132013-10-31 17:48:44 +0900356 image1_id = data_utils.parse_image_id(resp['location'])
ivan-zhuccc89462013-10-31 16:53:12 +0800357 self.addCleanup(_clean_oldest_backup, image1_id)
Matt Riedemann2aa19d42016-06-06 17:45:41 -0400358 waiters.wait_for_image_status(glance_client,
Yaroslav Lobankov2fea4052016-04-19 15:05:57 +0300359 image1_id, 'active')
ivan-zhuccc89462013-10-31 16:53:12 +0800360
Matt Riedemanne699f822014-01-24 08:11:42 -0800361 backup2 = data_utils.rand_name('backup-2')
Ken'ichi Ohmichi32752ff2015-07-13 04:33:23 +0000362 waiters.wait_for_server_status(self.client, self.server_id, 'ACTIVE')
363 resp = self.client.create_backup(self.server_id,
Ken'ichi Ohmichie6349f32015-12-09 06:47:54 +0000364 backup_type='daily',
365 rotation=2,
366 name=backup2).response
Masayuki Igawa259c1132013-10-31 17:48:44 +0900367 image2_id = data_utils.parse_image_id(resp['location'])
Matt Riedemann2aa19d42016-06-06 17:45:41 -0400368 self.addCleanup(glance_client.delete_image, image2_id)
369 waiters.wait_for_image_status(glance_client,
Yaroslav Lobankov2fea4052016-04-19 15:05:57 +0300370 image2_id, 'active')
ivan-zhuccc89462013-10-31 16:53:12 +0800371
372 # verify they have been created
373 properties = {
374 'image_type': 'backup',
375 'backup_type': "daily",
376 'instance_uuid': self.server_id,
377 }
Matt Riedemann2aa19d42016-06-06 17:45:41 -0400378 if CONF.image_feature_enabled.api_v1:
379 params = dict(
380 properties=properties, status='active',
381 sort_key='created_at', sort_dir='asc',)
382 image_list = glance_client.list_images(
383 detail=True,
384 **params)['images']
385 else:
386 # Additional properties are flattened in glance v2.
387 params = dict(
388 status='active', sort_key='created_at', sort_dir='asc')
389 params.update(properties)
390 image_list = glance_client.list_images(params)['images']
391
ivan-zhuccc89462013-10-31 16:53:12 +0800392 self.assertEqual(2, len(image_list))
393 self.assertEqual((backup1, backup2),
394 (image_list[0]['name'], image_list[1]['name']))
395
396 # create the third one, due to the rotation is 2,
397 # the first one will be deleted
Matt Riedemanne699f822014-01-24 08:11:42 -0800398 backup3 = data_utils.rand_name('backup-3')
Ken'ichi Ohmichi32752ff2015-07-13 04:33:23 +0000399 waiters.wait_for_server_status(self.client, self.server_id, 'ACTIVE')
400 resp = self.client.create_backup(self.server_id,
Ken'ichi Ohmichie6349f32015-12-09 06:47:54 +0000401 backup_type='daily',
402 rotation=2,
403 name=backup3).response
Masayuki Igawa259c1132013-10-31 17:48:44 +0900404 image3_id = data_utils.parse_image_id(resp['location'])
Matt Riedemann2aa19d42016-06-06 17:45:41 -0400405 self.addCleanup(glance_client.delete_image, image3_id)
ivan-zhuccc89462013-10-31 16:53:12 +0800406 # the first back up should be deleted
Ken'ichi Ohmichi32752ff2015-07-13 04:33:23 +0000407 waiters.wait_for_server_status(self.client, self.server_id, 'ACTIVE')
Matt Riedemann2aa19d42016-06-06 17:45:41 -0400408 glance_client.wait_for_resource_deletion(image1_id)
ivan-zhuccc89462013-10-31 16:53:12 +0800409 oldest_backup_exist = False
Matt Riedemann2aa19d42016-06-06 17:45:41 -0400410 if CONF.image_feature_enabled.api_v1:
411 image_list = glance_client.list_images(
412 detail=True, **params)['images']
413 else:
414 image_list = glance_client.list_images(params)['images']
Matt Riedemanne699f822014-01-24 08:11:42 -0800415 self.assertEqual(2, len(image_list),
416 'Unexpected number of images for '
417 'v2:test_create_backup; was the oldest backup not '
418 'yet deleted? Image list: %s' %
419 [image['name'] for image in image_list])
ivan-zhuccc89462013-10-31 16:53:12 +0800420 self.assertEqual((backup2, backup3),
421 (image_list[0]['name'], image_list[1]['name']))
422
Ken'ichi Ohmichi547a3062013-12-02 09:30:36 +0900423 def _get_output(self):
Ken'ichi Ohmichi32752ff2015-07-13 04:33:23 +0000424 output = self.client.get_console_output(
Ken'ichi Ohmichibf4766a2015-12-09 07:48:43 +0000425 self.server_id, length=10)['output']
Ken'ichi Ohmichi547a3062013-12-02 09:30:36 +0900426 self.assertTrue(output, "Console output was empty.")
427 lines = len(output.split('\n'))
428 self.assertEqual(lines, 10)
429
Chris Hoge7579c1a2015-02-26 14:12:15 -0800430 @test.idempotent_id('4b8867e6-fffa-4d54-b1d1-6fdda57be2f3')
Adam Gandelmanc6eefb42014-07-15 16:44:08 -0700431 @testtools.skipUnless(CONF.compute_feature_enabled.console_output,
432 'Console output not supported.')
Attila Fazekas45c3fbc2013-02-24 16:39:52 +0100433 def test_get_console_output(self):
434 # Positive test:Should be able to GET the console output
435 # for a given server_id and number of lines
Ken'ichi Ohmichi851a1352013-11-26 18:42:52 +0900436
437 # This reboot is necessary for outputting some console log after
Takashi NATSUME6d5a2b42015-09-08 11:27:49 +0900438 # creating an instance backup. If an instance backup, the console
Ken'ichi Ohmichi851a1352013-11-26 18:42:52 +0900439 # log file is truncated and we cannot get any console log through
440 # "console-log" API.
441 # The detail is https://bugs.launchpad.net/nova/+bug/1251920
Ken'ichi Ohmichi36b714c2015-12-09 08:12:47 +0000442 self.client.reboot_server(self.server_id, type='HARD')
Ken'ichi Ohmichi32752ff2015-07-13 04:33:23 +0000443 waiters.wait_for_server_status(self.client, self.server_id, 'ACTIVE')
Ken'ichi Ohmichi547a3062013-12-02 09:30:36 +0900444 self.wait_for(self._get_output)
Attila Fazekas45c3fbc2013-02-24 16:39:52 +0100445
Chris Hoge7579c1a2015-02-26 14:12:15 -0800446 @test.idempotent_id('89104062-69d8-4b19-a71b-f47b7af093d7')
Adam Gandelmanc6eefb42014-07-15 16:44:08 -0700447 @testtools.skipUnless(CONF.compute_feature_enabled.console_output,
448 'Console output not supported.')
Ken'ichi Ohmichibd5df122014-09-18 08:03:52 +0000449 def test_get_console_output_with_unlimited_size(self):
David Kranz0fb14292015-02-11 15:55:20 -0500450 server = self.create_test_server(wait_until='ACTIVE')
Ken'ichi Ohmichibd5df122014-09-18 08:03:52 +0000451
452 def _check_full_length_console_log():
Ken'ichi Ohmichibf4766a2015-12-09 07:48:43 +0000453 output = self.client.get_console_output(server['id'])['output']
Ken'ichi Ohmichibd5df122014-09-18 08:03:52 +0000454 self.assertTrue(output, "Console output was empty.")
455 lines = len(output.split('\n'))
456
457 # NOTE: This test tries to get full length console log, and the
458 # length should be bigger than the one of test_get_console_output.
459 self.assertTrue(lines > 10, "Cannot get enough console log length."
460 " (lines: %s)" % lines)
461
462 self.wait_for(_check_full_length_console_log)
463
Chris Hoge7579c1a2015-02-26 14:12:15 -0800464 @test.idempotent_id('5b65d4e7-4ecd-437c-83c0-d6b79d927568')
Ken'ichi Ohmichibd5df122014-09-18 08:03:52 +0000465 @testtools.skipUnless(CONF.compute_feature_enabled.console_output,
466 'Console output not supported.')
Ken'ichi Ohmichi547a3062013-12-02 09:30:36 +0900467 def test_get_console_output_server_id_in_shutoff_status(self):
Attila Fazekas45c3fbc2013-02-24 16:39:52 +0100468 # Positive test:Should be able to GET the console output
Ken'ichi Ohmichi547a3062013-12-02 09:30:36 +0900469 # for a given server_id in SHUTOFF status
470
471 # NOTE: SHUTOFF is irregular status. To avoid test instability,
472 # one server is created only for this test without using
473 # the server that was created in setupClass.
David Kranz0fb14292015-02-11 15:55:20 -0500474 server = self.create_test_server(wait_until='ACTIVE')
Ken'ichi Ohmichi547a3062013-12-02 09:30:36 +0900475 temp_server_id = server['id']
476
Ken'ichi Ohmichib2631082015-08-27 01:31:00 +0000477 self.client.stop_server(temp_server_id)
Ken'ichi Ohmichi32752ff2015-07-13 04:33:23 +0000478 waiters.wait_for_server_status(self.client, temp_server_id, 'SHUTOFF')
Ken'ichi Ohmichi547a3062013-12-02 09:30:36 +0900479 self.wait_for(self._get_output)
Dan Smithbc3bd242012-08-14 09:48:48 -0700480
Chris Hoge7579c1a2015-02-26 14:12:15 -0800481 @test.idempotent_id('bd61a9fd-062f-4670-972b-2d6c3e3b9e73')
Matt Riedemann992162e2014-03-24 09:11:06 -0700482 @testtools.skipUnless(CONF.compute_feature_enabled.pause,
483 'Pause is not available.')
Prem Karat6631f802013-07-04 12:07:33 +0530484 def test_pause_unpause_server(self):
David Kranzae99b9a2015-02-16 13:37:01 -0500485 self.client.pause_server(self.server_id)
Ken'ichi Ohmichi0eb153c2015-07-13 02:18:25 +0000486 waiters.wait_for_server_status(self.client, self.server_id, 'PAUSED')
David Kranzae99b9a2015-02-16 13:37:01 -0500487 self.client.unpause_server(self.server_id)
Ken'ichi Ohmichi0eb153c2015-07-13 02:18:25 +0000488 waiters.wait_for_server_status(self.client, self.server_id, 'ACTIVE')
Prem Karat6631f802013-07-04 12:07:33 +0530489
Chris Hoge7579c1a2015-02-26 14:12:15 -0800490 @test.idempotent_id('0d8ee21e-b749-462d-83da-b85b41c86c7f')
Matt Riedemannf0cf6952014-03-24 09:08:52 -0700491 @testtools.skipUnless(CONF.compute_feature_enabled.suspend,
492 'Suspend is not available.')
Prem Karat6631f802013-07-04 12:07:33 +0530493 def test_suspend_resume_server(self):
David Kranzae99b9a2015-02-16 13:37:01 -0500494 self.client.suspend_server(self.server_id)
Ken'ichi Ohmichi0eb153c2015-07-13 02:18:25 +0000495 waiters.wait_for_server_status(self.client, self.server_id,
496 'SUSPENDED')
David Kranzae99b9a2015-02-16 13:37:01 -0500497 self.client.resume_server(self.server_id)
Ken'ichi Ohmichi0eb153c2015-07-13 02:18:25 +0000498 waiters.wait_for_server_status(self.client, self.server_id, 'ACTIVE')
Prem Karat6631f802013-07-04 12:07:33 +0530499
Chris Hoge7579c1a2015-02-26 14:12:15 -0800500 @test.idempotent_id('77eba8e0-036e-4635-944b-f7a8f3b78dc9')
David Shrewsbury25f666f2014-07-22 12:17:59 -0400501 @testtools.skipUnless(CONF.compute_feature_enabled.shelve,
502 'Shelve is not available.')
Ken'ichi Ohmichi39437e22013-10-06 00:21:38 +0900503 def test_shelve_unshelve_server(self):
ghanshyam017b5fe2016-04-15 18:49:26 +0900504 compute.shelve_server(self.client, self.server_id,
505 force_shelve_offload=True)
Ken'ichi Ohmichi17b7f112014-02-20 06:33:49 +0900506
ghanshyam0f825252015-08-25 16:02:50 +0900507 server = self.client.show_server(self.server_id)['server']
Ken'ichi Ohmichi39437e22013-10-06 00:21:38 +0900508 image_name = server['name'] + '-shelved'
509 params = {'name': image_name}
Ghanshyamae76c122015-12-22 13:41:35 +0900510 images = self.compute_images_client.list_images(**params)['images']
Ken'ichi Ohmichi39437e22013-10-06 00:21:38 +0900511 self.assertEqual(1, len(images))
512 self.assertEqual(image_name, images[0]['name'])
513
David Kranzae99b9a2015-02-16 13:37:01 -0500514 self.client.unshelve_server(self.server_id)
Ken'ichi Ohmichi0eb153c2015-07-13 02:18:25 +0000515 waiters.wait_for_server_status(self.client, self.server_id, 'ACTIVE')
Ken'ichi Ohmichi39437e22013-10-06 00:21:38 +0900516
Chris Hoge7579c1a2015-02-26 14:12:15 -0800517 @test.idempotent_id('af8eafd4-38a7-4a4b-bdbc-75145a580560')
Anju Tiwariaf98d222013-08-05 15:19:50 +0530518 def test_stop_start_server(self):
Ken'ichi Ohmichib2631082015-08-27 01:31:00 +0000519 self.client.stop_server(self.server_id)
Ken'ichi Ohmichi32752ff2015-07-13 04:33:23 +0000520 waiters.wait_for_server_status(self.client, self.server_id, 'SHUTOFF')
Ken'ichi Ohmichib2631082015-08-27 01:31:00 +0000521 self.client.start_server(self.server_id)
Ken'ichi Ohmichi32752ff2015-07-13 04:33:23 +0000522 waiters.wait_for_server_status(self.client, self.server_id, 'ACTIVE')
Anju Tiwariaf98d222013-08-05 15:19:50 +0530523
Chris Hoge7579c1a2015-02-26 14:12:15 -0800524 @test.idempotent_id('80a8094c-211e-440a-ab88-9e59d556c7ee')
Zhu Zhu9643e512013-09-23 09:13:07 -0500525 def test_lock_unlock_server(self):
526 # Lock the server,try server stop(exceptions throw),unlock it and retry
Ken'ichi Ohmichi32752ff2015-07-13 04:33:23 +0000527 self.client.lock_server(self.server_id)
Viktor Tikkanen3d063df2015-06-26 07:55:11 +0300528 self.addCleanup(self.client.unlock_server, self.server_id)
ghanshyam0f825252015-08-25 16:02:50 +0900529 server = self.client.show_server(self.server_id)['server']
Zhu Zhu9643e512013-09-23 09:13:07 -0500530 self.assertEqual(server['status'], 'ACTIVE')
531 # Locked server is not allowed to be stopped by non-admin user
Masayuki Igawad9388762015-01-20 14:56:42 +0900532 self.assertRaises(lib_exc.Conflict,
Ken'ichi Ohmichib2631082015-08-27 01:31:00 +0000533 self.client.stop_server, self.server_id)
Ken'ichi Ohmichi32752ff2015-07-13 04:33:23 +0000534 self.client.unlock_server(self.server_id)
Ken'ichi Ohmichib2631082015-08-27 01:31:00 +0000535 self.client.stop_server(self.server_id)
Ken'ichi Ohmichi32752ff2015-07-13 04:33:23 +0000536 waiters.wait_for_server_status(self.client, self.server_id, 'SHUTOFF')
Ken'ichi Ohmichib2631082015-08-27 01:31:00 +0000537 self.client.start_server(self.server_id)
Ken'ichi Ohmichi32752ff2015-07-13 04:33:23 +0000538 waiters.wait_for_server_status(self.client, self.server_id, 'ACTIVE')
Zhu Zhu9643e512013-09-23 09:13:07 -0500539
Ghanshyam86d1a572014-03-05 10:19:25 +0900540 def _validate_url(self, url):
541 valid_scheme = ['http', 'https']
542 parsed_url = urlparse.urlparse(url)
543 self.assertNotEqual('None', parsed_url.port)
544 self.assertNotEqual('None', parsed_url.hostname)
545 self.assertIn(parsed_url.scheme, valid_scheme)
546
Chris Hoge7579c1a2015-02-26 14:12:15 -0800547 @test.idempotent_id('c6bc11bf-592e-4015-9319-1c98dc64daf5')
Ghanshyam86d1a572014-03-05 10:19:25 +0900548 @testtools.skipUnless(CONF.compute_feature_enabled.vnc_console,
549 'VNC Console feature is disabled.')
Ghanshyam86d1a572014-03-05 10:19:25 +0900550 def test_get_vnc_console(self):
551 # Get the VNC console of type 'novnc' and 'xvpvnc'
552 console_types = ['novnc', 'xvpvnc']
553 for console_type in console_types:
Ken'ichi Ohmichi32752ff2015-07-13 04:33:23 +0000554 body = self.client.get_vnc_console(self.server_id,
Ken'ichi Ohmichibf4766a2015-12-09 07:48:43 +0000555 type=console_type)['console']
Ghanshyam86d1a572014-03-05 10:19:25 +0900556 self.assertEqual(console_type, body['type'])
557 self.assertNotEqual('', body['url'])
558 self._validate_url(body['url'])