blob: 21e7d103a2369fcee616287ddf24fb46e9b45830 [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 Ohmichi05ab8562016-07-12 00:06:18 -0700113 # NOTE: This sync is for avoiding the loss of pub key data
114 # in a server
115 linux_client.exec_command("sync")
116
Ken'ichi Ohmichi36b714c2015-12-09 08:12:47 +0000117 self.client.reboot_server(self.server_id, type=reboot_type)
Ken'ichi Ohmichi0eb153c2015-07-13 02:18:25 +0000118 waiters.wait_for_server_status(self.client, self.server_id, 'ACTIVE')
Daryl Wallecked8bef32011-12-05 23:02:08 -0600119
Joseph Lanouxffe09dd2015-03-18 16:45:33 +0000120 if CONF.validation.run_validation:
Daryl Walleck98e66dd2012-06-21 04:58:39 -0500121 # Log in and verify the boot time has changed
Joseph Lanouxffe09dd2015-03-18 16:45:33 +0000122 linux_client = remote_client.RemoteClient(
123 self.get_server_ip(server),
124 self.ssh_user,
125 self.password,
Andrea Frittoli (andreaf)2a70a612016-04-29 16:09:13 -0500126 self.validation_resources['keypair']['private_key'],
127 server=server,
128 servers_client=self.client)
Daryl Walleck98e66dd2012-06-21 04:58:39 -0500129 new_boot_time = linux_client.get_boot_time()
Vincent Untz32173d12014-01-19 20:34:47 +0100130 self.assertTrue(new_boot_time > boot_time,
131 '%s > %s' % (new_boot_time, boot_time))
Daryl Walleck98e66dd2012-06-21 04:58:39 -0500132
Ken'ichi Ohmichi84d7fbc2014-09-30 01:42:33 +0000133 @test.attr(type='smoke')
Chris Hoge7579c1a2015-02-26 14:12:15 -0800134 @test.idempotent_id('2cb1baf6-ac8d-4429-bf0d-ba8a0ba53e32')
Ken'ichi Ohmichi84d7fbc2014-09-30 01:42:33 +0000135 def test_reboot_server_hard(self):
136 # The server should be power cycled
137 self._test_reboot_server('HARD')
138
Matthew Treinishc49fcbe2015-02-05 23:37:34 -0500139 @decorators.skip_because(bug="1014647")
Chris Hoge7579c1a2015-02-26 14:12:15 -0800140 @test.idempotent_id('4640e3ef-a5df-482e-95a1-ceeeb0faa84d')
Daryl Wallecked8bef32011-12-05 23:02:08 -0600141 def test_reboot_server_soft(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500142 # The server should be signaled to reboot gracefully
Ken'ichi Ohmichi84d7fbc2014-09-30 01:42:33 +0000143 self._test_reboot_server('SOFT')
Daryl Walleck98e66dd2012-06-21 04:58:39 -0500144
Yaroslav Lobankovfb1c3642015-05-13 18:38:47 +0300145 def _rebuild_server_and_check(self, image_ref):
ghanshyam0f825252015-08-25 16:02:50 +0900146 rebuilt_server = (self.client.rebuild_server(self.server_id, image_ref)
147 ['server'])
Ken'ichi Ohmichi0eb153c2015-07-13 02:18:25 +0000148 waiters.wait_for_server_status(self.client, self.server_id, 'ACTIVE')
Yaroslav Lobankovfb1c3642015-05-13 18:38:47 +0300149 msg = ('Server was not rebuilt to the original image. '
150 'The original image: {0}. The current image: {1}'
151 .format(image_ref, rebuilt_server['image']['id']))
152 self.assertEqual(image_ref, rebuilt_server['image']['id'], msg)
153
Chris Hoge7579c1a2015-02-26 14:12:15 -0800154 @test.idempotent_id('aaa6cdf3-55a7-461a-add9-1c8596b9a07c')
Daryl Wallecked8bef32011-12-05 23:02:08 -0600155 def test_rebuild_server(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500156 # The server should be rebuilt using the provided image and data
Daryl Wallecked8bef32011-12-05 23:02:08 -0600157 meta = {'rebuild': 'server'}
Masayuki Igawa259c1132013-10-31 17:48:44 +0900158 new_name = data_utils.rand_name('server')
Daryl Walleck98e66dd2012-06-21 04:58:39 -0500159 password = 'rebuildPassw0rd'
ghanshyam0f825252015-08-25 16:02:50 +0900160 rebuilt_server = self.client.rebuild_server(
161 self.server_id,
162 self.image_ref_alt,
163 name=new_name,
164 metadata=meta,
ghanshyam0f825252015-08-25 16:02:50 +0900165 adminPass=password)['server']
Daryl Wallecked8bef32011-12-05 23:02:08 -0600166
Andrea Frittolie8040812015-04-28 14:26:35 +0100167 # If the server was rebuilt on a different image, restore it to the
168 # original image once the test ends
169 if self.image_ref_alt != self.image_ref:
Yaroslav Lobankovfb1c3642015-05-13 18:38:47 +0300170 self.addCleanup(self._rebuild_server_and_check, self.image_ref)
Andrea Frittolie8040812015-04-28 14:26:35 +0100171
Attila Fazekasf7f34f92013-08-01 17:01:44 +0200172 # Verify the properties in the initial response are correct
Brian Waldon3bde07f2011-12-13 15:11:22 -0500173 self.assertEqual(self.server_id, rebuilt_server['id'])
Eoghan Glynn57c1a3d2012-03-01 16:50:29 -0500174 rebuilt_image_id = rebuilt_server['image']['id']
175 self.assertTrue(self.image_ref_alt.endswith(rebuilt_image_id))
Ken'ichi Ohmichi35772602013-11-14 15:03:27 +0900176 self.assertEqual(self.flavor_ref, rebuilt_server['flavor']['id'])
Daryl Wallecked8bef32011-12-05 23:02:08 -0600177
Attila Fazekasf7f34f92013-08-01 17:01:44 +0200178 # Verify the server properties after the rebuild completes
Ken'ichi Ohmichi0eb153c2015-07-13 02:18:25 +0000179 waiters.wait_for_server_status(self.client,
180 rebuilt_server['id'], 'ACTIVE')
ghanshyam0f825252015-08-25 16:02:50 +0900181 server = self.client.show_server(rebuilt_server['id'])['server']
Zhi Kun Liue5401762013-09-11 20:45:48 +0800182 rebuilt_image_id = server['image']['id']
Eoghan Glynn57c1a3d2012-03-01 16:50:29 -0500183 self.assertTrue(self.image_ref_alt.endswith(rebuilt_image_id))
Zhi Kun Liue5401762013-09-11 20:45:48 +0800184 self.assertEqual(new_name, server['name'])
Daryl Wallecked8bef32011-12-05 23:02:08 -0600185
Joseph Lanouxffe09dd2015-03-18 16:45:33 +0000186 if CONF.validation.run_validation:
wangxiyuan878c50e2016-01-04 19:24:17 +0800187 # Authentication is attempted in the following order of priority:
188 # 1.The key passed in, if one was passed in.
189 # 2.Any key we can find through an SSH agent (if allowed).
190 # 3.Any "id_rsa", "id_dsa" or "id_ecdsa" key discoverable in
191 # ~/.ssh/ (if allowed).
192 # 4.Plain username/password auth, if a password was given.
Joseph Lanouxffe09dd2015-03-18 16:45:33 +0000193 linux_client = remote_client.RemoteClient(
194 self.get_server_ip(rebuilt_server),
195 self.ssh_user,
wangxiyuan878c50e2016-01-04 19:24:17 +0800196 password,
Andrea Frittoli (andreaf)2a70a612016-04-29 16:09:13 -0500197 self.validation_resources['keypair']['private_key'],
198 server=rebuilt_server,
199 servers_client=self.client)
Attila Fazekasad7ef7d2013-11-20 10:12:53 +0100200 linux_client.validate_authentication()
Daryl Walleck98e66dd2012-06-21 04:58:39 -0500201
Chris Hoge7579c1a2015-02-26 14:12:15 -0800202 @test.idempotent_id('30449a88-5aff-4f9b-9866-6ee9b17f906d')
Zhi Kun Liue5401762013-09-11 20:45:48 +0800203 def test_rebuild_server_in_stop_state(self):
204 # The server in stop state should be rebuilt using the provided
205 # image and remain in SHUTOFF state
ghanshyam0f825252015-08-25 16:02:50 +0900206 server = self.client.show_server(self.server_id)['server']
Zhi Kun Liue5401762013-09-11 20:45:48 +0800207 old_image = server['image']['id']
Yaroslav Lobankovfb1c3642015-05-13 18:38:47 +0300208 new_image = (self.image_ref_alt
209 if old_image == self.image_ref else self.image_ref)
Ken'ichi Ohmichib2631082015-08-27 01:31:00 +0000210 self.client.stop_server(self.server_id)
Ken'ichi Ohmichi0eb153c2015-07-13 02:18:25 +0000211 waiters.wait_for_server_status(self.client, self.server_id, 'SHUTOFF')
ghanshyam0f825252015-08-25 16:02:50 +0900212 rebuilt_server = (self.client.rebuild_server(self.server_id, new_image)
213 ['server'])
Yaroslav Lobankovfb1c3642015-05-13 18:38:47 +0300214 # If the server was rebuilt on a different image, restore it to the
215 # original image once the test ends
216 if self.image_ref_alt != self.image_ref:
217 self.addCleanup(self._rebuild_server_and_check, old_image)
Zhi Kun Liue5401762013-09-11 20:45:48 +0800218
219 # Verify the properties in the initial response are correct
220 self.assertEqual(self.server_id, rebuilt_server['id'])
221 rebuilt_image_id = rebuilt_server['image']['id']
222 self.assertEqual(new_image, rebuilt_image_id)
223 self.assertEqual(self.flavor_ref, rebuilt_server['flavor']['id'])
224
225 # Verify the server properties after the rebuild completes
Ken'ichi Ohmichi0eb153c2015-07-13 02:18:25 +0000226 waiters.wait_for_server_status(self.client,
227 rebuilt_server['id'], 'SHUTOFF')
ghanshyam0f825252015-08-25 16:02:50 +0900228 server = self.client.show_server(rebuilt_server['id'])['server']
Zhi Kun Liue5401762013-09-11 20:45:48 +0800229 rebuilt_image_id = server['image']['id']
230 self.assertEqual(new_image, rebuilt_image_id)
231
Ken'ichi Ohmichib2631082015-08-27 01:31:00 +0000232 self.client.start_server(self.server_id)
Attila Fazekas305e65b2013-10-29 13:23:07 +0100233
Roman Podoliaka908f9062015-04-21 16:52:20 +0300234 @test.idempotent_id('b68bd8d6-855d-4212-b59b-2e704044dace')
235 @test.services('volume')
236 def test_rebuild_server_with_volume_attached(self):
237 # create a new volume and attach it to the server
238 volume = self.volumes_client.create_volume(
239 size=CONF.volume.volume_size)
240 volume = volume['volume']
241 self.addCleanup(self.volumes_client.delete_volume, volume['id'])
242 waiters.wait_for_volume_status(self.volumes_client, volume['id'],
243 'available')
244
245 self.client.attach_volume(self.server_id, volumeId=volume['id'])
246 self.addCleanup(waiters.wait_for_volume_status, self.volumes_client,
247 volume['id'], 'available')
248 self.addCleanup(self.client.detach_volume,
249 self.server_id, volume['id'])
250 waiters.wait_for_volume_status(self.volumes_client, volume['id'],
251 'in-use')
252
253 # run general rebuild test
254 self.test_rebuild_server()
255
256 # make sure the volume is attached to the instance after rebuild
257 vol_after_rebuild = self.volumes_client.show_volume(volume['id'])
258 vol_after_rebuild = vol_after_rebuild['volume']
259 self.assertEqual('in-use', vol_after_rebuild['status'])
260 self.assertEqual(self.server_id,
261 vol_after_rebuild['attachments'][0]['server_id'])
262
Matt Riedemann9fd63b82014-04-14 09:33:05 -0700263 def _test_resize_server_confirm(self, stop=False):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500264 # The server's RAM and disk space should be modified to that of
265 # the provided flavor
Daryl Wallecked8bef32011-12-05 23:02:08 -0600266
Matt Riedemann9fd63b82014-04-14 09:33:05 -0700267 if stop:
Ken'ichi Ohmichib2631082015-08-27 01:31:00 +0000268 self.client.stop_server(self.server_id)
Ken'ichi Ohmichi32752ff2015-07-13 04:33:23 +0000269 waiters.wait_for_server_status(self.client, self.server_id,
Ken'ichi Ohmichi0eb153c2015-07-13 02:18:25 +0000270 'SHUTOFF')
Matt Riedemann9fd63b82014-04-14 09:33:05 -0700271
Ken'ichi Ohmichi5271b0f2015-08-10 07:53:27 +0000272 self.client.resize_server(self.server_id, self.flavor_ref_alt)
Ken'ichi Ohmichi0eb153c2015-07-13 02:18:25 +0000273 waiters.wait_for_server_status(self.client, self.server_id,
274 'VERIFY_RESIZE')
Daryl Wallecked8bef32011-12-05 23:02:08 -0600275
Ken'ichi Ohmichib2631082015-08-27 01:31:00 +0000276 self.client.confirm_resize_server(self.server_id)
Matt Riedemann9fd63b82014-04-14 09:33:05 -0700277 expected_status = 'SHUTOFF' if stop else 'ACTIVE'
Ken'ichi Ohmichi0eb153c2015-07-13 02:18:25 +0000278 waiters.wait_for_server_status(self.client, self.server_id,
279 expected_status)
Daryl Wallecked8bef32011-12-05 23:02:08 -0600280
ghanshyam0f825252015-08-25 16:02:50 +0900281 server = self.client.show_server(self.server_id)['server']
Jesse Keating613b4982015-05-04 15:05:19 -0700282 self.assertEqual(self.flavor_ref_alt, server['flavor']['id'])
Daryl Wallecked8bef32011-12-05 23:02:08 -0600283
Matt Riedemann9fd63b82014-04-14 09:33:05 -0700284 if stop:
285 # NOTE(mriedem): tearDown requires the server to be started.
Ken'ichi Ohmichib2631082015-08-27 01:31:00 +0000286 self.client.start_server(self.server_id)
Matt Riedemann9fd63b82014-04-14 09:33:05 -0700287
Jesse Keating613b4982015-05-04 15:05:19 -0700288 # NOTE(jlk): Explicitly delete the server to get a new one for later
289 # tests. Avoids resize down race issues.
290 self.addCleanup(self.delete_server, self.server_id)
291
Chris Hoge7579c1a2015-02-26 14:12:15 -0800292 @test.idempotent_id('1499262a-9328-4eda-9068-db1ac57498d2')
Matt Riedemann9fd63b82014-04-14 09:33:05 -0700293 @testtools.skipUnless(CONF.compute_feature_enabled.resize,
294 'Resize not available.')
Matt Riedemann9fd63b82014-04-14 09:33:05 -0700295 def test_resize_server_confirm(self):
296 self._test_resize_server_confirm(stop=False)
297
Chris Hoge7579c1a2015-02-26 14:12:15 -0800298 @test.idempotent_id('138b131d-66df-48c9-a171-64f45eb92962')
Matt Riedemann9fd63b82014-04-14 09:33:05 -0700299 @testtools.skipUnless(CONF.compute_feature_enabled.resize,
300 'Resize not available.')
Matt Riedemann9fd63b82014-04-14 09:33:05 -0700301 def test_resize_server_confirm_from_stopped(self):
302 self._test_resize_server_confirm(stop=True)
303
Chris Hoge7579c1a2015-02-26 14:12:15 -0800304 @test.idempotent_id('c03aab19-adb1-44f5-917d-c419577e9e68')
Matt Riedemann5d1f8b12014-03-24 09:12:53 -0700305 @testtools.skipUnless(CONF.compute_feature_enabled.resize,
306 'Resize not available.')
Daryl Wallecked8bef32011-12-05 23:02:08 -0600307 def test_resize_server_revert(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500308 # The server's RAM and disk space should return to its original
309 # values after a resize is reverted
Daryl Wallecked8bef32011-12-05 23:02:08 -0600310
Ken'ichi Ohmichi5271b0f2015-08-10 07:53:27 +0000311 self.client.resize_server(self.server_id, self.flavor_ref_alt)
Ken'ichi Ohmichi0eb153c2015-07-13 02:18:25 +0000312 waiters.wait_for_server_status(self.client, self.server_id,
313 'VERIFY_RESIZE')
Daryl Wallecked8bef32011-12-05 23:02:08 -0600314
Ken'ichi Ohmichib2631082015-08-27 01:31:00 +0000315 self.client.revert_resize_server(self.server_id)
Ken'ichi Ohmichi0eb153c2015-07-13 02:18:25 +0000316 waiters.wait_for_server_status(self.client, self.server_id, 'ACTIVE')
Daryl Wallecked8bef32011-12-05 23:02:08 -0600317
ghanshyam0f825252015-08-25 16:02:50 +0900318 server = self.client.show_server(self.server_id)['server']
Jesse Keating613b4982015-05-04 15:05:19 -0700319 self.assertEqual(self.flavor_ref, server['flavor']['id'])
sapan-konaf1e3f002011-12-22 23:18:44 +0530320
Chris Hoge7579c1a2015-02-26 14:12:15 -0800321 @test.idempotent_id('b963d4f1-94b3-4c40-9e97-7b583f46e470')
Adam Gandelmanfbc95ac2014-06-19 17:33:43 -0700322 @testtools.skipUnless(CONF.compute_feature_enabled.snapshot,
323 'Snapshotting not available, backup not possible.')
ekhugen0b3bc522014-08-04 20:58:21 +0000324 @test.services('image')
ivan-zhuccc89462013-10-31 16:53:12 +0800325 def test_create_backup(self):
326 # Positive test:create backup successfully and rotate backups correctly
327 # create the first and the second backup
Matt Riedemann2aa19d42016-06-06 17:45:41 -0400328
329 # Check if glance v1 is available to determine which client to use. We
330 # prefer glance v1 for the compute API tests since the compute image
331 # API proxy was written for glance v1.
332 if CONF.image_feature_enabled.api_v1:
333 glance_client = self.os.image_client
334 elif CONF.image_feature_enabled.api_v2:
335 glance_client = self.os.image_client_v2
336 else:
337 raise exceptions.InvalidConfiguration(
338 'Either api_v1 or api_v2 must be True in '
339 '[image-feature-enabled].')
340
Matt Riedemanne699f822014-01-24 08:11:42 -0800341 backup1 = data_utils.rand_name('backup-1')
Ken'ichi Ohmichi32752ff2015-07-13 04:33:23 +0000342 resp = self.client.create_backup(self.server_id,
Ken'ichi Ohmichie6349f32015-12-09 06:47:54 +0000343 backup_type='daily',
344 rotation=2,
345 name=backup1).response
ivan-zhuccc89462013-10-31 16:53:12 +0800346 oldest_backup_exist = True
347
348 # the oldest one should be deleted automatically in this test
349 def _clean_oldest_backup(oldest_backup):
350 if oldest_backup_exist:
Ryan Hsu38231092014-06-08 23:12:10 -0700351 try:
Matt Riedemann2aa19d42016-06-06 17:45:41 -0400352 glance_client.delete_image(oldest_backup)
Masayuki Igawabfa07602015-01-20 18:47:17 +0900353 except lib_exc.NotFound:
Ryan Hsu38231092014-06-08 23:12:10 -0700354 pass
355 else:
356 LOG.warning("Deletion of oldest backup %s should not have "
357 "been successful as it should have been "
358 "deleted during rotation." % oldest_backup)
ivan-zhuccc89462013-10-31 16:53:12 +0800359
Masayuki Igawa259c1132013-10-31 17:48:44 +0900360 image1_id = data_utils.parse_image_id(resp['location'])
ivan-zhuccc89462013-10-31 16:53:12 +0800361 self.addCleanup(_clean_oldest_backup, image1_id)
Matt Riedemann2aa19d42016-06-06 17:45:41 -0400362 waiters.wait_for_image_status(glance_client,
Yaroslav Lobankov2fea4052016-04-19 15:05:57 +0300363 image1_id, 'active')
ivan-zhuccc89462013-10-31 16:53:12 +0800364
Matt Riedemanne699f822014-01-24 08:11:42 -0800365 backup2 = data_utils.rand_name('backup-2')
Ken'ichi Ohmichi32752ff2015-07-13 04:33:23 +0000366 waiters.wait_for_server_status(self.client, self.server_id, 'ACTIVE')
367 resp = self.client.create_backup(self.server_id,
Ken'ichi Ohmichie6349f32015-12-09 06:47:54 +0000368 backup_type='daily',
369 rotation=2,
370 name=backup2).response
Masayuki Igawa259c1132013-10-31 17:48:44 +0900371 image2_id = data_utils.parse_image_id(resp['location'])
Matt Riedemann2aa19d42016-06-06 17:45:41 -0400372 self.addCleanup(glance_client.delete_image, image2_id)
373 waiters.wait_for_image_status(glance_client,
Yaroslav Lobankov2fea4052016-04-19 15:05:57 +0300374 image2_id, 'active')
ivan-zhuccc89462013-10-31 16:53:12 +0800375
376 # verify they have been created
377 properties = {
378 'image_type': 'backup',
379 'backup_type': "daily",
380 'instance_uuid': self.server_id,
381 }
Ken'ichi Ohmichi45d7d422016-06-22 10:03:28 -0700382 params = {
383 'status': 'active',
384 'sort_key': 'created_at',
385 'sort_dir': 'asc'
386 }
Matt Riedemann2aa19d42016-06-06 17:45:41 -0400387 if CONF.image_feature_enabled.api_v1:
Ken'ichi Ohmichie28b2c22016-06-22 10:07:27 -0700388 for key, value in properties.items():
389 params['property-%s' % key] = value
Matt Riedemann2aa19d42016-06-06 17:45:41 -0400390 image_list = glance_client.list_images(
391 detail=True,
392 **params)['images']
393 else:
394 # Additional properties are flattened in glance v2.
Matt Riedemann2aa19d42016-06-06 17:45:41 -0400395 params.update(properties)
396 image_list = glance_client.list_images(params)['images']
397
ivan-zhuccc89462013-10-31 16:53:12 +0800398 self.assertEqual(2, len(image_list))
399 self.assertEqual((backup1, backup2),
400 (image_list[0]['name'], image_list[1]['name']))
401
402 # create the third one, due to the rotation is 2,
403 # the first one will be deleted
Matt Riedemanne699f822014-01-24 08:11:42 -0800404 backup3 = data_utils.rand_name('backup-3')
Ken'ichi Ohmichi32752ff2015-07-13 04:33:23 +0000405 waiters.wait_for_server_status(self.client, self.server_id, 'ACTIVE')
406 resp = self.client.create_backup(self.server_id,
Ken'ichi Ohmichie6349f32015-12-09 06:47:54 +0000407 backup_type='daily',
408 rotation=2,
409 name=backup3).response
Masayuki Igawa259c1132013-10-31 17:48:44 +0900410 image3_id = data_utils.parse_image_id(resp['location'])
Matt Riedemann2aa19d42016-06-06 17:45:41 -0400411 self.addCleanup(glance_client.delete_image, image3_id)
ivan-zhuccc89462013-10-31 16:53:12 +0800412 # the first back up should be deleted
Ken'ichi Ohmichi32752ff2015-07-13 04:33:23 +0000413 waiters.wait_for_server_status(self.client, self.server_id, 'ACTIVE')
Matt Riedemann2aa19d42016-06-06 17:45:41 -0400414 glance_client.wait_for_resource_deletion(image1_id)
ivan-zhuccc89462013-10-31 16:53:12 +0800415 oldest_backup_exist = False
Matt Riedemann2aa19d42016-06-06 17:45:41 -0400416 if CONF.image_feature_enabled.api_v1:
417 image_list = glance_client.list_images(
418 detail=True, **params)['images']
419 else:
420 image_list = glance_client.list_images(params)['images']
Matt Riedemanne699f822014-01-24 08:11:42 -0800421 self.assertEqual(2, len(image_list),
422 'Unexpected number of images for '
423 'v2:test_create_backup; was the oldest backup not '
424 'yet deleted? Image list: %s' %
425 [image['name'] for image in image_list])
ivan-zhuccc89462013-10-31 16:53:12 +0800426 self.assertEqual((backup2, backup3),
427 (image_list[0]['name'], image_list[1]['name']))
428
Ken'ichi Ohmichi547a3062013-12-02 09:30:36 +0900429 def _get_output(self):
Ken'ichi Ohmichi32752ff2015-07-13 04:33:23 +0000430 output = self.client.get_console_output(
Ken'ichi Ohmichibf4766a2015-12-09 07:48:43 +0000431 self.server_id, length=10)['output']
Ken'ichi Ohmichi547a3062013-12-02 09:30:36 +0900432 self.assertTrue(output, "Console output was empty.")
433 lines = len(output.split('\n'))
434 self.assertEqual(lines, 10)
435
Chris Hoge7579c1a2015-02-26 14:12:15 -0800436 @test.idempotent_id('4b8867e6-fffa-4d54-b1d1-6fdda57be2f3')
Adam Gandelmanc6eefb42014-07-15 16:44:08 -0700437 @testtools.skipUnless(CONF.compute_feature_enabled.console_output,
438 'Console output not supported.')
Attila Fazekas45c3fbc2013-02-24 16:39:52 +0100439 def test_get_console_output(self):
440 # Positive test:Should be able to GET the console output
441 # for a given server_id and number of lines
Ken'ichi Ohmichi851a1352013-11-26 18:42:52 +0900442
443 # This reboot is necessary for outputting some console log after
Takashi NATSUME6d5a2b42015-09-08 11:27:49 +0900444 # creating an instance backup. If an instance backup, the console
Ken'ichi Ohmichi851a1352013-11-26 18:42:52 +0900445 # log file is truncated and we cannot get any console log through
446 # "console-log" API.
447 # The detail is https://bugs.launchpad.net/nova/+bug/1251920
Ken'ichi Ohmichi36b714c2015-12-09 08:12:47 +0000448 self.client.reboot_server(self.server_id, type='HARD')
Ken'ichi Ohmichi32752ff2015-07-13 04:33:23 +0000449 waiters.wait_for_server_status(self.client, self.server_id, 'ACTIVE')
Ken'ichi Ohmichi547a3062013-12-02 09:30:36 +0900450 self.wait_for(self._get_output)
Attila Fazekas45c3fbc2013-02-24 16:39:52 +0100451
Chris Hoge7579c1a2015-02-26 14:12:15 -0800452 @test.idempotent_id('89104062-69d8-4b19-a71b-f47b7af093d7')
Adam Gandelmanc6eefb42014-07-15 16:44:08 -0700453 @testtools.skipUnless(CONF.compute_feature_enabled.console_output,
454 'Console output not supported.')
Ken'ichi Ohmichibd5df122014-09-18 08:03:52 +0000455 def test_get_console_output_with_unlimited_size(self):
David Kranz0fb14292015-02-11 15:55:20 -0500456 server = self.create_test_server(wait_until='ACTIVE')
Ken'ichi Ohmichibd5df122014-09-18 08:03:52 +0000457
458 def _check_full_length_console_log():
Ken'ichi Ohmichibf4766a2015-12-09 07:48:43 +0000459 output = self.client.get_console_output(server['id'])['output']
Ken'ichi Ohmichibd5df122014-09-18 08:03:52 +0000460 self.assertTrue(output, "Console output was empty.")
461 lines = len(output.split('\n'))
462
463 # NOTE: This test tries to get full length console log, and the
464 # length should be bigger than the one of test_get_console_output.
465 self.assertTrue(lines > 10, "Cannot get enough console log length."
466 " (lines: %s)" % lines)
467
468 self.wait_for(_check_full_length_console_log)
469
Chris Hoge7579c1a2015-02-26 14:12:15 -0800470 @test.idempotent_id('5b65d4e7-4ecd-437c-83c0-d6b79d927568')
Ken'ichi Ohmichibd5df122014-09-18 08:03:52 +0000471 @testtools.skipUnless(CONF.compute_feature_enabled.console_output,
472 'Console output not supported.')
Ken'ichi Ohmichi547a3062013-12-02 09:30:36 +0900473 def test_get_console_output_server_id_in_shutoff_status(self):
Attila Fazekas45c3fbc2013-02-24 16:39:52 +0100474 # Positive test:Should be able to GET the console output
Ken'ichi Ohmichi547a3062013-12-02 09:30:36 +0900475 # for a given server_id in SHUTOFF status
476
477 # NOTE: SHUTOFF is irregular status. To avoid test instability,
478 # one server is created only for this test without using
479 # the server that was created in setupClass.
David Kranz0fb14292015-02-11 15:55:20 -0500480 server = self.create_test_server(wait_until='ACTIVE')
Ken'ichi Ohmichi547a3062013-12-02 09:30:36 +0900481 temp_server_id = server['id']
482
Ken'ichi Ohmichib2631082015-08-27 01:31:00 +0000483 self.client.stop_server(temp_server_id)
Ken'ichi Ohmichi32752ff2015-07-13 04:33:23 +0000484 waiters.wait_for_server_status(self.client, temp_server_id, 'SHUTOFF')
Ken'ichi Ohmichi547a3062013-12-02 09:30:36 +0900485 self.wait_for(self._get_output)
Dan Smithbc3bd242012-08-14 09:48:48 -0700486
Chris Hoge7579c1a2015-02-26 14:12:15 -0800487 @test.idempotent_id('bd61a9fd-062f-4670-972b-2d6c3e3b9e73')
Matt Riedemann992162e2014-03-24 09:11:06 -0700488 @testtools.skipUnless(CONF.compute_feature_enabled.pause,
489 'Pause is not available.')
Prem Karat6631f802013-07-04 12:07:33 +0530490 def test_pause_unpause_server(self):
David Kranzae99b9a2015-02-16 13:37:01 -0500491 self.client.pause_server(self.server_id)
Ken'ichi Ohmichi0eb153c2015-07-13 02:18:25 +0000492 waiters.wait_for_server_status(self.client, self.server_id, 'PAUSED')
David Kranzae99b9a2015-02-16 13:37:01 -0500493 self.client.unpause_server(self.server_id)
Ken'ichi Ohmichi0eb153c2015-07-13 02:18:25 +0000494 waiters.wait_for_server_status(self.client, self.server_id, 'ACTIVE')
Prem Karat6631f802013-07-04 12:07:33 +0530495
Chris Hoge7579c1a2015-02-26 14:12:15 -0800496 @test.idempotent_id('0d8ee21e-b749-462d-83da-b85b41c86c7f')
Matt Riedemannf0cf6952014-03-24 09:08:52 -0700497 @testtools.skipUnless(CONF.compute_feature_enabled.suspend,
498 'Suspend is not available.')
Prem Karat6631f802013-07-04 12:07:33 +0530499 def test_suspend_resume_server(self):
David Kranzae99b9a2015-02-16 13:37:01 -0500500 self.client.suspend_server(self.server_id)
Ken'ichi Ohmichi0eb153c2015-07-13 02:18:25 +0000501 waiters.wait_for_server_status(self.client, self.server_id,
502 'SUSPENDED')
David Kranzae99b9a2015-02-16 13:37:01 -0500503 self.client.resume_server(self.server_id)
Ken'ichi Ohmichi0eb153c2015-07-13 02:18:25 +0000504 waiters.wait_for_server_status(self.client, self.server_id, 'ACTIVE')
Prem Karat6631f802013-07-04 12:07:33 +0530505
Chris Hoge7579c1a2015-02-26 14:12:15 -0800506 @test.idempotent_id('77eba8e0-036e-4635-944b-f7a8f3b78dc9')
David Shrewsbury25f666f2014-07-22 12:17:59 -0400507 @testtools.skipUnless(CONF.compute_feature_enabled.shelve,
508 'Shelve is not available.')
Ken'ichi Ohmichi39437e22013-10-06 00:21:38 +0900509 def test_shelve_unshelve_server(self):
ghanshyam017b5fe2016-04-15 18:49:26 +0900510 compute.shelve_server(self.client, self.server_id,
511 force_shelve_offload=True)
Ken'ichi Ohmichi17b7f112014-02-20 06:33:49 +0900512
ghanshyam0f825252015-08-25 16:02:50 +0900513 server = self.client.show_server(self.server_id)['server']
Ken'ichi Ohmichi39437e22013-10-06 00:21:38 +0900514 image_name = server['name'] + '-shelved'
515 params = {'name': image_name}
Ghanshyamae76c122015-12-22 13:41:35 +0900516 images = self.compute_images_client.list_images(**params)['images']
Ken'ichi Ohmichi39437e22013-10-06 00:21:38 +0900517 self.assertEqual(1, len(images))
518 self.assertEqual(image_name, images[0]['name'])
519
David Kranzae99b9a2015-02-16 13:37:01 -0500520 self.client.unshelve_server(self.server_id)
Ken'ichi Ohmichi0eb153c2015-07-13 02:18:25 +0000521 waiters.wait_for_server_status(self.client, self.server_id, 'ACTIVE')
Ken'ichi Ohmichi39437e22013-10-06 00:21:38 +0900522
Chris Hoge7579c1a2015-02-26 14:12:15 -0800523 @test.idempotent_id('af8eafd4-38a7-4a4b-bdbc-75145a580560')
Anju Tiwariaf98d222013-08-05 15:19:50 +0530524 def test_stop_start_server(self):
Ken'ichi Ohmichib2631082015-08-27 01:31:00 +0000525 self.client.stop_server(self.server_id)
Ken'ichi Ohmichi32752ff2015-07-13 04:33:23 +0000526 waiters.wait_for_server_status(self.client, self.server_id, 'SHUTOFF')
Ken'ichi Ohmichib2631082015-08-27 01:31:00 +0000527 self.client.start_server(self.server_id)
Ken'ichi Ohmichi32752ff2015-07-13 04:33:23 +0000528 waiters.wait_for_server_status(self.client, self.server_id, 'ACTIVE')
Anju Tiwariaf98d222013-08-05 15:19:50 +0530529
Chris Hoge7579c1a2015-02-26 14:12:15 -0800530 @test.idempotent_id('80a8094c-211e-440a-ab88-9e59d556c7ee')
Zhu Zhu9643e512013-09-23 09:13:07 -0500531 def test_lock_unlock_server(self):
532 # Lock the server,try server stop(exceptions throw),unlock it and retry
Ken'ichi Ohmichi32752ff2015-07-13 04:33:23 +0000533 self.client.lock_server(self.server_id)
Viktor Tikkanen3d063df2015-06-26 07:55:11 +0300534 self.addCleanup(self.client.unlock_server, self.server_id)
ghanshyam0f825252015-08-25 16:02:50 +0900535 server = self.client.show_server(self.server_id)['server']
Zhu Zhu9643e512013-09-23 09:13:07 -0500536 self.assertEqual(server['status'], 'ACTIVE')
537 # Locked server is not allowed to be stopped by non-admin user
Masayuki Igawad9388762015-01-20 14:56:42 +0900538 self.assertRaises(lib_exc.Conflict,
Ken'ichi Ohmichib2631082015-08-27 01:31:00 +0000539 self.client.stop_server, self.server_id)
Ken'ichi Ohmichi32752ff2015-07-13 04:33:23 +0000540 self.client.unlock_server(self.server_id)
Ken'ichi Ohmichib2631082015-08-27 01:31:00 +0000541 self.client.stop_server(self.server_id)
Ken'ichi Ohmichi32752ff2015-07-13 04:33:23 +0000542 waiters.wait_for_server_status(self.client, self.server_id, 'SHUTOFF')
Ken'ichi Ohmichib2631082015-08-27 01:31:00 +0000543 self.client.start_server(self.server_id)
Ken'ichi Ohmichi32752ff2015-07-13 04:33:23 +0000544 waiters.wait_for_server_status(self.client, self.server_id, 'ACTIVE')
Zhu Zhu9643e512013-09-23 09:13:07 -0500545
Ghanshyam86d1a572014-03-05 10:19:25 +0900546 def _validate_url(self, url):
547 valid_scheme = ['http', 'https']
548 parsed_url = urlparse.urlparse(url)
549 self.assertNotEqual('None', parsed_url.port)
550 self.assertNotEqual('None', parsed_url.hostname)
551 self.assertIn(parsed_url.scheme, valid_scheme)
552
Chris Hoge7579c1a2015-02-26 14:12:15 -0800553 @test.idempotent_id('c6bc11bf-592e-4015-9319-1c98dc64daf5')
Ghanshyam86d1a572014-03-05 10:19:25 +0900554 @testtools.skipUnless(CONF.compute_feature_enabled.vnc_console,
555 'VNC Console feature is disabled.')
Ghanshyam86d1a572014-03-05 10:19:25 +0900556 def test_get_vnc_console(self):
557 # Get the VNC console of type 'novnc' and 'xvpvnc'
558 console_types = ['novnc', 'xvpvnc']
559 for console_type in console_types:
Ken'ichi Ohmichi32752ff2015-07-13 04:33:23 +0000560 body = self.client.get_vnc_console(self.server_id,
Ken'ichi Ohmichibf4766a2015-12-09 07:48:43 +0000561 type=console_type)['console']
Ghanshyam86d1a572014-03-05 10:19:25 +0900562 self.assertEqual(console_type, body['type'])
563 self.assertNotEqual('', body['url'])
564 self._validate_url(body['url'])