blob: e68ab7e2a28a43dfd78efee0dd8a24c11bd91924 [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
Benny Kopilovcdcf53c2017-03-29 07:25:05 +030013import testtools
lkuchland8277372017-02-22 15:07:52 +020014from testtools import matchers
15
Sean Dague1937d092013-05-17 16:36:38 -040016from tempest.api.volume import base
Xiao Chen47fcbf42014-01-13 16:42:41 +080017from tempest import config
Ken'ichi Ohmichief1c1ce2017-03-10 11:07:10 -080018from tempest.lib.common.utils import data_utils
Ken'ichi Ohmichi6b279c72017-01-27 18:26:59 -080019from tempest.lib import decorators
lianghao6c011992017-04-24 20:50:59 +080020from tempest.lib import exceptions as lib_exc
Masayuki Igawa1edf94f2014-03-04 18:34:16 +090021from tempest import test
Attila Fazekas36b1fcf2013-01-31 16:41:04 +010022
Xiao Chen47fcbf42014-01-13 16:42:41 +080023CONF = config.CONF
Giulio Fidente3a465e32013-05-07 13:38:18 +020024
Attila Fazekas36b1fcf2013-01-31 16:41:04 +010025
Ken'ichi Ohmichie8afb8c2017-03-27 11:25:37 -070026class VolumesSnapshotTestJSON(base.BaseVolumeTest):
Attila Fazekas36b1fcf2013-01-31 16:41:04 +010027
Giulio Fidente73332932013-05-03 18:04:09 +020028 @classmethod
Rohan Kanade05749152015-01-30 17:15:18 +053029 def skip_checks(cls):
Ken'ichi Ohmichie8afb8c2017-03-27 11:25:37 -070030 super(VolumesSnapshotTestJSON, cls).skip_checks()
Rohan Kanade05749152015-01-30 17:15:18 +053031 if not CONF.volume_feature_enabled.snapshot:
32 raise cls.skipException("Cinder volume snapshots are disabled")
33
34 @classmethod
Andrea Frittoli61a12e22014-09-15 13:14:54 +010035 def resource_setup(cls):
Ken'ichi Ohmichie8afb8c2017-03-27 11:25:37 -070036 super(VolumesSnapshotTestJSON, cls).resource_setup()
Zhi Kun Liu43f9af12014-03-19 21:01:35 +080037 cls.volume_origin = cls.create_volume()
Giulio Fidente73332932013-05-03 18:04:09 +020038
zhufl529eefa2017-05-12 16:00:32 +080039 @decorators.idempotent_id('8567b54c-4455-446d-a1cf-651ddeaa3ff2')
Matthew Treinish7ea69e62014-06-03 17:23:50 -040040 @test.services('compute')
zhufl529eefa2017-05-12 16:00:32 +080041 def test_snapshot_create_delete_with_volume_in_use(self):
Xiao Chen47fcbf42014-01-13 16:42:41 +080042 # Create a test instance
lkuchland4ecd0e2017-06-11 12:01:27 +030043 server = self.create_server()
Erlon R. Cruzba19bc72016-09-28 14:32:11 -030044 self.attach_volume(server['id'], self.volume_origin['id'])
45
lianghao6c011992017-04-24 20:50:59 +080046 # Snapshot a volume which attached to an instance with force=False
47 self.assertRaises(lib_exc.BadRequest, self.create_snapshot,
48 self.volume_origin['id'], force=False)
49
Erlon R. Cruzba19bc72016-09-28 14:32:11 -030050 # Snapshot a volume attached to an instance
51 snapshot1 = self.create_snapshot(self.volume_origin['id'], force=True)
52 snapshot2 = self.create_snapshot(self.volume_origin['id'], force=True)
53 snapshot3 = self.create_snapshot(self.volume_origin['id'], force=True)
54
55 # Delete the snapshots. Some snapshot implementations can take
56 # different paths according to order they are deleted.
lkuchlan5b2b3622017-02-14 15:48:36 +020057 self.delete_snapshot(snapshot1['id'])
58 self.delete_snapshot(snapshot3['id'])
59 self.delete_snapshot(snapshot2['id'])
Erlon R. Cruzba19bc72016-09-28 14:32:11 -030060
Ken'ichi Ohmichi6b279c72017-01-27 18:26:59 -080061 @decorators.idempotent_id('5210a1de-85a0-11e6-bb21-641c676a5d61')
Erlon R. Cruzba19bc72016-09-28 14:32:11 -030062 @test.services('compute')
63 def test_snapshot_create_offline_delete_online(self):
64
65 # Create a snapshot while it is not attached
66 snapshot1 = self.create_snapshot(self.volume_origin['id'])
67
68 # Create a server and attach it
lkuchland4ecd0e2017-06-11 12:01:27 +030069 server = self.create_server()
Erlon R. Cruzba19bc72016-09-28 14:32:11 -030070 self.attach_volume(server['id'], self.volume_origin['id'])
71
72 # Now that the volume is attached, create another snapshots
73 snapshot2 = self.create_snapshot(self.volume_origin['id'], force=True)
74 snapshot3 = self.create_snapshot(self.volume_origin['id'], force=True)
75
76 # Delete the snapshots. Some snapshot implementations can take
77 # different paths according to order they are deleted.
lkuchlan5b2b3622017-02-14 15:48:36 +020078 self.delete_snapshot(snapshot3['id'])
79 self.delete_snapshot(snapshot1['id'])
80 self.delete_snapshot(snapshot2['id'])
Erlon R. Cruzba19bc72016-09-28 14:32:11 -030081
Ken'ichi Ohmichi6b279c72017-01-27 18:26:59 -080082 @decorators.idempotent_id('2a8abbe4-d871-46db-b049-c41f5af8216e')
QingXin Mengdc95f5e2013-09-16 19:06:44 -070083 def test_snapshot_create_get_list_update_delete(self):
lkuchland8277372017-02-22 15:07:52 +020084 # Create a snapshot with metadata
85 metadata = {"snap-meta1": "value1",
86 "snap-meta2": "value2",
87 "snap-meta3": "value3"}
88 snapshot = self.create_snapshot(self.volume_origin['id'],
89 metadata=metadata)
Giulio Fidente73332932013-05-03 18:04:09 +020090
Giulio Fidentef41b8ee2013-05-21 11:07:21 +020091 # Get the snap and check for some of its details
John Warrenff7faf62015-08-17 16:59:06 +000092 snap_get = self.snapshots_client.show_snapshot(
93 snapshot['id'])['snapshot']
Giulio Fidentef41b8ee2013-05-21 11:07:21 +020094 self.assertEqual(self.volume_origin['id'],
95 snap_get['volume_id'],
96 "Referred volume origin mismatch")
jeremy.zhang681dff82017-04-06 19:21:01 +080097 self.assertEqual(self.volume_origin['size'], snap_get['size'])
Giulio Fidentef41b8ee2013-05-21 11:07:21 +020098
lkuchland8277372017-02-22 15:07:52 +020099 # Verify snapshot metadata
100 self.assertThat(snap_get['metadata'].items(),
101 matchers.ContainsAll(metadata.items()))
102
Giulio Fidentef41b8ee2013-05-21 11:07:21 +0200103 # Compare also with the output from the list action
zhufla57530c2017-03-23 11:38:12 +0800104 tracking_data = (snapshot['id'], snapshot['name'])
John Warrenff7faf62015-08-17 16:59:06 +0000105 snaps_list = self.snapshots_client.list_snapshots()['snapshots']
zhufla57530c2017-03-23 11:38:12 +0800106 snaps_data = [(f['id'], f['name']) for f in snaps_list]
Giulio Fidentef41b8ee2013-05-21 11:07:21 +0200107 self.assertIn(tracking_data, snaps_data)
108
QingXin Mengdc95f5e2013-09-16 19:06:44 -0700109 # Updates snapshot with new values
zhuflc6ce5392016-08-17 14:34:37 +0800110 new_s_name = data_utils.rand_name(
111 self.__class__.__name__ + '-new-snap')
QingXin Mengdc95f5e2013-09-16 19:06:44 -0700112 new_desc = 'This is the new description of snapshot.'
zhufla57530c2017-03-23 11:38:12 +0800113 params = {'name': new_s_name,
114 'description': new_desc}
John Warrenff7faf62015-08-17 16:59:06 +0000115 update_snapshot = self.snapshots_client.update_snapshot(
116 snapshot['id'], **params)['snapshot']
QingXin Mengdc95f5e2013-09-16 19:06:44 -0700117 # Assert response body for update_snapshot method
zhufla57530c2017-03-23 11:38:12 +0800118 self.assertEqual(new_s_name, update_snapshot['name'])
119 self.assertEqual(new_desc, update_snapshot['description'])
Ken'ichi Ohmichi35798fb2015-04-06 01:22:41 +0000120 # Assert response body for show_snapshot method
John Warrenff7faf62015-08-17 16:59:06 +0000121 updated_snapshot = self.snapshots_client.show_snapshot(
122 snapshot['id'])['snapshot']
zhufla57530c2017-03-23 11:38:12 +0800123 self.assertEqual(new_s_name, updated_snapshot['name'])
124 self.assertEqual(new_desc, updated_snapshot['description'])
QingXin Mengdc95f5e2013-09-16 19:06:44 -0700125
Giulio Fidentef41b8ee2013-05-21 11:07:21 +0200126 # Delete the snapshot
lkuchlan5b2b3622017-02-14 15:48:36 +0200127 self.delete_snapshot(snapshot['id'])
Giulio Fidentef41b8ee2013-05-21 11:07:21 +0200128
Ken'ichi Ohmichi6b279c72017-01-27 18:26:59 -0800129 @decorators.idempotent_id('677863d1-3142-456d-b6ac-9924f667a7f4')
Giulio Fidente73332932013-05-03 18:04:09 +0200130 def test_volume_from_snapshot(self):
jeremy.zhang681dff82017-04-06 19:21:01 +0800131 # Creates a volume from a snapshot passing a size
132 # different from the source
Erlon R. Cruz8dbbc292016-06-17 15:40:36 -0300133 src_size = CONF.volume.volume_size
134
135 src_vol = self.create_volume(size=src_size)
136 src_snap = self.create_snapshot(src_vol['id'])
137 # Destination volume bigger than source snapshot
138 dst_vol = self.create_volume(snapshot_id=src_snap['id'],
139 size=src_size + 1)
zhufld37b6a72016-11-29 16:56:01 +0800140 # NOTE(zhufl): dst_vol is created based on snapshot, so dst_vol
141 # should be deleted before deleting snapshot, otherwise deleting
142 # snapshot will end with status 'error-deleting'. This depends on
143 # the implementation mechanism of vendors, generally speaking,
144 # some verdors will use "virtual disk clone" which will promote
145 # disk clone speed, and in this situation the "disk clone"
146 # is just a relationship between volume and snapshot.
147 self.addCleanup(self.delete_volume, self.volumes_client, dst_vol['id'])
Erlon R. Cruz8dbbc292016-06-17 15:40:36 -0300148
149 volume = self.volumes_client.show_volume(dst_vol['id'])['volume']
150 # Should allow
151 self.assertEqual(volume['snapshot_id'], src_snap['id'])
Avi Avrahamd77d3d12017-02-15 16:45:25 +0200152 self.assertEqual(volume['size'], src_size + 1)
Benny Kopilovcdcf53c2017-03-29 07:25:05 +0300153
154 @decorators.idempotent_id('bbcfa285-af7f-479e-8c1a-8c34fc16543c')
155 @testtools.skipUnless(CONF.volume_feature_enabled.backup,
156 "Cinder backup is disabled")
157 def test_snapshot_backup(self):
158 # Create a snapshot
159 snapshot = self.create_snapshot(volume_id=self.volume_origin['id'])
160
161 backup = self.create_backup(volume_id=self.volume_origin['id'],
162 snapshot_id=snapshot['id'])
163 backup_info = self.backups_client.show_backup(backup['id'])['backup']
164 self.assertEqual(self.volume_origin['id'], backup_info['volume_id'])
165 self.assertEqual(snapshot['id'], backup_info['snapshot_id'])