blob: 6fcd38a9e6dec2348abe484aaba482d871ef1557 [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
Daryl Wallecked8bef32011-12-05 23:02:08 -060016import base64
Ryan Hsu38231092014-06-08 23:12:10 -070017import logging
Brian Waldon738cd632011-12-12 18:45:09 -050018
Matthew Treinishf077dd22015-04-23 09:37:41 -040019from six.moves.urllib import parse as urlparse
Matthew Treinish01472ff2015-02-20 17:26:52 -050020from tempest_lib.common.utils import data_utils
Matthew Treinishc49fcbe2015-02-05 23:37:34 -050021from tempest_lib import decorators
Masayuki Igawad9388762015-01-20 14:56:42 +090022from tempest_lib import exceptions as lib_exc
ivan-zhu1feeb382013-01-24 10:14:39 +080023import testtools
Jay Pipes13b479b2012-06-11 14:52:27 -040024
Sean Dague1937d092013-05-17 16:36:38 -040025from tempest.api.compute import base
Masayuki Igawa209fd502014-02-17 14:46:43 +090026from tempest.common.utils.linux import remote_client
Sean Dague86bd8422013-12-20 09:56:44 -050027from tempest import config
Masayuki Igawa209fd502014-02-17 14:46:43 +090028from tempest import test
Daryl Wallecked8bef32011-12-05 23:02:08 -060029
Sean Dague86bd8422013-12-20 09:56:44 -050030CONF = config.CONF
31
Ryan Hsu38231092014-06-08 23:12:10 -070032LOG = logging.getLogger(__name__)
33
Daryl Walleckc7251962012-03-12 17:26:54 -050034
ivan-zhuf2b00502013-10-18 10:06:52 +080035class ServerActionsTestJSON(base.BaseV2ComputeTest):
Matthew Treinishe5cca002015-05-11 15:36:50 -040036 run_ssh = CONF.validation.run_validation
Daryl Wallecked8bef32011-12-05 23:02:08 -060037
Attila Fazekas19044d52013-02-16 07:35:06 +010038 def setUp(self):
Matt Riedemann2da58592014-06-08 12:46:02 +000039 # NOTE(afazekas): Normally we use the same server with all test cases,
40 # but if it has an issue, we build a new one
Attila Fazekas19044d52013-02-16 07:35:06 +010041 super(ServerActionsTestJSON, self).setUp()
Matt Riedemann2da58592014-06-08 12:46:02 +000042 # Check if the server is in a clean state after test
43 try:
44 self.client.wait_for_server_status(self.server_id, 'ACTIVE')
Viktor Tikkanen1b0ce232015-05-28 10:21:27 +030045 except lib_exc.NotFound:
46 # The server was deleted by previous test, create a new one
47 server = self.create_test_server(wait_until='ACTIVE')
48 self.__class__.server_id = server['id']
Matt Riedemann2da58592014-06-08 12:46:02 +000049 except Exception:
50 # Rebuild server if something happened to it during a test
51 self.__class__.server_id = self.rebuild_server(self.server_id)
52
53 def tearDown(self):
Matt Riedemann2da58592014-06-08 12:46:02 +000054 self.server_check_teardown()
55 super(ServerActionsTestJSON, self).tearDown()
Attila Fazekas305e65b2013-10-29 13:23:07 +010056
Attila Fazekas19044d52013-02-16 07:35:06 +010057 @classmethod
Rohan Kanade60b73092015-02-04 17:58:19 +053058 def setup_clients(cls):
59 super(ServerActionsTestJSON, cls).setup_clients()
60 cls.client = cls.servers_client
61
62 @classmethod
Andrea Frittoli50bb80d2014-09-15 12:34:27 +010063 def resource_setup(cls):
Attila Fazekas423834d2014-03-14 17:33:13 +010064 cls.prepare_instance_network()
Andrea Frittoli50bb80d2014-09-15 12:34:27 +010065 super(ServerActionsTestJSON, cls).resource_setup()
Matt Riedemann2da58592014-06-08 12:46:02 +000066 cls.server_id = cls.rebuild_server(None)
Attila Fazekas19044d52013-02-16 07:35:06 +010067
Chris Hoge7579c1a2015-02-26 14:12:15 -080068 @test.idempotent_id('6158df09-4b82-4ab3-af6d-29cf36af858d')
Sean Dague86bd8422013-12-20 09:56:44 -050069 @testtools.skipUnless(CONF.compute_feature_enabled.change_password,
ivan-zhu1feeb382013-01-24 10:14:39 +080070 'Change password not available.')
Daryl Wallecked8bef32011-12-05 23:02:08 -060071 def test_change_server_password(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -050072 # The server's password should be set to the provided password
Daryl Walleck98e66dd2012-06-21 04:58:39 -050073 new_password = 'Newpass1234'
David Kranzae99b9a2015-02-16 13:37:01 -050074 self.client.change_password(self.server_id, new_password)
Brian Waldon3bde07f2011-12-13 15:11:22 -050075 self.client.wait_for_server_status(self.server_id, 'ACTIVE')
Daryl Wallecked8bef32011-12-05 23:02:08 -060076
Daryl Walleck98e66dd2012-06-21 04:58:39 -050077 if self.run_ssh:
78 # Verify that the user can authenticate with the new password
David Kranz0fb14292015-02-11 15:55:20 -050079 server = self.client.get_server(self.server_id)
Masayuki Igawa209fd502014-02-17 14:46:43 +090080 linux_client = remote_client.RemoteClient(server, self.ssh_user,
81 new_password)
Attila Fazekasad7ef7d2013-11-20 10:12:53 +010082 linux_client.validate_authentication()
Daryl Walleck98e66dd2012-06-21 04:58:39 -050083
Ken'ichi Ohmichi84d7fbc2014-09-30 01:42:33 +000084 def _test_reboot_server(self, reboot_type):
Daryl Walleck98e66dd2012-06-21 04:58:39 -050085 if self.run_ssh:
86 # Get the time the server was last rebooted,
David Kranz0fb14292015-02-11 15:55:20 -050087 server = self.client.get_server(self.server_id)
Masayuki Igawa209fd502014-02-17 14:46:43 +090088 linux_client = remote_client.RemoteClient(server, self.ssh_user,
89 self.password)
Daryl Walleck98e66dd2012-06-21 04:58:39 -050090 boot_time = linux_client.get_boot_time()
Daryl Walleck98e66dd2012-06-21 04:58:39 -050091
David Kranzae99b9a2015-02-16 13:37:01 -050092 self.client.reboot(self.server_id, reboot_type)
Brian Waldon3bde07f2011-12-13 15:11:22 -050093 self.client.wait_for_server_status(self.server_id, 'ACTIVE')
Daryl Wallecked8bef32011-12-05 23:02:08 -060094
Daryl Walleck98e66dd2012-06-21 04:58:39 -050095 if self.run_ssh:
96 # Log in and verify the boot time has changed
Masayuki Igawa209fd502014-02-17 14:46:43 +090097 linux_client = remote_client.RemoteClient(server, self.ssh_user,
98 self.password)
Daryl Walleck98e66dd2012-06-21 04:58:39 -050099 new_boot_time = linux_client.get_boot_time()
Vincent Untz32173d12014-01-19 20:34:47 +0100100 self.assertTrue(new_boot_time > boot_time,
101 '%s > %s' % (new_boot_time, boot_time))
Daryl Walleck98e66dd2012-06-21 04:58:39 -0500102
Ken'ichi Ohmichi84d7fbc2014-09-30 01:42:33 +0000103 @test.attr(type='smoke')
Chris Hoge7579c1a2015-02-26 14:12:15 -0800104 @test.idempotent_id('2cb1baf6-ac8d-4429-bf0d-ba8a0ba53e32')
Ken'ichi Ohmichi84d7fbc2014-09-30 01:42:33 +0000105 def test_reboot_server_hard(self):
106 # The server should be power cycled
107 self._test_reboot_server('HARD')
108
Matthew Treinishc49fcbe2015-02-05 23:37:34 -0500109 @decorators.skip_because(bug="1014647")
Chris Hoge7579c1a2015-02-26 14:12:15 -0800110 @test.idempotent_id('4640e3ef-a5df-482e-95a1-ceeeb0faa84d')
Daryl Wallecked8bef32011-12-05 23:02:08 -0600111 def test_reboot_server_soft(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500112 # The server should be signaled to reboot gracefully
Ken'ichi Ohmichi84d7fbc2014-09-30 01:42:33 +0000113 self._test_reboot_server('SOFT')
Daryl Walleck98e66dd2012-06-21 04:58:39 -0500114
Yaroslav Lobankovfb1c3642015-05-13 18:38:47 +0300115 def _rebuild_server_and_check(self, image_ref):
116 rebuilt_server = self.client.rebuild(self.server_id, image_ref)
117 self.client.wait_for_server_status(self.server_id, 'ACTIVE')
118 msg = ('Server was not rebuilt to the original image. '
119 'The original image: {0}. The current image: {1}'
120 .format(image_ref, rebuilt_server['image']['id']))
121 self.assertEqual(image_ref, rebuilt_server['image']['id'], msg)
122
Chris Hoge7579c1a2015-02-26 14:12:15 -0800123 @test.idempotent_id('aaa6cdf3-55a7-461a-add9-1c8596b9a07c')
Daryl Wallecked8bef32011-12-05 23:02:08 -0600124 def test_rebuild_server(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500125 # The server should be rebuilt using the provided image and data
Daryl Wallecked8bef32011-12-05 23:02:08 -0600126 meta = {'rebuild': 'server'}
Masayuki Igawa259c1132013-10-31 17:48:44 +0900127 new_name = data_utils.rand_name('server')
Daryl Wallecked8bef32011-12-05 23:02:08 -0600128 file_contents = 'Test server rebuild.'
Mahesh Panchaksharaiah21599a92013-07-03 15:28:58 +0530129 personality = [{'path': 'rebuild.txt',
Daryl Wallecked8bef32011-12-05 23:02:08 -0600130 'contents': base64.b64encode(file_contents)}]
Daryl Walleck98e66dd2012-06-21 04:58:39 -0500131 password = 'rebuildPassw0rd'
David Kranzae99b9a2015-02-16 13:37:01 -0500132 rebuilt_server = self.client.rebuild(self.server_id,
133 self.image_ref_alt,
134 name=new_name,
135 metadata=meta,
136 personality=personality,
137 adminPass=password)
Daryl Wallecked8bef32011-12-05 23:02:08 -0600138
Andrea Frittolie8040812015-04-28 14:26:35 +0100139 # If the server was rebuilt on a different image, restore it to the
140 # original image once the test ends
141 if self.image_ref_alt != self.image_ref:
Yaroslav Lobankovfb1c3642015-05-13 18:38:47 +0300142 self.addCleanup(self._rebuild_server_and_check, self.image_ref)
Andrea Frittolie8040812015-04-28 14:26:35 +0100143
Attila Fazekasf7f34f92013-08-01 17:01:44 +0200144 # Verify the properties in the initial response are correct
Brian Waldon3bde07f2011-12-13 15:11:22 -0500145 self.assertEqual(self.server_id, rebuilt_server['id'])
Eoghan Glynn57c1a3d2012-03-01 16:50:29 -0500146 rebuilt_image_id = rebuilt_server['image']['id']
147 self.assertTrue(self.image_ref_alt.endswith(rebuilt_image_id))
Ken'ichi Ohmichi35772602013-11-14 15:03:27 +0900148 self.assertEqual(self.flavor_ref, rebuilt_server['flavor']['id'])
Daryl Wallecked8bef32011-12-05 23:02:08 -0600149
Attila Fazekasf7f34f92013-08-01 17:01:44 +0200150 # Verify the server properties after the rebuild completes
Daryl Wallecked8bef32011-12-05 23:02:08 -0600151 self.client.wait_for_server_status(rebuilt_server['id'], 'ACTIVE')
David Kranz0fb14292015-02-11 15:55:20 -0500152 server = self.client.get_server(rebuilt_server['id'])
Zhi Kun Liue5401762013-09-11 20:45:48 +0800153 rebuilt_image_id = server['image']['id']
Eoghan Glynn57c1a3d2012-03-01 16:50:29 -0500154 self.assertTrue(self.image_ref_alt.endswith(rebuilt_image_id))
Zhi Kun Liue5401762013-09-11 20:45:48 +0800155 self.assertEqual(new_name, server['name'])
Daryl Wallecked8bef32011-12-05 23:02:08 -0600156
Daryl Walleck98e66dd2012-06-21 04:58:39 -0500157 if self.run_ssh:
158 # Verify that the user can authenticate with the provided password
Masayuki Igawa209fd502014-02-17 14:46:43 +0900159 linux_client = remote_client.RemoteClient(server, self.ssh_user,
160 password)
Attila Fazekasad7ef7d2013-11-20 10:12:53 +0100161 linux_client.validate_authentication()
Daryl Walleck98e66dd2012-06-21 04:58:39 -0500162
Chris Hoge7579c1a2015-02-26 14:12:15 -0800163 @test.idempotent_id('30449a88-5aff-4f9b-9866-6ee9b17f906d')
Zhi Kun Liue5401762013-09-11 20:45:48 +0800164 def test_rebuild_server_in_stop_state(self):
165 # The server in stop state should be rebuilt using the provided
166 # image and remain in SHUTOFF state
David Kranz0fb14292015-02-11 15:55:20 -0500167 server = self.client.get_server(self.server_id)
Zhi Kun Liue5401762013-09-11 20:45:48 +0800168 old_image = server['image']['id']
Yaroslav Lobankovfb1c3642015-05-13 18:38:47 +0300169 new_image = (self.image_ref_alt
170 if old_image == self.image_ref else self.image_ref)
David Kranzae99b9a2015-02-16 13:37:01 -0500171 self.client.stop(self.server_id)
Zhi Kun Liue5401762013-09-11 20:45:48 +0800172 self.client.wait_for_server_status(self.server_id, 'SHUTOFF')
David Kranzae99b9a2015-02-16 13:37:01 -0500173 rebuilt_server = self.client.rebuild(self.server_id, new_image)
Yaroslav Lobankovfb1c3642015-05-13 18:38:47 +0300174 # If the server was rebuilt on a different image, restore it to the
175 # original image once the test ends
176 if self.image_ref_alt != self.image_ref:
177 self.addCleanup(self._rebuild_server_and_check, old_image)
Zhi Kun Liue5401762013-09-11 20:45:48 +0800178
179 # Verify the properties in the initial response are correct
180 self.assertEqual(self.server_id, rebuilt_server['id'])
181 rebuilt_image_id = rebuilt_server['image']['id']
182 self.assertEqual(new_image, rebuilt_image_id)
183 self.assertEqual(self.flavor_ref, rebuilt_server['flavor']['id'])
184
185 # Verify the server properties after the rebuild completes
186 self.client.wait_for_server_status(rebuilt_server['id'], 'SHUTOFF')
David Kranz0fb14292015-02-11 15:55:20 -0500187 server = self.client.get_server(rebuilt_server['id'])
Zhi Kun Liue5401762013-09-11 20:45:48 +0800188 rebuilt_image_id = server['image']['id']
189 self.assertEqual(new_image, rebuilt_image_id)
190
Attila Fazekas305e65b2013-10-29 13:23:07 +0100191 self.client.start(self.server_id)
192
Matt Riedemann9fd63b82014-04-14 09:33:05 -0700193 def _test_resize_server_confirm(self, stop=False):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500194 # The server's RAM and disk space should be modified to that of
195 # the provided flavor
Daryl Wallecked8bef32011-12-05 23:02:08 -0600196
Matt Riedemann9fd63b82014-04-14 09:33:05 -0700197 if stop:
David Kranzae99b9a2015-02-16 13:37:01 -0500198 self.servers_client.stop(self.server_id)
Matt Riedemann9fd63b82014-04-14 09:33:05 -0700199 self.servers_client.wait_for_server_status(self.server_id,
200 'SHUTOFF')
201
Jesse Keating613b4982015-05-04 15:05:19 -0700202 self.client.resize(self.server_id, self.flavor_ref_alt)
Brian Waldon3bde07f2011-12-13 15:11:22 -0500203 self.client.wait_for_server_status(self.server_id, 'VERIFY_RESIZE')
Daryl Wallecked8bef32011-12-05 23:02:08 -0600204
Brian Waldon3bde07f2011-12-13 15:11:22 -0500205 self.client.confirm_resize(self.server_id)
Matt Riedemann9fd63b82014-04-14 09:33:05 -0700206 expected_status = 'SHUTOFF' if stop else 'ACTIVE'
207 self.client.wait_for_server_status(self.server_id, expected_status)
Daryl Wallecked8bef32011-12-05 23:02:08 -0600208
David Kranz0fb14292015-02-11 15:55:20 -0500209 server = self.client.get_server(self.server_id)
Jesse Keating613b4982015-05-04 15:05:19 -0700210 self.assertEqual(self.flavor_ref_alt, server['flavor']['id'])
Daryl Wallecked8bef32011-12-05 23:02:08 -0600211
Matt Riedemann9fd63b82014-04-14 09:33:05 -0700212 if stop:
213 # NOTE(mriedem): tearDown requires the server to be started.
214 self.client.start(self.server_id)
215
Jesse Keating613b4982015-05-04 15:05:19 -0700216 # NOTE(jlk): Explicitly delete the server to get a new one for later
217 # tests. Avoids resize down race issues.
218 self.addCleanup(self.delete_server, self.server_id)
219
Chris Hoge7579c1a2015-02-26 14:12:15 -0800220 @test.idempotent_id('1499262a-9328-4eda-9068-db1ac57498d2')
Matt Riedemann9fd63b82014-04-14 09:33:05 -0700221 @testtools.skipUnless(CONF.compute_feature_enabled.resize,
222 'Resize not available.')
Matt Riedemann9fd63b82014-04-14 09:33:05 -0700223 def test_resize_server_confirm(self):
224 self._test_resize_server_confirm(stop=False)
225
Chris Hoge7579c1a2015-02-26 14:12:15 -0800226 @test.idempotent_id('138b131d-66df-48c9-a171-64f45eb92962')
Matt Riedemann9fd63b82014-04-14 09:33:05 -0700227 @testtools.skipUnless(CONF.compute_feature_enabled.resize,
228 'Resize not available.')
Matt Riedemann9fd63b82014-04-14 09:33:05 -0700229 def test_resize_server_confirm_from_stopped(self):
230 self._test_resize_server_confirm(stop=True)
231
Chris Hoge7579c1a2015-02-26 14:12:15 -0800232 @test.idempotent_id('c03aab19-adb1-44f5-917d-c419577e9e68')
Matt Riedemann5d1f8b12014-03-24 09:12:53 -0700233 @testtools.skipUnless(CONF.compute_feature_enabled.resize,
234 'Resize not available.')
Daryl Wallecked8bef32011-12-05 23:02:08 -0600235 def test_resize_server_revert(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500236 # The server's RAM and disk space should return to its original
237 # values after a resize is reverted
Daryl Wallecked8bef32011-12-05 23:02:08 -0600238
Jesse Keating613b4982015-05-04 15:05:19 -0700239 self.client.resize(self.server_id, self.flavor_ref_alt)
Brian Waldon3bde07f2011-12-13 15:11:22 -0500240 self.client.wait_for_server_status(self.server_id, 'VERIFY_RESIZE')
Daryl Wallecked8bef32011-12-05 23:02:08 -0600241
Brian Waldon3bde07f2011-12-13 15:11:22 -0500242 self.client.revert_resize(self.server_id)
243 self.client.wait_for_server_status(self.server_id, 'ACTIVE')
Daryl Wallecked8bef32011-12-05 23:02:08 -0600244
David Kranz0fb14292015-02-11 15:55:20 -0500245 server = self.client.get_server(self.server_id)
Jesse Keating613b4982015-05-04 15:05:19 -0700246 self.assertEqual(self.flavor_ref, server['flavor']['id'])
sapan-konaf1e3f002011-12-22 23:18:44 +0530247
Chris Hoge7579c1a2015-02-26 14:12:15 -0800248 @test.idempotent_id('b963d4f1-94b3-4c40-9e97-7b583f46e470')
Adam Gandelmanfbc95ac2014-06-19 17:33:43 -0700249 @testtools.skipUnless(CONF.compute_feature_enabled.snapshot,
250 'Snapshotting not available, backup not possible.')
ekhugen0b3bc522014-08-04 20:58:21 +0000251 @test.services('image')
ivan-zhuccc89462013-10-31 16:53:12 +0800252 def test_create_backup(self):
253 # Positive test:create backup successfully and rotate backups correctly
254 # create the first and the second backup
Matt Riedemanne699f822014-01-24 08:11:42 -0800255 backup1 = data_utils.rand_name('backup-1')
David Kranzae99b9a2015-02-16 13:37:01 -0500256 resp = self.servers_client.create_backup(self.server_id,
257 'daily',
258 2,
259 backup1).response
ivan-zhuccc89462013-10-31 16:53:12 +0800260 oldest_backup_exist = True
261
262 # the oldest one should be deleted automatically in this test
263 def _clean_oldest_backup(oldest_backup):
264 if oldest_backup_exist:
Ryan Hsu38231092014-06-08 23:12:10 -0700265 try:
266 self.os.image_client.delete_image(oldest_backup)
Masayuki Igawabfa07602015-01-20 18:47:17 +0900267 except lib_exc.NotFound:
Ryan Hsu38231092014-06-08 23:12:10 -0700268 pass
269 else:
270 LOG.warning("Deletion of oldest backup %s should not have "
271 "been successful as it should have been "
272 "deleted during rotation." % oldest_backup)
ivan-zhuccc89462013-10-31 16:53:12 +0800273
Masayuki Igawa259c1132013-10-31 17:48:44 +0900274 image1_id = data_utils.parse_image_id(resp['location'])
ivan-zhuccc89462013-10-31 16:53:12 +0800275 self.addCleanup(_clean_oldest_backup, image1_id)
Matt Riedemann46c1b2c2013-12-11 19:51:39 -0800276 self.os.image_client.wait_for_image_status(image1_id, 'active')
ivan-zhuccc89462013-10-31 16:53:12 +0800277
Matt Riedemanne699f822014-01-24 08:11:42 -0800278 backup2 = data_utils.rand_name('backup-2')
ivan-zhuccc89462013-10-31 16:53:12 +0800279 self.servers_client.wait_for_server_status(self.server_id, 'ACTIVE')
David Kranzae99b9a2015-02-16 13:37:01 -0500280 resp = self.servers_client.create_backup(self.server_id,
281 'daily',
282 2,
283 backup2).response
Masayuki Igawa259c1132013-10-31 17:48:44 +0900284 image2_id = data_utils.parse_image_id(resp['location'])
ivan-zhuccc89462013-10-31 16:53:12 +0800285 self.addCleanup(self.os.image_client.delete_image, image2_id)
Matt Riedemann46c1b2c2013-12-11 19:51:39 -0800286 self.os.image_client.wait_for_image_status(image2_id, 'active')
ivan-zhuccc89462013-10-31 16:53:12 +0800287
288 # verify they have been created
289 properties = {
290 'image_type': 'backup',
291 'backup_type': "daily",
292 'instance_uuid': self.server_id,
293 }
Ken'ichi Ohmichibcad2a22015-05-22 09:37:06 +0000294 image_list = self.os.image_client.list_images(
295 detail=True,
296 properties=properties,
Ken'ichi Ohmichi06d37cf2014-01-28 07:55:46 +0900297 status='active',
ivan-zhuccc89462013-10-31 16:53:12 +0800298 sort_key='created_at',
299 sort_dir='asc')
ivan-zhuccc89462013-10-31 16:53:12 +0800300 self.assertEqual(2, len(image_list))
301 self.assertEqual((backup1, backup2),
302 (image_list[0]['name'], image_list[1]['name']))
303
304 # create the third one, due to the rotation is 2,
305 # the first one will be deleted
Matt Riedemanne699f822014-01-24 08:11:42 -0800306 backup3 = data_utils.rand_name('backup-3')
ivan-zhuccc89462013-10-31 16:53:12 +0800307 self.servers_client.wait_for_server_status(self.server_id, 'ACTIVE')
David Kranzae99b9a2015-02-16 13:37:01 -0500308 resp = self.servers_client.create_backup(self.server_id,
309 'daily',
310 2,
311 backup3).response
Masayuki Igawa259c1132013-10-31 17:48:44 +0900312 image3_id = data_utils.parse_image_id(resp['location'])
ivan-zhuccc89462013-10-31 16:53:12 +0800313 self.addCleanup(self.os.image_client.delete_image, image3_id)
ivan-zhuccc89462013-10-31 16:53:12 +0800314 # the first back up should be deleted
Chang Ye Wang02970572013-12-03 03:32:38 -0600315 self.servers_client.wait_for_server_status(self.server_id, 'ACTIVE')
ivan-zhuccc89462013-10-31 16:53:12 +0800316 self.os.image_client.wait_for_resource_deletion(image1_id)
317 oldest_backup_exist = False
Ken'ichi Ohmichibcad2a22015-05-22 09:37:06 +0000318 image_list = self.os.image_client.list_images(
319 detail=True,
320 properties=properties,
Ken'ichi Ohmichi06d37cf2014-01-28 07:55:46 +0900321 status='active',
ivan-zhuccc89462013-10-31 16:53:12 +0800322 sort_key='created_at',
323 sort_dir='asc')
Matt Riedemanne699f822014-01-24 08:11:42 -0800324 self.assertEqual(2, len(image_list),
325 'Unexpected number of images for '
326 'v2:test_create_backup; was the oldest backup not '
327 'yet deleted? Image list: %s' %
328 [image['name'] for image in image_list])
ivan-zhuccc89462013-10-31 16:53:12 +0800329 self.assertEqual((backup2, backup3),
330 (image_list[0]['name'], image_list[1]['name']))
331
Ken'ichi Ohmichi547a3062013-12-02 09:30:36 +0900332 def _get_output(self):
David Kranzae99b9a2015-02-16 13:37:01 -0500333 output = self.servers_client.get_console_output(
334 self.server_id, 10).data
Ken'ichi Ohmichi547a3062013-12-02 09:30:36 +0900335 self.assertTrue(output, "Console output was empty.")
336 lines = len(output.split('\n'))
337 self.assertEqual(lines, 10)
338
Chris Hoge7579c1a2015-02-26 14:12:15 -0800339 @test.idempotent_id('4b8867e6-fffa-4d54-b1d1-6fdda57be2f3')
Adam Gandelmanc6eefb42014-07-15 16:44:08 -0700340 @testtools.skipUnless(CONF.compute_feature_enabled.console_output,
341 'Console output not supported.')
Attila Fazekas45c3fbc2013-02-24 16:39:52 +0100342 def test_get_console_output(self):
343 # Positive test:Should be able to GET the console output
344 # for a given server_id and number of lines
Ken'ichi Ohmichi851a1352013-11-26 18:42:52 +0900345
346 # This reboot is necessary for outputting some console log after
347 # creating a instance backup. If a instance backup, the console
348 # log file is truncated and we cannot get any console log through
349 # "console-log" API.
350 # The detail is https://bugs.launchpad.net/nova/+bug/1251920
David Kranzae99b9a2015-02-16 13:37:01 -0500351 self.servers_client.reboot(self.server_id, 'HARD')
Ken'ichi Ohmichi851a1352013-11-26 18:42:52 +0900352 self.servers_client.wait_for_server_status(self.server_id, 'ACTIVE')
353
Ken'ichi Ohmichi547a3062013-12-02 09:30:36 +0900354 self.wait_for(self._get_output)
Attila Fazekas45c3fbc2013-02-24 16:39:52 +0100355
Chris Hoge7579c1a2015-02-26 14:12:15 -0800356 @test.idempotent_id('89104062-69d8-4b19-a71b-f47b7af093d7')
Adam Gandelmanc6eefb42014-07-15 16:44:08 -0700357 @testtools.skipUnless(CONF.compute_feature_enabled.console_output,
358 'Console output not supported.')
Ken'ichi Ohmichibd5df122014-09-18 08:03:52 +0000359 def test_get_console_output_with_unlimited_size(self):
David Kranz0fb14292015-02-11 15:55:20 -0500360 server = self.create_test_server(wait_until='ACTIVE')
Ken'ichi Ohmichibd5df122014-09-18 08:03:52 +0000361
362 def _check_full_length_console_log():
David Kranzae99b9a2015-02-16 13:37:01 -0500363 output = self.servers_client.get_console_output(server['id'],
364 None).data
Ken'ichi Ohmichibd5df122014-09-18 08:03:52 +0000365 self.assertTrue(output, "Console output was empty.")
366 lines = len(output.split('\n'))
367
368 # NOTE: This test tries to get full length console log, and the
369 # length should be bigger than the one of test_get_console_output.
370 self.assertTrue(lines > 10, "Cannot get enough console log length."
371 " (lines: %s)" % lines)
372
373 self.wait_for(_check_full_length_console_log)
374
Chris Hoge7579c1a2015-02-26 14:12:15 -0800375 @test.idempotent_id('5b65d4e7-4ecd-437c-83c0-d6b79d927568')
Ken'ichi Ohmichibd5df122014-09-18 08:03:52 +0000376 @testtools.skipUnless(CONF.compute_feature_enabled.console_output,
377 'Console output not supported.')
Ken'ichi Ohmichi547a3062013-12-02 09:30:36 +0900378 def test_get_console_output_server_id_in_shutoff_status(self):
Attila Fazekas45c3fbc2013-02-24 16:39:52 +0100379 # Positive test:Should be able to GET the console output
Ken'ichi Ohmichi547a3062013-12-02 09:30:36 +0900380 # for a given server_id in SHUTOFF status
381
382 # NOTE: SHUTOFF is irregular status. To avoid test instability,
383 # one server is created only for this test without using
384 # the server that was created in setupClass.
David Kranz0fb14292015-02-11 15:55:20 -0500385 server = self.create_test_server(wait_until='ACTIVE')
Ken'ichi Ohmichi547a3062013-12-02 09:30:36 +0900386 temp_server_id = server['id']
387
David Kranzae99b9a2015-02-16 13:37:01 -0500388 self.servers_client.stop(temp_server_id)
Ken'ichi Ohmichi547a3062013-12-02 09:30:36 +0900389 self.servers_client.wait_for_server_status(temp_server_id, 'SHUTOFF')
390
391 self.wait_for(self._get_output)
Dan Smithbc3bd242012-08-14 09:48:48 -0700392
Chris Hoge7579c1a2015-02-26 14:12:15 -0800393 @test.idempotent_id('bd61a9fd-062f-4670-972b-2d6c3e3b9e73')
Matt Riedemann992162e2014-03-24 09:11:06 -0700394 @testtools.skipUnless(CONF.compute_feature_enabled.pause,
395 'Pause is not available.')
Prem Karat6631f802013-07-04 12:07:33 +0530396 def test_pause_unpause_server(self):
David Kranzae99b9a2015-02-16 13:37:01 -0500397 self.client.pause_server(self.server_id)
Prem Karat6631f802013-07-04 12:07:33 +0530398 self.client.wait_for_server_status(self.server_id, 'PAUSED')
David Kranzae99b9a2015-02-16 13:37:01 -0500399 self.client.unpause_server(self.server_id)
Prem Karat6631f802013-07-04 12:07:33 +0530400 self.client.wait_for_server_status(self.server_id, 'ACTIVE')
401
Chris Hoge7579c1a2015-02-26 14:12:15 -0800402 @test.idempotent_id('0d8ee21e-b749-462d-83da-b85b41c86c7f')
Matt Riedemannf0cf6952014-03-24 09:08:52 -0700403 @testtools.skipUnless(CONF.compute_feature_enabled.suspend,
404 'Suspend is not available.')
Prem Karat6631f802013-07-04 12:07:33 +0530405 def test_suspend_resume_server(self):
David Kranzae99b9a2015-02-16 13:37:01 -0500406 self.client.suspend_server(self.server_id)
Prem Karat6631f802013-07-04 12:07:33 +0530407 self.client.wait_for_server_status(self.server_id, 'SUSPENDED')
David Kranzae99b9a2015-02-16 13:37:01 -0500408 self.client.resume_server(self.server_id)
Prem Karat6631f802013-07-04 12:07:33 +0530409 self.client.wait_for_server_status(self.server_id, 'ACTIVE')
410
Chris Hoge7579c1a2015-02-26 14:12:15 -0800411 @test.idempotent_id('77eba8e0-036e-4635-944b-f7a8f3b78dc9')
David Shrewsbury25f666f2014-07-22 12:17:59 -0400412 @testtools.skipUnless(CONF.compute_feature_enabled.shelve,
413 'Shelve is not available.')
Ken'ichi Ohmichi39437e22013-10-06 00:21:38 +0900414 def test_shelve_unshelve_server(self):
David Kranzae99b9a2015-02-16 13:37:01 -0500415 self.client.shelve_server(self.server_id)
Ken'ichi Ohmichi39437e22013-10-06 00:21:38 +0900416
Matthew Treinishb0a78fc2014-01-29 16:49:12 +0000417 offload_time = CONF.compute.shelved_offload_time
Ken'ichi Ohmichi39437e22013-10-06 00:21:38 +0900418 if offload_time >= 0:
419 self.client.wait_for_server_status(self.server_id,
420 'SHELVED_OFFLOADED',
421 extra_timeout=offload_time)
422 else:
423 self.client.wait_for_server_status(self.server_id,
424 'SHELVED')
425
David Kranzae99b9a2015-02-16 13:37:01 -0500426 self.client.shelve_offload_server(self.server_id)
Ken'ichi Ohmichi17b7f112014-02-20 06:33:49 +0900427 self.client.wait_for_server_status(self.server_id,
428 'SHELVED_OFFLOADED')
429
David Kranz0fb14292015-02-11 15:55:20 -0500430 server = self.client.get_server(self.server_id)
Ken'ichi Ohmichi39437e22013-10-06 00:21:38 +0900431 image_name = server['name'] + '-shelved'
432 params = {'name': image_name}
Ken'ichi Ohmichi0943d9b2015-06-17 02:27:05 +0000433 images = self.images_client.list_images(**params)
Ken'ichi Ohmichi39437e22013-10-06 00:21:38 +0900434 self.assertEqual(1, len(images))
435 self.assertEqual(image_name, images[0]['name'])
436
David Kranzae99b9a2015-02-16 13:37:01 -0500437 self.client.unshelve_server(self.server_id)
Ken'ichi Ohmichi39437e22013-10-06 00:21:38 +0900438 self.client.wait_for_server_status(self.server_id, 'ACTIVE')
439
Chris Hoge7579c1a2015-02-26 14:12:15 -0800440 @test.idempotent_id('af8eafd4-38a7-4a4b-bdbc-75145a580560')
Anju Tiwariaf98d222013-08-05 15:19:50 +0530441 def test_stop_start_server(self):
David Kranzae99b9a2015-02-16 13:37:01 -0500442 self.servers_client.stop(self.server_id)
Anju Tiwariaf98d222013-08-05 15:19:50 +0530443 self.servers_client.wait_for_server_status(self.server_id, 'SHUTOFF')
David Kranzae99b9a2015-02-16 13:37:01 -0500444 self.servers_client.start(self.server_id)
Anju Tiwariaf98d222013-08-05 15:19:50 +0530445 self.servers_client.wait_for_server_status(self.server_id, 'ACTIVE')
446
Chris Hoge7579c1a2015-02-26 14:12:15 -0800447 @test.idempotent_id('80a8094c-211e-440a-ab88-9e59d556c7ee')
Zhu Zhu9643e512013-09-23 09:13:07 -0500448 def test_lock_unlock_server(self):
449 # Lock the server,try server stop(exceptions throw),unlock it and retry
David Kranzae99b9a2015-02-16 13:37:01 -0500450 self.servers_client.lock_server(self.server_id)
David Kranz0fb14292015-02-11 15:55:20 -0500451 server = self.servers_client.get_server(self.server_id)
Zhu Zhu9643e512013-09-23 09:13:07 -0500452 self.assertEqual(server['status'], 'ACTIVE')
453 # Locked server is not allowed to be stopped by non-admin user
Masayuki Igawad9388762015-01-20 14:56:42 +0900454 self.assertRaises(lib_exc.Conflict,
Zhu Zhu9643e512013-09-23 09:13:07 -0500455 self.servers_client.stop, self.server_id)
David Kranzae99b9a2015-02-16 13:37:01 -0500456 self.servers_client.unlock_server(self.server_id)
457 self.servers_client.stop(self.server_id)
Zhu Zhu9643e512013-09-23 09:13:07 -0500458 self.servers_client.wait_for_server_status(self.server_id, 'SHUTOFF')
David Kranzae99b9a2015-02-16 13:37:01 -0500459 self.servers_client.start(self.server_id)
Zhu Zhu9643e512013-09-23 09:13:07 -0500460 self.servers_client.wait_for_server_status(self.server_id, 'ACTIVE')
461
Ghanshyam86d1a572014-03-05 10:19:25 +0900462 def _validate_url(self, url):
463 valid_scheme = ['http', 'https']
464 parsed_url = urlparse.urlparse(url)
465 self.assertNotEqual('None', parsed_url.port)
466 self.assertNotEqual('None', parsed_url.hostname)
467 self.assertIn(parsed_url.scheme, valid_scheme)
468
Chris Hoge7579c1a2015-02-26 14:12:15 -0800469 @test.idempotent_id('c6bc11bf-592e-4015-9319-1c98dc64daf5')
Ghanshyam86d1a572014-03-05 10:19:25 +0900470 @testtools.skipUnless(CONF.compute_feature_enabled.vnc_console,
471 'VNC Console feature is disabled.')
Ghanshyam86d1a572014-03-05 10:19:25 +0900472 def test_get_vnc_console(self):
473 # Get the VNC console of type 'novnc' and 'xvpvnc'
474 console_types = ['novnc', 'xvpvnc']
475 for console_type in console_types:
David Kranzae99b9a2015-02-16 13:37:01 -0500476 body = self.servers_client.get_vnc_console(self.server_id,
477 console_type)
Ghanshyam86d1a572014-03-05 10:19:25 +0900478 self.assertEqual(console_type, body['type'])
479 self.assertNotEqual('', body['url'])
480 self._validate_url(body['url'])