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 |
zhufl | 6b7040a | 2017-01-18 16:38:34 +0800 | [diff] [blame] | 14 | import testtools |
Sean Dague | 52abbd9 | 2016-03-01 09:38:09 -0500 | [diff] [blame] | 15 | |
Fei Long Wang | d39431f | 2015-05-14 11:30:48 +1200 | [diff] [blame] | 16 | from tempest.common.utils import data_utils |
Ken'ichi Ohmichi | 0eb153c | 2015-07-13 02:18:25 +0000 | [diff] [blame] | 17 | from tempest.common import waiters |
Matthew Treinish | 6c07229 | 2014-01-29 19:15:52 +0000 | [diff] [blame] | 18 | from tempest import config |
Ken'ichi Ohmichi | c85a951 | 2017-01-27 18:34:24 -0800 | [diff] [blame] | 19 | from tempest.lib import decorators |
fujioka yuuichi | 636f8db | 2013-08-09 12:05:24 +0900 | [diff] [blame] | 20 | from tempest.scenario import manager |
Masayuki Igawa | 4ded9f0 | 2014-02-17 15:05:59 +0900 | [diff] [blame] | 21 | from tempest import test |
fujioka yuuichi | 636f8db | 2013-08-09 12:05:24 +0900 | [diff] [blame] | 22 | |
Matthew Treinish | 6c07229 | 2014-01-29 19:15:52 +0000 | [diff] [blame] | 23 | CONF = config.CONF |
Sean Dague | 52abbd9 | 2016-03-01 09:38:09 -0500 | [diff] [blame] | 24 | LOG = logging.getLogger(__name__) |
fujioka yuuichi | 636f8db | 2013-08-09 12:05:24 +0900 | [diff] [blame] | 25 | |
Nachi Ueno | 95b4128 | 2014-01-15 06:54:21 -0800 | [diff] [blame] | 26 | |
Joseph Lanoux | eef192f | 2014-08-01 14:32:53 +0000 | [diff] [blame] | 27 | class TestVolumeBootPattern(manager.ScenarioTest): |
fujioka yuuichi | 636f8db | 2013-08-09 12:05:24 +0900 | [diff] [blame] | 28 | |
Sean Dague | 02620fd | 2016-03-02 15:52:51 -0500 | [diff] [blame] | 29 | # Boot from volume scenario is quite slow, and needs extra |
| 30 | # breathing room to get through deletes in the time allotted. |
| 31 | TIMEOUT_SCALING_FACTOR = 2 |
| 32 | |
JordanP | bce5553 | 2014-03-19 12:10:32 +0100 | [diff] [blame] | 33 | @classmethod |
Emily Hugenbruch | 5e2d2a2 | 2015-02-25 21:35:45 +0000 | [diff] [blame] | 34 | def skip_checks(cls): |
| 35 | super(TestVolumeBootPattern, cls).skip_checks() |
JordanP | bce5553 | 2014-03-19 12:10:32 +0100 | [diff] [blame] | 36 | if not CONF.volume_feature_enabled.snapshot: |
| 37 | raise cls.skipException("Cinder volume snapshots are disabled") |
fujioka yuuichi | 636f8db | 2013-08-09 12:05:24 +0900 | [diff] [blame] | 38 | |
| 39 | def _create_volume_from_image(self): |
Matthew Treinish | 6c07229 | 2014-01-29 19:15:52 +0000 | [diff] [blame] | 40 | img_uuid = CONF.compute.image_ref |
zhufl | c6ce539 | 2016-08-17 14:34:37 +0800 | [diff] [blame] | 41 | vol_name = data_utils.rand_name( |
| 42 | self.__class__.__name__ + '-volume-origin') |
fujioka yuuichi | 636f8db | 2013-08-09 12:05:24 +0900 | [diff] [blame] | 43 | return self.create_volume(name=vol_name, imageRef=img_uuid) |
| 44 | |
lkuchlan | 8789c55 | 2017-01-08 11:40:27 +0200 | [diff] [blame] | 45 | def _get_bdm(self, source_id, source_type, delete_on_termination=False): |
fujioka yuuichi | 636f8db | 2013-08-09 12:05:24 +0900 | [diff] [blame] | 46 | # NOTE(gfidente): the syntax for block_device_mapping is |
| 47 | # dev_name=id:type:size:delete_on_terminate |
| 48 | # where type needs to be "snap" if the server is booted |
| 49 | # from a snapshot, size instead can be safely left empty |
lkuchlan | 8789c55 | 2017-01-08 11:40:27 +0200 | [diff] [blame] | 50 | |
Joseph Lanoux | eef192f | 2014-08-01 14:32:53 +0000 | [diff] [blame] | 51 | bd_map = [{ |
| 52 | 'device_name': 'vda', |
lkuchlan | 8789c55 | 2017-01-08 11:40:27 +0200 | [diff] [blame] | 53 | '{}_id'.format(source_type): source_id, |
Andrey Pavlov | c8bd4b1 | 2015-08-17 10:20:17 +0300 | [diff] [blame] | 54 | 'delete_on_termination': str(int(delete_on_termination))}] |
| 55 | return {'block_device_mapping': bd_map} |
| 56 | |
lkuchlan | 8789c55 | 2017-01-08 11:40:27 +0200 | [diff] [blame] | 57 | def _boot_instance_from_resource(self, source_id, |
| 58 | source_type, |
| 59 | keypair=None, |
| 60 | security_group=None, |
| 61 | delete_on_termination=False): |
Andrey Pavlov | c8bd4b1 | 2015-08-17 10:20:17 +0300 | [diff] [blame] | 62 | create_kwargs = dict() |
| 63 | if keypair: |
| 64 | create_kwargs['key_name'] = keypair['name'] |
| 65 | if security_group: |
| 66 | create_kwargs['security_groups'] = [ |
| 67 | {'name': security_group['name']}] |
| 68 | create_kwargs.update(self._get_bdm( |
lkuchlan | 8789c55 | 2017-01-08 11:40:27 +0200 | [diff] [blame] | 69 | source_id, |
| 70 | source_type, |
| 71 | delete_on_termination=delete_on_termination)) |
| 72 | |
zhufl | 13c9c89 | 2017-02-10 12:04:07 +0800 | [diff] [blame] | 73 | return self.create_server(image_id='', **create_kwargs) |
fujioka yuuichi | 636f8db | 2013-08-09 12:05:24 +0900 | [diff] [blame] | 74 | |
| 75 | def _create_snapshot_from_volume(self, vol_id): |
zhufl | c6ce539 | 2016-08-17 14:34:37 +0800 | [diff] [blame] | 76 | snap_name = data_utils.rand_name( |
| 77 | self.__class__.__name__ + '-snapshot') |
melanie witt | 8741222 | 2015-01-21 04:32:17 +0000 | [diff] [blame] | 78 | snap = self.snapshots_client.create_snapshot( |
Joseph Lanoux | eef192f | 2014-08-01 14:32:53 +0000 | [diff] [blame] | 79 | volume_id=vol_id, |
| 80 | force=True, |
John Warren | ff7faf6 | 2015-08-17 16:59:06 +0000 | [diff] [blame] | 81 | display_name=snap_name)['snapshot'] |
Yaroslav Lobankov | 46a78c3 | 2015-04-08 13:45:27 +0300 | [diff] [blame] | 82 | self.addCleanup( |
| 83 | self.snapshots_client.wait_for_resource_deletion, snap['id']) |
| 84 | self.addCleanup(self.snapshots_client.delete_snapshot, snap['id']) |
lkuchlan | 52d7b0d | 2016-11-07 20:53:19 +0200 | [diff] [blame^] | 85 | waiters.wait_for_volume_resource_status(self.snapshots_client, |
| 86 | snap['id'], 'available') |
Ivan Kolodyazhny | bcfc32e | 2015-08-06 13:31:36 +0300 | [diff] [blame] | 87 | |
| 88 | # NOTE(e0ne): Cinder API v2 uses name instead of display_name |
| 89 | if 'display_name' in snap: |
| 90 | self.assertEqual(snap_name, snap['display_name']) |
| 91 | else: |
| 92 | self.assertEqual(snap_name, snap['name']) |
| 93 | |
fujioka yuuichi | 636f8db | 2013-08-09 12:05:24 +0900 | [diff] [blame] | 94 | return snap |
| 95 | |
fujioka yuuichi | 636f8db | 2013-08-09 12:05:24 +0900 | [diff] [blame] | 96 | def _delete_server(self, server): |
Joseph Lanoux | eef192f | 2014-08-01 14:32:53 +0000 | [diff] [blame] | 97 | self.servers_client.delete_server(server['id']) |
Ken'ichi Ohmichi | e91a0c6 | 2015-08-13 02:09:16 +0000 | [diff] [blame] | 98 | waiters.wait_for_server_termination(self.servers_client, server['id']) |
fujioka yuuichi | 636f8db | 2013-08-09 12:05:24 +0900 | [diff] [blame] | 99 | |
Ken'ichi Ohmichi | c85a951 | 2017-01-27 18:34:24 -0800 | [diff] [blame] | 100 | @decorators.idempotent_id('557cd2c2-4eb8-4dce-98be-f86765ff311b') |
Sean Dague | 3c634d1 | 2015-04-27 12:09:19 -0400 | [diff] [blame] | 101 | @test.attr(type='smoke') |
zhufl | 6b7040a | 2017-01-18 16:38:34 +0800 | [diff] [blame] | 102 | @testtools.skipUnless(CONF.network.public_network_id, |
| 103 | 'The public_network_id option must be specified.') |
Masayuki Igawa | 4ded9f0 | 2014-02-17 15:05:59 +0900 | [diff] [blame] | 104 | @test.services('compute', 'volume', 'image') |
fujioka yuuichi | 636f8db | 2013-08-09 12:05:24 +0900 | [diff] [blame] | 105 | def test_volume_boot_pattern(self): |
lkuchlan | 2041cdd | 2016-08-15 13:50:43 +0300 | [diff] [blame] | 106 | |
| 107 | """This test case attempts to reproduce the following steps: |
| 108 | |
| 109 | * Create in Cinder some bootable volume importing a Glance image |
| 110 | * Boot an instance from the bootable volume |
| 111 | * Write content to the volume |
| 112 | * Delete an instance and Boot a new instance from the volume |
| 113 | * Check written content in the instance |
| 114 | * Create a volume snapshot while the instance is running |
| 115 | * Boot an additional instance from the new snapshot based volume |
| 116 | * Check written content in the instance booted from snapshot |
| 117 | """ |
| 118 | |
Sean Dague | 52abbd9 | 2016-03-01 09:38:09 -0500 | [diff] [blame] | 119 | LOG.info("Creating keypair and security group") |
fujioka yuuichi | 636f8db | 2013-08-09 12:05:24 +0900 | [diff] [blame] | 120 | keypair = self.create_keypair() |
Yaroslav Lobankov | 0089af5 | 2015-07-02 19:14:40 +0300 | [diff] [blame] | 121 | security_group = self._create_security_group() |
fujioka yuuichi | 636f8db | 2013-08-09 12:05:24 +0900 | [diff] [blame] | 122 | |
| 123 | # create an instance from volume |
Sean Dague | 52abbd9 | 2016-03-01 09:38:09 -0500 | [diff] [blame] | 124 | LOG.info("Booting instance 1 from volume") |
fujioka yuuichi | 636f8db | 2013-08-09 12:05:24 +0900 | [diff] [blame] | 125 | volume_origin = self._create_volume_from_image() |
lkuchlan | 8789c55 | 2017-01-08 11:40:27 +0200 | [diff] [blame] | 126 | instance_1st = self._boot_instance_from_resource( |
| 127 | source_id=volume_origin['id'], |
| 128 | source_type='volume', |
| 129 | keypair=keypair, |
| 130 | security_group=security_group) |
Jordan Pittier | 525ec71 | 2016-12-07 17:51:26 +0100 | [diff] [blame] | 131 | LOG.info("Booted first instance: %s", instance_1st) |
fujioka yuuichi | 636f8db | 2013-08-09 12:05:24 +0900 | [diff] [blame] | 132 | |
| 133 | # write content to volume on instance |
Jordan Pittier | 525ec71 | 2016-12-07 17:51:26 +0100 | [diff] [blame] | 134 | LOG.info("Setting timestamp in instance %s", instance_1st) |
Sean Dague | 20e9861 | 2016-01-06 14:33:28 -0500 | [diff] [blame] | 135 | ip_instance_1st = self.get_server_ip(instance_1st) |
Alexander Gubanov | 59cc303 | 2015-11-05 11:58:03 +0200 | [diff] [blame] | 136 | timestamp = self.create_timestamp(ip_instance_1st, |
| 137 | private_key=keypair['private_key']) |
fujioka yuuichi | 636f8db | 2013-08-09 12:05:24 +0900 | [diff] [blame] | 138 | |
| 139 | # delete instance |
Jordan Pittier | 525ec71 | 2016-12-07 17:51:26 +0100 | [diff] [blame] | 140 | LOG.info("Deleting first instance: %s", instance_1st) |
fujioka yuuichi | 636f8db | 2013-08-09 12:05:24 +0900 | [diff] [blame] | 141 | self._delete_server(instance_1st) |
| 142 | |
| 143 | # create a 2nd instance from volume |
lkuchlan | 8789c55 | 2017-01-08 11:40:27 +0200 | [diff] [blame] | 144 | instance_2nd = self._boot_instance_from_resource( |
| 145 | source_id=volume_origin['id'], |
| 146 | source_type='volume', |
| 147 | keypair=keypair, |
| 148 | security_group=security_group) |
Jordan Pittier | 525ec71 | 2016-12-07 17:51:26 +0100 | [diff] [blame] | 149 | LOG.info("Booted second instance %s", instance_2nd) |
fujioka yuuichi | 636f8db | 2013-08-09 12:05:24 +0900 | [diff] [blame] | 150 | |
| 151 | # check the content of written file |
Jordan Pittier | 525ec71 | 2016-12-07 17:51:26 +0100 | [diff] [blame] | 152 | LOG.info("Getting timestamp in instance %s", instance_2nd) |
Sean Dague | 20e9861 | 2016-01-06 14:33:28 -0500 | [diff] [blame] | 153 | ip_instance_2nd = self.get_server_ip(instance_2nd) |
Alexander Gubanov | 59cc303 | 2015-11-05 11:58:03 +0200 | [diff] [blame] | 154 | timestamp2 = self.get_timestamp(ip_instance_2nd, |
| 155 | private_key=keypair['private_key']) |
| 156 | self.assertEqual(timestamp, timestamp2) |
fujioka yuuichi | 636f8db | 2013-08-09 12:05:24 +0900 | [diff] [blame] | 157 | |
| 158 | # snapshot a volume |
Jordan Pittier | 525ec71 | 2016-12-07 17:51:26 +0100 | [diff] [blame] | 159 | LOG.info("Creating snapshot from volume: %s", volume_origin['id']) |
Joseph Lanoux | eef192f | 2014-08-01 14:32:53 +0000 | [diff] [blame] | 160 | snapshot = self._create_snapshot_from_volume(volume_origin['id']) |
fujioka yuuichi | 636f8db | 2013-08-09 12:05:24 +0900 | [diff] [blame] | 161 | |
| 162 | # create a 3rd instance from snapshot |
Jordan Pittier | 525ec71 | 2016-12-07 17:51:26 +0100 | [diff] [blame] | 163 | LOG.info("Creating third instance from snapshot: %s", snapshot['id']) |
Nuno Santos | da89962 | 2016-11-17 12:32:53 -0500 | [diff] [blame] | 164 | volume = self.create_volume(snapshot_id=snapshot['id'], |
| 165 | size=snapshot['size']) |
| 166 | LOG.info("Booting third instance from snapshot") |
Alexander Gubanov | c8829f8 | 2015-11-12 10:35:13 +0200 | [diff] [blame] | 167 | server_from_snapshot = ( |
lkuchlan | 8789c55 | 2017-01-08 11:40:27 +0200 | [diff] [blame] | 168 | self._boot_instance_from_resource(source_id=volume['id'], |
| 169 | source_type='volume', |
| 170 | keypair=keypair, |
| 171 | security_group=security_group)) |
Nuno Santos | da89962 | 2016-11-17 12:32:53 -0500 | [diff] [blame] | 172 | LOG.info("Booted third instance %s", server_from_snapshot) |
fujioka yuuichi | 636f8db | 2013-08-09 12:05:24 +0900 | [diff] [blame] | 173 | |
| 174 | # check the content of written file |
Jordan Pittier | 525ec71 | 2016-12-07 17:51:26 +0100 | [diff] [blame] | 175 | LOG.info("Logging into third instance to get timestamp: %s", |
Sean Dague | 52abbd9 | 2016-03-01 09:38:09 -0500 | [diff] [blame] | 176 | server_from_snapshot) |
Sean Dague | 20e9861 | 2016-01-06 14:33:28 -0500 | [diff] [blame] | 177 | server_from_snapshot_ip = self.get_server_ip(server_from_snapshot) |
Alexander Gubanov | c8829f8 | 2015-11-12 10:35:13 +0200 | [diff] [blame] | 178 | timestamp3 = self.get_timestamp(server_from_snapshot_ip, |
Alexander Gubanov | 59cc303 | 2015-11-05 11:58:03 +0200 | [diff] [blame] | 179 | private_key=keypair['private_key']) |
| 180 | self.assertEqual(timestamp, timestamp3) |
fujioka yuuichi | 636f8db | 2013-08-09 12:05:24 +0900 | [diff] [blame] | 181 | |
Ken'ichi Ohmichi | c85a951 | 2017-01-27 18:34:24 -0800 | [diff] [blame] | 182 | @decorators.idempotent_id('05795fb2-b2a7-4c9f-8fac-ff25aedb1489') |
lkuchlan | 8789c55 | 2017-01-08 11:40:27 +0200 | [diff] [blame] | 183 | @test.services('compute', 'image', 'volume') |
| 184 | def test_create_server_from_volume_snapshot(self): |
| 185 | # Create a volume from an image |
| 186 | boot_volume = self._create_volume_from_image() |
| 187 | |
| 188 | # Create a snapshot |
| 189 | boot_snapshot = self._create_snapshot_from_volume(boot_volume['id']) |
| 190 | |
| 191 | # Create a server from a volume snapshot |
| 192 | server = self._boot_instance_from_resource( |
| 193 | source_id=boot_snapshot['id'], |
| 194 | source_type='snapshot', |
| 195 | delete_on_termination=True) |
| 196 | |
| 197 | server_info = self.servers_client.show_server(server['id'])['server'] |
| 198 | |
| 199 | # The created volume when creating a server from a snapshot |
| 200 | created_volume = server_info['os-extended-volumes:volumes_attached'] |
| 201 | |
lkuchlan | 9e22b85 | 2017-02-05 15:38:29 +0200 | [diff] [blame] | 202 | self.assertNotEmpty(created_volume, "No volume attachment found.") |
| 203 | |
lkuchlan | 8789c55 | 2017-01-08 11:40:27 +0200 | [diff] [blame] | 204 | created_volume_info = self.volumes_client.show_volume( |
| 205 | created_volume[0]['id'])['volume'] |
| 206 | |
| 207 | # Verify the server was created from the snapshot |
| 208 | self.assertEqual( |
| 209 | boot_volume['volume_image_metadata']['image_id'], |
| 210 | created_volume_info['volume_image_metadata']['image_id']) |
| 211 | self.assertEqual(boot_snapshot['id'], |
| 212 | created_volume_info['snapshot_id']) |
| 213 | self.assertEqual(server['id'], |
| 214 | created_volume_info['attachments'][0]['server_id']) |
| 215 | self.assertEqual(created_volume[0]['id'], |
| 216 | created_volume_info['attachments'][0]['volume_id']) |
| 217 | |
Ken'ichi Ohmichi | c85a951 | 2017-01-27 18:34:24 -0800 | [diff] [blame] | 218 | @decorators.idempotent_id('36c34c67-7b54-4b59-b188-02a2f458a63b') |
Andrey Pavlov | c8bd4b1 | 2015-08-17 10:20:17 +0300 | [diff] [blame] | 219 | @test.services('compute', 'volume', 'image') |
| 220 | def test_create_ebs_image_and_check_boot(self): |
| 221 | # create an instance from volume |
| 222 | volume_origin = self._create_volume_from_image() |
lkuchlan | 8789c55 | 2017-01-08 11:40:27 +0200 | [diff] [blame] | 223 | instance = self._boot_instance_from_resource( |
| 224 | source_id=volume_origin['id'], |
| 225 | source_type='volume', |
| 226 | delete_on_termination=True) |
Andrey Pavlov | c8bd4b1 | 2015-08-17 10:20:17 +0300 | [diff] [blame] | 227 | # create EBS image |
zhufl | f9d9572 | 2016-10-19 16:06:17 +0800 | [diff] [blame] | 228 | image = self.create_server_snapshot(instance) |
Andrey Pavlov | c8bd4b1 | 2015-08-17 10:20:17 +0300 | [diff] [blame] | 229 | |
| 230 | # delete instance |
| 231 | self._delete_server(instance) |
| 232 | |
| 233 | # boot instance from EBS image |
zhufl | 13c9c89 | 2017-02-10 12:04:07 +0800 | [diff] [blame] | 234 | instance = self.create_server(image_id=image['id']) |
Andrey Pavlov | c8bd4b1 | 2015-08-17 10:20:17 +0300 | [diff] [blame] | 235 | # just ensure that instance booted |
| 236 | |
| 237 | # delete instance |
| 238 | self._delete_server(instance) |
| 239 | |
Nikola Dipanov | 7cff03f | 2014-03-12 14:06:25 +0100 | [diff] [blame] | 240 | |
| 241 | class TestVolumeBootPatternV2(TestVolumeBootPattern): |
lkuchlan | 8789c55 | 2017-01-08 11:40:27 +0200 | [diff] [blame] | 242 | def _get_bdm(self, source_id, source_type, delete_on_termination=False): |
Yaroslav Lobankov | 0089af5 | 2015-07-02 19:14:40 +0300 | [diff] [blame] | 243 | bd_map_v2 = [{ |
lkuchlan | 8789c55 | 2017-01-08 11:40:27 +0200 | [diff] [blame] | 244 | 'uuid': source_id, |
| 245 | 'source_type': source_type, |
Yaroslav Lobankov | 0089af5 | 2015-07-02 19:14:40 +0300 | [diff] [blame] | 246 | 'destination_type': 'volume', |
| 247 | 'boot_index': 0, |
Andrey Pavlov | c8bd4b1 | 2015-08-17 10:20:17 +0300 | [diff] [blame] | 248 | 'delete_on_termination': delete_on_termination}] |
| 249 | return {'block_device_mapping_v2': bd_map_v2} |