blob: 204471e367ef37e0d1a775432141762c80fee4b6 [file] [log] [blame]
JordanPc240f7b2014-11-14 19:16:01 +01001# Copyright 2014 Scality
2# 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
zhufl6b7040a2017-01-18 16:38:34 +080016import testtools
17
ghanshyam017b5fe2016-04-15 18:49:26 +090018from tempest.common import compute
Andrea Frittolicd368412017-08-14 21:37:56 +010019from tempest.common import utils
Ken'ichi Ohmichi0eb153c2015-07-13 02:18:25 +000020from tempest.common import waiters
JordanPc240f7b2014-11-14 19:16:01 +010021from tempest import config
Ken'ichi Ohmichic85a9512017-01-27 18:34:24 -080022from tempest.lib import decorators
JordanPc240f7b2014-11-14 19:16:01 +010023from tempest.scenario import manager
JordanPc240f7b2014-11-14 19:16:01 +010024
25CONF = config.CONF
26
JordanPc240f7b2014-11-14 19:16:01 +010027
28class TestShelveInstance(manager.ScenarioTest):
Ken'ichi Ohmichic4e4f1c2015-11-17 08:16:12 +000029 """This test shelves then unshelves a Nova instance
30
JordanPc240f7b2014-11-14 19:16:01 +010031 The following is the scenario outline:
Takashi NATSUME6d5a2b42015-09-08 11:27:49 +090032 * boot an instance and create a timestamp file in it
JordanPc240f7b2014-11-14 19:16:01 +010033 * shelve the instance
34 * unshelve the instance
35 * check the existence of the timestamp file in the unshelved instance
Alexandre Arents0a9b8232020-07-29 09:52:57 +000036 * check the existence of the timestamp file in the unshelved instance,
37 after a cold migrate
JordanPc240f7b2014-11-14 19:16:01 +010038
39 """
40
Alexandre Arents0a9b8232020-07-29 09:52:57 +000041 credentials = ['primary', 'admin']
42
43 @classmethod
44 def setup_clients(cls):
45 super(TestShelveInstance, cls).setup_clients()
46 cls.admin_servers_client = cls.os_admin.servers_client
47
zhufl8ed23d22016-07-13 11:00:05 +080048 @classmethod
49 def skip_checks(cls):
50 super(TestShelveInstance, cls).skip_checks()
51 if not CONF.compute_feature_enabled.shelve:
52 raise cls.skipException("Shelve is not available.")
53
JordanPc240f7b2014-11-14 19:16:01 +010054 def _shelve_then_unshelve_server(self, server):
ghanshyam017b5fe2016-04-15 18:49:26 +090055 compute.shelve_server(self.servers_client, server['id'],
56 force_shelve_offload=True)
57
JordanPc240f7b2014-11-14 19:16:01 +010058 self.servers_client.unshelve_server(server['id'])
Ken'ichi Ohmichi0eb153c2015-07-13 02:18:25 +000059 waiters.wait_for_server_status(self.servers_client, server['id'],
60 'ACTIVE')
JordanPc240f7b2014-11-14 19:16:01 +010061
Alexandre Arents0a9b8232020-07-29 09:52:57 +000062 def _cold_migrate_server(self, server):
63 src_host = self.get_host_for_server(server['id'])
64
65 self.admin_servers_client.migrate_server(server['id'])
66 waiters.wait_for_server_status(self.servers_client,
67 server['id'], 'VERIFY_RESIZE')
68 self.servers_client.confirm_resize_server(server['id'])
69 waiters.wait_for_server_status(self.servers_client,
70 server['id'], 'ACTIVE')
71
72 dst_host = self.get_host_for_server(server['id'])
73 self.assertNotEqual(src_host, dst_host)
74
75 def _create_server_then_shelve_and_unshelve(self, boot_from_volume=False,
76 cold_migrate=False):
Matt Riedemann73764bf2015-09-30 14:53:25 -070077 keypair = self.create_keypair()
JordanPc240f7b2014-11-14 19:16:01 +010078
Soniya Vyas582c1702021-02-22 18:26:17 +053079 security_group = self.create_security_group()
Matt Riedemann73764bf2015-09-30 14:53:25 -070080 security_groups = [{'name': security_group['name']}]
PranaliDeore9fe5eb32015-07-22 05:28:00 -070081
Xiangfei Zhu0b5dca02016-08-16 21:16:25 -070082 server = self.create_server(
Xiangfei Zhu0b5dca02016-08-16 21:16:25 -070083 key_name=keypair['name'],
84 security_groups=security_groups,
Xiangfei Zhu0b5dca02016-08-16 21:16:25 -070085 volume_backed=boot_from_volume)
JordanPc240f7b2014-11-14 19:16:01 +010086
Sean Dague20e98612016-01-06 14:33:28 -050087 instance_ip = self.get_server_ip(server)
Alexander Gubanovc8829f82015-11-12 10:35:13 +020088 timestamp = self.create_timestamp(instance_ip,
Slawek Kaplonski79d8b0f2018-07-30 22:43:41 +020089 private_key=keypair['private_key'],
90 server=server)
JordanPc240f7b2014-11-14 19:16:01 +010091
92 # Prevent bug #1257594 from coming back
93 # Unshelve used to boot the instance with the original image, not
94 # with the instance snapshot
95 self._shelve_then_unshelve_server(server)
Alexander Gubanovc8829f82015-11-12 10:35:13 +020096
Alexandre Arents0a9b8232020-07-29 09:52:57 +000097 if cold_migrate:
98 # Prevent bug #1732428 from coming back
99 self._cold_migrate_server(server)
100
Alexander Gubanovc8829f82015-11-12 10:35:13 +0200101 timestamp2 = self.get_timestamp(instance_ip,
Slawek Kaplonski79d8b0f2018-07-30 22:43:41 +0200102 private_key=keypair['private_key'],
103 server=server)
Alexander Gubanovabd154c2015-09-23 23:24:06 +0300104 self.assertEqual(timestamp, timestamp2)
PranaliDeore9fe5eb32015-07-22 05:28:00 -0700105
Jordan Pittier3b46d272017-04-12 16:17:28 +0200106 @decorators.attr(type='slow')
Ken'ichi Ohmichic85a9512017-01-27 18:34:24 -0800107 @decorators.idempotent_id('1164e700-0af0-4a4c-8792-35909a88743c')
zhufl6b7040a2017-01-18 16:38:34 +0800108 @testtools.skipUnless(CONF.network.public_network_id,
109 'The public_network_id option must be specified.')
Andrea Frittolicd368412017-08-14 21:37:56 +0100110 @utils.services('compute', 'network', 'image')
PranaliDeore9fe5eb32015-07-22 05:28:00 -0700111 def test_shelve_instance(self):
112 self._create_server_then_shelve_and_unshelve()
113
Jordan Pittier3b46d272017-04-12 16:17:28 +0200114 @decorators.attr(type='slow')
Ken'ichi Ohmichic85a9512017-01-27 18:34:24 -0800115 @decorators.idempotent_id('c1b6318c-b9da-490b-9c67-9339b627271f')
zhufl6b7040a2017-01-18 16:38:34 +0800116 @testtools.skipUnless(CONF.network.public_network_id,
117 'The public_network_id option must be specified.')
Andrea Frittolicd368412017-08-14 21:37:56 +0100118 @utils.services('compute', 'volume', 'network', 'image')
PranaliDeore9fe5eb32015-07-22 05:28:00 -0700119 def test_shelve_volume_backed_instance(self):
120 self._create_server_then_shelve_and_unshelve(boot_from_volume=True)
Alexandre Arents0a9b8232020-07-29 09:52:57 +0000121
Ghanshyam Manne2183ca2023-02-10 19:31:52 -0600122 @decorators.attr(type=['slow', 'multinode'])
Alexandre Arents0a9b8232020-07-29 09:52:57 +0000123 @decorators.idempotent_id('1295fd9e-193a-4cf8-b211-55358e021bae')
124 @testtools.skipUnless(CONF.network.public_network_id,
125 'The public_network_id option must be specified.')
126 @testtools.skipUnless(CONF.compute_feature_enabled.cold_migration,
127 'Cold migration not available.')
128 @testtools.skipUnless(CONF.compute_feature_enabled.shelve_migrate,
129 'Shelve migrate not available.')
130 @testtools.skipUnless(CONF.compute.min_compute_nodes > 1,
131 'Less than 2 compute nodes, skipping multinode '
132 'tests.')
133 @utils.services('compute', 'network', 'image')
134 def test_cold_migrate_unshelved_instance(self):
135 self._create_server_then_shelve_and_unshelve(cold_migrate=True)