blob: 54451138560b33c1d907fe6c728f2e5f03d3d746 [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
Ken'ichi Ohmichi0eb153c2015-07-13 02:18:25 +000019from tempest.common import waiters
Adam Gandelman2e37b4f2014-06-18 17:34:21 -070020from tempest import config
Ken'ichi Ohmichi757833a2017-03-10 10:30:30 -080021from tempest.lib.common.utils import data_utils
Ken'ichi Ohmichi14b0ae12017-01-27 17:18:52 -080022from tempest.lib import decorators
nithya-ganesane6a36c82013-02-15 14:38:27 +000023
Adam Gandelman2e37b4f2014-06-18 17:34:21 -070024CONF = config.CONF
25
nithya-ganesane6a36c82013-02-15 14:38:27 +000026
zhufl3cf7aa22018-08-02 10:38:31 +080027class ServerRescueTestBase(base.BaseV2ComputeTest):
Ghanshyam Mann2c22e282020-04-21 21:37:54 -050028 create_default_network = True
nithya-ganesane6a36c82013-02-15 14:38:27 +000029
nithya-ganesane6a36c82013-02-15 14:38:27 +000030 @classmethod
Emily Hugenbruche7991d92014-12-12 16:53:36 +000031 def skip_checks(cls):
zhufl3cf7aa22018-08-02 10:38:31 +080032 super(ServerRescueTestBase, cls).skip_checks()
Adam Gandelman2e37b4f2014-06-18 17:34:21 -070033 if not CONF.compute_feature_enabled.rescue:
34 msg = "Server rescue not available."
35 raise cls.skipException(msg)
36
Emily Hugenbruche7991d92014-12-12 16:53:36 +000037 @classmethod
38 def setup_credentials(cls):
Attila Fazekas69095972014-02-06 16:46:18 +010039 cls.set_network_resources(network=True, subnet=True, router=True)
zhufl3cf7aa22018-08-02 10:38:31 +080040 super(ServerRescueTestBase, cls).setup_credentials()
Emily Hugenbruche7991d92014-12-12 16:53:36 +000041
42 @classmethod
43 def resource_setup(cls):
zhufl3cf7aa22018-08-02 10:38:31 +080044 super(ServerRescueTestBase, cls).resource_setup()
nithya-ganesane6a36c82013-02-15 14:38:27 +000045
zhufl0c042a52017-05-10 16:24:00 +080046 password = data_utils.rand_password()
47 server = cls.create_test_server(adminPass=password,
zhufl3b9e42e2017-02-24 15:59:01 +080048 wait_until='ACTIVE')
zhufl0c042a52017-05-10 16:24:00 +080049 cls.servers_client.rescue_server(server['id'], adminPass=password)
50 waiters.wait_for_server_status(cls.servers_client, server['id'],
51 'RESCUE')
52 cls.rescued_server_id = server['id']
Matthew Treinish149142e2013-03-20 16:25:55 -040053
zhufl3cf7aa22018-08-02 10:38:31 +080054
55class ServerRescueTestJSON(ServerRescueTestBase):
zhufl735e1692020-08-13 16:46:50 +080056 """Test server rescue"""
zhufl3cf7aa22018-08-02 10:38:31 +080057
Ken'ichi Ohmichi14b0ae12017-01-27 17:18:52 -080058 @decorators.idempotent_id('fd032140-714c-42e4-a8fd-adcd8df06be6')
nithya-ganesane6a36c82013-02-15 14:38:27 +000059 def test_rescue_unrescue_instance(self):
zhufl735e1692020-08-13 16:46:50 +080060 """Test rescue/unrescue server"""
zhufl0c042a52017-05-10 16:24:00 +080061 password = data_utils.rand_password()
62 server = self.create_test_server(adminPass=password,
63 wait_until='ACTIVE')
64 self.servers_client.rescue_server(server['id'], adminPass=password)
65 waiters.wait_for_server_status(self.servers_client, server['id'],
Ken'ichi Ohmichi0eb153c2015-07-13 02:18:25 +000066 'RESCUE')
zhufl0c042a52017-05-10 16:24:00 +080067 self.servers_client.unrescue_server(server['id'])
68 waiters.wait_for_server_status(self.servers_client, server['id'],
Ken'ichi Ohmichi0eb153c2015-07-13 02:18:25 +000069 'ACTIVE')
nithya-ganesane6a36c82013-02-15 14:38:27 +000070
zhufl3cf7aa22018-08-02 10:38:31 +080071
72class ServerRescueTestJSONUnderV235(ServerRescueTestBase):
zhufl735e1692020-08-13 16:46:50 +080073 """Test server rescue with compute microversion less than 2.36"""
zhufl3cf7aa22018-08-02 10:38:31 +080074
75 max_microversion = '2.35'
76
77 # TODO(zhufl): After 2.35 we should switch to neutron client to create
78 # floating ip, but that will need admin credential, so the testcases will
79 # have to be added in somewhere in admin directory.
80
Ken'ichi Ohmichi14b0ae12017-01-27 17:18:52 -080081 @decorators.idempotent_id('4842e0cf-e87d-4d9d-b61f-f4791da3cacc')
zhufl6b7040a2017-01-18 16:38:34 +080082 @testtools.skipUnless(CONF.network.public_network_id,
83 'The public_network_id option must be specified.')
Matthew Treinish3312de32017-05-19 12:08:17 -040084 @testtools.skipUnless(CONF.network_feature_enabled.floating_ips,
85 "Floating ips are not available")
nithya-ganesane6a36c82013-02-15 14:38:27 +000086 def test_rescued_vm_associate_dissociate_floating_ip(self):
zhufl735e1692020-08-13 16:46:50 +080087 """Test associate/dissociate floating ip for rescued server"""
zhufl0c042a52017-05-10 16:24:00 +080088 floating_ip_body = self.floating_ips_client.create_floating_ip(
89 pool=CONF.network.floating_network_name)['floating_ip']
90 self.addCleanup(self.floating_ips_client.delete_floating_ip,
91 floating_ip_body['id'])
92
93 self.floating_ips_client.associate_floating_ip_to_server(
94 str(floating_ip_body['ip']).strip(), self.rescued_server_id)
nithya-ganesane6a36c82013-02-15 14:38:27 +000095
Attila Fazekasf7f34f92013-08-01 17:01:44 +020096 # Disassociation of floating IP that was associated in this method
zhufl0c042a52017-05-10 16:24:00 +080097 self.floating_ips_client.disassociate_floating_ip_from_server(
98 str(floating_ip_body['ip']).strip(), self.rescued_server_id)
nithya-ganesane6a36c82013-02-15 14:38:27 +000099
Ken'ichi Ohmichi14b0ae12017-01-27 17:18:52 -0800100 @decorators.idempotent_id('affca41f-7195-492d-8065-e09eee245404')
nithya-ganesane6a36c82013-02-15 14:38:27 +0000101 def test_rescued_vm_add_remove_security_group(self):
zhufl735e1692020-08-13 16:46:50 +0800102 """Test add/remove security group to for rescued server"""
Attila Fazekasf7f34f92013-08-01 17:01:44 +0200103 # Add Security group
zhufl0c042a52017-05-10 16:24:00 +0800104 sg = self.create_security_group()
105 self.servers_client.add_security_group(self.rescued_server_id,
106 name=sg['name'])
nithya-ganesane6a36c82013-02-15 14:38:27 +0000107
Attila Fazekasf7f34f92013-08-01 17:01:44 +0200108 # Delete Security group
zhufl0c042a52017-05-10 16:24:00 +0800109 self.servers_client.remove_security_group(self.rescued_server_id,
110 name=sg['name'])
Lee Yarwoodc0ad55c2019-12-06 13:39:19 +0000111
112
Lee Yarwood2ad7ca42020-01-07 13:06:25 +0000113class BaseServerStableDeviceRescueTest(base.BaseV2ComputeTest):
Ghanshyam Mann2c22e282020-04-21 21:37:54 -0500114 create_default_network = True
Lee Yarwoodc0ad55c2019-12-06 13:39:19 +0000115
116 @classmethod
zhufl40e5eaa2020-05-21 12:54:16 +0800117 def skip_checks(cls):
118 super(BaseServerStableDeviceRescueTest, cls).skip_checks()
Lee Yarwoodc0ad55c2019-12-06 13:39:19 +0000119 if not CONF.compute_feature_enabled.rescue:
120 msg = "Server rescue not available."
zhufl40e5eaa2020-05-21 12:54:16 +0800121 raise cls.skipException(msg)
Lee Yarwoodc0ad55c2019-12-06 13:39:19 +0000122 if not CONF.compute_feature_enabled.stable_rescue:
123 msg = "Stable rescue not available."
zhufl40e5eaa2020-05-21 12:54:16 +0800124 raise cls.skipException(msg)
Lee Yarwoodc0ad55c2019-12-06 13:39:19 +0000125
126 def _create_server_and_rescue_image(self, hw_rescue_device=None,
Lee Yarwood2ad7ca42020-01-07 13:06:25 +0000127 hw_rescue_bus=None,
128 block_device_mapping_v2=None):
Lee Yarwood2fd745f2020-05-05 11:24:56 +0100129
130 server_id = self.create_test_server(
131 wait_until='ACTIVE')['id']
132 image_id = self.create_image_from_server(
133 server_id, wait_until='ACTIVE')['id']
134
Lee Yarwood2ad7ca42020-01-07 13:06:25 +0000135 if block_device_mapping_v2:
136 server_id = self.create_test_server(
137 wait_until='ACTIVE',
138 block_device_mapping_v2=block_device_mapping_v2)['id']
Lee Yarwood2ad7ca42020-01-07 13:06:25 +0000139
Lee Yarwoodc0ad55c2019-12-06 13:39:19 +0000140 if hw_rescue_bus:
141 self.images_client.update_image(
142 image_id, [dict(add='/hw_rescue_bus',
143 value=hw_rescue_bus)])
144 if hw_rescue_device:
145 self.images_client.update_image(
146 image_id, [dict(add='/hw_rescue_device',
147 value=hw_rescue_device)])
148 return server_id, image_id
149
150 def _test_stable_device_rescue(self, server_id, rescue_image_id):
151 self.servers_client.rescue_server(
152 server_id, rescue_image_ref=rescue_image_id)
153 waiters.wait_for_server_status(
154 self.servers_client, server_id, 'RESCUE')
155 self.servers_client.unrescue_server(server_id)
156 waiters.wait_for_server_status(
157 self.servers_client, server_id, 'ACTIVE')
158
Lee Yarwood2ad7ca42020-01-07 13:06:25 +0000159
160class ServerStableDeviceRescueTest(BaseServerStableDeviceRescueTest):
zhufl735e1692020-08-13 16:46:50 +0800161 """Test rescuing server specifying type of device for the rescue disk"""
Lee Yarwood2ad7ca42020-01-07 13:06:25 +0000162
Lee Yarwoodc0ad55c2019-12-06 13:39:19 +0000163 @decorators.idempotent_id('947004c3-e8ef-47d9-9f00-97b74f9eaf96')
164 def test_stable_device_rescue_cdrom_ide(self):
zhufl735e1692020-08-13 16:46:50 +0800165 """Test rescuing server with cdrom and ide as the rescue disk"""
Lee Yarwoodc0ad55c2019-12-06 13:39:19 +0000166 server_id, rescue_image_id = self._create_server_and_rescue_image(
167 hw_rescue_device='cdrom', hw_rescue_bus='ide')
168 self._test_stable_device_rescue(server_id, rescue_image_id)
169
170 @decorators.idempotent_id('16865750-1417-4854-bcf7-496e6753c01e')
171 def test_stable_device_rescue_disk_virtio(self):
zhufl735e1692020-08-13 16:46:50 +0800172 """Test rescuing server with disk and virtio 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='disk', hw_rescue_bus='virtio')
175 self._test_stable_device_rescue(server_id, rescue_image_id)
176
177 @decorators.idempotent_id('12340157-6306-4745-bdda-cfa019908b48')
178 def test_stable_device_rescue_disk_scsi(self):
zhufl735e1692020-08-13 16:46:50 +0800179 """Test rescuing server with disk and scsi as the rescue disk"""
Lee Yarwoodc0ad55c2019-12-06 13:39:19 +0000180 server_id, rescue_image_id = self._create_server_and_rescue_image(
181 hw_rescue_device='disk', hw_rescue_bus='scsi')
182 self._test_stable_device_rescue(server_id, rescue_image_id)
183
184 @decorators.idempotent_id('647d04cf-ad35-4956-89ab-b05c5c16f30c')
185 def test_stable_device_rescue_disk_usb(self):
zhufl735e1692020-08-13 16:46:50 +0800186 """Test rescuing server with disk and usb as the rescue disk"""
Lee Yarwoodc0ad55c2019-12-06 13:39:19 +0000187 server_id, rescue_image_id = self._create_server_and_rescue_image(
188 hw_rescue_device='disk', hw_rescue_bus='usb')
189 self._test_stable_device_rescue(server_id, rescue_image_id)
190
191 @decorators.idempotent_id('a3772b42-00bf-4310-a90b-1cc6fd3e7eab')
192 def test_stable_device_rescue_disk_virtio_with_volume_attached(self):
zhufl735e1692020-08-13 16:46:50 +0800193 """Test rescuing server with volume attached
194
195 Attach a volume to the server and then rescue the server with disk
196 and virtio as the rescue disk.
197 """
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='virtio')
200 server = self.servers_client.show_server(server_id)['server']
201 volume = self.create_volume()
202 self.attach_volume(server, volume)
203 waiters.wait_for_volume_resource_status(self.volumes_client,
204 volume['id'], 'in-use')
205 self._test_stable_device_rescue(server_id, rescue_image_id)
Lee Yarwood2ad7ca42020-01-07 13:06:25 +0000206
207
208class ServerBootFromVolumeStableRescueTest(BaseServerStableDeviceRescueTest):
zhufl735e1692020-08-13 16:46:50 +0800209 """Test rescuing server specifying type of device for the rescue disk
210
211 Test rescuing server specifying type of device for the rescue disk with
212 compute microversion greater than 2.86.
213 """
Lee Yarwood2ad7ca42020-01-07 13:06:25 +0000214
215 min_microversion = '2.87'
216
Lee Yarwood2fd745f2020-05-05 11:24:56 +0100217 @decorators.attr(type='slow')
Lee Yarwood2ad7ca42020-01-07 13:06:25 +0000218 @decorators.idempotent_id('48f123cb-922a-4065-8db6-b9a9074a556b')
219 def test_stable_device_rescue_bfv_blank_volume(self):
zhufl735e1692020-08-13 16:46:50 +0800220 """Test rescuing server with blank volume as block_device_mapping_v2
221
222 Create a server with block_device_mapping_v2 with blank volume,
223 then rescue the server with disk and virtio as the rescue disk.
224 """
Lee Yarwood2ad7ca42020-01-07 13:06:25 +0000225 block_device_mapping_v2 = [{
226 "boot_index": "0",
227 "source_type": "blank",
Martin Kopecabda8712020-05-11 15:31:13 +0000228 "volume_size": CONF.volume.volume_size,
Lee Yarwood2ad7ca42020-01-07 13:06:25 +0000229 "destination_type": "volume"}]
230 server_id, rescue_image_id = self._create_server_and_rescue_image(
231 hw_rescue_device='disk', hw_rescue_bus='virtio',
232 block_device_mapping_v2=block_device_mapping_v2)
233 self._test_stable_device_rescue(server_id, rescue_image_id)
234
Lee Yarwood2fd745f2020-05-05 11:24:56 +0100235 @decorators.attr(type='slow')
Lee Yarwood2ad7ca42020-01-07 13:06:25 +0000236 @decorators.idempotent_id('e4636333-c928-40fc-98b7-70a23eef4224')
237 def test_stable_device_rescue_bfv_image_volume(self):
zhufl735e1692020-08-13 16:46:50 +0800238 """Test rescuing server with blank volume as block_device_mapping_v2
239
240 Create a server with block_device_mapping_v2 with image volume,
241 then rescue the server with disk and virtio as the rescue disk.
242 """
Lee Yarwood2ad7ca42020-01-07 13:06:25 +0000243 block_device_mapping_v2 = [{
244 "boot_index": "0",
245 "source_type": "image",
Martin Kopecabda8712020-05-11 15:31:13 +0000246 "volume_size": CONF.volume.volume_size,
Lee Yarwood2ad7ca42020-01-07 13:06:25 +0000247 "uuid": CONF.compute.image_ref,
248 "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)