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 | |
Doug Hellmann | 583ce2c | 2015-03-11 14:55:46 +0000 | [diff] [blame] | 13 | from oslo_log import log |
Matt Riedemann | ebaf245 | 2015-08-31 07:12:51 -0700 | [diff] [blame] | 14 | from tempest_lib import decorators |
Matthew Treinish | c49fcbe | 2015-02-05 23:37:34 -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 |
fujioka yuuichi | 636f8db | 2013-08-09 12:05:24 +0900 | [diff] [blame] | 19 | from tempest.scenario import manager |
Masayuki Igawa | 4ded9f0 | 2014-02-17 15:05:59 +0900 | [diff] [blame] | 20 | from tempest import test |
fujioka yuuichi | 636f8db | 2013-08-09 12:05:24 +0900 | [diff] [blame] | 21 | |
Matthew Treinish | 6c07229 | 2014-01-29 19:15:52 +0000 | [diff] [blame] | 22 | CONF = config.CONF |
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 | LOG = log.getLogger(__name__) |
| 25 | |
| 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 | |
| 29 | """ |
| 30 | This test case attempts to reproduce the following steps: |
| 31 | |
| 32 | * Create in Cinder some bootable volume importing a Glance image |
| 33 | * Boot an instance from the bootable volume |
| 34 | * Write content to the volume |
| 35 | * Delete an instance and Boot a new instance from the volume |
| 36 | * Check written content in the instance |
| 37 | * Create a volume snapshot while the instance is running |
| 38 | * Boot an additional instance from the new snapshot based volume |
| 39 | * Check written content in the instance booted from snapshot |
| 40 | """ |
JordanP | bce5553 | 2014-03-19 12:10:32 +0100 | [diff] [blame] | 41 | @classmethod |
Emily Hugenbruch | 5e2d2a2 | 2015-02-25 21:35:45 +0000 | [diff] [blame] | 42 | def skip_checks(cls): |
| 43 | super(TestVolumeBootPattern, cls).skip_checks() |
JordanP | bce5553 | 2014-03-19 12:10:32 +0100 | [diff] [blame] | 44 | if not CONF.volume_feature_enabled.snapshot: |
| 45 | raise cls.skipException("Cinder volume snapshots are disabled") |
fujioka yuuichi | 636f8db | 2013-08-09 12:05:24 +0900 | [diff] [blame] | 46 | |
| 47 | def _create_volume_from_image(self): |
Matthew Treinish | 6c07229 | 2014-01-29 19:15:52 +0000 | [diff] [blame] | 48 | img_uuid = CONF.compute.image_ref |
Masayuki Igawa | 259c113 | 2013-10-31 17:48:44 +0900 | [diff] [blame] | 49 | vol_name = data_utils.rand_name('volume-origin') |
fujioka yuuichi | 636f8db | 2013-08-09 12:05:24 +0900 | [diff] [blame] | 50 | return self.create_volume(name=vol_name, imageRef=img_uuid) |
| 51 | |
Andrey Pavlov | c8bd4b1 | 2015-08-17 10:20:17 +0300 | [diff] [blame] | 52 | def _get_bdm(self, vol_id, delete_on_termination=False): |
fujioka yuuichi | 636f8db | 2013-08-09 12:05:24 +0900 | [diff] [blame] | 53 | # NOTE(gfidente): the syntax for block_device_mapping is |
| 54 | # dev_name=id:type:size:delete_on_terminate |
| 55 | # where type needs to be "snap" if the server is booted |
| 56 | # from a snapshot, size instead can be safely left empty |
Joseph Lanoux | eef192f | 2014-08-01 14:32:53 +0000 | [diff] [blame] | 57 | bd_map = [{ |
| 58 | 'device_name': 'vda', |
| 59 | 'volume_id': vol_id, |
Andrey Pavlov | c8bd4b1 | 2015-08-17 10:20:17 +0300 | [diff] [blame] | 60 | 'delete_on_termination': str(int(delete_on_termination))}] |
| 61 | return {'block_device_mapping': bd_map} |
| 62 | |
| 63 | def _boot_instance_from_volume(self, vol_id, keypair=None, |
| 64 | security_group=None, |
| 65 | delete_on_termination=False): |
| 66 | create_kwargs = dict() |
| 67 | if keypair: |
| 68 | create_kwargs['key_name'] = keypair['name'] |
| 69 | if security_group: |
| 70 | create_kwargs['security_groups'] = [ |
| 71 | {'name': security_group['name']}] |
| 72 | create_kwargs.update(self._get_bdm( |
| 73 | vol_id, delete_on_termination=delete_on_termination)) |
Xavier Queralt | 249cac3 | 2014-03-05 13:51:39 +0100 | [diff] [blame] | 74 | return self.create_server(image='', create_kwargs=create_kwargs) |
fujioka yuuichi | 636f8db | 2013-08-09 12:05:24 +0900 | [diff] [blame] | 75 | |
| 76 | def _create_snapshot_from_volume(self, vol_id): |
Masayuki Igawa | 259c113 | 2013-10-31 17:48:44 +0900 | [diff] [blame] | 77 | snap_name = data_utils.rand_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']) |
Joseph Lanoux | eef192f | 2014-08-01 14:32:53 +0000 | [diff] [blame] | 85 | self.snapshots_client.wait_for_snapshot_status(snap['id'], 'available') |
Ivan Kolodyazhny | bcfc32e | 2015-08-06 13:31:36 +0300 | [diff] [blame] | 86 | |
| 87 | # NOTE(e0ne): Cinder API v2 uses name instead of display_name |
| 88 | if 'display_name' in snap: |
| 89 | self.assertEqual(snap_name, snap['display_name']) |
| 90 | else: |
| 91 | self.assertEqual(snap_name, snap['name']) |
| 92 | |
fujioka yuuichi | 636f8db | 2013-08-09 12:05:24 +0900 | [diff] [blame] | 93 | return snap |
| 94 | |
| 95 | def _create_volume_from_snapshot(self, snap_id): |
Masayuki Igawa | 259c113 | 2013-10-31 17:48:44 +0900 | [diff] [blame] | 96 | vol_name = data_utils.rand_name('volume') |
fujioka yuuichi | 636f8db | 2013-08-09 12:05:24 +0900 | [diff] [blame] | 97 | return self.create_volume(name=vol_name, snapshot_id=snap_id) |
| 98 | |
fujioka yuuichi | 636f8db | 2013-08-09 12:05:24 +0900 | [diff] [blame] | 99 | def _ssh_to_server(self, server, keypair): |
Matthew Treinish | 6c07229 | 2014-01-29 19:15:52 +0000 | [diff] [blame] | 100 | if CONF.compute.use_floatingip_for_ssh: |
Matt Riedemann | 3ed0904 | 2015-09-01 10:48:24 -0700 | [diff] [blame] | 101 | ip = self.create_floating_ip(server)['ip'] |
fujioka yuuichi | 636f8db | 2013-08-09 12:05:24 +0900 | [diff] [blame] | 102 | else: |
Yaroslav Lobankov | fc99707 | 2015-07-27 11:57:49 +0300 | [diff] [blame] | 103 | ip = server |
fujioka yuuichi | 636f8db | 2013-08-09 12:05:24 +0900 | [diff] [blame] | 104 | |
JordanP | 3fe2dc3 | 2014-11-17 13:06:01 +0100 | [diff] [blame] | 105 | return self.get_remote_client(ip, private_key=keypair['private_key'], |
| 106 | log_console_of_servers=[server]) |
fujioka yuuichi | 636f8db | 2013-08-09 12:05:24 +0900 | [diff] [blame] | 107 | |
| 108 | def _get_content(self, ssh_client): |
| 109 | return ssh_client.exec_command('cat /tmp/text') |
| 110 | |
| 111 | def _write_text(self, ssh_client): |
Ken'ichi Ohmichi | 07308f1 | 2015-03-23 00:24:28 +0000 | [diff] [blame] | 112 | text = data_utils.rand_name('text') |
fujioka yuuichi | 636f8db | 2013-08-09 12:05:24 +0900 | [diff] [blame] | 113 | ssh_client.exec_command('echo "%s" > /tmp/text; sync' % (text)) |
| 114 | |
| 115 | return self._get_content(ssh_client) |
| 116 | |
| 117 | def _delete_server(self, server): |
Joseph Lanoux | eef192f | 2014-08-01 14:32:53 +0000 | [diff] [blame] | 118 | self.servers_client.delete_server(server['id']) |
Ken'ichi Ohmichi | e91a0c6 | 2015-08-13 02:09:16 +0000 | [diff] [blame] | 119 | waiters.wait_for_server_termination(self.servers_client, server['id']) |
fujioka yuuichi | 636f8db | 2013-08-09 12:05:24 +0900 | [diff] [blame] | 120 | |
| 121 | def _check_content_of_written_file(self, ssh_client, expected): |
| 122 | actual = self._get_content(ssh_client) |
| 123 | self.assertEqual(expected, actual) |
| 124 | |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 125 | @test.idempotent_id('557cd2c2-4eb8-4dce-98be-f86765ff311b') |
Sean Dague | 3c634d1 | 2015-04-27 12:09:19 -0400 | [diff] [blame] | 126 | @test.attr(type='smoke') |
Masayuki Igawa | 4ded9f0 | 2014-02-17 15:05:59 +0900 | [diff] [blame] | 127 | @test.services('compute', 'volume', 'image') |
fujioka yuuichi | 636f8db | 2013-08-09 12:05:24 +0900 | [diff] [blame] | 128 | def test_volume_boot_pattern(self): |
| 129 | keypair = self.create_keypair() |
Yaroslav Lobankov | 0089af5 | 2015-07-02 19:14:40 +0300 | [diff] [blame] | 130 | security_group = self._create_security_group() |
fujioka yuuichi | 636f8db | 2013-08-09 12:05:24 +0900 | [diff] [blame] | 131 | |
| 132 | # create an instance from volume |
| 133 | volume_origin = self._create_volume_from_image() |
Joseph Lanoux | eef192f | 2014-08-01 14:32:53 +0000 | [diff] [blame] | 134 | instance_1st = self._boot_instance_from_volume(volume_origin['id'], |
Yaroslav Lobankov | 0089af5 | 2015-07-02 19:14:40 +0300 | [diff] [blame] | 135 | keypair, security_group) |
fujioka yuuichi | 636f8db | 2013-08-09 12:05:24 +0900 | [diff] [blame] | 136 | |
| 137 | # write content to volume on instance |
| 138 | ssh_client_for_instance_1st = self._ssh_to_server(instance_1st, |
| 139 | keypair) |
| 140 | text = self._write_text(ssh_client_for_instance_1st) |
| 141 | |
| 142 | # delete instance |
| 143 | self._delete_server(instance_1st) |
| 144 | |
| 145 | # create a 2nd instance from volume |
Joseph Lanoux | eef192f | 2014-08-01 14:32:53 +0000 | [diff] [blame] | 146 | instance_2nd = self._boot_instance_from_volume(volume_origin['id'], |
Yaroslav Lobankov | 0089af5 | 2015-07-02 19:14:40 +0300 | [diff] [blame] | 147 | keypair, security_group) |
fujioka yuuichi | 636f8db | 2013-08-09 12:05:24 +0900 | [diff] [blame] | 148 | |
| 149 | # check the content of written file |
| 150 | ssh_client_for_instance_2nd = self._ssh_to_server(instance_2nd, |
| 151 | keypair) |
| 152 | self._check_content_of_written_file(ssh_client_for_instance_2nd, text) |
| 153 | |
| 154 | # snapshot a volume |
Joseph Lanoux | eef192f | 2014-08-01 14:32:53 +0000 | [diff] [blame] | 155 | snapshot = self._create_snapshot_from_volume(volume_origin['id']) |
fujioka yuuichi | 636f8db | 2013-08-09 12:05:24 +0900 | [diff] [blame] | 156 | |
| 157 | # create a 3rd instance from snapshot |
Joseph Lanoux | eef192f | 2014-08-01 14:32:53 +0000 | [diff] [blame] | 158 | volume = self._create_volume_from_snapshot(snapshot['id']) |
Yaroslav Lobankov | 0089af5 | 2015-07-02 19:14:40 +0300 | [diff] [blame] | 159 | instance_from_snapshot = ( |
| 160 | self._boot_instance_from_volume(volume['id'], |
| 161 | keypair, security_group)) |
fujioka yuuichi | 636f8db | 2013-08-09 12:05:24 +0900 | [diff] [blame] | 162 | |
| 163 | # check the content of written file |
| 164 | ssh_client = self._ssh_to_server(instance_from_snapshot, keypair) |
| 165 | self._check_content_of_written_file(ssh_client, text) |
| 166 | |
Matt Riedemann | ebaf245 | 2015-08-31 07:12:51 -0700 | [diff] [blame] | 167 | @decorators.skip_because(bug='1489581') |
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 |
| 176 | name = data_utils.rand_name('image') |
| 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 |
| 183 | instance = self.create_server(image=image['id']) |
| 184 | # just ensure that instance booted |
| 185 | |
| 186 | # delete instance |
| 187 | self._delete_server(instance) |
| 188 | |
Nikola Dipanov | 7cff03f | 2014-03-12 14:06:25 +0100 | [diff] [blame] | 189 | |
| 190 | class TestVolumeBootPatternV2(TestVolumeBootPattern): |
Andrey Pavlov | c8bd4b1 | 2015-08-17 10:20:17 +0300 | [diff] [blame] | 191 | def _get_bdm(self, vol_id, delete_on_termination=False): |
Yaroslav Lobankov | 0089af5 | 2015-07-02 19:14:40 +0300 | [diff] [blame] | 192 | bd_map_v2 = [{ |
| 193 | 'uuid': vol_id, |
| 194 | 'source_type': 'volume', |
| 195 | 'destination_type': 'volume', |
| 196 | 'boot_index': 0, |
Andrey Pavlov | c8bd4b1 | 2015-08-17 10:20:17 +0300 | [diff] [blame] | 197 | 'delete_on_termination': delete_on_termination}] |
| 198 | return {'block_device_mapping_v2': bd_map_v2} |