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 |
melanie witt | ca30e8c | 2018-08-07 21:39:52 +0000 | [diff] [blame] | 14 | from oslo_serialization import jsonutils |
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 | |
fujioka yuuichi | 636f8db | 2013-08-09 12:05:24 +0900 | [diff] [blame] | 34 | def _create_volume_from_image(self): |
Matthew Treinish | 6c07229 | 2014-01-29 19:15:52 +0000 | [diff] [blame] | 35 | img_uuid = CONF.compute.image_ref |
zhufl | c6ce539 | 2016-08-17 14:34:37 +0800 | [diff] [blame] | 36 | vol_name = data_utils.rand_name( |
| 37 | self.__class__.__name__ + '-volume-origin') |
fujioka yuuichi | 636f8db | 2013-08-09 12:05:24 +0900 | [diff] [blame] | 38 | return self.create_volume(name=vol_name, imageRef=img_uuid) |
| 39 | |
lkuchlan | 8789c55 | 2017-01-08 11:40:27 +0200 | [diff] [blame] | 40 | def _get_bdm(self, source_id, source_type, delete_on_termination=False): |
Sean Dague | d571e03 | 2017-02-27 12:27:10 -0500 | [diff] [blame] | 41 | bd_map_v2 = [{ |
| 42 | 'uuid': source_id, |
| 43 | 'source_type': source_type, |
| 44 | 'destination_type': 'volume', |
| 45 | 'boot_index': 0, |
| 46 | 'delete_on_termination': delete_on_termination}] |
| 47 | return {'block_device_mapping_v2': bd_map_v2} |
Andrey Pavlov | c8bd4b1 | 2015-08-17 10:20:17 +0300 | [diff] [blame] | 48 | |
lkuchlan | 8789c55 | 2017-01-08 11:40:27 +0200 | [diff] [blame] | 49 | def _boot_instance_from_resource(self, source_id, |
| 50 | source_type, |
| 51 | keypair=None, |
| 52 | security_group=None, |
melanie witt | ca30e8c | 2018-08-07 21:39:52 +0000 | [diff] [blame] | 53 | delete_on_termination=False, |
| 54 | name=None): |
Andrey Pavlov | c8bd4b1 | 2015-08-17 10:20:17 +0300 | [diff] [blame] | 55 | create_kwargs = dict() |
| 56 | if keypair: |
| 57 | create_kwargs['key_name'] = keypair['name'] |
| 58 | if security_group: |
| 59 | create_kwargs['security_groups'] = [ |
| 60 | {'name': security_group['name']}] |
| 61 | create_kwargs.update(self._get_bdm( |
lkuchlan | 8789c55 | 2017-01-08 11:40:27 +0200 | [diff] [blame] | 62 | source_id, |
| 63 | source_type, |
| 64 | delete_on_termination=delete_on_termination)) |
melanie witt | ca30e8c | 2018-08-07 21:39:52 +0000 | [diff] [blame] | 65 | if name: |
| 66 | create_kwargs['name'] = name |
lkuchlan | 8789c55 | 2017-01-08 11:40:27 +0200 | [diff] [blame] | 67 | |
zhufl | 13c9c89 | 2017-02-10 12:04:07 +0800 | [diff] [blame] | 68 | return self.create_server(image_id='', **create_kwargs) |
fujioka yuuichi | 636f8db | 2013-08-09 12:05:24 +0900 | [diff] [blame] | 69 | |
fujioka yuuichi | 636f8db | 2013-08-09 12:05:24 +0900 | [diff] [blame] | 70 | def _delete_server(self, server): |
Joseph Lanoux | eef192f | 2014-08-01 14:32:53 +0000 | [diff] [blame] | 71 | self.servers_client.delete_server(server['id']) |
Ken'ichi Ohmichi | e91a0c6 | 2015-08-13 02:09:16 +0000 | [diff] [blame] | 72 | waiters.wait_for_server_termination(self.servers_client, server['id']) |
fujioka yuuichi | 636f8db | 2013-08-09 12:05:24 +0900 | [diff] [blame] | 73 | |
melanie witt | ca30e8c | 2018-08-07 21:39:52 +0000 | [diff] [blame] | 74 | def _delete_snapshot(self, snapshot_id): |
| 75 | self.snapshots_client.delete_snapshot(snapshot_id) |
| 76 | self.snapshots_client.wait_for_resource_deletion(snapshot_id) |
| 77 | |
Ken'ichi Ohmichi | c85a951 | 2017-01-27 18:34:24 -0800 | [diff] [blame] | 78 | @decorators.idempotent_id('557cd2c2-4eb8-4dce-98be-f86765ff311b') |
msidana | e1f990b | 2018-06-05 12:10:24 +0530 | [diff] [blame] | 79 | # Note: This test is being skipped based on 'public_network_id'. |
| 80 | # It is being used in create_floating_ip() method which gets called |
| 81 | # from get_server_ip() method |
zhufl | 6b7040a | 2017-01-18 16:38:34 +0800 | [diff] [blame] | 82 | @testtools.skipUnless(CONF.network.public_network_id, |
| 83 | 'The public_network_id option must be specified.') |
zhufl | 36214c5 | 2018-03-02 15:49:41 +0800 | [diff] [blame] | 84 | @testtools.skipUnless(CONF.volume_feature_enabled.snapshot, |
| 85 | 'Cinder volume snapshots are disabled') |
Andrea Frittoli | cd36841 | 2017-08-14 21:37:56 +0100 | [diff] [blame] | 86 | @utils.services('compute', 'volume', 'image') |
fujioka yuuichi | 636f8db | 2013-08-09 12:05:24 +0900 | [diff] [blame] | 87 | def test_volume_boot_pattern(self): |
lkuchlan | 2041cdd | 2016-08-15 13:50:43 +0300 | [diff] [blame] | 88 | |
| 89 | """This test case attempts to reproduce the following steps: |
| 90 | |
| 91 | * Create in Cinder some bootable volume importing a Glance image |
| 92 | * Boot an instance from the bootable volume |
| 93 | * Write content to the volume |
| 94 | * Delete an instance and Boot a new instance from the volume |
| 95 | * Check written content in the instance |
| 96 | * Create a volume snapshot while the instance is running |
| 97 | * Boot an additional instance from the new snapshot based volume |
| 98 | * Check written content in the instance booted from snapshot |
| 99 | """ |
| 100 | |
Sean Dague | 52abbd9 | 2016-03-01 09:38:09 -0500 | [diff] [blame] | 101 | LOG.info("Creating keypair and security group") |
fujioka yuuichi | 636f8db | 2013-08-09 12:05:24 +0900 | [diff] [blame] | 102 | keypair = self.create_keypair() |
Yaroslav Lobankov | 0089af5 | 2015-07-02 19:14:40 +0300 | [diff] [blame] | 103 | security_group = self._create_security_group() |
fujioka yuuichi | 636f8db | 2013-08-09 12:05:24 +0900 | [diff] [blame] | 104 | |
| 105 | # create an instance from volume |
Sean Dague | 52abbd9 | 2016-03-01 09:38:09 -0500 | [diff] [blame] | 106 | LOG.info("Booting instance 1 from volume") |
fujioka yuuichi | 636f8db | 2013-08-09 12:05:24 +0900 | [diff] [blame] | 107 | volume_origin = self._create_volume_from_image() |
lkuchlan | 8789c55 | 2017-01-08 11:40:27 +0200 | [diff] [blame] | 108 | instance_1st = self._boot_instance_from_resource( |
| 109 | source_id=volume_origin['id'], |
| 110 | source_type='volume', |
| 111 | keypair=keypair, |
| 112 | security_group=security_group) |
Jordan Pittier | 525ec71 | 2016-12-07 17:51:26 +0100 | [diff] [blame] | 113 | LOG.info("Booted first instance: %s", instance_1st) |
fujioka yuuichi | 636f8db | 2013-08-09 12:05:24 +0900 | [diff] [blame] | 114 | |
| 115 | # write content to volume on instance |
Jordan Pittier | 525ec71 | 2016-12-07 17:51:26 +0100 | [diff] [blame] | 116 | LOG.info("Setting timestamp in instance %s", instance_1st) |
Sean Dague | 20e9861 | 2016-01-06 14:33:28 -0500 | [diff] [blame] | 117 | ip_instance_1st = self.get_server_ip(instance_1st) |
Alexander Gubanov | 59cc303 | 2015-11-05 11:58:03 +0200 | [diff] [blame] | 118 | timestamp = self.create_timestamp(ip_instance_1st, |
Slawek Kaplonski | 79d8b0f | 2018-07-30 22:43:41 +0200 | [diff] [blame] | 119 | private_key=keypair['private_key'], |
| 120 | server=instance_1st) |
fujioka yuuichi | 636f8db | 2013-08-09 12:05:24 +0900 | [diff] [blame] | 121 | |
| 122 | # delete instance |
Jordan Pittier | 525ec71 | 2016-12-07 17:51:26 +0100 | [diff] [blame] | 123 | LOG.info("Deleting first instance: %s", instance_1st) |
fujioka yuuichi | 636f8db | 2013-08-09 12:05:24 +0900 | [diff] [blame] | 124 | self._delete_server(instance_1st) |
| 125 | |
| 126 | # create a 2nd instance from volume |
lkuchlan | 8789c55 | 2017-01-08 11:40:27 +0200 | [diff] [blame] | 127 | instance_2nd = self._boot_instance_from_resource( |
| 128 | source_id=volume_origin['id'], |
| 129 | source_type='volume', |
| 130 | keypair=keypair, |
| 131 | security_group=security_group) |
Jordan Pittier | 525ec71 | 2016-12-07 17:51:26 +0100 | [diff] [blame] | 132 | LOG.info("Booted second instance %s", instance_2nd) |
fujioka yuuichi | 636f8db | 2013-08-09 12:05:24 +0900 | [diff] [blame] | 133 | |
| 134 | # check the content of written file |
Jordan Pittier | 525ec71 | 2016-12-07 17:51:26 +0100 | [diff] [blame] | 135 | LOG.info("Getting timestamp in instance %s", instance_2nd) |
Sean Dague | 20e9861 | 2016-01-06 14:33:28 -0500 | [diff] [blame] | 136 | ip_instance_2nd = self.get_server_ip(instance_2nd) |
Alexander Gubanov | 59cc303 | 2015-11-05 11:58:03 +0200 | [diff] [blame] | 137 | timestamp2 = self.get_timestamp(ip_instance_2nd, |
Slawek Kaplonski | 79d8b0f | 2018-07-30 22:43:41 +0200 | [diff] [blame] | 138 | private_key=keypair['private_key'], |
| 139 | server=instance_2nd) |
Alexander Gubanov | 59cc303 | 2015-11-05 11:58:03 +0200 | [diff] [blame] | 140 | self.assertEqual(timestamp, timestamp2) |
fujioka yuuichi | 636f8db | 2013-08-09 12:05:24 +0900 | [diff] [blame] | 141 | |
| 142 | # snapshot a volume |
Jordan Pittier | 525ec71 | 2016-12-07 17:51:26 +0100 | [diff] [blame] | 143 | LOG.info("Creating snapshot from volume: %s", volume_origin['id']) |
lkuchlan | 73ed1f3 | 2017-07-06 16:22:12 +0300 | [diff] [blame] | 144 | snapshot = self.create_volume_snapshot(volume_origin['id'], force=True) |
fujioka yuuichi | 636f8db | 2013-08-09 12:05:24 +0900 | [diff] [blame] | 145 | |
| 146 | # create a 3rd instance from snapshot |
Jordan Pittier | 525ec71 | 2016-12-07 17:51:26 +0100 | [diff] [blame] | 147 | LOG.info("Creating third instance from snapshot: %s", snapshot['id']) |
Nuno Santos | da89962 | 2016-11-17 12:32:53 -0500 | [diff] [blame] | 148 | volume = self.create_volume(snapshot_id=snapshot['id'], |
| 149 | size=snapshot['size']) |
| 150 | LOG.info("Booting third instance from snapshot") |
Alexander Gubanov | c8829f8 | 2015-11-12 10:35:13 +0200 | [diff] [blame] | 151 | server_from_snapshot = ( |
lkuchlan | 8789c55 | 2017-01-08 11:40:27 +0200 | [diff] [blame] | 152 | self._boot_instance_from_resource(source_id=volume['id'], |
| 153 | source_type='volume', |
| 154 | keypair=keypair, |
| 155 | security_group=security_group)) |
Nuno Santos | da89962 | 2016-11-17 12:32:53 -0500 | [diff] [blame] | 156 | LOG.info("Booted third instance %s", server_from_snapshot) |
fujioka yuuichi | 636f8db | 2013-08-09 12:05:24 +0900 | [diff] [blame] | 157 | |
| 158 | # check the content of written file |
Jordan Pittier | 525ec71 | 2016-12-07 17:51:26 +0100 | [diff] [blame] | 159 | LOG.info("Logging into third instance to get timestamp: %s", |
Sean Dague | 52abbd9 | 2016-03-01 09:38:09 -0500 | [diff] [blame] | 160 | server_from_snapshot) |
Sean Dague | 20e9861 | 2016-01-06 14:33:28 -0500 | [diff] [blame] | 161 | server_from_snapshot_ip = self.get_server_ip(server_from_snapshot) |
Alexander Gubanov | c8829f8 | 2015-11-12 10:35:13 +0200 | [diff] [blame] | 162 | timestamp3 = self.get_timestamp(server_from_snapshot_ip, |
Slawek Kaplonski | 79d8b0f | 2018-07-30 22:43:41 +0200 | [diff] [blame] | 163 | private_key=keypair['private_key'], |
| 164 | server=server_from_snapshot) |
Alexander Gubanov | 59cc303 | 2015-11-05 11:58:03 +0200 | [diff] [blame] | 165 | self.assertEqual(timestamp, timestamp3) |
fujioka yuuichi | 636f8db | 2013-08-09 12:05:24 +0900 | [diff] [blame] | 166 | |
Ken'ichi Ohmichi | c85a951 | 2017-01-27 18:34:24 -0800 | [diff] [blame] | 167 | @decorators.idempotent_id('05795fb2-b2a7-4c9f-8fac-ff25aedb1489') |
Jordan Pittier | 3b46d27 | 2017-04-12 16:17:28 +0200 | [diff] [blame] | 168 | @decorators.attr(type='slow') |
zhufl | 36214c5 | 2018-03-02 15:49:41 +0800 | [diff] [blame] | 169 | @testtools.skipUnless(CONF.volume_feature_enabled.snapshot, |
| 170 | 'Cinder volume snapshots are disabled') |
Andrea Frittoli | cd36841 | 2017-08-14 21:37:56 +0100 | [diff] [blame] | 171 | @utils.services('compute', 'image', 'volume') |
lkuchlan | 8789c55 | 2017-01-08 11:40:27 +0200 | [diff] [blame] | 172 | def test_create_server_from_volume_snapshot(self): |
| 173 | # Create a volume from an image |
| 174 | boot_volume = self._create_volume_from_image() |
| 175 | |
| 176 | # Create a snapshot |
lkuchlan | 73ed1f3 | 2017-07-06 16:22:12 +0300 | [diff] [blame] | 177 | boot_snapshot = self.create_volume_snapshot(boot_volume['id']) |
lkuchlan | 8789c55 | 2017-01-08 11:40:27 +0200 | [diff] [blame] | 178 | |
| 179 | # Create a server from a volume snapshot |
| 180 | server = self._boot_instance_from_resource( |
| 181 | source_id=boot_snapshot['id'], |
| 182 | source_type='snapshot', |
| 183 | delete_on_termination=True) |
| 184 | |
| 185 | server_info = self.servers_client.show_server(server['id'])['server'] |
| 186 | |
| 187 | # The created volume when creating a server from a snapshot |
| 188 | created_volume = server_info['os-extended-volumes:volumes_attached'] |
| 189 | |
lkuchlan | 9e22b85 | 2017-02-05 15:38:29 +0200 | [diff] [blame] | 190 | self.assertNotEmpty(created_volume, "No volume attachment found.") |
| 191 | |
lkuchlan | 8789c55 | 2017-01-08 11:40:27 +0200 | [diff] [blame] | 192 | created_volume_info = self.volumes_client.show_volume( |
| 193 | created_volume[0]['id'])['volume'] |
| 194 | |
| 195 | # Verify the server was created from the snapshot |
| 196 | self.assertEqual( |
| 197 | boot_volume['volume_image_metadata']['image_id'], |
| 198 | created_volume_info['volume_image_metadata']['image_id']) |
| 199 | self.assertEqual(boot_snapshot['id'], |
| 200 | created_volume_info['snapshot_id']) |
| 201 | self.assertEqual(server['id'], |
| 202 | created_volume_info['attachments'][0]['server_id']) |
| 203 | self.assertEqual(created_volume[0]['id'], |
| 204 | created_volume_info['attachments'][0]['volume_id']) |
| 205 | |
Ken'ichi Ohmichi | c85a951 | 2017-01-27 18:34:24 -0800 | [diff] [blame] | 206 | @decorators.idempotent_id('36c34c67-7b54-4b59-b188-02a2f458a63b') |
zhufl | 36214c5 | 2018-03-02 15:49:41 +0800 | [diff] [blame] | 207 | @testtools.skipUnless(CONF.volume_feature_enabled.snapshot, |
| 208 | 'Cinder volume snapshots are disabled') |
Andrea Frittoli | cd36841 | 2017-08-14 21:37:56 +0100 | [diff] [blame] | 209 | @utils.services('compute', 'volume', 'image') |
Matt Riedemann | 2db6c27 | 2018-03-22 18:57:19 -0400 | [diff] [blame] | 210 | def test_image_defined_boot_from_volume(self): |
| 211 | # create an instance from image-backed volume |
Andrey Pavlov | c8bd4b1 | 2015-08-17 10:20:17 +0300 | [diff] [blame] | 212 | volume_origin = self._create_volume_from_image() |
melanie witt | ca30e8c | 2018-08-07 21:39:52 +0000 | [diff] [blame] | 213 | name = data_utils.rand_name(self.__class__.__name__ + |
| 214 | '-volume-backed-server') |
| 215 | instance1 = self._boot_instance_from_resource( |
lkuchlan | 8789c55 | 2017-01-08 11:40:27 +0200 | [diff] [blame] | 216 | source_id=volume_origin['id'], |
| 217 | source_type='volume', |
melanie witt | ca30e8c | 2018-08-07 21:39:52 +0000 | [diff] [blame] | 218 | delete_on_termination=True, |
| 219 | name=name) |
Matt Riedemann | 2db6c27 | 2018-03-22 18:57:19 -0400 | [diff] [blame] | 220 | # Create a snapshot image from the volume-backed server. |
| 221 | # The compute service will have the block service create a snapshot of |
| 222 | # the root volume and store its metadata in the image. |
melanie witt | ca30e8c | 2018-08-07 21:39:52 +0000 | [diff] [blame] | 223 | image = self.create_server_snapshot(instance1) |
Andrey Pavlov | c8bd4b1 | 2015-08-17 10:20:17 +0300 | [diff] [blame] | 224 | |
Matt Riedemann | 2db6c27 | 2018-03-22 18:57:19 -0400 | [diff] [blame] | 225 | # Create a server from the image snapshot which has an |
| 226 | # "image-defined block device mapping (BDM)" in it, i.e. the metadata |
| 227 | # about the volume snapshot. The compute service will use this to |
| 228 | # create a volume from the volume snapshot and use that as the root |
| 229 | # disk for the server. |
melanie witt | ca30e8c | 2018-08-07 21:39:52 +0000 | [diff] [blame] | 230 | name = data_utils.rand_name(self.__class__.__name__ + |
| 231 | '-image-snapshot-server') |
| 232 | instance2 = self.create_server(image_id=image['id'], name=name) |
lianghao | 2e0ee04 | 2017-10-26 19:38:28 +0800 | [diff] [blame] | 233 | |
Matt Riedemann | 2db6c27 | 2018-03-22 18:57:19 -0400 | [diff] [blame] | 234 | # Verify the server was created from the image-defined BDM. |
melanie witt | ca30e8c | 2018-08-07 21:39:52 +0000 | [diff] [blame] | 235 | volume_attachments = instance2['os-extended-volumes:volumes_attached'] |
Matt Riedemann | 2db6c27 | 2018-03-22 18:57:19 -0400 | [diff] [blame] | 236 | self.assertEqual(1, len(volume_attachments), |
| 237 | "No volume attachment found.") |
| 238 | created_volume = self.volumes_client.show_volume( |
| 239 | volume_attachments[0]['id'])['volume'] |
| 240 | # Assert that the volume service also shows the server attachment. |
| 241 | self.assertEqual(1, len(created_volume['attachments']), |
| 242 | "No server attachment found for volume: %s" % |
| 243 | created_volume) |
melanie witt | ca30e8c | 2018-08-07 21:39:52 +0000 | [diff] [blame] | 244 | self.assertEqual(instance2['id'], |
Matt Riedemann | 2db6c27 | 2018-03-22 18:57:19 -0400 | [diff] [blame] | 245 | created_volume['attachments'][0]['server_id']) |
| 246 | self.assertEqual(volume_attachments[0]['id'], |
| 247 | created_volume['attachments'][0]['volume_id']) |
lianghao | 2e0ee04 | 2017-10-26 19:38:28 +0800 | [diff] [blame] | 248 | self.assertEqual( |
| 249 | volume_origin['volume_image_metadata']['image_id'], |
Matt Riedemann | 2db6c27 | 2018-03-22 18:57:19 -0400 | [diff] [blame] | 250 | created_volume['volume_image_metadata']['image_id']) |
Andrey Pavlov | c8bd4b1 | 2015-08-17 10:20:17 +0300 | [diff] [blame] | 251 | |
Matt Riedemann | 2db6c27 | 2018-03-22 18:57:19 -0400 | [diff] [blame] | 252 | # Delete the second server which should also delete the second volume |
| 253 | # created from the volume snapshot. |
melanie witt | ca30e8c | 2018-08-07 21:39:52 +0000 | [diff] [blame] | 254 | self._delete_server(instance2) |
lkuchlan | 3023e75 | 2017-06-08 12:53:13 +0300 | [diff] [blame] | 255 | |
melanie witt | c50cc24 | 2018-05-01 22:00:39 +0000 | [diff] [blame] | 256 | # Assert that the underlying volume is gone. |
| 257 | self.volumes_client.wait_for_resource_deletion(created_volume['id']) |
| 258 | |
melanie witt | ca30e8c | 2018-08-07 21:39:52 +0000 | [diff] [blame] | 259 | # Delete the volume snapshot. We must do this before deleting the first |
| 260 | # server created in this test because the snapshot depends on the first |
| 261 | # instance's underlying volume (volume_origin). |
| 262 | # In glance v2, the image properties are flattened and in glance v1, |
| 263 | # the image properties are under the 'properties' key. |
| 264 | bdms = image.get('block_device_mapping') |
| 265 | if not bdms: |
| 266 | bdms = image['properties']['block_device_mapping'] |
| 267 | bdms = jsonutils.loads(bdms) |
| 268 | snapshot_id = bdms[0]['snapshot_id'] |
| 269 | self._delete_snapshot(snapshot_id) |
| 270 | |
| 271 | # Now, delete the first server which will also delete the first |
| 272 | # image-backed volume. |
| 273 | self._delete_server(instance1) |
| 274 | |
| 275 | # Assert that the underlying volume is gone. |
| 276 | self.volumes_client.wait_for_resource_deletion(volume_origin['id']) |
| 277 | |
lkuchlan | 3023e75 | 2017-06-08 12:53:13 +0300 | [diff] [blame] | 278 | @decorators.idempotent_id('cb78919a-e553-4bab-b73b-10cf4d2eb125') |
Attila Fazekas | 1c39a2f | 2017-07-18 19:39:06 +0200 | [diff] [blame] | 279 | @testtools.skipUnless(CONF.compute_feature_enabled.attach_encrypted_volume, |
| 280 | 'Encrypted volume attach is not supported') |
Andrea Frittoli | cd36841 | 2017-08-14 21:37:56 +0100 | [diff] [blame] | 281 | @utils.services('compute', 'volume') |
lkuchlan | 3023e75 | 2017-06-08 12:53:13 +0300 | [diff] [blame] | 282 | def test_boot_server_from_encrypted_volume_luks(self): |
| 283 | # Create an encrypted volume |
| 284 | volume = self.create_encrypted_volume('nova.volume.encryptors.' |
| 285 | 'luks.LuksEncryptor', |
| 286 | volume_type='luks') |
| 287 | |
| 288 | self.volumes_client.set_bootable_volume(volume['id'], bootable=True) |
| 289 | |
| 290 | # Boot a server from the encrypted volume |
| 291 | server = self._boot_instance_from_resource( |
| 292 | source_id=volume['id'], |
| 293 | source_type='volume', |
| 294 | delete_on_termination=False) |
| 295 | |
| 296 | server_info = self.servers_client.show_server(server['id'])['server'] |
| 297 | created_volume = server_info['os-extended-volumes:volumes_attached'] |
| 298 | self.assertEqual(volume['id'], created_volume[0]['id']) |