blob: 9f4ce95117537fc5fcc17e52d52849adcadf2061 [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
Sean Dague1937d092013-05-17 16:36:38 -040013from tempest.api.volume import base
Fei Long Wangd39431f2015-05-14 11:30:48 +120014from tempest.common.utils import data_utils
Xiao Chen47fcbf42014-01-13 16:42:41 +080015from tempest import config
Ken'ichi Ohmichi6b279c72017-01-27 18:26:59 -080016from tempest.lib import decorators
Masayuki Igawa1edf94f2014-03-04 18:34:16 +090017from tempest import test
Attila Fazekas36b1fcf2013-01-31 16:41:04 +010018
Xiao Chen47fcbf42014-01-13 16:42:41 +080019CONF = config.CONF
Giulio Fidente3a465e32013-05-07 13:38:18 +020020
Attila Fazekas36b1fcf2013-01-31 16:41:04 +010021
Zhi Kun Liu38641c62014-07-10 20:12:48 +080022class VolumesV2SnapshotTestJSON(base.BaseVolumeTest):
Attila Fazekas36b1fcf2013-01-31 16:41:04 +010023
Giulio Fidente73332932013-05-03 18:04:09 +020024 @classmethod
Rohan Kanade05749152015-01-30 17:15:18 +053025 def skip_checks(cls):
26 super(VolumesV2SnapshotTestJSON, cls).skip_checks()
27 if not CONF.volume_feature_enabled.snapshot:
28 raise cls.skipException("Cinder volume snapshots are disabled")
29
30 @classmethod
Andrea Frittoli61a12e22014-09-15 13:14:54 +010031 def resource_setup(cls):
32 super(VolumesV2SnapshotTestJSON, cls).resource_setup()
Zhi Kun Liu43f9af12014-03-19 21:01:35 +080033 cls.volume_origin = cls.create_volume()
Zhi Kun Liu38641c62014-07-10 20:12:48 +080034 cls.name_field = cls.special_fields['name_field']
35 cls.descrip_field = cls.special_fields['descrip_field']
Giulio Fidente73332932013-05-03 18:04:09 +020036
zhufl95a50e92016-10-09 17:38:56 +080037 def cleanup_snapshot(self, snapshot):
38 # Delete the snapshot
39 self.snapshots_client.delete_snapshot(snapshot['id'])
40 self.snapshots_client.wait_for_resource_deletion(snapshot['id'])
41 self.snapshots.remove(snapshot)
Xiao Chen47fcbf42014-01-13 16:42:41 +080042
Ken'ichi Ohmichi6b279c72017-01-27 18:26:59 -080043 @decorators.idempotent_id('b467b54c-07a4-446d-a1cf-651dedcc3ff1')
Matthew Treinish7ea69e62014-06-03 17:23:50 -040044 @test.services('compute')
Xiao Chen47fcbf42014-01-13 16:42:41 +080045 def test_snapshot_create_with_volume_in_use(self):
46 # Create a snapshot when volume status is in-use
47 # Create a test instance
zhufl7867a6e2016-10-18 15:37:12 +080048 server = self.create_server(wait_until='ACTIVE')
Erlon R. Cruzba19bc72016-09-28 14:32:11 -030049 self.attach_volume(server['id'], self.volume_origin['id'])
50
Xiao Chen47fcbf42014-01-13 16:42:41 +080051 # Snapshot a volume even if it's attached to an instance
52 snapshot = self.create_snapshot(self.volume_origin['id'],
53 force=True)
54 # Delete the snapshot
Yuriy Nesenenko551e1a92015-09-11 18:26:05 +030055 self.cleanup_snapshot(snapshot)
Xiao Chen47fcbf42014-01-13 16:42:41 +080056
Ken'ichi Ohmichi6b279c72017-01-27 18:26:59 -080057 @decorators.idempotent_id('8567b54c-4455-446d-a1cf-651ddeaa3ff2')
Erlon R. Cruzba19bc72016-09-28 14:32:11 -030058 @test.services('compute')
59 def test_snapshot_delete_with_volume_in_use(self):
60 # Create a test instance
61 server = self.create_server(wait_until='ACTIVE')
62 self.attach_volume(server['id'], self.volume_origin['id'])
63
64 # Snapshot a volume attached to an instance
65 snapshot1 = self.create_snapshot(self.volume_origin['id'], force=True)
66 snapshot2 = self.create_snapshot(self.volume_origin['id'], force=True)
67 snapshot3 = self.create_snapshot(self.volume_origin['id'], force=True)
68
69 # Delete the snapshots. Some snapshot implementations can take
70 # different paths according to order they are deleted.
71 self.cleanup_snapshot(snapshot1)
72 self.cleanup_snapshot(snapshot3)
73 self.cleanup_snapshot(snapshot2)
74
Ken'ichi Ohmichi6b279c72017-01-27 18:26:59 -080075 @decorators.idempotent_id('5210a1de-85a0-11e6-bb21-641c676a5d61')
Erlon R. Cruzba19bc72016-09-28 14:32:11 -030076 @test.services('compute')
77 def test_snapshot_create_offline_delete_online(self):
78
79 # Create a snapshot while it is not attached
80 snapshot1 = self.create_snapshot(self.volume_origin['id'])
81
82 # Create a server and attach it
83 server = self.create_server(wait_until='ACTIVE')
84 self.attach_volume(server['id'], self.volume_origin['id'])
85
86 # Now that the volume is attached, create another snapshots
87 snapshot2 = self.create_snapshot(self.volume_origin['id'], force=True)
88 snapshot3 = self.create_snapshot(self.volume_origin['id'], force=True)
89
90 # Delete the snapshots. Some snapshot implementations can take
91 # different paths according to order they are deleted.
92 self.cleanup_snapshot(snapshot3)
93 self.cleanup_snapshot(snapshot1)
94 self.cleanup_snapshot(snapshot2)
95
Ken'ichi Ohmichi6b279c72017-01-27 18:26:59 -080096 @decorators.idempotent_id('2a8abbe4-d871-46db-b049-c41f5af8216e')
QingXin Mengdc95f5e2013-09-16 19:06:44 -070097 def test_snapshot_create_get_list_update_delete(self):
Giulio Fidentef41b8ee2013-05-21 11:07:21 +020098 # Create a snapshot
zhufl354b2fb2016-10-24 15:24:22 +080099 snapshot = self.create_snapshot(self.volume_origin['id'])
Giulio Fidente73332932013-05-03 18:04:09 +0200100
Giulio Fidentef41b8ee2013-05-21 11:07:21 +0200101 # Get the snap and check for some of its details
John Warrenff7faf62015-08-17 16:59:06 +0000102 snap_get = self.snapshots_client.show_snapshot(
103 snapshot['id'])['snapshot']
Giulio Fidentef41b8ee2013-05-21 11:07:21 +0200104 self.assertEqual(self.volume_origin['id'],
105 snap_get['volume_id'],
106 "Referred volume origin mismatch")
107
108 # Compare also with the output from the list action
Zhi Kun Liu38641c62014-07-10 20:12:48 +0800109 tracking_data = (snapshot['id'], snapshot[self.name_field])
John Warrenff7faf62015-08-17 16:59:06 +0000110 snaps_list = self.snapshots_client.list_snapshots()['snapshots']
Zhi Kun Liu38641c62014-07-10 20:12:48 +0800111 snaps_data = [(f['id'], f[self.name_field]) for f in snaps_list]
Giulio Fidentef41b8ee2013-05-21 11:07:21 +0200112 self.assertIn(tracking_data, snaps_data)
113
QingXin Mengdc95f5e2013-09-16 19:06:44 -0700114 # Updates snapshot with new values
zhuflc6ce5392016-08-17 14:34:37 +0800115 new_s_name = data_utils.rand_name(
116 self.__class__.__name__ + '-new-snap')
QingXin Mengdc95f5e2013-09-16 19:06:44 -0700117 new_desc = 'This is the new description of snapshot.'
Zhi Kun Liu38641c62014-07-10 20:12:48 +0800118 params = {self.name_field: new_s_name,
119 self.descrip_field: new_desc}
John Warrenff7faf62015-08-17 16:59:06 +0000120 update_snapshot = self.snapshots_client.update_snapshot(
121 snapshot['id'], **params)['snapshot']
QingXin Mengdc95f5e2013-09-16 19:06:44 -0700122 # Assert response body for update_snapshot method
Zhi Kun Liu38641c62014-07-10 20:12:48 +0800123 self.assertEqual(new_s_name, update_snapshot[self.name_field])
124 self.assertEqual(new_desc, update_snapshot[self.descrip_field])
Ken'ichi Ohmichi35798fb2015-04-06 01:22:41 +0000125 # Assert response body for show_snapshot method
John Warrenff7faf62015-08-17 16:59:06 +0000126 updated_snapshot = self.snapshots_client.show_snapshot(
127 snapshot['id'])['snapshot']
Zhi Kun Liu38641c62014-07-10 20:12:48 +0800128 self.assertEqual(new_s_name, updated_snapshot[self.name_field])
129 self.assertEqual(new_desc, updated_snapshot[self.descrip_field])
QingXin Mengdc95f5e2013-09-16 19:06:44 -0700130
Giulio Fidentef41b8ee2013-05-21 11:07:21 +0200131 # Delete the snapshot
Yuriy Nesenenko551e1a92015-09-11 18:26:05 +0300132 self.cleanup_snapshot(snapshot)
Giulio Fidentef41b8ee2013-05-21 11:07:21 +0200133
Ken'ichi Ohmichi6b279c72017-01-27 18:26:59 -0800134 @decorators.idempotent_id('677863d1-3142-456d-b6ac-9924f667a7f4')
Giulio Fidente73332932013-05-03 18:04:09 +0200135 def test_volume_from_snapshot(self):
Erlon R. Cruz8dbbc292016-06-17 15:40:36 -0300136 # Creates a volume a snapshot passing a size different from the source
137 src_size = CONF.volume.volume_size
138
139 src_vol = self.create_volume(size=src_size)
140 src_snap = self.create_snapshot(src_vol['id'])
141 # Destination volume bigger than source snapshot
142 dst_vol = self.create_volume(snapshot_id=src_snap['id'],
143 size=src_size + 1)
zhufld37b6a72016-11-29 16:56:01 +0800144 # NOTE(zhufl): dst_vol is created based on snapshot, so dst_vol
145 # should be deleted before deleting snapshot, otherwise deleting
146 # snapshot will end with status 'error-deleting'. This depends on
147 # the implementation mechanism of vendors, generally speaking,
148 # some verdors will use "virtual disk clone" which will promote
149 # disk clone speed, and in this situation the "disk clone"
150 # is just a relationship between volume and snapshot.
151 self.addCleanup(self.delete_volume, self.volumes_client, dst_vol['id'])
Erlon R. Cruz8dbbc292016-06-17 15:40:36 -0300152
153 volume = self.volumes_client.show_volume(dst_vol['id'])['volume']
154 # Should allow
155 self.assertEqual(volume['snapshot_id'], src_snap['id'])
Avi Avrahamd77d3d12017-02-15 16:45:25 +0200156 self.assertEqual(volume['size'], src_size + 1)
Yuriy Nesenenko551e1a92015-09-11 18:26:05 +0300157
Attila Fazekas36b1fcf2013-01-31 16:41:04 +0100158
Zhi Kun Liu38641c62014-07-10 20:12:48 +0800159class VolumesV1SnapshotTestJSON(VolumesV2SnapshotTestJSON):
160 _api_version = 1