fujioka yuuichi | 636f8db | 2013-08-09 12:05:24 +0900 | [diff] [blame] | 1 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 2 | # not use this file except in compliance with the License. You may obtain |
| 3 | # a copy of the License at |
| 4 | # |
| 5 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 6 | # |
| 7 | # Unless required by applicable law or agreed to in writing, software |
| 8 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 9 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 10 | # License for the specific language governing permissions and limitations |
| 11 | # under the License. |
| 12 | |
Sean Dague | 52abbd9 | 2016-03-01 09:38:09 -0500 | [diff] [blame] | 13 | from oslo_log import log as logging |
zhulingjie | 92b87a5 | 2019-02-21 01:05:54 +0800 | [diff] [blame] | 14 | from oslo_serialization import jsonutils as json |
zhufl | 6b7040a | 2017-01-18 16:38:34 +0800 | [diff] [blame] | 15 | import testtools |
Sean Dague | 52abbd9 | 2016-03-01 09:38:09 -0500 | [diff] [blame] | 16 | |
Andrea Frittoli | cd36841 | 2017-08-14 21:37:56 +0100 | [diff] [blame] | 17 | from tempest.common import utils |
Ken'ichi Ohmichi | 0eb153c | 2015-07-13 02:18:25 +0000 | [diff] [blame] | 18 | from tempest.common import waiters |
Matthew Treinish | 6c07229 | 2014-01-29 19:15:52 +0000 | [diff] [blame] | 19 | from tempest import config |
Ken'ichi Ohmichi | be4fb50 | 2017-03-10 10:04:48 -0800 | [diff] [blame] | 20 | from tempest.lib.common.utils import data_utils |
Ken'ichi Ohmichi | c85a951 | 2017-01-27 18:34:24 -0800 | [diff] [blame] | 21 | from tempest.lib import decorators |
fujioka yuuichi | 636f8db | 2013-08-09 12:05:24 +0900 | [diff] [blame] | 22 | from tempest.scenario import manager |
| 23 | |
Matthew Treinish | 6c07229 | 2014-01-29 19:15:52 +0000 | [diff] [blame] | 24 | CONF = config.CONF |
Sean Dague | 52abbd9 | 2016-03-01 09:38:09 -0500 | [diff] [blame] | 25 | LOG = logging.getLogger(__name__) |
fujioka yuuichi | 636f8db | 2013-08-09 12:05:24 +0900 | [diff] [blame] | 26 | |
Nachi Ueno | 95b4128 | 2014-01-15 06:54:21 -0800 | [diff] [blame] | 27 | |
lkuchlan | 3023e75 | 2017-06-08 12:53:13 +0300 | [diff] [blame] | 28 | class TestVolumeBootPattern(manager.EncryptionScenarioTest): |
fujioka yuuichi | 636f8db | 2013-08-09 12:05:24 +0900 | [diff] [blame] | 29 | |
Sean Dague | 02620fd | 2016-03-02 15:52:51 -0500 | [diff] [blame] | 30 | # Boot from volume scenario is quite slow, and needs extra |
| 31 | # breathing room to get through deletes in the time allotted. |
| 32 | TIMEOUT_SCALING_FACTOR = 2 |
| 33 | |
Ghanshyam Mann | 2803b57 | 2023-08-04 12:11:59 -0700 | [diff] [blame] | 34 | @classmethod |
| 35 | def skip_checks(cls): |
| 36 | super(TestVolumeBootPattern, cls).skip_checks() |
| 37 | if not CONF.service_available.cinder: |
| 38 | raise cls.skipException("Cinder is not available") |
| 39 | |
fujioka yuuichi | 636f8db | 2013-08-09 12:05:24 +0900 | [diff] [blame] | 40 | def _delete_server(self, server): |
Joseph Lanoux | eef192f | 2014-08-01 14:32:53 +0000 | [diff] [blame] | 41 | self.servers_client.delete_server(server['id']) |
Ken'ichi Ohmichi | e91a0c6 | 2015-08-13 02:09:16 +0000 | [diff] [blame] | 42 | waiters.wait_for_server_termination(self.servers_client, server['id']) |
fujioka yuuichi | 636f8db | 2013-08-09 12:05:24 +0900 | [diff] [blame] | 43 | |
melanie witt | ca30e8c | 2018-08-07 21:39:52 +0000 | [diff] [blame] | 44 | def _delete_snapshot(self, snapshot_id): |
| 45 | self.snapshots_client.delete_snapshot(snapshot_id) |
| 46 | self.snapshots_client.wait_for_resource_deletion(snapshot_id) |
| 47 | |
Ken'ichi Ohmichi | c85a951 | 2017-01-27 18:34:24 -0800 | [diff] [blame] | 48 | @decorators.idempotent_id('557cd2c2-4eb8-4dce-98be-f86765ff311b') |
Matt Riedemann | 4b8a7b8 | 2019-02-14 14:07:11 -0500 | [diff] [blame] | 49 | @decorators.attr(type='slow') |
msidana | e1f990b | 2018-06-05 12:10:24 +0530 | [diff] [blame] | 50 | # Note: This test is being skipped based on 'public_network_id'. |
| 51 | # It is being used in create_floating_ip() method which gets called |
| 52 | # from get_server_ip() method |
zhufl | 6b7040a | 2017-01-18 16:38:34 +0800 | [diff] [blame] | 53 | @testtools.skipUnless(CONF.network.public_network_id, |
| 54 | 'The public_network_id option must be specified.') |
zhufl | 36214c5 | 2018-03-02 15:49:41 +0800 | [diff] [blame] | 55 | @testtools.skipUnless(CONF.volume_feature_enabled.snapshot, |
| 56 | 'Cinder volume snapshots are disabled') |
Andrea Frittoli | cd36841 | 2017-08-14 21:37:56 +0100 | [diff] [blame] | 57 | @utils.services('compute', 'volume', 'image') |
fujioka yuuichi | 636f8db | 2013-08-09 12:05:24 +0900 | [diff] [blame] | 58 | def test_volume_boot_pattern(self): |
lkuchlan | 2041cdd | 2016-08-15 13:50:43 +0300 | [diff] [blame] | 59 | """This test case attempts to reproduce the following steps: |
| 60 | |
| 61 | * Create in Cinder some bootable volume importing a Glance image |
| 62 | * Boot an instance from the bootable volume |
| 63 | * Write content to the volume |
| 64 | * Delete an instance and Boot a new instance from the volume |
| 65 | * Check written content in the instance |
| 66 | * Create a volume snapshot while the instance is running |
| 67 | * Boot an additional instance from the new snapshot based volume |
| 68 | * Check written content in the instance booted from snapshot |
| 69 | """ |
| 70 | |
Sean Dague | 52abbd9 | 2016-03-01 09:38:09 -0500 | [diff] [blame] | 71 | LOG.info("Creating keypair and security group") |
fujioka yuuichi | 636f8db | 2013-08-09 12:05:24 +0900 | [diff] [blame] | 72 | keypair = self.create_keypair() |
Soniya Vyas | 582c170 | 2021-02-22 18:26:17 +0530 | [diff] [blame] | 73 | security_group = self.create_security_group() |
fujioka yuuichi | 636f8db | 2013-08-09 12:05:24 +0900 | [diff] [blame] | 74 | |
| 75 | # create an instance from volume |
Sean Dague | 52abbd9 | 2016-03-01 09:38:09 -0500 | [diff] [blame] | 76 | LOG.info("Booting instance 1 from volume") |
Rajat Dhasmana | a8bfa17 | 2020-01-14 17:34:44 +0000 | [diff] [blame] | 77 | volume_origin = self.create_volume_from_image() |
| 78 | instance_1st = self.boot_instance_from_resource( |
lkuchlan | 8789c55 | 2017-01-08 11:40:27 +0200 | [diff] [blame] | 79 | source_id=volume_origin['id'], |
| 80 | source_type='volume', |
| 81 | keypair=keypair, |
| 82 | security_group=security_group) |
Jordan Pittier | 525ec71 | 2016-12-07 17:51:26 +0100 | [diff] [blame] | 83 | LOG.info("Booted first instance: %s", instance_1st) |
fujioka yuuichi | 636f8db | 2013-08-09 12:05:24 +0900 | [diff] [blame] | 84 | |
| 85 | # write content to volume on instance |
Jordan Pittier | 525ec71 | 2016-12-07 17:51:26 +0100 | [diff] [blame] | 86 | LOG.info("Setting timestamp in instance %s", instance_1st) |
Sean Dague | 20e9861 | 2016-01-06 14:33:28 -0500 | [diff] [blame] | 87 | ip_instance_1st = self.get_server_ip(instance_1st) |
Alexander Gubanov | 59cc303 | 2015-11-05 11:58:03 +0200 | [diff] [blame] | 88 | timestamp = self.create_timestamp(ip_instance_1st, |
Slawek Kaplonski | 79d8b0f | 2018-07-30 22:43:41 +0200 | [diff] [blame] | 89 | private_key=keypair['private_key'], |
| 90 | server=instance_1st) |
fujioka yuuichi | 636f8db | 2013-08-09 12:05:24 +0900 | [diff] [blame] | 91 | |
| 92 | # delete instance |
Jordan Pittier | 525ec71 | 2016-12-07 17:51:26 +0100 | [diff] [blame] | 93 | LOG.info("Deleting first instance: %s", instance_1st) |
fujioka yuuichi | 636f8db | 2013-08-09 12:05:24 +0900 | [diff] [blame] | 94 | self._delete_server(instance_1st) |
| 95 | |
| 96 | # create a 2nd instance from volume |
Rajat Dhasmana | a8bfa17 | 2020-01-14 17:34:44 +0000 | [diff] [blame] | 97 | instance_2nd = self.boot_instance_from_resource( |
lkuchlan | 8789c55 | 2017-01-08 11:40:27 +0200 | [diff] [blame] | 98 | source_id=volume_origin['id'], |
| 99 | source_type='volume', |
| 100 | keypair=keypair, |
| 101 | security_group=security_group) |
Jordan Pittier | 525ec71 | 2016-12-07 17:51:26 +0100 | [diff] [blame] | 102 | LOG.info("Booted second instance %s", instance_2nd) |
fujioka yuuichi | 636f8db | 2013-08-09 12:05:24 +0900 | [diff] [blame] | 103 | |
| 104 | # check the content of written file |
Jordan Pittier | 525ec71 | 2016-12-07 17:51:26 +0100 | [diff] [blame] | 105 | LOG.info("Getting timestamp in instance %s", instance_2nd) |
Sean Dague | 20e9861 | 2016-01-06 14:33:28 -0500 | [diff] [blame] | 106 | ip_instance_2nd = self.get_server_ip(instance_2nd) |
Alexander Gubanov | 59cc303 | 2015-11-05 11:58:03 +0200 | [diff] [blame] | 107 | timestamp2 = self.get_timestamp(ip_instance_2nd, |
Slawek Kaplonski | 79d8b0f | 2018-07-30 22:43:41 +0200 | [diff] [blame] | 108 | private_key=keypair['private_key'], |
| 109 | server=instance_2nd) |
Alexander Gubanov | 59cc303 | 2015-11-05 11:58:03 +0200 | [diff] [blame] | 110 | self.assertEqual(timestamp, timestamp2) |
fujioka yuuichi | 636f8db | 2013-08-09 12:05:24 +0900 | [diff] [blame] | 111 | |
| 112 | # snapshot a volume |
Jordan Pittier | 525ec71 | 2016-12-07 17:51:26 +0100 | [diff] [blame] | 113 | LOG.info("Creating snapshot from volume: %s", volume_origin['id']) |
lkuchlan | 73ed1f3 | 2017-07-06 16:22:12 +0300 | [diff] [blame] | 114 | snapshot = self.create_volume_snapshot(volume_origin['id'], force=True) |
fujioka yuuichi | 636f8db | 2013-08-09 12:05:24 +0900 | [diff] [blame] | 115 | |
| 116 | # create a 3rd instance from snapshot |
Jordan Pittier | 525ec71 | 2016-12-07 17:51:26 +0100 | [diff] [blame] | 117 | LOG.info("Creating third instance from snapshot: %s", snapshot['id']) |
Nuno Santos | da89962 | 2016-11-17 12:32:53 -0500 | [diff] [blame] | 118 | volume = self.create_volume(snapshot_id=snapshot['id'], |
| 119 | size=snapshot['size']) |
| 120 | LOG.info("Booting third instance from snapshot") |
Alexander Gubanov | c8829f8 | 2015-11-12 10:35:13 +0200 | [diff] [blame] | 121 | server_from_snapshot = ( |
Rajat Dhasmana | a8bfa17 | 2020-01-14 17:34:44 +0000 | [diff] [blame] | 122 | self.boot_instance_from_resource(source_id=volume['id'], |
| 123 | source_type='volume', |
| 124 | keypair=keypair, |
| 125 | security_group=security_group)) |
Nuno Santos | da89962 | 2016-11-17 12:32:53 -0500 | [diff] [blame] | 126 | LOG.info("Booted third instance %s", server_from_snapshot) |
fujioka yuuichi | 636f8db | 2013-08-09 12:05:24 +0900 | [diff] [blame] | 127 | |
| 128 | # check the content of written file |
Jordan Pittier | 525ec71 | 2016-12-07 17:51:26 +0100 | [diff] [blame] | 129 | LOG.info("Logging into third instance to get timestamp: %s", |
Sean Dague | 52abbd9 | 2016-03-01 09:38:09 -0500 | [diff] [blame] | 130 | server_from_snapshot) |
Sean Dague | 20e9861 | 2016-01-06 14:33:28 -0500 | [diff] [blame] | 131 | server_from_snapshot_ip = self.get_server_ip(server_from_snapshot) |
Alexander Gubanov | c8829f8 | 2015-11-12 10:35:13 +0200 | [diff] [blame] | 132 | timestamp3 = self.get_timestamp(server_from_snapshot_ip, |
Slawek Kaplonski | 79d8b0f | 2018-07-30 22:43:41 +0200 | [diff] [blame] | 133 | private_key=keypair['private_key'], |
| 134 | server=server_from_snapshot) |
Alexander Gubanov | 59cc303 | 2015-11-05 11:58:03 +0200 | [diff] [blame] | 135 | self.assertEqual(timestamp, timestamp3) |
fujioka yuuichi | 636f8db | 2013-08-09 12:05:24 +0900 | [diff] [blame] | 136 | |
Ken'ichi Ohmichi | c85a951 | 2017-01-27 18:34:24 -0800 | [diff] [blame] | 137 | @decorators.idempotent_id('05795fb2-b2a7-4c9f-8fac-ff25aedb1489') |
Jordan Pittier | 3b46d27 | 2017-04-12 16:17:28 +0200 | [diff] [blame] | 138 | @decorators.attr(type='slow') |
zhufl | 36214c5 | 2018-03-02 15:49:41 +0800 | [diff] [blame] | 139 | @testtools.skipUnless(CONF.volume_feature_enabled.snapshot, |
| 140 | 'Cinder volume snapshots are disabled') |
Andrea Frittoli | cd36841 | 2017-08-14 21:37:56 +0100 | [diff] [blame] | 141 | @utils.services('compute', 'image', 'volume') |
lkuchlan | 8789c55 | 2017-01-08 11:40:27 +0200 | [diff] [blame] | 142 | def test_create_server_from_volume_snapshot(self): |
| 143 | # Create a volume from an image |
Rajat Dhasmana | a8bfa17 | 2020-01-14 17:34:44 +0000 | [diff] [blame] | 144 | boot_volume = self.create_volume_from_image() |
lkuchlan | 8789c55 | 2017-01-08 11:40:27 +0200 | [diff] [blame] | 145 | |
| 146 | # Create a snapshot |
lkuchlan | 73ed1f3 | 2017-07-06 16:22:12 +0300 | [diff] [blame] | 147 | boot_snapshot = self.create_volume_snapshot(boot_volume['id']) |
lkuchlan | 8789c55 | 2017-01-08 11:40:27 +0200 | [diff] [blame] | 148 | |
| 149 | # Create a server from a volume snapshot |
Rajat Dhasmana | a8bfa17 | 2020-01-14 17:34:44 +0000 | [diff] [blame] | 150 | server = self.boot_instance_from_resource( |
lkuchlan | 8789c55 | 2017-01-08 11:40:27 +0200 | [diff] [blame] | 151 | source_id=boot_snapshot['id'], |
| 152 | source_type='snapshot', |
| 153 | delete_on_termination=True) |
| 154 | |
| 155 | server_info = self.servers_client.show_server(server['id'])['server'] |
| 156 | |
| 157 | # The created volume when creating a server from a snapshot |
| 158 | created_volume = server_info['os-extended-volumes:volumes_attached'] |
| 159 | |
lkuchlan | 9e22b85 | 2017-02-05 15:38:29 +0200 | [diff] [blame] | 160 | self.assertNotEmpty(created_volume, "No volume attachment found.") |
| 161 | |
lkuchlan | 8789c55 | 2017-01-08 11:40:27 +0200 | [diff] [blame] | 162 | created_volume_info = self.volumes_client.show_volume( |
| 163 | created_volume[0]['id'])['volume'] |
| 164 | |
| 165 | # Verify the server was created from the snapshot |
| 166 | self.assertEqual( |
| 167 | boot_volume['volume_image_metadata']['image_id'], |
| 168 | created_volume_info['volume_image_metadata']['image_id']) |
| 169 | self.assertEqual(boot_snapshot['id'], |
| 170 | created_volume_info['snapshot_id']) |
| 171 | self.assertEqual(server['id'], |
| 172 | created_volume_info['attachments'][0]['server_id']) |
| 173 | self.assertEqual(created_volume[0]['id'], |
| 174 | created_volume_info['attachments'][0]['volume_id']) |
| 175 | |
Giulio Fidente | 0d2b331 | 2020-03-04 10:15:03 +0100 | [diff] [blame] | 176 | # Delete the server and wait |
| 177 | self._delete_server(server) |
| 178 | |
| 179 | # Assert that the underlying volume is gone before class tearDown |
| 180 | # to prevent snapshot deletion from failing |
| 181 | self.volumes_client.wait_for_resource_deletion(created_volume[0]['id']) |
| 182 | |
Ken'ichi Ohmichi | c85a951 | 2017-01-27 18:34:24 -0800 | [diff] [blame] | 183 | @decorators.idempotent_id('36c34c67-7b54-4b59-b188-02a2f458a63b') |
zhufl | 36214c5 | 2018-03-02 15:49:41 +0800 | [diff] [blame] | 184 | @testtools.skipUnless(CONF.volume_feature_enabled.snapshot, |
| 185 | 'Cinder volume snapshots are disabled') |
Andrea Frittoli | cd36841 | 2017-08-14 21:37:56 +0100 | [diff] [blame] | 186 | @utils.services('compute', 'volume', 'image') |
Matt Riedemann | 2db6c27 | 2018-03-22 18:57:19 -0400 | [diff] [blame] | 187 | def test_image_defined_boot_from_volume(self): |
| 188 | # create an instance from image-backed volume |
Rajat Dhasmana | a8bfa17 | 2020-01-14 17:34:44 +0000 | [diff] [blame] | 189 | volume_origin = self.create_volume_from_image() |
melanie witt | ca30e8c | 2018-08-07 21:39:52 +0000 | [diff] [blame] | 190 | name = data_utils.rand_name(self.__class__.__name__ + |
| 191 | '-volume-backed-server') |
Rajat Dhasmana | a8bfa17 | 2020-01-14 17:34:44 +0000 | [diff] [blame] | 192 | instance1 = self.boot_instance_from_resource( |
lkuchlan | 8789c55 | 2017-01-08 11:40:27 +0200 | [diff] [blame] | 193 | source_id=volume_origin['id'], |
| 194 | source_type='volume', |
melanie witt | ca30e8c | 2018-08-07 21:39:52 +0000 | [diff] [blame] | 195 | delete_on_termination=True, |
Dan Smith | 49c2b3b | 2023-04-26 15:52:22 -0700 | [diff] [blame] | 196 | wait_until='SSHABLE', |
melanie witt | ca30e8c | 2018-08-07 21:39:52 +0000 | [diff] [blame] | 197 | name=name) |
Matt Riedemann | 2db6c27 | 2018-03-22 18:57:19 -0400 | [diff] [blame] | 198 | # Create a snapshot image from the volume-backed server. |
| 199 | # The compute service will have the block service create a snapshot of |
| 200 | # the root volume and store its metadata in the image. |
melanie witt | ca30e8c | 2018-08-07 21:39:52 +0000 | [diff] [blame] | 201 | image = self.create_server_snapshot(instance1) |
Andrey Pavlov | c8bd4b1 | 2015-08-17 10:20:17 +0300 | [diff] [blame] | 202 | |
Matt Riedemann | 2db6c27 | 2018-03-22 18:57:19 -0400 | [diff] [blame] | 203 | # Create a server from the image snapshot which has an |
| 204 | # "image-defined block device mapping (BDM)" in it, i.e. the metadata |
| 205 | # about the volume snapshot. The compute service will use this to |
| 206 | # create a volume from the volume snapshot and use that as the root |
| 207 | # disk for the server. |
melanie witt | ca30e8c | 2018-08-07 21:39:52 +0000 | [diff] [blame] | 208 | name = data_utils.rand_name(self.__class__.__name__ + |
| 209 | '-image-snapshot-server') |
Dan Smith | 49c2b3b | 2023-04-26 15:52:22 -0700 | [diff] [blame] | 210 | instance2 = self.create_server(image_id=image['id'], name=name, |
| 211 | wait_until='SSHABLE') |
lianghao | 2e0ee04 | 2017-10-26 19:38:28 +0800 | [diff] [blame] | 212 | |
Matt Riedemann | 2db6c27 | 2018-03-22 18:57:19 -0400 | [diff] [blame] | 213 | # Verify the server was created from the image-defined BDM. |
melanie witt | ca30e8c | 2018-08-07 21:39:52 +0000 | [diff] [blame] | 214 | volume_attachments = instance2['os-extended-volumes:volumes_attached'] |
Matt Riedemann | 2db6c27 | 2018-03-22 18:57:19 -0400 | [diff] [blame] | 215 | self.assertEqual(1, len(volume_attachments), |
| 216 | "No volume attachment found.") |
| 217 | created_volume = self.volumes_client.show_volume( |
| 218 | volume_attachments[0]['id'])['volume'] |
| 219 | # Assert that the volume service also shows the server attachment. |
| 220 | self.assertEqual(1, len(created_volume['attachments']), |
| 221 | "No server attachment found for volume: %s" % |
| 222 | created_volume) |
melanie witt | ca30e8c | 2018-08-07 21:39:52 +0000 | [diff] [blame] | 223 | self.assertEqual(instance2['id'], |
Matt Riedemann | 2db6c27 | 2018-03-22 18:57:19 -0400 | [diff] [blame] | 224 | created_volume['attachments'][0]['server_id']) |
| 225 | self.assertEqual(volume_attachments[0]['id'], |
| 226 | created_volume['attachments'][0]['volume_id']) |
lianghao | 2e0ee04 | 2017-10-26 19:38:28 +0800 | [diff] [blame] | 227 | self.assertEqual( |
| 228 | volume_origin['volume_image_metadata']['image_id'], |
Matt Riedemann | 2db6c27 | 2018-03-22 18:57:19 -0400 | [diff] [blame] | 229 | created_volume['volume_image_metadata']['image_id']) |
Andrey Pavlov | c8bd4b1 | 2015-08-17 10:20:17 +0300 | [diff] [blame] | 230 | |
Matt Riedemann | 2db6c27 | 2018-03-22 18:57:19 -0400 | [diff] [blame] | 231 | # Delete the second server which should also delete the second volume |
| 232 | # created from the volume snapshot. |
melanie witt | ca30e8c | 2018-08-07 21:39:52 +0000 | [diff] [blame] | 233 | self._delete_server(instance2) |
lkuchlan | 3023e75 | 2017-06-08 12:53:13 +0300 | [diff] [blame] | 234 | |
melanie witt | c50cc24 | 2018-05-01 22:00:39 +0000 | [diff] [blame] | 235 | # Assert that the underlying volume is gone. |
| 236 | self.volumes_client.wait_for_resource_deletion(created_volume['id']) |
| 237 | |
melanie witt | ca30e8c | 2018-08-07 21:39:52 +0000 | [diff] [blame] | 238 | # Delete the volume snapshot. We must do this before deleting the first |
| 239 | # server created in this test because the snapshot depends on the first |
| 240 | # instance's underlying volume (volume_origin). |
| 241 | # In glance v2, the image properties are flattened and in glance v1, |
| 242 | # the image properties are under the 'properties' key. |
| 243 | bdms = image.get('block_device_mapping') |
| 244 | if not bdms: |
| 245 | bdms = image['properties']['block_device_mapping'] |
zhulingjie | 92b87a5 | 2019-02-21 01:05:54 +0800 | [diff] [blame] | 246 | bdms = json.loads(bdms) |
melanie witt | ca30e8c | 2018-08-07 21:39:52 +0000 | [diff] [blame] | 247 | snapshot_id = bdms[0]['snapshot_id'] |
| 248 | self._delete_snapshot(snapshot_id) |
| 249 | |
| 250 | # Now, delete the first server which will also delete the first |
| 251 | # image-backed volume. |
| 252 | self._delete_server(instance1) |
| 253 | |
| 254 | # Assert that the underlying volume is gone. |
| 255 | self.volumes_client.wait_for_resource_deletion(volume_origin['id']) |
| 256 | |
Gorka Eguileor | 5e6fc7a | 2022-03-31 10:59:17 +0200 | [diff] [blame] | 257 | def _do_test_boot_server_from_encrypted_volume_luks(self, provider): |
lkuchlan | 3023e75 | 2017-06-08 12:53:13 +0300 | [diff] [blame] | 258 | # Create an encrypted volume |
Gorka Eguileor | 5e6fc7a | 2022-03-31 10:59:17 +0200 | [diff] [blame] | 259 | volume = self.create_encrypted_volume(provider, |
| 260 | volume_type=provider) |
lkuchlan | 3023e75 | 2017-06-08 12:53:13 +0300 | [diff] [blame] | 261 | |
| 262 | self.volumes_client.set_bootable_volume(volume['id'], bootable=True) |
| 263 | |
| 264 | # Boot a server from the encrypted volume |
Rajat Dhasmana | a8bfa17 | 2020-01-14 17:34:44 +0000 | [diff] [blame] | 265 | server = self.boot_instance_from_resource( |
lkuchlan | 3023e75 | 2017-06-08 12:53:13 +0300 | [diff] [blame] | 266 | source_id=volume['id'], |
| 267 | source_type='volume', |
| 268 | delete_on_termination=False) |
| 269 | |
| 270 | server_info = self.servers_client.show_server(server['id'])['server'] |
| 271 | created_volume = server_info['os-extended-volumes:volumes_attached'] |
| 272 | self.assertEqual(volume['id'], created_volume[0]['id']) |
Gorka Eguileor | 5e6fc7a | 2022-03-31 10:59:17 +0200 | [diff] [blame] | 273 | |
| 274 | @decorators.idempotent_id('cb78919a-e553-4bab-b73b-10cf4d2eb125') |
| 275 | @testtools.skipUnless(CONF.compute_feature_enabled.attach_encrypted_volume, |
| 276 | 'Encrypted volume attach is not supported') |
| 277 | @utils.services('compute', 'volume') |
| 278 | def test_boot_server_from_encrypted_volume_luks(self): |
| 279 | """LUKs v1 decrypts volume through libvirt.""" |
| 280 | self._do_test_boot_server_from_encrypted_volume_luks('luks') |
| 281 | |
| 282 | @decorators.idempotent_id('5ab6100f-1b31-4dd0-a774-68cfd837ef77') |
| 283 | @testtools.skipIf(CONF.volume.storage_protocol == 'ceph', |
| 284 | 'Ceph only supports LUKSv2 if doing host attach.') |
| 285 | @testtools.skipUnless(CONF.compute_feature_enabled.attach_encrypted_volume, |
| 286 | 'Encrypted volume attach is not supported') |
| 287 | @utils.services('compute', 'volume') |
| 288 | def test_boot_server_from_encrypted_volume_luksv2(self): |
| 289 | """LUKs v2 decrypts volume through os-brick.""" |
| 290 | self._do_test_boot_server_from_encrypted_volume_luks('luks2') |