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 |
| 14 | |
Fei Long Wang | d39431f | 2015-05-14 11:30:48 +1200 | [diff] [blame] | 15 | from tempest.common.utils import data_utils |
Ken'ichi Ohmichi | 0eb153c | 2015-07-13 02:18:25 +0000 | [diff] [blame] | 16 | from tempest.common import waiters |
Matthew Treinish | 6c07229 | 2014-01-29 19:15:52 +0000 | [diff] [blame] | 17 | from tempest import config |
fujioka yuuichi | 636f8db | 2013-08-09 12:05:24 +0900 | [diff] [blame] | 18 | from tempest.scenario import manager |
Masayuki Igawa | 4ded9f0 | 2014-02-17 15:05:59 +0900 | [diff] [blame] | 19 | from tempest import test |
fujioka yuuichi | 636f8db | 2013-08-09 12:05:24 +0900 | [diff] [blame] | 20 | |
Matthew Treinish | 6c07229 | 2014-01-29 19:15:52 +0000 | [diff] [blame] | 21 | CONF = config.CONF |
Sean Dague | 52abbd9 | 2016-03-01 09:38:09 -0500 | [diff] [blame] | 22 | LOG = logging.getLogger(__name__) |
fujioka yuuichi | 636f8db | 2013-08-09 12:05:24 +0900 | [diff] [blame] | 23 | |
Nachi Ueno | 95b4128 | 2014-01-15 06:54:21 -0800 | [diff] [blame] | 24 | |
Joseph Lanoux | eef192f | 2014-08-01 14:32:53 +0000 | [diff] [blame] | 25 | class TestVolumeBootPattern(manager.ScenarioTest): |
fujioka yuuichi | 636f8db | 2013-08-09 12:05:24 +0900 | [diff] [blame] | 26 | |
Ken'ichi Ohmichi | c4e4f1c | 2015-11-17 08:16:12 +0000 | [diff] [blame] | 27 | """This test case attempts to reproduce the following steps: |
fujioka yuuichi | 636f8db | 2013-08-09 12:05:24 +0900 | [diff] [blame] | 28 | |
| 29 | * Create in Cinder some bootable volume importing a Glance image |
| 30 | * Boot an instance from the bootable volume |
| 31 | * Write content to the volume |
| 32 | * Delete an instance and Boot a new instance from the volume |
| 33 | * Check written content in the instance |
| 34 | * Create a volume snapshot while the instance is running |
| 35 | * Boot an additional instance from the new snapshot based volume |
| 36 | * Check written content in the instance booted from snapshot |
| 37 | """ |
Sean Dague | 02620fd | 2016-03-02 15:52:51 -0500 | [diff] [blame] | 38 | |
| 39 | # Boot from volume scenario is quite slow, and needs extra |
| 40 | # breathing room to get through deletes in the time allotted. |
| 41 | TIMEOUT_SCALING_FACTOR = 2 |
| 42 | |
JordanP | bce5553 | 2014-03-19 12:10:32 +0100 | [diff] [blame] | 43 | @classmethod |
Emily Hugenbruch | 5e2d2a2 | 2015-02-25 21:35:45 +0000 | [diff] [blame] | 44 | def skip_checks(cls): |
| 45 | super(TestVolumeBootPattern, cls).skip_checks() |
JordanP | bce5553 | 2014-03-19 12:10:32 +0100 | [diff] [blame] | 46 | if not CONF.volume_feature_enabled.snapshot: |
| 47 | raise cls.skipException("Cinder volume snapshots are disabled") |
fujioka yuuichi | 636f8db | 2013-08-09 12:05:24 +0900 | [diff] [blame] | 48 | |
| 49 | def _create_volume_from_image(self): |
Matthew Treinish | 6c07229 | 2014-01-29 19:15:52 +0000 | [diff] [blame] | 50 | img_uuid = CONF.compute.image_ref |
zhufl | c6ce539 | 2016-08-17 14:34:37 +0800 | [diff] [blame] | 51 | vol_name = data_utils.rand_name( |
| 52 | self.__class__.__name__ + '-volume-origin') |
fujioka yuuichi | 636f8db | 2013-08-09 12:05:24 +0900 | [diff] [blame] | 53 | return self.create_volume(name=vol_name, imageRef=img_uuid) |
| 54 | |
Andrey Pavlov | c8bd4b1 | 2015-08-17 10:20:17 +0300 | [diff] [blame] | 55 | def _get_bdm(self, vol_id, delete_on_termination=False): |
fujioka yuuichi | 636f8db | 2013-08-09 12:05:24 +0900 | [diff] [blame] | 56 | # NOTE(gfidente): the syntax for block_device_mapping is |
| 57 | # dev_name=id:type:size:delete_on_terminate |
| 58 | # where type needs to be "snap" if the server is booted |
| 59 | # from a snapshot, size instead can be safely left empty |
Joseph Lanoux | eef192f | 2014-08-01 14:32:53 +0000 | [diff] [blame] | 60 | bd_map = [{ |
| 61 | 'device_name': 'vda', |
| 62 | 'volume_id': vol_id, |
Andrey Pavlov | c8bd4b1 | 2015-08-17 10:20:17 +0300 | [diff] [blame] | 63 | 'delete_on_termination': str(int(delete_on_termination))}] |
| 64 | return {'block_device_mapping': bd_map} |
| 65 | |
| 66 | def _boot_instance_from_volume(self, vol_id, keypair=None, |
| 67 | security_group=None, |
| 68 | delete_on_termination=False): |
| 69 | create_kwargs = dict() |
| 70 | if keypair: |
| 71 | create_kwargs['key_name'] = keypair['name'] |
| 72 | if security_group: |
| 73 | create_kwargs['security_groups'] = [ |
| 74 | {'name': security_group['name']}] |
| 75 | create_kwargs.update(self._get_bdm( |
| 76 | vol_id, delete_on_termination=delete_on_termination)) |
lanoux | 5fc1452 | 2015-09-21 08:17:35 +0000 | [diff] [blame] | 77 | return self.create_server( |
Anusha Ramineni | 9aaef8b | 2016-01-19 10:56:40 +0530 | [diff] [blame] | 78 | image_id='', |
lanoux | 5fc1452 | 2015-09-21 08:17:35 +0000 | [diff] [blame] | 79 | wait_until='ACTIVE', |
| 80 | **create_kwargs) |
fujioka yuuichi | 636f8db | 2013-08-09 12:05:24 +0900 | [diff] [blame] | 81 | |
| 82 | def _create_snapshot_from_volume(self, vol_id): |
zhufl | c6ce539 | 2016-08-17 14:34:37 +0800 | [diff] [blame] | 83 | snap_name = data_utils.rand_name( |
| 84 | self.__class__.__name__ + '-snapshot') |
melanie witt | 8741222 | 2015-01-21 04:32:17 +0000 | [diff] [blame] | 85 | snap = self.snapshots_client.create_snapshot( |
Joseph Lanoux | eef192f | 2014-08-01 14:32:53 +0000 | [diff] [blame] | 86 | volume_id=vol_id, |
| 87 | force=True, |
John Warren | ff7faf6 | 2015-08-17 16:59:06 +0000 | [diff] [blame] | 88 | display_name=snap_name)['snapshot'] |
Yaroslav Lobankov | 46a78c3 | 2015-04-08 13:45:27 +0300 | [diff] [blame] | 89 | self.addCleanup( |
| 90 | self.snapshots_client.wait_for_resource_deletion, snap['id']) |
| 91 | self.addCleanup(self.snapshots_client.delete_snapshot, snap['id']) |
Yaroslav Lobankov | 667aaa2 | 2016-03-24 23:13:28 -0500 | [diff] [blame] | 92 | waiters.wait_for_snapshot_status(self.snapshots_client, |
| 93 | snap['id'], 'available') |
Ivan Kolodyazhny | bcfc32e | 2015-08-06 13:31:36 +0300 | [diff] [blame] | 94 | |
| 95 | # NOTE(e0ne): Cinder API v2 uses name instead of display_name |
| 96 | if 'display_name' in snap: |
| 97 | self.assertEqual(snap_name, snap['display_name']) |
| 98 | else: |
| 99 | self.assertEqual(snap_name, snap['name']) |
| 100 | |
fujioka yuuichi | 636f8db | 2013-08-09 12:05:24 +0900 | [diff] [blame] | 101 | return snap |
| 102 | |
| 103 | def _create_volume_from_snapshot(self, snap_id): |
zhufl | c6ce539 | 2016-08-17 14:34:37 +0800 | [diff] [blame] | 104 | vol_name = data_utils.rand_name( |
| 105 | self.__class__.__name__ + '-volume') |
fujioka yuuichi | 636f8db | 2013-08-09 12:05:24 +0900 | [diff] [blame] | 106 | return self.create_volume(name=vol_name, snapshot_id=snap_id) |
| 107 | |
fujioka yuuichi | 636f8db | 2013-08-09 12:05:24 +0900 | [diff] [blame] | 108 | def _delete_server(self, server): |
Joseph Lanoux | eef192f | 2014-08-01 14:32:53 +0000 | [diff] [blame] | 109 | self.servers_client.delete_server(server['id']) |
Ken'ichi Ohmichi | e91a0c6 | 2015-08-13 02:09:16 +0000 | [diff] [blame] | 110 | waiters.wait_for_server_termination(self.servers_client, server['id']) |
fujioka yuuichi | 636f8db | 2013-08-09 12:05:24 +0900 | [diff] [blame] | 111 | |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 112 | @test.idempotent_id('557cd2c2-4eb8-4dce-98be-f86765ff311b') |
Sean Dague | 3c634d1 | 2015-04-27 12:09:19 -0400 | [diff] [blame] | 113 | @test.attr(type='smoke') |
Masayuki Igawa | 4ded9f0 | 2014-02-17 15:05:59 +0900 | [diff] [blame] | 114 | @test.services('compute', 'volume', 'image') |
fujioka yuuichi | 636f8db | 2013-08-09 12:05:24 +0900 | [diff] [blame] | 115 | def test_volume_boot_pattern(self): |
Sean Dague | 52abbd9 | 2016-03-01 09:38:09 -0500 | [diff] [blame] | 116 | LOG.info("Creating keypair and security group") |
fujioka yuuichi | 636f8db | 2013-08-09 12:05:24 +0900 | [diff] [blame] | 117 | keypair = self.create_keypair() |
Yaroslav Lobankov | 0089af5 | 2015-07-02 19:14:40 +0300 | [diff] [blame] | 118 | security_group = self._create_security_group() |
fujioka yuuichi | 636f8db | 2013-08-09 12:05:24 +0900 | [diff] [blame] | 119 | |
| 120 | # create an instance from volume |
Sean Dague | 52abbd9 | 2016-03-01 09:38:09 -0500 | [diff] [blame] | 121 | LOG.info("Booting instance 1 from volume") |
fujioka yuuichi | 636f8db | 2013-08-09 12:05:24 +0900 | [diff] [blame] | 122 | volume_origin = self._create_volume_from_image() |
Joseph Lanoux | eef192f | 2014-08-01 14:32:53 +0000 | [diff] [blame] | 123 | instance_1st = self._boot_instance_from_volume(volume_origin['id'], |
Yaroslav Lobankov | 0089af5 | 2015-07-02 19:14:40 +0300 | [diff] [blame] | 124 | keypair, security_group) |
Sean Dague | 52abbd9 | 2016-03-01 09:38:09 -0500 | [diff] [blame] | 125 | LOG.info("Booted first instance: %s" % instance_1st) |
fujioka yuuichi | 636f8db | 2013-08-09 12:05:24 +0900 | [diff] [blame] | 126 | |
| 127 | # write content to volume on instance |
Sean Dague | 52abbd9 | 2016-03-01 09:38:09 -0500 | [diff] [blame] | 128 | LOG.info("Setting timestamp in instance %s" % instance_1st) |
Sean Dague | 20e9861 | 2016-01-06 14:33:28 -0500 | [diff] [blame] | 129 | ip_instance_1st = self.get_server_ip(instance_1st) |
Alexander Gubanov | 59cc303 | 2015-11-05 11:58:03 +0200 | [diff] [blame] | 130 | timestamp = self.create_timestamp(ip_instance_1st, |
| 131 | private_key=keypair['private_key']) |
fujioka yuuichi | 636f8db | 2013-08-09 12:05:24 +0900 | [diff] [blame] | 132 | |
| 133 | # delete instance |
Sean Dague | 52abbd9 | 2016-03-01 09:38:09 -0500 | [diff] [blame] | 134 | LOG.info("Deleting first instance: %s" % instance_1st) |
fujioka yuuichi | 636f8db | 2013-08-09 12:05:24 +0900 | [diff] [blame] | 135 | self._delete_server(instance_1st) |
| 136 | |
| 137 | # create a 2nd instance from volume |
Joseph Lanoux | eef192f | 2014-08-01 14:32:53 +0000 | [diff] [blame] | 138 | instance_2nd = self._boot_instance_from_volume(volume_origin['id'], |
Yaroslav Lobankov | 0089af5 | 2015-07-02 19:14:40 +0300 | [diff] [blame] | 139 | keypair, security_group) |
Sean Dague | 52abbd9 | 2016-03-01 09:38:09 -0500 | [diff] [blame] | 140 | LOG.info("Booted second instance %s" % instance_2nd) |
fujioka yuuichi | 636f8db | 2013-08-09 12:05:24 +0900 | [diff] [blame] | 141 | |
| 142 | # check the content of written file |
Sean Dague | 52abbd9 | 2016-03-01 09:38:09 -0500 | [diff] [blame] | 143 | LOG.info("Getting timestamp in instance %s" % instance_2nd) |
Sean Dague | 20e9861 | 2016-01-06 14:33:28 -0500 | [diff] [blame] | 144 | ip_instance_2nd = self.get_server_ip(instance_2nd) |
Alexander Gubanov | 59cc303 | 2015-11-05 11:58:03 +0200 | [diff] [blame] | 145 | timestamp2 = self.get_timestamp(ip_instance_2nd, |
| 146 | private_key=keypair['private_key']) |
| 147 | self.assertEqual(timestamp, timestamp2) |
fujioka yuuichi | 636f8db | 2013-08-09 12:05:24 +0900 | [diff] [blame] | 148 | |
| 149 | # snapshot a volume |
Sean Dague | 52abbd9 | 2016-03-01 09:38:09 -0500 | [diff] [blame] | 150 | LOG.info("Creating snapshot from volume: %s" % volume_origin['id']) |
Joseph Lanoux | eef192f | 2014-08-01 14:32:53 +0000 | [diff] [blame] | 151 | snapshot = self._create_snapshot_from_volume(volume_origin['id']) |
fujioka yuuichi | 636f8db | 2013-08-09 12:05:24 +0900 | [diff] [blame] | 152 | |
| 153 | # create a 3rd instance from snapshot |
Sean Dague | 52abbd9 | 2016-03-01 09:38:09 -0500 | [diff] [blame] | 154 | LOG.info("Creating third instance from snapshot: %s" % snapshot['id']) |
Joseph Lanoux | eef192f | 2014-08-01 14:32:53 +0000 | [diff] [blame] | 155 | volume = self._create_volume_from_snapshot(snapshot['id']) |
Alexander Gubanov | c8829f8 | 2015-11-12 10:35:13 +0200 | [diff] [blame] | 156 | server_from_snapshot = ( |
Yaroslav Lobankov | 0089af5 | 2015-07-02 19:14:40 +0300 | [diff] [blame] | 157 | self._boot_instance_from_volume(volume['id'], |
| 158 | keypair, security_group)) |
fujioka yuuichi | 636f8db | 2013-08-09 12:05:24 +0900 | [diff] [blame] | 159 | |
| 160 | # check the content of written file |
Sean Dague | 52abbd9 | 2016-03-01 09:38:09 -0500 | [diff] [blame] | 161 | LOG.info("Logging into third instance to get timestamp: %s" % |
| 162 | server_from_snapshot) |
Sean Dague | 20e9861 | 2016-01-06 14:33:28 -0500 | [diff] [blame] | 163 | server_from_snapshot_ip = self.get_server_ip(server_from_snapshot) |
Alexander Gubanov | c8829f8 | 2015-11-12 10:35:13 +0200 | [diff] [blame] | 164 | timestamp3 = self.get_timestamp(server_from_snapshot_ip, |
Alexander Gubanov | 59cc303 | 2015-11-05 11:58:03 +0200 | [diff] [blame] | 165 | private_key=keypair['private_key']) |
| 166 | self.assertEqual(timestamp, timestamp3) |
fujioka yuuichi | 636f8db | 2013-08-09 12:05:24 +0900 | [diff] [blame] | 167 | |
Andrey Pavlov | c8bd4b1 | 2015-08-17 10:20:17 +0300 | [diff] [blame] | 168 | @test.idempotent_id('36c34c67-7b54-4b59-b188-02a2f458a63b') |
| 169 | @test.services('compute', 'volume', 'image') |
| 170 | def test_create_ebs_image_and_check_boot(self): |
| 171 | # create an instance from volume |
| 172 | volume_origin = self._create_volume_from_image() |
| 173 | instance = self._boot_instance_from_volume(volume_origin['id'], |
| 174 | delete_on_termination=True) |
| 175 | # create EBS image |
zhufl | c6ce539 | 2016-08-17 14:34:37 +0800 | [diff] [blame] | 176 | name = data_utils.rand_name(self.__class__.__name__ + '-image') |
Andrey Pavlov | c8bd4b1 | 2015-08-17 10:20:17 +0300 | [diff] [blame] | 177 | image = self.create_server_snapshot(instance, name=name) |
| 178 | |
| 179 | # delete instance |
| 180 | self._delete_server(instance) |
| 181 | |
| 182 | # boot instance from EBS image |
lanoux | 5fc1452 | 2015-09-21 08:17:35 +0000 | [diff] [blame] | 183 | instance = self.create_server( |
| 184 | image_id=image['id']) |
Andrey Pavlov | c8bd4b1 | 2015-08-17 10:20:17 +0300 | [diff] [blame] | 185 | # just ensure that instance booted |
| 186 | |
| 187 | # delete instance |
| 188 | self._delete_server(instance) |
| 189 | |
Nikola Dipanov | 7cff03f | 2014-03-12 14:06:25 +0100 | [diff] [blame] | 190 | |
| 191 | class TestVolumeBootPatternV2(TestVolumeBootPattern): |
Andrey Pavlov | c8bd4b1 | 2015-08-17 10:20:17 +0300 | [diff] [blame] | 192 | def _get_bdm(self, vol_id, delete_on_termination=False): |
Yaroslav Lobankov | 0089af5 | 2015-07-02 19:14:40 +0300 | [diff] [blame] | 193 | bd_map_v2 = [{ |
| 194 | 'uuid': vol_id, |
| 195 | 'source_type': 'volume', |
| 196 | 'destination_type': 'volume', |
| 197 | 'boot_index': 0, |
Andrey Pavlov | c8bd4b1 | 2015-08-17 10:20:17 +0300 | [diff] [blame] | 198 | 'delete_on_termination': delete_on_termination}] |
| 199 | return {'block_device_mapping_v2': bd_map_v2} |