blob: a9f8c09521adbb70e341e91e6f5af0f9dae8dd02 [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
Slawek Kaplonskibc360ae2020-11-13 10:09:43 +010019from tempest.common import utils
Ken'ichi Ohmichi0eb153c2015-07-13 02:18:25 +000020from tempest.common import waiters
Adam Gandelman2e37b4f2014-06-18 17:34:21 -070021from tempest import config
Ken'ichi Ohmichi757833a2017-03-10 10:30:30 -080022from tempest.lib.common.utils import data_utils
Ken'ichi Ohmichi14b0ae12017-01-27 17:18:52 -080023from tempest.lib import decorators
nithya-ganesane6a36c82013-02-15 14:38:27 +000024
Adam Gandelman2e37b4f2014-06-18 17:34:21 -070025CONF = config.CONF
26
nithya-ganesane6a36c82013-02-15 14:38:27 +000027
zhufl3cf7aa22018-08-02 10:38:31 +080028class ServerRescueTestBase(base.BaseV2ComputeTest):
Ghanshyam Mann2c22e282020-04-21 21:37:54 -050029 create_default_network = True
nithya-ganesane6a36c82013-02-15 14:38:27 +000030
nithya-ganesane6a36c82013-02-15 14:38:27 +000031 @classmethod
Emily Hugenbruche7991d92014-12-12 16:53:36 +000032 def skip_checks(cls):
zhufl3cf7aa22018-08-02 10:38:31 +080033 super(ServerRescueTestBase, cls).skip_checks()
Adam Gandelman2e37b4f2014-06-18 17:34:21 -070034 if not CONF.compute_feature_enabled.rescue:
35 msg = "Server rescue not available."
36 raise cls.skipException(msg)
37
Emily Hugenbruche7991d92014-12-12 16:53:36 +000038 @classmethod
39 def setup_credentials(cls):
Attila Fazekas69095972014-02-06 16:46:18 +010040 cls.set_network_resources(network=True, subnet=True, router=True)
zhufl3cf7aa22018-08-02 10:38:31 +080041 super(ServerRescueTestBase, cls).setup_credentials()
Emily Hugenbruche7991d92014-12-12 16:53:36 +000042
43 @classmethod
44 def resource_setup(cls):
zhufl3cf7aa22018-08-02 10:38:31 +080045 super(ServerRescueTestBase, cls).resource_setup()
nithya-ganesane6a36c82013-02-15 14:38:27 +000046
zhufl0c042a52017-05-10 16:24:00 +080047 password = data_utils.rand_password()
48 server = cls.create_test_server(adminPass=password,
zhufl3b9e42e2017-02-24 15:59:01 +080049 wait_until='ACTIVE')
zhufl0c042a52017-05-10 16:24:00 +080050 cls.servers_client.rescue_server(server['id'], adminPass=password)
51 waiters.wait_for_server_status(cls.servers_client, server['id'],
52 'RESCUE')
53 cls.rescued_server_id = server['id']
Matthew Treinish149142e2013-03-20 16:25:55 -040054
zhufl3cf7aa22018-08-02 10:38:31 +080055
56class ServerRescueTestJSON(ServerRescueTestBase):
zhufl735e1692020-08-13 16:46:50 +080057 """Test server rescue"""
zhufl3cf7aa22018-08-02 10:38:31 +080058
Ken'ichi Ohmichi14b0ae12017-01-27 17:18:52 -080059 @decorators.idempotent_id('fd032140-714c-42e4-a8fd-adcd8df06be6')
nithya-ganesane6a36c82013-02-15 14:38:27 +000060 def test_rescue_unrescue_instance(self):
zhufl735e1692020-08-13 16:46:50 +080061 """Test rescue/unrescue server"""
zhufl0c042a52017-05-10 16:24:00 +080062 password = data_utils.rand_password()
63 server = self.create_test_server(adminPass=password,
64 wait_until='ACTIVE')
65 self.servers_client.rescue_server(server['id'], adminPass=password)
66 waiters.wait_for_server_status(self.servers_client, server['id'],
Ken'ichi Ohmichi0eb153c2015-07-13 02:18:25 +000067 'RESCUE')
zhufl0c042a52017-05-10 16:24:00 +080068 self.servers_client.unrescue_server(server['id'])
69 waiters.wait_for_server_status(self.servers_client, server['id'],
Ken'ichi Ohmichi0eb153c2015-07-13 02:18:25 +000070 'ACTIVE')
nithya-ganesane6a36c82013-02-15 14:38:27 +000071
zhufl3cf7aa22018-08-02 10:38:31 +080072
73class ServerRescueTestJSONUnderV235(ServerRescueTestBase):
zhufl735e1692020-08-13 16:46:50 +080074 """Test server rescue with compute microversion less than 2.36"""
zhufl3cf7aa22018-08-02 10:38:31 +080075
76 max_microversion = '2.35'
77
78 # TODO(zhufl): After 2.35 we should switch to neutron client to create
79 # floating ip, but that will need admin credential, so the testcases will
80 # have to be added in somewhere in admin directory.
81
Ken'ichi Ohmichi14b0ae12017-01-27 17:18:52 -080082 @decorators.idempotent_id('4842e0cf-e87d-4d9d-b61f-f4791da3cacc')
zhufl6b7040a2017-01-18 16:38:34 +080083 @testtools.skipUnless(CONF.network.public_network_id,
84 'The public_network_id option must be specified.')
Matthew Treinish3312de32017-05-19 12:08:17 -040085 @testtools.skipUnless(CONF.network_feature_enabled.floating_ips,
86 "Floating ips are not available")
nithya-ganesane6a36c82013-02-15 14:38:27 +000087 def test_rescued_vm_associate_dissociate_floating_ip(self):
zhufl735e1692020-08-13 16:46:50 +080088 """Test associate/dissociate floating ip for rescued server"""
zhufl0c042a52017-05-10 16:24:00 +080089 floating_ip_body = self.floating_ips_client.create_floating_ip(
90 pool=CONF.network.floating_network_name)['floating_ip']
91 self.addCleanup(self.floating_ips_client.delete_floating_ip,
92 floating_ip_body['id'])
93
94 self.floating_ips_client.associate_floating_ip_to_server(
95 str(floating_ip_body['ip']).strip(), self.rescued_server_id)
nithya-ganesane6a36c82013-02-15 14:38:27 +000096
Attila Fazekasf7f34f92013-08-01 17:01:44 +020097 # Disassociation of floating IP that was associated in this method
zhufl0c042a52017-05-10 16:24:00 +080098 self.floating_ips_client.disassociate_floating_ip_from_server(
99 str(floating_ip_body['ip']).strip(), self.rescued_server_id)
nithya-ganesane6a36c82013-02-15 14:38:27 +0000100
Ken'ichi Ohmichi14b0ae12017-01-27 17:18:52 -0800101 @decorators.idempotent_id('affca41f-7195-492d-8065-e09eee245404')
nithya-ganesane6a36c82013-02-15 14:38:27 +0000102 def test_rescued_vm_add_remove_security_group(self):
zhufl735e1692020-08-13 16:46:50 +0800103 """Test add/remove security group to for rescued server"""
Attila Fazekasf7f34f92013-08-01 17:01:44 +0200104 # Add Security group
zhufl0c042a52017-05-10 16:24:00 +0800105 sg = self.create_security_group()
106 self.servers_client.add_security_group(self.rescued_server_id,
107 name=sg['name'])
nithya-ganesane6a36c82013-02-15 14:38:27 +0000108
Attila Fazekasf7f34f92013-08-01 17:01:44 +0200109 # Delete Security group
zhufl0c042a52017-05-10 16:24:00 +0800110 self.servers_client.remove_security_group(self.rescued_server_id,
111 name=sg['name'])
Lee Yarwoodc0ad55c2019-12-06 13:39:19 +0000112
113
Lee Yarwood2ad7ca42020-01-07 13:06:25 +0000114class BaseServerStableDeviceRescueTest(base.BaseV2ComputeTest):
Ghanshyam Mann2c22e282020-04-21 21:37:54 -0500115 create_default_network = True
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
127 def _create_server_and_rescue_image(self, hw_rescue_device=None,
Lee Yarwood2ad7ca42020-01-07 13:06:25 +0000128 hw_rescue_bus=None,
129 block_device_mapping_v2=None):
Lee Yarwood2fd745f2020-05-05 11:24:56 +0100130
131 server_id = self.create_test_server(
132 wait_until='ACTIVE')['id']
133 image_id = self.create_image_from_server(
134 server_id, wait_until='ACTIVE')['id']
135
Lee Yarwood2ad7ca42020-01-07 13:06:25 +0000136 if block_device_mapping_v2:
137 server_id = self.create_test_server(
138 wait_until='ACTIVE',
139 block_device_mapping_v2=block_device_mapping_v2)['id']
Lee Yarwood2ad7ca42020-01-07 13:06:25 +0000140
Lee Yarwoodc0ad55c2019-12-06 13:39:19 +0000141 if hw_rescue_bus:
142 self.images_client.update_image(
143 image_id, [dict(add='/hw_rescue_bus',
144 value=hw_rescue_bus)])
145 if hw_rescue_device:
146 self.images_client.update_image(
147 image_id, [dict(add='/hw_rescue_device',
148 value=hw_rescue_device)])
149 return server_id, image_id
150
151 def _test_stable_device_rescue(self, server_id, rescue_image_id):
152 self.servers_client.rescue_server(
153 server_id, rescue_image_ref=rescue_image_id)
154 waiters.wait_for_server_status(
155 self.servers_client, server_id, 'RESCUE')
156 self.servers_client.unrescue_server(server_id)
157 waiters.wait_for_server_status(
158 self.servers_client, server_id, 'ACTIVE')
159
Lee Yarwood2ad7ca42020-01-07 13:06:25 +0000160
Lee Yarwood56a446d2021-02-15 13:34:35 +0000161class ServerStableDeviceRescueTestIDE(BaseServerStableDeviceRescueTest):
162 """Test rescuing server using an IDE device for the rescue disk"""
163
164 @classmethod
165 def skip_checks(cls):
166 super().skip_checks()
167 if not CONF.compute_feature_enabled.ide_bus:
168 raise cls.skipException("IDE bus not available.")
Lee Yarwood2ad7ca42020-01-07 13:06:25 +0000169
Lee Yarwoodc0ad55c2019-12-06 13:39:19 +0000170 @decorators.idempotent_id('947004c3-e8ef-47d9-9f00-97b74f9eaf96')
171 def test_stable_device_rescue_cdrom_ide(self):
zhufl735e1692020-08-13 16:46:50 +0800172 """Test rescuing server with cdrom and ide as the rescue disk"""
Lee Yarwoodc0ad55c2019-12-06 13:39:19 +0000173 server_id, rescue_image_id = self._create_server_and_rescue_image(
174 hw_rescue_device='cdrom', hw_rescue_bus='ide')
175 self._test_stable_device_rescue(server_id, rescue_image_id)
176
Lee Yarwood56a446d2021-02-15 13:34:35 +0000177
178class ServerStableDeviceRescueTest(BaseServerStableDeviceRescueTest):
179 """Test rescuing server specifying type of device for the rescue disk"""
180
Lee Yarwoodc0ad55c2019-12-06 13:39:19 +0000181 @decorators.idempotent_id('16865750-1417-4854-bcf7-496e6753c01e')
182 def test_stable_device_rescue_disk_virtio(self):
zhufl735e1692020-08-13 16:46:50 +0800183 """Test rescuing server with disk and virtio as the rescue disk"""
Lee Yarwoodc0ad55c2019-12-06 13:39:19 +0000184 server_id, rescue_image_id = self._create_server_and_rescue_image(
185 hw_rescue_device='disk', hw_rescue_bus='virtio')
186 self._test_stable_device_rescue(server_id, rescue_image_id)
187
188 @decorators.idempotent_id('12340157-6306-4745-bdda-cfa019908b48')
189 def test_stable_device_rescue_disk_scsi(self):
zhufl735e1692020-08-13 16:46:50 +0800190 """Test rescuing server with disk and scsi as the rescue disk"""
Lee Yarwoodc0ad55c2019-12-06 13:39:19 +0000191 server_id, rescue_image_id = self._create_server_and_rescue_image(
192 hw_rescue_device='disk', hw_rescue_bus='scsi')
193 self._test_stable_device_rescue(server_id, rescue_image_id)
194
195 @decorators.idempotent_id('647d04cf-ad35-4956-89ab-b05c5c16f30c')
196 def test_stable_device_rescue_disk_usb(self):
zhufl735e1692020-08-13 16:46:50 +0800197 """Test rescuing server with disk and usb as the rescue disk"""
Lee Yarwoodc0ad55c2019-12-06 13:39:19 +0000198 server_id, rescue_image_id = self._create_server_and_rescue_image(
199 hw_rescue_device='disk', hw_rescue_bus='usb')
200 self._test_stable_device_rescue(server_id, rescue_image_id)
201
202 @decorators.idempotent_id('a3772b42-00bf-4310-a90b-1cc6fd3e7eab')
Slawek Kaplonskibc360ae2020-11-13 10:09:43 +0100203 @utils.services('volume')
Lee Yarwoodc0ad55c2019-12-06 13:39:19 +0000204 def test_stable_device_rescue_disk_virtio_with_volume_attached(self):
zhufl735e1692020-08-13 16:46:50 +0800205 """Test rescuing server with volume attached
206
207 Attach a volume to the server and then rescue the server with disk
208 and virtio as the rescue disk.
209 """
Lee Yarwoodc0ad55c2019-12-06 13:39:19 +0000210 server_id, rescue_image_id = self._create_server_and_rescue_image(
211 hw_rescue_device='disk', hw_rescue_bus='virtio')
212 server = self.servers_client.show_server(server_id)['server']
213 volume = self.create_volume()
214 self.attach_volume(server, volume)
215 waiters.wait_for_volume_resource_status(self.volumes_client,
216 volume['id'], 'in-use')
217 self._test_stable_device_rescue(server_id, rescue_image_id)
Lee Yarwood2ad7ca42020-01-07 13:06:25 +0000218
219
220class ServerBootFromVolumeStableRescueTest(BaseServerStableDeviceRescueTest):
zhufl735e1692020-08-13 16:46:50 +0800221 """Test rescuing server specifying type of device for the rescue disk
222
223 Test rescuing server specifying type of device for the rescue disk with
224 compute microversion greater than 2.86.
225 """
Lee Yarwood2ad7ca42020-01-07 13:06:25 +0000226
227 min_microversion = '2.87'
228
Slawek Kaplonskibc360ae2020-11-13 10:09:43 +0100229 @classmethod
230 def skip_checks(cls):
231 super(ServerBootFromVolumeStableRescueTest, cls).skip_checks()
232 if not CONF.service_available.cinder:
233 skip_msg = ("%s skipped as Cinder is not available" % cls.__name__)
234 raise cls.skipException(skip_msg)
235
Lee Yarwood2fd745f2020-05-05 11:24:56 +0100236 @decorators.attr(type='slow')
Lee Yarwood2ad7ca42020-01-07 13:06:25 +0000237 @decorators.idempotent_id('48f123cb-922a-4065-8db6-b9a9074a556b')
238 def test_stable_device_rescue_bfv_blank_volume(self):
zhufl735e1692020-08-13 16:46:50 +0800239 """Test rescuing server with blank volume as block_device_mapping_v2
240
241 Create a server with block_device_mapping_v2 with blank volume,
242 then rescue the server with disk and virtio as the rescue disk.
243 """
Lee Yarwood2ad7ca42020-01-07 13:06:25 +0000244 block_device_mapping_v2 = [{
245 "boot_index": "0",
246 "source_type": "blank",
Martin Kopecabda8712020-05-11 15:31:13 +0000247 "volume_size": CONF.volume.volume_size,
Lee Yarwood2ad7ca42020-01-07 13:06:25 +0000248 "destination_type": "volume"}]
249 server_id, rescue_image_id = self._create_server_and_rescue_image(
250 hw_rescue_device='disk', hw_rescue_bus='virtio',
251 block_device_mapping_v2=block_device_mapping_v2)
252 self._test_stable_device_rescue(server_id, rescue_image_id)
253
Lee Yarwood2fd745f2020-05-05 11:24:56 +0100254 @decorators.attr(type='slow')
Lee Yarwood2ad7ca42020-01-07 13:06:25 +0000255 @decorators.idempotent_id('e4636333-c928-40fc-98b7-70a23eef4224')
256 def test_stable_device_rescue_bfv_image_volume(self):
zhufl735e1692020-08-13 16:46:50 +0800257 """Test rescuing server with blank volume as block_device_mapping_v2
258
259 Create a server with block_device_mapping_v2 with image volume,
260 then rescue the server with disk and virtio as the rescue disk.
261 """
Lee Yarwood2ad7ca42020-01-07 13:06:25 +0000262 block_device_mapping_v2 = [{
263 "boot_index": "0",
264 "source_type": "image",
Martin Kopecabda8712020-05-11 15:31:13 +0000265 "volume_size": CONF.volume.volume_size,
Lee Yarwood2ad7ca42020-01-07 13:06:25 +0000266 "uuid": CONF.compute.image_ref,
267 "destination_type": "volume"}]
268 server_id, rescue_image_id = self._create_server_and_rescue_image(
269 hw_rescue_device='disk', hw_rescue_bus='virtio',
270 block_device_mapping_v2=block_device_mapping_v2)
271 self._test_stable_device_rescue(server_id, rescue_image_id)