blob: 124749405b48bc03b689a3dbed609743d39b768f [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):
56
Ken'ichi Ohmichi14b0ae12017-01-27 17:18:52 -080057 @decorators.idempotent_id('fd032140-714c-42e4-a8fd-adcd8df06be6')
nithya-ganesane6a36c82013-02-15 14:38:27 +000058 def test_rescue_unrescue_instance(self):
zhufl0c042a52017-05-10 16:24:00 +080059 password = data_utils.rand_password()
60 server = self.create_test_server(adminPass=password,
61 wait_until='ACTIVE')
62 self.servers_client.rescue_server(server['id'], adminPass=password)
63 waiters.wait_for_server_status(self.servers_client, server['id'],
Ken'ichi Ohmichi0eb153c2015-07-13 02:18:25 +000064 'RESCUE')
zhufl0c042a52017-05-10 16:24:00 +080065 self.servers_client.unrescue_server(server['id'])
66 waiters.wait_for_server_status(self.servers_client, server['id'],
Ken'ichi Ohmichi0eb153c2015-07-13 02:18:25 +000067 'ACTIVE')
nithya-ganesane6a36c82013-02-15 14:38:27 +000068
zhufl3cf7aa22018-08-02 10:38:31 +080069
70class ServerRescueTestJSONUnderV235(ServerRescueTestBase):
71
72 max_microversion = '2.35'
73
74 # TODO(zhufl): After 2.35 we should switch to neutron client to create
75 # floating ip, but that will need admin credential, so the testcases will
76 # have to be added in somewhere in admin directory.
77
Ken'ichi Ohmichi14b0ae12017-01-27 17:18:52 -080078 @decorators.idempotent_id('4842e0cf-e87d-4d9d-b61f-f4791da3cacc')
zhufl6b7040a2017-01-18 16:38:34 +080079 @testtools.skipUnless(CONF.network.public_network_id,
80 'The public_network_id option must be specified.')
Matthew Treinish3312de32017-05-19 12:08:17 -040081 @testtools.skipUnless(CONF.network_feature_enabled.floating_ips,
82 "Floating ips are not available")
nithya-ganesane6a36c82013-02-15 14:38:27 +000083 def test_rescued_vm_associate_dissociate_floating_ip(self):
Attila Fazekasf7f34f92013-08-01 17:01:44 +020084 # Association of floating IP to a rescued vm
zhufl0c042a52017-05-10 16:24:00 +080085 floating_ip_body = self.floating_ips_client.create_floating_ip(
86 pool=CONF.network.floating_network_name)['floating_ip']
87 self.addCleanup(self.floating_ips_client.delete_floating_ip,
88 floating_ip_body['id'])
89
90 self.floating_ips_client.associate_floating_ip_to_server(
91 str(floating_ip_body['ip']).strip(), self.rescued_server_id)
nithya-ganesane6a36c82013-02-15 14:38:27 +000092
Attila Fazekasf7f34f92013-08-01 17:01:44 +020093 # Disassociation of floating IP that was associated in this method
zhufl0c042a52017-05-10 16:24:00 +080094 self.floating_ips_client.disassociate_floating_ip_from_server(
95 str(floating_ip_body['ip']).strip(), self.rescued_server_id)
nithya-ganesane6a36c82013-02-15 14:38:27 +000096
Ken'ichi Ohmichi14b0ae12017-01-27 17:18:52 -080097 @decorators.idempotent_id('affca41f-7195-492d-8065-e09eee245404')
nithya-ganesane6a36c82013-02-15 14:38:27 +000098 def test_rescued_vm_add_remove_security_group(self):
Attila Fazekasf7f34f92013-08-01 17:01:44 +020099 # Add Security group
zhufl0c042a52017-05-10 16:24:00 +0800100 sg = self.create_security_group()
101 self.servers_client.add_security_group(self.rescued_server_id,
102 name=sg['name'])
nithya-ganesane6a36c82013-02-15 14:38:27 +0000103
Attila Fazekasf7f34f92013-08-01 17:01:44 +0200104 # Delete Security group
zhufl0c042a52017-05-10 16:24:00 +0800105 self.servers_client.remove_security_group(self.rescued_server_id,
106 name=sg['name'])
Lee Yarwoodc0ad55c2019-12-06 13:39:19 +0000107
108
Lee Yarwood2ad7ca42020-01-07 13:06:25 +0000109class BaseServerStableDeviceRescueTest(base.BaseV2ComputeTest):
Ghanshyam Mann2c22e282020-04-21 21:37:54 -0500110 create_default_network = True
Lee Yarwoodc0ad55c2019-12-06 13:39:19 +0000111
112 @classmethod
zhufl40e5eaa2020-05-21 12:54:16 +0800113 def skip_checks(cls):
114 super(BaseServerStableDeviceRescueTest, cls).skip_checks()
Lee Yarwoodc0ad55c2019-12-06 13:39:19 +0000115 if not CONF.compute_feature_enabled.rescue:
116 msg = "Server rescue not available."
zhufl40e5eaa2020-05-21 12:54:16 +0800117 raise cls.skipException(msg)
Lee Yarwoodc0ad55c2019-12-06 13:39:19 +0000118 if not CONF.compute_feature_enabled.stable_rescue:
119 msg = "Stable rescue not available."
zhufl40e5eaa2020-05-21 12:54:16 +0800120 raise cls.skipException(msg)
Lee Yarwoodc0ad55c2019-12-06 13:39:19 +0000121
122 def _create_server_and_rescue_image(self, hw_rescue_device=None,
Lee Yarwood2ad7ca42020-01-07 13:06:25 +0000123 hw_rescue_bus=None,
124 block_device_mapping_v2=None):
Lee Yarwood2fd745f2020-05-05 11:24:56 +0100125
126 server_id = self.create_test_server(
127 wait_until='ACTIVE')['id']
128 image_id = self.create_image_from_server(
129 server_id, wait_until='ACTIVE')['id']
130
Lee Yarwood2ad7ca42020-01-07 13:06:25 +0000131 if block_device_mapping_v2:
132 server_id = self.create_test_server(
133 wait_until='ACTIVE',
134 block_device_mapping_v2=block_device_mapping_v2)['id']
Lee Yarwood2ad7ca42020-01-07 13:06:25 +0000135
Lee Yarwoodc0ad55c2019-12-06 13:39:19 +0000136 if hw_rescue_bus:
137 self.images_client.update_image(
138 image_id, [dict(add='/hw_rescue_bus',
139 value=hw_rescue_bus)])
140 if hw_rescue_device:
141 self.images_client.update_image(
142 image_id, [dict(add='/hw_rescue_device',
143 value=hw_rescue_device)])
144 return server_id, image_id
145
146 def _test_stable_device_rescue(self, server_id, rescue_image_id):
147 self.servers_client.rescue_server(
148 server_id, rescue_image_ref=rescue_image_id)
149 waiters.wait_for_server_status(
150 self.servers_client, server_id, 'RESCUE')
151 self.servers_client.unrescue_server(server_id)
152 waiters.wait_for_server_status(
153 self.servers_client, server_id, 'ACTIVE')
154
Lee Yarwood2ad7ca42020-01-07 13:06:25 +0000155
156class ServerStableDeviceRescueTest(BaseServerStableDeviceRescueTest):
157
Lee Yarwoodc0ad55c2019-12-06 13:39:19 +0000158 @decorators.idempotent_id('947004c3-e8ef-47d9-9f00-97b74f9eaf96')
159 def test_stable_device_rescue_cdrom_ide(self):
160 server_id, rescue_image_id = self._create_server_and_rescue_image(
161 hw_rescue_device='cdrom', hw_rescue_bus='ide')
162 self._test_stable_device_rescue(server_id, rescue_image_id)
163
164 @decorators.idempotent_id('16865750-1417-4854-bcf7-496e6753c01e')
165 def test_stable_device_rescue_disk_virtio(self):
166 server_id, rescue_image_id = self._create_server_and_rescue_image(
167 hw_rescue_device='disk', hw_rescue_bus='virtio')
168 self._test_stable_device_rescue(server_id, rescue_image_id)
169
170 @decorators.idempotent_id('12340157-6306-4745-bdda-cfa019908b48')
171 def test_stable_device_rescue_disk_scsi(self):
172 server_id, rescue_image_id = self._create_server_and_rescue_image(
173 hw_rescue_device='disk', hw_rescue_bus='scsi')
174 self._test_stable_device_rescue(server_id, rescue_image_id)
175
176 @decorators.idempotent_id('647d04cf-ad35-4956-89ab-b05c5c16f30c')
177 def test_stable_device_rescue_disk_usb(self):
178 server_id, rescue_image_id = self._create_server_and_rescue_image(
179 hw_rescue_device='disk', hw_rescue_bus='usb')
180 self._test_stable_device_rescue(server_id, rescue_image_id)
181
182 @decorators.idempotent_id('a3772b42-00bf-4310-a90b-1cc6fd3e7eab')
183 def test_stable_device_rescue_disk_virtio_with_volume_attached(self):
184 server_id, rescue_image_id = self._create_server_and_rescue_image(
185 hw_rescue_device='disk', hw_rescue_bus='virtio')
186 server = self.servers_client.show_server(server_id)['server']
187 volume = self.create_volume()
188 self.attach_volume(server, volume)
189 waiters.wait_for_volume_resource_status(self.volumes_client,
190 volume['id'], 'in-use')
191 self._test_stable_device_rescue(server_id, rescue_image_id)
Lee Yarwood2ad7ca42020-01-07 13:06:25 +0000192
193
194class ServerBootFromVolumeStableRescueTest(BaseServerStableDeviceRescueTest):
195
196 min_microversion = '2.87'
197
Lee Yarwood2fd745f2020-05-05 11:24:56 +0100198 @decorators.attr(type='slow')
Lee Yarwood2ad7ca42020-01-07 13:06:25 +0000199 @decorators.idempotent_id('48f123cb-922a-4065-8db6-b9a9074a556b')
200 def test_stable_device_rescue_bfv_blank_volume(self):
201 block_device_mapping_v2 = [{
202 "boot_index": "0",
203 "source_type": "blank",
Martin Kopecabda8712020-05-11 15:31:13 +0000204 "volume_size": CONF.volume.volume_size,
Lee Yarwood2ad7ca42020-01-07 13:06:25 +0000205 "destination_type": "volume"}]
206 server_id, rescue_image_id = self._create_server_and_rescue_image(
207 hw_rescue_device='disk', hw_rescue_bus='virtio',
208 block_device_mapping_v2=block_device_mapping_v2)
209 self._test_stable_device_rescue(server_id, rescue_image_id)
210
Lee Yarwood2fd745f2020-05-05 11:24:56 +0100211 @decorators.attr(type='slow')
Lee Yarwood2ad7ca42020-01-07 13:06:25 +0000212 @decorators.idempotent_id('e4636333-c928-40fc-98b7-70a23eef4224')
213 def test_stable_device_rescue_bfv_image_volume(self):
214 block_device_mapping_v2 = [{
215 "boot_index": "0",
216 "source_type": "image",
Martin Kopecabda8712020-05-11 15:31:13 +0000217 "volume_size": CONF.volume.volume_size,
Lee Yarwood2ad7ca42020-01-07 13:06:25 +0000218 "uuid": CONF.compute.image_ref,
219 "destination_type": "volume"}]
220 server_id, rescue_image_id = self._create_server_and_rescue_image(
221 hw_rescue_device='disk', hw_rescue_bus='virtio',
222 block_device_mapping_v2=block_device_mapping_v2)
223 self._test_stable_device_rescue(server_id, rescue_image_id)