blob: 4ce57dbc168f078b625ac832866b6543d719b507 [file] [log] [blame]
fujioka yuuichi636f8db2013-08-09 12:05:24 +09001# 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
Fei Long Wangd39431f2015-05-14 11:30:48 +120013from tempest.common.utils import data_utils
Ken'ichi Ohmichi0eb153c2015-07-13 02:18:25 +000014from tempest.common import waiters
Matthew Treinish6c072292014-01-29 19:15:52 +000015from tempest import config
fujioka yuuichi636f8db2013-08-09 12:05:24 +090016from tempest.scenario import manager
Masayuki Igawa4ded9f02014-02-17 15:05:59 +090017from tempest import test
fujioka yuuichi636f8db2013-08-09 12:05:24 +090018
Matthew Treinish6c072292014-01-29 19:15:52 +000019CONF = config.CONF
fujioka yuuichi636f8db2013-08-09 12:05:24 +090020
Nachi Ueno95b41282014-01-15 06:54:21 -080021
Joseph Lanouxeef192f2014-08-01 14:32:53 +000022class TestVolumeBootPattern(manager.ScenarioTest):
fujioka yuuichi636f8db2013-08-09 12:05:24 +090023
Ken'ichi Ohmichic4e4f1c2015-11-17 08:16:12 +000024 """This test case attempts to reproduce the following steps:
fujioka yuuichi636f8db2013-08-09 12:05:24 +090025
26 * Create in Cinder some bootable volume importing a Glance image
27 * Boot an instance from the bootable volume
28 * Write content to the volume
29 * Delete an instance and Boot a new instance from the volume
30 * Check written content in the instance
31 * Create a volume snapshot while the instance is running
32 * Boot an additional instance from the new snapshot based volume
33 * Check written content in the instance booted from snapshot
34 """
JordanPbce55532014-03-19 12:10:32 +010035 @classmethod
Emily Hugenbruch5e2d2a22015-02-25 21:35:45 +000036 def skip_checks(cls):
37 super(TestVolumeBootPattern, cls).skip_checks()
JordanPbce55532014-03-19 12:10:32 +010038 if not CONF.volume_feature_enabled.snapshot:
39 raise cls.skipException("Cinder volume snapshots are disabled")
fujioka yuuichi636f8db2013-08-09 12:05:24 +090040
41 def _create_volume_from_image(self):
Matthew Treinish6c072292014-01-29 19:15:52 +000042 img_uuid = CONF.compute.image_ref
Masayuki Igawa259c1132013-10-31 17:48:44 +090043 vol_name = data_utils.rand_name('volume-origin')
fujioka yuuichi636f8db2013-08-09 12:05:24 +090044 return self.create_volume(name=vol_name, imageRef=img_uuid)
45
Andrey Pavlovc8bd4b12015-08-17 10:20:17 +030046 def _get_bdm(self, vol_id, delete_on_termination=False):
fujioka yuuichi636f8db2013-08-09 12:05:24 +090047 # NOTE(gfidente): the syntax for block_device_mapping is
48 # dev_name=id:type:size:delete_on_terminate
49 # where type needs to be "snap" if the server is booted
50 # from a snapshot, size instead can be safely left empty
Joseph Lanouxeef192f2014-08-01 14:32:53 +000051 bd_map = [{
52 'device_name': 'vda',
53 'volume_id': vol_id,
Andrey Pavlovc8bd4b12015-08-17 10:20:17 +030054 'delete_on_termination': str(int(delete_on_termination))}]
55 return {'block_device_mapping': bd_map}
56
57 def _boot_instance_from_volume(self, vol_id, keypair=None,
58 security_group=None,
59 delete_on_termination=False):
60 create_kwargs = dict()
61 if keypair:
62 create_kwargs['key_name'] = keypair['name']
63 if security_group:
64 create_kwargs['security_groups'] = [
65 {'name': security_group['name']}]
66 create_kwargs.update(self._get_bdm(
67 vol_id, delete_on_termination=delete_on_termination))
lanoux5fc14522015-09-21 08:17:35 +000068 return self.create_server(
Anusha Ramineni9aaef8b2016-01-19 10:56:40 +053069 image_id='',
lanoux5fc14522015-09-21 08:17:35 +000070 wait_until='ACTIVE',
71 **create_kwargs)
fujioka yuuichi636f8db2013-08-09 12:05:24 +090072
73 def _create_snapshot_from_volume(self, vol_id):
Masayuki Igawa259c1132013-10-31 17:48:44 +090074 snap_name = data_utils.rand_name('snapshot')
melanie witt87412222015-01-21 04:32:17 +000075 snap = self.snapshots_client.create_snapshot(
Joseph Lanouxeef192f2014-08-01 14:32:53 +000076 volume_id=vol_id,
77 force=True,
John Warrenff7faf62015-08-17 16:59:06 +000078 display_name=snap_name)['snapshot']
Yaroslav Lobankov46a78c32015-04-08 13:45:27 +030079 self.addCleanup(
80 self.snapshots_client.wait_for_resource_deletion, snap['id'])
81 self.addCleanup(self.snapshots_client.delete_snapshot, snap['id'])
Joseph Lanouxeef192f2014-08-01 14:32:53 +000082 self.snapshots_client.wait_for_snapshot_status(snap['id'], 'available')
Ivan Kolodyazhnybcfc32e2015-08-06 13:31:36 +030083
84 # NOTE(e0ne): Cinder API v2 uses name instead of display_name
85 if 'display_name' in snap:
86 self.assertEqual(snap_name, snap['display_name'])
87 else:
88 self.assertEqual(snap_name, snap['name'])
89
fujioka yuuichi636f8db2013-08-09 12:05:24 +090090 return snap
91
92 def _create_volume_from_snapshot(self, snap_id):
Masayuki Igawa259c1132013-10-31 17:48:44 +090093 vol_name = data_utils.rand_name('volume')
fujioka yuuichi636f8db2013-08-09 12:05:24 +090094 return self.create_volume(name=vol_name, snapshot_id=snap_id)
95
fujioka yuuichi636f8db2013-08-09 12:05:24 +090096 def _delete_server(self, server):
Joseph Lanouxeef192f2014-08-01 14:32:53 +000097 self.servers_client.delete_server(server['id'])
Ken'ichi Ohmichie91a0c62015-08-13 02:09:16 +000098 waiters.wait_for_server_termination(self.servers_client, server['id'])
fujioka yuuichi636f8db2013-08-09 12:05:24 +090099
Chris Hoge7579c1a2015-02-26 14:12:15 -0800100 @test.idempotent_id('557cd2c2-4eb8-4dce-98be-f86765ff311b')
Sean Dague3c634d12015-04-27 12:09:19 -0400101 @test.attr(type='smoke')
Masayuki Igawa4ded9f02014-02-17 15:05:59 +0900102 @test.services('compute', 'volume', 'image')
fujioka yuuichi636f8db2013-08-09 12:05:24 +0900103 def test_volume_boot_pattern(self):
104 keypair = self.create_keypair()
Yaroslav Lobankov0089af52015-07-02 19:14:40 +0300105 security_group = self._create_security_group()
fujioka yuuichi636f8db2013-08-09 12:05:24 +0900106
107 # create an instance from volume
108 volume_origin = self._create_volume_from_image()
Joseph Lanouxeef192f2014-08-01 14:32:53 +0000109 instance_1st = self._boot_instance_from_volume(volume_origin['id'],
Yaroslav Lobankov0089af52015-07-02 19:14:40 +0300110 keypair, security_group)
fujioka yuuichi636f8db2013-08-09 12:05:24 +0900111
112 # write content to volume on instance
Sean Dague20e98612016-01-06 14:33:28 -0500113 ip_instance_1st = self.get_server_ip(instance_1st)
Alexander Gubanov59cc3032015-11-05 11:58:03 +0200114 timestamp = self.create_timestamp(ip_instance_1st,
115 private_key=keypair['private_key'])
fujioka yuuichi636f8db2013-08-09 12:05:24 +0900116
117 # delete instance
118 self._delete_server(instance_1st)
119
120 # create a 2nd instance from volume
Joseph Lanouxeef192f2014-08-01 14:32:53 +0000121 instance_2nd = self._boot_instance_from_volume(volume_origin['id'],
Yaroslav Lobankov0089af52015-07-02 19:14:40 +0300122 keypair, security_group)
fujioka yuuichi636f8db2013-08-09 12:05:24 +0900123
124 # check the content of written file
Sean Dague20e98612016-01-06 14:33:28 -0500125 ip_instance_2nd = self.get_server_ip(instance_2nd)
Alexander Gubanov59cc3032015-11-05 11:58:03 +0200126 timestamp2 = self.get_timestamp(ip_instance_2nd,
127 private_key=keypair['private_key'])
128 self.assertEqual(timestamp, timestamp2)
fujioka yuuichi636f8db2013-08-09 12:05:24 +0900129
130 # snapshot a volume
Joseph Lanouxeef192f2014-08-01 14:32:53 +0000131 snapshot = self._create_snapshot_from_volume(volume_origin['id'])
fujioka yuuichi636f8db2013-08-09 12:05:24 +0900132
133 # create a 3rd instance from snapshot
Joseph Lanouxeef192f2014-08-01 14:32:53 +0000134 volume = self._create_volume_from_snapshot(snapshot['id'])
Alexander Gubanovc8829f82015-11-12 10:35:13 +0200135 server_from_snapshot = (
Yaroslav Lobankov0089af52015-07-02 19:14:40 +0300136 self._boot_instance_from_volume(volume['id'],
137 keypair, security_group))
fujioka yuuichi636f8db2013-08-09 12:05:24 +0900138
139 # check the content of written file
Sean Dague20e98612016-01-06 14:33:28 -0500140 server_from_snapshot_ip = self.get_server_ip(server_from_snapshot)
Alexander Gubanovc8829f82015-11-12 10:35:13 +0200141 timestamp3 = self.get_timestamp(server_from_snapshot_ip,
Alexander Gubanov59cc3032015-11-05 11:58:03 +0200142 private_key=keypair['private_key'])
143 self.assertEqual(timestamp, timestamp3)
fujioka yuuichi636f8db2013-08-09 12:05:24 +0900144
Andrey Pavlovc8bd4b12015-08-17 10:20:17 +0300145 @test.idempotent_id('36c34c67-7b54-4b59-b188-02a2f458a63b')
146 @test.services('compute', 'volume', 'image')
147 def test_create_ebs_image_and_check_boot(self):
148 # create an instance from volume
149 volume_origin = self._create_volume_from_image()
150 instance = self._boot_instance_from_volume(volume_origin['id'],
151 delete_on_termination=True)
152 # create EBS image
153 name = data_utils.rand_name('image')
154 image = self.create_server_snapshot(instance, name=name)
155
156 # delete instance
157 self._delete_server(instance)
158
159 # boot instance from EBS image
lanoux5fc14522015-09-21 08:17:35 +0000160 instance = self.create_server(
161 image_id=image['id'])
Andrey Pavlovc8bd4b12015-08-17 10:20:17 +0300162 # just ensure that instance booted
163
164 # delete instance
165 self._delete_server(instance)
166
Nikola Dipanov7cff03f2014-03-12 14:06:25 +0100167
168class TestVolumeBootPatternV2(TestVolumeBootPattern):
Andrey Pavlovc8bd4b12015-08-17 10:20:17 +0300169 def _get_bdm(self, vol_id, delete_on_termination=False):
Yaroslav Lobankov0089af52015-07-02 19:14:40 +0300170 bd_map_v2 = [{
171 'uuid': vol_id,
172 'source_type': 'volume',
173 'destination_type': 'volume',
174 'boot_index': 0,
Andrey Pavlovc8bd4b12015-08-17 10:20:17 +0300175 'delete_on_termination': delete_on_termination}]
176 return {'block_device_mapping_v2': bd_map_v2}