blob: 8ffc99df5b516c4ed6135c89526eb61fe40e11cc [file] [log] [blame]
Attila Fazekas36b1fcf2013-01-31 16:41:04 +01001# 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
lkuchland8277372017-02-22 15:07:52 +020013from testtools import matchers
14
Sean Dague1937d092013-05-17 16:36:38 -040015from tempest.api.volume import base
Xiao Chen47fcbf42014-01-13 16:42:41 +080016from tempest import config
Ken'ichi Ohmichief1c1ce2017-03-10 11:07:10 -080017from tempest.lib.common.utils import data_utils
Ken'ichi Ohmichi6b279c72017-01-27 18:26:59 -080018from tempest.lib import decorators
Masayuki Igawa1edf94f2014-03-04 18:34:16 +090019from tempest import test
Attila Fazekas36b1fcf2013-01-31 16:41:04 +010020
Xiao Chen47fcbf42014-01-13 16:42:41 +080021CONF = config.CONF
Giulio Fidente3a465e32013-05-07 13:38:18 +020022
Attila Fazekas36b1fcf2013-01-31 16:41:04 +010023
Ken'ichi Ohmichie8afb8c2017-03-27 11:25:37 -070024class VolumesSnapshotTestJSON(base.BaseVolumeTest):
Attila Fazekas36b1fcf2013-01-31 16:41:04 +010025
Giulio Fidente73332932013-05-03 18:04:09 +020026 @classmethod
Rohan Kanade05749152015-01-30 17:15:18 +053027 def skip_checks(cls):
Ken'ichi Ohmichie8afb8c2017-03-27 11:25:37 -070028 super(VolumesSnapshotTestJSON, cls).skip_checks()
Rohan Kanade05749152015-01-30 17:15:18 +053029 if not CONF.volume_feature_enabled.snapshot:
30 raise cls.skipException("Cinder volume snapshots are disabled")
31
32 @classmethod
Andrea Frittoli61a12e22014-09-15 13:14:54 +010033 def resource_setup(cls):
Ken'ichi Ohmichie8afb8c2017-03-27 11:25:37 -070034 super(VolumesSnapshotTestJSON, cls).resource_setup()
Zhi Kun Liu43f9af12014-03-19 21:01:35 +080035 cls.volume_origin = cls.create_volume()
Giulio Fidente73332932013-05-03 18:04:09 +020036
Ken'ichi Ohmichi6b279c72017-01-27 18:26:59 -080037 @decorators.idempotent_id('b467b54c-07a4-446d-a1cf-651dedcc3ff1')
Matthew Treinish7ea69e62014-06-03 17:23:50 -040038 @test.services('compute')
Xiao Chen47fcbf42014-01-13 16:42:41 +080039 def test_snapshot_create_with_volume_in_use(self):
40 # Create a snapshot when volume status is in-use
41 # Create a test instance
zhufl7867a6e2016-10-18 15:37:12 +080042 server = self.create_server(wait_until='ACTIVE')
Erlon R. Cruzba19bc72016-09-28 14:32:11 -030043 self.attach_volume(server['id'], self.volume_origin['id'])
44
Xiao Chen47fcbf42014-01-13 16:42:41 +080045 # Snapshot a volume even if it's attached to an instance
46 snapshot = self.create_snapshot(self.volume_origin['id'],
47 force=True)
48 # Delete the snapshot
lkuchlan5b2b3622017-02-14 15:48:36 +020049 self.delete_snapshot(snapshot['id'])
Xiao Chen47fcbf42014-01-13 16:42:41 +080050
Ken'ichi Ohmichi6b279c72017-01-27 18:26:59 -080051 @decorators.idempotent_id('8567b54c-4455-446d-a1cf-651ddeaa3ff2')
Erlon R. Cruzba19bc72016-09-28 14:32:11 -030052 @test.services('compute')
53 def test_snapshot_delete_with_volume_in_use(self):
54 # Create a test instance
55 server = self.create_server(wait_until='ACTIVE')
56 self.attach_volume(server['id'], self.volume_origin['id'])
57
58 # Snapshot a volume attached to an instance
59 snapshot1 = self.create_snapshot(self.volume_origin['id'], force=True)
60 snapshot2 = self.create_snapshot(self.volume_origin['id'], force=True)
61 snapshot3 = self.create_snapshot(self.volume_origin['id'], force=True)
62
63 # Delete the snapshots. Some snapshot implementations can take
64 # different paths according to order they are deleted.
lkuchlan5b2b3622017-02-14 15:48:36 +020065 self.delete_snapshot(snapshot1['id'])
66 self.delete_snapshot(snapshot3['id'])
67 self.delete_snapshot(snapshot2['id'])
Erlon R. Cruzba19bc72016-09-28 14:32:11 -030068
Ken'ichi Ohmichi6b279c72017-01-27 18:26:59 -080069 @decorators.idempotent_id('5210a1de-85a0-11e6-bb21-641c676a5d61')
Erlon R. Cruzba19bc72016-09-28 14:32:11 -030070 @test.services('compute')
71 def test_snapshot_create_offline_delete_online(self):
72
73 # Create a snapshot while it is not attached
74 snapshot1 = self.create_snapshot(self.volume_origin['id'])
75
76 # Create a server and attach it
77 server = self.create_server(wait_until='ACTIVE')
78 self.attach_volume(server['id'], self.volume_origin['id'])
79
80 # Now that the volume is attached, create another snapshots
81 snapshot2 = self.create_snapshot(self.volume_origin['id'], force=True)
82 snapshot3 = self.create_snapshot(self.volume_origin['id'], force=True)
83
84 # Delete the snapshots. Some snapshot implementations can take
85 # different paths according to order they are deleted.
lkuchlan5b2b3622017-02-14 15:48:36 +020086 self.delete_snapshot(snapshot3['id'])
87 self.delete_snapshot(snapshot1['id'])
88 self.delete_snapshot(snapshot2['id'])
Erlon R. Cruzba19bc72016-09-28 14:32:11 -030089
Ken'ichi Ohmichi6b279c72017-01-27 18:26:59 -080090 @decorators.idempotent_id('2a8abbe4-d871-46db-b049-c41f5af8216e')
QingXin Mengdc95f5e2013-09-16 19:06:44 -070091 def test_snapshot_create_get_list_update_delete(self):
lkuchland8277372017-02-22 15:07:52 +020092 # Create a snapshot with metadata
93 metadata = {"snap-meta1": "value1",
94 "snap-meta2": "value2",
95 "snap-meta3": "value3"}
96 snapshot = self.create_snapshot(self.volume_origin['id'],
97 metadata=metadata)
Giulio Fidente73332932013-05-03 18:04:09 +020098
Giulio Fidentef41b8ee2013-05-21 11:07:21 +020099 # Get the snap and check for some of its details
John Warrenff7faf62015-08-17 16:59:06 +0000100 snap_get = self.snapshots_client.show_snapshot(
101 snapshot['id'])['snapshot']
Giulio Fidentef41b8ee2013-05-21 11:07:21 +0200102 self.assertEqual(self.volume_origin['id'],
103 snap_get['volume_id'],
104 "Referred volume origin mismatch")
jeremy.zhang681dff82017-04-06 19:21:01 +0800105 self.assertEqual(self.volume_origin['size'], snap_get['size'])
Giulio Fidentef41b8ee2013-05-21 11:07:21 +0200106
lkuchland8277372017-02-22 15:07:52 +0200107 # Verify snapshot metadata
108 self.assertThat(snap_get['metadata'].items(),
109 matchers.ContainsAll(metadata.items()))
110
Giulio Fidentef41b8ee2013-05-21 11:07:21 +0200111 # Compare also with the output from the list action
zhufla57530c2017-03-23 11:38:12 +0800112 tracking_data = (snapshot['id'], snapshot['name'])
John Warrenff7faf62015-08-17 16:59:06 +0000113 snaps_list = self.snapshots_client.list_snapshots()['snapshots']
zhufla57530c2017-03-23 11:38:12 +0800114 snaps_data = [(f['id'], f['name']) for f in snaps_list]
Giulio Fidentef41b8ee2013-05-21 11:07:21 +0200115 self.assertIn(tracking_data, snaps_data)
116
QingXin Mengdc95f5e2013-09-16 19:06:44 -0700117 # Updates snapshot with new values
zhuflc6ce5392016-08-17 14:34:37 +0800118 new_s_name = data_utils.rand_name(
119 self.__class__.__name__ + '-new-snap')
QingXin Mengdc95f5e2013-09-16 19:06:44 -0700120 new_desc = 'This is the new description of snapshot.'
zhufla57530c2017-03-23 11:38:12 +0800121 params = {'name': new_s_name,
122 'description': new_desc}
John Warrenff7faf62015-08-17 16:59:06 +0000123 update_snapshot = self.snapshots_client.update_snapshot(
124 snapshot['id'], **params)['snapshot']
QingXin Mengdc95f5e2013-09-16 19:06:44 -0700125 # Assert response body for update_snapshot method
zhufla57530c2017-03-23 11:38:12 +0800126 self.assertEqual(new_s_name, update_snapshot['name'])
127 self.assertEqual(new_desc, update_snapshot['description'])
Ken'ichi Ohmichi35798fb2015-04-06 01:22:41 +0000128 # Assert response body for show_snapshot method
John Warrenff7faf62015-08-17 16:59:06 +0000129 updated_snapshot = self.snapshots_client.show_snapshot(
130 snapshot['id'])['snapshot']
zhufla57530c2017-03-23 11:38:12 +0800131 self.assertEqual(new_s_name, updated_snapshot['name'])
132 self.assertEqual(new_desc, updated_snapshot['description'])
QingXin Mengdc95f5e2013-09-16 19:06:44 -0700133
Giulio Fidentef41b8ee2013-05-21 11:07:21 +0200134 # Delete the snapshot
lkuchlan5b2b3622017-02-14 15:48:36 +0200135 self.delete_snapshot(snapshot['id'])
Giulio Fidentef41b8ee2013-05-21 11:07:21 +0200136
Ken'ichi Ohmichi6b279c72017-01-27 18:26:59 -0800137 @decorators.idempotent_id('677863d1-3142-456d-b6ac-9924f667a7f4')
Giulio Fidente73332932013-05-03 18:04:09 +0200138 def test_volume_from_snapshot(self):
jeremy.zhang681dff82017-04-06 19:21:01 +0800139 # Creates a volume from a snapshot passing a size
140 # different from the source
Erlon R. Cruz8dbbc292016-06-17 15:40:36 -0300141 src_size = CONF.volume.volume_size
142
143 src_vol = self.create_volume(size=src_size)
144 src_snap = self.create_snapshot(src_vol['id'])
145 # Destination volume bigger than source snapshot
146 dst_vol = self.create_volume(snapshot_id=src_snap['id'],
147 size=src_size + 1)
zhufld37b6a72016-11-29 16:56:01 +0800148 # NOTE(zhufl): dst_vol is created based on snapshot, so dst_vol
149 # should be deleted before deleting snapshot, otherwise deleting
150 # snapshot will end with status 'error-deleting'. This depends on
151 # the implementation mechanism of vendors, generally speaking,
152 # some verdors will use "virtual disk clone" which will promote
153 # disk clone speed, and in this situation the "disk clone"
154 # is just a relationship between volume and snapshot.
155 self.addCleanup(self.delete_volume, self.volumes_client, dst_vol['id'])
Erlon R. Cruz8dbbc292016-06-17 15:40:36 -0300156
157 volume = self.volumes_client.show_volume(dst_vol['id'])['volume']
158 # Should allow
159 self.assertEqual(volume['snapshot_id'], src_snap['id'])
Avi Avrahamd77d3d12017-02-15 16:45:25 +0200160 self.assertEqual(volume['size'], src_size + 1)