blob: 97c277460f422b3d3b936b5a2f3ec5e2eef260f5 [file] [log] [blame]
nithya-ganesane6a36c82013-02-15 14:38:27 +00001# Copyright 2013 Hewlett-Packard Development Company, L.P.
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
Sean Dague1937d092013-05-17 16:36:38 -040018from tempest.api.compute import base
Ghanshyam Mann7304e3a2022-03-18 13:58:25 -050019from tempest.common import compute
Slawek Kaplonskibc360ae2020-11-13 10:09:43 +010020from tempest.common import utils
Ken'ichi Ohmichi0eb153c2015-07-13 02:18:25 +000021from tempest.common import waiters
Adam Gandelman2e37b4f2014-06-18 17:34:21 -070022from tempest import config
Ken'ichi Ohmichi757833a2017-03-10 10:30:30 -080023from tempest.lib.common.utils import data_utils
Ken'ichi Ohmichi14b0ae12017-01-27 17:18:52 -080024from tempest.lib import decorators
nithya-ganesane6a36c82013-02-15 14:38:27 +000025
Adam Gandelman2e37b4f2014-06-18 17:34:21 -070026CONF = config.CONF
27
nithya-ganesane6a36c82013-02-15 14:38:27 +000028
zhufl3cf7aa22018-08-02 10:38:31 +080029class ServerRescueTestBase(base.BaseV2ComputeTest):
Ghanshyam Mann2c22e282020-04-21 21:37:54 -050030 create_default_network = True
nithya-ganesane6a36c82013-02-15 14:38:27 +000031
nithya-ganesane6a36c82013-02-15 14:38:27 +000032 @classmethod
Emily Hugenbruche7991d92014-12-12 16:53:36 +000033 def skip_checks(cls):
zhufl3cf7aa22018-08-02 10:38:31 +080034 super(ServerRescueTestBase, cls).skip_checks()
Adam Gandelman2e37b4f2014-06-18 17:34:21 -070035 if not CONF.compute_feature_enabled.rescue:
36 msg = "Server rescue not available."
37 raise cls.skipException(msg)
38
Emily Hugenbruche7991d92014-12-12 16:53:36 +000039 @classmethod
40 def setup_credentials(cls):
Attila Fazekas69095972014-02-06 16:46:18 +010041 cls.set_network_resources(network=True, subnet=True, router=True)
zhufl3cf7aa22018-08-02 10:38:31 +080042 super(ServerRescueTestBase, cls).setup_credentials()
Emily Hugenbruche7991d92014-12-12 16:53:36 +000043
44 @classmethod
45 def resource_setup(cls):
zhufl3cf7aa22018-08-02 10:38:31 +080046 super(ServerRescueTestBase, cls).resource_setup()
nithya-ganesane6a36c82013-02-15 14:38:27 +000047
zhufl0c042a52017-05-10 16:24:00 +080048 password = data_utils.rand_password()
49 server = cls.create_test_server(adminPass=password,
zhufl3b9e42e2017-02-24 15:59:01 +080050 wait_until='ACTIVE')
zhufl0c042a52017-05-10 16:24:00 +080051 cls.servers_client.rescue_server(server['id'], adminPass=password)
52 waiters.wait_for_server_status(cls.servers_client, server['id'],
53 'RESCUE')
54 cls.rescued_server_id = server['id']
Matthew Treinish149142e2013-03-20 16:25:55 -040055
zhufl3cf7aa22018-08-02 10:38:31 +080056
57class ServerRescueTestJSON(ServerRescueTestBase):
zhufl735e1692020-08-13 16:46:50 +080058 """Test server rescue"""
zhufl3cf7aa22018-08-02 10:38:31 +080059
Ken'ichi Ohmichi14b0ae12017-01-27 17:18:52 -080060 @decorators.idempotent_id('fd032140-714c-42e4-a8fd-adcd8df06be6')
nithya-ganesane6a36c82013-02-15 14:38:27 +000061 def test_rescue_unrescue_instance(self):
zhufl735e1692020-08-13 16:46:50 +080062 """Test rescue/unrescue server"""
zhufl0c042a52017-05-10 16:24:00 +080063 password = data_utils.rand_password()
64 server = self.create_test_server(adminPass=password,
65 wait_until='ACTIVE')
66 self.servers_client.rescue_server(server['id'], adminPass=password)
67 waiters.wait_for_server_status(self.servers_client, server['id'],
Ken'ichi Ohmichi0eb153c2015-07-13 02:18:25 +000068 'RESCUE')
zhufl0c042a52017-05-10 16:24:00 +080069 self.servers_client.unrescue_server(server['id'])
70 waiters.wait_for_server_status(self.servers_client, server['id'],
Ken'ichi Ohmichi0eb153c2015-07-13 02:18:25 +000071 'ACTIVE')
nithya-ganesane6a36c82013-02-15 14:38:27 +000072
zhufl3cf7aa22018-08-02 10:38:31 +080073
74class ServerRescueTestJSONUnderV235(ServerRescueTestBase):
zhufl735e1692020-08-13 16:46:50 +080075 """Test server rescue with compute microversion less than 2.36"""
zhufl3cf7aa22018-08-02 10:38:31 +080076
77 max_microversion = '2.35'
78
79 # TODO(zhufl): After 2.35 we should switch to neutron client to create
80 # floating ip, but that will need admin credential, so the testcases will
81 # have to be added in somewhere in admin directory.
82
Ken'ichi Ohmichi14b0ae12017-01-27 17:18:52 -080083 @decorators.idempotent_id('4842e0cf-e87d-4d9d-b61f-f4791da3cacc')
zhufl6b7040a2017-01-18 16:38:34 +080084 @testtools.skipUnless(CONF.network.public_network_id,
85 'The public_network_id option must be specified.')
Matthew Treinish3312de32017-05-19 12:08:17 -040086 @testtools.skipUnless(CONF.network_feature_enabled.floating_ips,
87 "Floating ips are not available")
nithya-ganesane6a36c82013-02-15 14:38:27 +000088 def test_rescued_vm_associate_dissociate_floating_ip(self):
zhufl735e1692020-08-13 16:46:50 +080089 """Test associate/dissociate floating ip for rescued server"""
zhufl0c042a52017-05-10 16:24:00 +080090 floating_ip_body = self.floating_ips_client.create_floating_ip(
91 pool=CONF.network.floating_network_name)['floating_ip']
92 self.addCleanup(self.floating_ips_client.delete_floating_ip,
93 floating_ip_body['id'])
94
95 self.floating_ips_client.associate_floating_ip_to_server(
96 str(floating_ip_body['ip']).strip(), self.rescued_server_id)
nithya-ganesane6a36c82013-02-15 14:38:27 +000097
Attila Fazekasf7f34f92013-08-01 17:01:44 +020098 # Disassociation of floating IP that was associated in this method
zhufl0c042a52017-05-10 16:24:00 +080099 self.floating_ips_client.disassociate_floating_ip_from_server(
100 str(floating_ip_body['ip']).strip(), self.rescued_server_id)
nithya-ganesane6a36c82013-02-15 14:38:27 +0000101
Ken'ichi Ohmichi14b0ae12017-01-27 17:18:52 -0800102 @decorators.idempotent_id('affca41f-7195-492d-8065-e09eee245404')
nithya-ganesane6a36c82013-02-15 14:38:27 +0000103 def test_rescued_vm_add_remove_security_group(self):
zhufl735e1692020-08-13 16:46:50 +0800104 """Test add/remove security group to for rescued server"""
Attila Fazekasf7f34f92013-08-01 17:01:44 +0200105 # Add Security group
zhufl0c042a52017-05-10 16:24:00 +0800106 sg = self.create_security_group()
107 self.servers_client.add_security_group(self.rescued_server_id,
108 name=sg['name'])
nithya-ganesane6a36c82013-02-15 14:38:27 +0000109
Attila Fazekasf7f34f92013-08-01 17:01:44 +0200110 # Delete Security group
zhufl0c042a52017-05-10 16:24:00 +0800111 self.servers_client.remove_security_group(self.rescued_server_id,
112 name=sg['name'])
Lee Yarwoodc0ad55c2019-12-06 13:39:19 +0000113
114
Lee Yarwood2ad7ca42020-01-07 13:06:25 +0000115class BaseServerStableDeviceRescueTest(base.BaseV2ComputeTest):
Lee Yarwoodc0ad55c2019-12-06 13:39:19 +0000116
117 @classmethod
zhufl40e5eaa2020-05-21 12:54:16 +0800118 def skip_checks(cls):
119 super(BaseServerStableDeviceRescueTest, cls).skip_checks()
Lee Yarwoodc0ad55c2019-12-06 13:39:19 +0000120 if not CONF.compute_feature_enabled.rescue:
121 msg = "Server rescue not available."
zhufl40e5eaa2020-05-21 12:54:16 +0800122 raise cls.skipException(msg)
Lee Yarwoodc0ad55c2019-12-06 13:39:19 +0000123 if not CONF.compute_feature_enabled.stable_rescue:
124 msg = "Stable rescue not available."
zhufl40e5eaa2020-05-21 12:54:16 +0800125 raise cls.skipException(msg)
Lee Yarwoodc0ad55c2019-12-06 13:39:19 +0000126
Ghanshyam Mann7304e3a2022-03-18 13:58:25 -0500127 @classmethod
128 def setup_credentials(cls):
129 cls.set_network_resources(network=True, subnet=True, router=True,
130 dhcp=True)
131 super(BaseServerStableDeviceRescueTest, cls).setup_credentials()
132
Lee Yarwoodc0ad55c2019-12-06 13:39:19 +0000133 def _create_server_and_rescue_image(self, hw_rescue_device=None,
Lee Yarwood2ad7ca42020-01-07 13:06:25 +0000134 hw_rescue_bus=None,
Ghanshyam Mann7304e3a2022-03-18 13:58:25 -0500135 block_device_mapping_v2=None,
136 validatable=False,
137 validation_resources=None,
138 wait_until='ACTIVE'):
139 server = self.create_test_server(
140 wait_until=wait_until,
141 validatable=validatable,
142 validation_resources=validation_resources)
Lee Yarwood2fd745f2020-05-05 11:24:56 +0100143 image_id = self.create_image_from_server(
Ghanshyam Mann7304e3a2022-03-18 13:58:25 -0500144 server['id'], wait_until='ACTIVE')['id']
Lee Yarwood2fd745f2020-05-05 11:24:56 +0100145
Lee Yarwood2ad7ca42020-01-07 13:06:25 +0000146 if block_device_mapping_v2:
Ghanshyam Mann7304e3a2022-03-18 13:58:25 -0500147 server = self.create_test_server(
148 wait_until=wait_until,
149 validatable=validatable,
150 validation_resources=validation_resources,
151 block_device_mapping_v2=block_device_mapping_v2)
Lee Yarwood2ad7ca42020-01-07 13:06:25 +0000152
Lee Yarwoodc0ad55c2019-12-06 13:39:19 +0000153 if hw_rescue_bus:
154 self.images_client.update_image(
155 image_id, [dict(add='/hw_rescue_bus',
156 value=hw_rescue_bus)])
157 if hw_rescue_device:
158 self.images_client.update_image(
159 image_id, [dict(add='/hw_rescue_device',
160 value=hw_rescue_device)])
Ghanshyam Mann7304e3a2022-03-18 13:58:25 -0500161 return server, image_id
Lee Yarwoodc0ad55c2019-12-06 13:39:19 +0000162
Ghanshyam Mann7304e3a2022-03-18 13:58:25 -0500163 def _test_stable_device_rescue(
164 self, server, rescue_image_id,
165 validation_resources=None):
Lee Yarwoodc0ad55c2019-12-06 13:39:19 +0000166 self.servers_client.rescue_server(
Ghanshyam Mann7304e3a2022-03-18 13:58:25 -0500167 server['id'], rescue_image_ref=rescue_image_id)
Lee Yarwoodc0ad55c2019-12-06 13:39:19 +0000168 waiters.wait_for_server_status(
Ghanshyam Mann7304e3a2022-03-18 13:58:25 -0500169 self.servers_client, server['id'], 'RESCUE')
170 self.servers_client.unrescue_server(server['id'])
171 # NOTE(gmann) In next addCleanup, server unrescue is called before the
172 # detach volume is called in cleanup (added by self.attach_volume()
173 # method) so to make sure server is ready before detach operation, we
174 # need to perform ssh on it, more details are in bug#1960346.
175 if validation_resources and CONF.validation.run_validation:
176 tenant_network = self.get_tenant_network()
177 compute.wait_for_ssh_or_ping(
178 server, self.os_primary, tenant_network,
179 True, validation_resources, "SSHABLE", True)
180 else:
181 waiters.wait_for_server_status(
182 self.servers_client, server['id'], 'ACTIVE')
Lee Yarwoodc0ad55c2019-12-06 13:39:19 +0000183
Lee Yarwood2ad7ca42020-01-07 13:06:25 +0000184
Lee Yarwood56a446d2021-02-15 13:34:35 +0000185class ServerStableDeviceRescueTestIDE(BaseServerStableDeviceRescueTest):
186 """Test rescuing server using an IDE device for the rescue disk"""
187
188 @classmethod
189 def skip_checks(cls):
190 super().skip_checks()
191 if not CONF.compute_feature_enabled.ide_bus:
192 raise cls.skipException("IDE bus not available.")
Lee Yarwood2ad7ca42020-01-07 13:06:25 +0000193
Lee Yarwoodc0ad55c2019-12-06 13:39:19 +0000194 @decorators.idempotent_id('947004c3-e8ef-47d9-9f00-97b74f9eaf96')
ricolin9d2effc2021-04-04 14:08:29 +0800195 @testtools.skipIf("aarch64" in CONF.scenario.img_file,
196 "Aarch64 does not support ide bus for cdrom")
Lee Yarwoodc0ad55c2019-12-06 13:39:19 +0000197 def test_stable_device_rescue_cdrom_ide(self):
zhufl735e1692020-08-13 16:46:50 +0800198 """Test rescuing server with cdrom and ide as the rescue disk"""
Ghanshyam Mann7304e3a2022-03-18 13:58:25 -0500199 server, rescue_image_id = self._create_server_and_rescue_image(
Lee Yarwoodc0ad55c2019-12-06 13:39:19 +0000200 hw_rescue_device='cdrom', hw_rescue_bus='ide')
Ghanshyam Mann7304e3a2022-03-18 13:58:25 -0500201 self._test_stable_device_rescue(server, rescue_image_id)
Lee Yarwoodc0ad55c2019-12-06 13:39:19 +0000202
Lee Yarwood56a446d2021-02-15 13:34:35 +0000203
204class ServerStableDeviceRescueTest(BaseServerStableDeviceRescueTest):
205 """Test rescuing server specifying type of device for the rescue disk"""
206
Lee Yarwoodc0ad55c2019-12-06 13:39:19 +0000207 @decorators.idempotent_id('16865750-1417-4854-bcf7-496e6753c01e')
208 def test_stable_device_rescue_disk_virtio(self):
zhufl735e1692020-08-13 16:46:50 +0800209 """Test rescuing server with disk and virtio as the rescue disk"""
Ghanshyam Mann7304e3a2022-03-18 13:58:25 -0500210 server, rescue_image_id = self._create_server_and_rescue_image(
Lee Yarwoodc0ad55c2019-12-06 13:39:19 +0000211 hw_rescue_device='disk', hw_rescue_bus='virtio')
Ghanshyam Mann7304e3a2022-03-18 13:58:25 -0500212 self._test_stable_device_rescue(server, rescue_image_id)
Lee Yarwoodc0ad55c2019-12-06 13:39:19 +0000213
214 @decorators.idempotent_id('12340157-6306-4745-bdda-cfa019908b48')
215 def test_stable_device_rescue_disk_scsi(self):
zhufl735e1692020-08-13 16:46:50 +0800216 """Test rescuing server with disk and scsi as the rescue disk"""
Ghanshyam Mann7304e3a2022-03-18 13:58:25 -0500217 server, rescue_image_id = self._create_server_and_rescue_image(
Lee Yarwoodc0ad55c2019-12-06 13:39:19 +0000218 hw_rescue_device='disk', hw_rescue_bus='scsi')
Ghanshyam Mann7304e3a2022-03-18 13:58:25 -0500219 self._test_stable_device_rescue(server, rescue_image_id)
Lee Yarwoodc0ad55c2019-12-06 13:39:19 +0000220
221 @decorators.idempotent_id('647d04cf-ad35-4956-89ab-b05c5c16f30c')
222 def test_stable_device_rescue_disk_usb(self):
zhufl735e1692020-08-13 16:46:50 +0800223 """Test rescuing server with disk and usb as the rescue disk"""
Ghanshyam Mann7304e3a2022-03-18 13:58:25 -0500224 server, rescue_image_id = self._create_server_and_rescue_image(
Lee Yarwoodc0ad55c2019-12-06 13:39:19 +0000225 hw_rescue_device='disk', hw_rescue_bus='usb')
Ghanshyam Mann7304e3a2022-03-18 13:58:25 -0500226 self._test_stable_device_rescue(server, rescue_image_id)
Lee Yarwoodc0ad55c2019-12-06 13:39:19 +0000227
228 @decorators.idempotent_id('a3772b42-00bf-4310-a90b-1cc6fd3e7eab')
Slawek Kaplonskibc360ae2020-11-13 10:09:43 +0100229 @utils.services('volume')
Lee Yarwoodc0ad55c2019-12-06 13:39:19 +0000230 def test_stable_device_rescue_disk_virtio_with_volume_attached(self):
zhufl735e1692020-08-13 16:46:50 +0800231 """Test rescuing server with volume attached
232
233 Attach a volume to the server and then rescue the server with disk
234 and virtio as the rescue disk.
235 """
Ghanshyam Mann7304e3a2022-03-18 13:58:25 -0500236 # This test just check detach fail and does not
237 # perfom the detach operation but in cleanup from
238 # self.attach_volume() it will try to detach the server
239 # after unrescue the server. Due to that we need to make
240 # server SSHable before it try to detach, more details are
241 # in bug#1960346
Dan Smith5e2019f2023-07-21 10:38:59 -0700242 volume = self.create_volume(wait_for_available=False)
Ghanshyam Mann7304e3a2022-03-18 13:58:25 -0500243 validation_resources = self.get_class_validation_resources(
244 self.os_primary)
245 server, rescue_image_id = self._create_server_and_rescue_image(
246 hw_rescue_device='disk', hw_rescue_bus='virtio', validatable=True,
247 validation_resources=validation_resources, wait_until="SSHABLE")
248 server = self.servers_client.show_server(server['id'])['server']
Dan Smith5e2019f2023-07-21 10:38:59 -0700249 waiters.wait_for_volume_resource_status(self.volumes_client,
250 volume['id'], 'available')
Lee Yarwoodc0ad55c2019-12-06 13:39:19 +0000251 self.attach_volume(server, volume)
252 waiters.wait_for_volume_resource_status(self.volumes_client,
253 volume['id'], 'in-use')
Ghanshyam Mann7304e3a2022-03-18 13:58:25 -0500254 self._test_stable_device_rescue(
255 server, rescue_image_id,
256 validation_resources=validation_resources)
Lee Yarwood2ad7ca42020-01-07 13:06:25 +0000257
258
259class ServerBootFromVolumeStableRescueTest(BaseServerStableDeviceRescueTest):
zhufl735e1692020-08-13 16:46:50 +0800260 """Test rescuing server specifying type of device for the rescue disk
261
262 Test rescuing server specifying type of device for the rescue disk with
263 compute microversion greater than 2.86.
264 """
Lee Yarwood2ad7ca42020-01-07 13:06:25 +0000265
266 min_microversion = '2.87'
267
Slawek Kaplonskibc360ae2020-11-13 10:09:43 +0100268 @classmethod
269 def skip_checks(cls):
270 super(ServerBootFromVolumeStableRescueTest, cls).skip_checks()
271 if not CONF.service_available.cinder:
272 skip_msg = ("%s skipped as Cinder is not available" % cls.__name__)
273 raise cls.skipException(skip_msg)
274
Lee Yarwood2fd745f2020-05-05 11:24:56 +0100275 @decorators.attr(type='slow')
Lee Yarwood2ad7ca42020-01-07 13:06:25 +0000276 @decorators.idempotent_id('48f123cb-922a-4065-8db6-b9a9074a556b')
277 def test_stable_device_rescue_bfv_blank_volume(self):
zhufl735e1692020-08-13 16:46:50 +0800278 """Test rescuing server with blank volume as block_device_mapping_v2
279
280 Create a server with block_device_mapping_v2 with blank volume,
281 then rescue the server with disk and virtio as the rescue disk.
282 """
Lee Yarwood2ad7ca42020-01-07 13:06:25 +0000283 block_device_mapping_v2 = [{
284 "boot_index": "0",
285 "source_type": "blank",
Martin Kopecabda8712020-05-11 15:31:13 +0000286 "volume_size": CONF.volume.volume_size,
Lee Yarwood2ad7ca42020-01-07 13:06:25 +0000287 "destination_type": "volume"}]
Ghanshyam Mann7304e3a2022-03-18 13:58:25 -0500288 server, rescue_image_id = self._create_server_and_rescue_image(
Lee Yarwood2ad7ca42020-01-07 13:06:25 +0000289 hw_rescue_device='disk', hw_rescue_bus='virtio',
290 block_device_mapping_v2=block_device_mapping_v2)
Ghanshyam Mann7304e3a2022-03-18 13:58:25 -0500291 self._test_stable_device_rescue(server, rescue_image_id)
Lee Yarwood2ad7ca42020-01-07 13:06:25 +0000292
Lee Yarwood2fd745f2020-05-05 11:24:56 +0100293 @decorators.attr(type='slow')
Lee Yarwood2ad7ca42020-01-07 13:06:25 +0000294 @decorators.idempotent_id('e4636333-c928-40fc-98b7-70a23eef4224')
295 def test_stable_device_rescue_bfv_image_volume(self):
zhufl735e1692020-08-13 16:46:50 +0800296 """Test rescuing server with blank volume as block_device_mapping_v2
297
298 Create a server with block_device_mapping_v2 with image volume,
299 then rescue the server with disk and virtio as the rescue disk.
300 """
Lee Yarwood2ad7ca42020-01-07 13:06:25 +0000301 block_device_mapping_v2 = [{
302 "boot_index": "0",
303 "source_type": "image",
Martin Kopecabda8712020-05-11 15:31:13 +0000304 "volume_size": CONF.volume.volume_size,
Lee Yarwood2ad7ca42020-01-07 13:06:25 +0000305 "uuid": CONF.compute.image_ref,
306 "destination_type": "volume"}]
Ghanshyam Mann7304e3a2022-03-18 13:58:25 -0500307 server, rescue_image_id = self._create_server_and_rescue_image(
Lee Yarwood2ad7ca42020-01-07 13:06:25 +0000308 hw_rescue_device='disk', hw_rescue_bus='virtio',
309 block_device_mapping_v2=block_device_mapping_v2)
Ghanshyam Mann7304e3a2022-03-18 13:58:25 -0500310 self._test_stable_device_rescue(server, rescue_image_id)