blob: 20c647a87c21c537c07ce531451b77def239a513 [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
Yaroslav Lobankoved3a35b2016-03-24 22:41:30 -050015from tempest.common import waiters
Xiao Chen47fcbf42014-01-13 16:42:41 +080016from tempest import config
lkuchlan755c6ee2016-03-30 15:55:35 +030017from tempest.lib import decorators
Masayuki Igawa1edf94f2014-03-04 18:34:16 +090018from tempest import test
Attila Fazekas36b1fcf2013-01-31 16:41:04 +010019
Xiao Chen47fcbf42014-01-13 16:42:41 +080020CONF = config.CONF
Giulio Fidente3a465e32013-05-07 13:38:18 +020021
Attila Fazekas36b1fcf2013-01-31 16:41:04 +010022
Zhi Kun Liu38641c62014-07-10 20:12:48 +080023class VolumesV2SnapshotTestJSON(base.BaseVolumeTest):
Attila Fazekas36b1fcf2013-01-31 16:41:04 +010024
Giulio Fidente73332932013-05-03 18:04:09 +020025 @classmethod
Rohan Kanade05749152015-01-30 17:15:18 +053026 def skip_checks(cls):
27 super(VolumesV2SnapshotTestJSON, cls).skip_checks()
28 if not CONF.volume_feature_enabled.snapshot:
29 raise cls.skipException("Cinder volume snapshots are disabled")
30
31 @classmethod
Andrea Frittoli61a12e22014-09-15 13:14:54 +010032 def resource_setup(cls):
33 super(VolumesV2SnapshotTestJSON, cls).resource_setup()
Zhi Kun Liu43f9af12014-03-19 21:01:35 +080034 cls.volume_origin = cls.create_volume()
Giulio Fidente73332932013-05-03 18:04:09 +020035
Zhi Kun Liu38641c62014-07-10 20:12:48 +080036 cls.name_field = cls.special_fields['name_field']
37 cls.descrip_field = cls.special_fields['descrip_field']
lkuchlan755c6ee2016-03-30 15:55:35 +030038 # Create 2 snapshots
39 for _ in xrange(2):
40 cls.create_snapshot(cls.volume_origin['id'])
Giulio Fidente73332932013-05-03 18:04:09 +020041
Xiao Chen47fcbf42014-01-13 16:42:41 +080042 def _detach(self, volume_id):
43 """Detach volume."""
44 self.volumes_client.detach_volume(volume_id)
Yaroslav Lobankoved3a35b2016-03-24 22:41:30 -050045 waiters.wait_for_volume_status(self.volumes_client,
46 volume_id, 'available')
Xiao Chen47fcbf42014-01-13 16:42:41 +080047
Ghanshyam0b75b632015-12-11 15:08:28 +090048 def _list_by_param_values_and_assert(self, with_detail=False, **params):
Ken'ichi Ohmichi9e3dac02015-11-19 07:01:07 +000049 """list or list_details with given params and validates result."""
50
Abhijeet Malawade5945ffe2013-09-17 05:54:44 -070051 if with_detail:
John Warrenff7faf62015-08-17 16:59:06 +000052 fetched_snap_list = self.snapshots_client.list_snapshots(
Ghanshyam0b75b632015-12-11 15:08:28 +090053 detail=True, **params)['snapshots']
Abhijeet Malawade5945ffe2013-09-17 05:54:44 -070054 else:
John Warrenff7faf62015-08-17 16:59:06 +000055 fetched_snap_list = self.snapshots_client.list_snapshots(
Ghanshyam0b75b632015-12-11 15:08:28 +090056 **params)['snapshots']
Abhijeet Malawade5945ffe2013-09-17 05:54:44 -070057
Abhijeet Malawade5945ffe2013-09-17 05:54:44 -070058 # Validating params of fetched snapshots
59 for snap in fetched_snap_list:
60 for key in params:
61 msg = "Failed to list snapshots %s by %s" % \
62 ('details' if with_detail else '', key)
63 self.assertEqual(params[key], snap[key], msg)
64
lkuchlan755c6ee2016-03-30 15:55:35 +030065 def _list_snapshots_by_param_limit(self, limit, expected_elements):
66 """list snapshots by limit param"""
67 # Get snapshots list using limit parameter
68 fetched_snap_list = self.snapshots_client.list_snapshots(
69 limit=limit)['snapshots']
70 # Validating filtered snapshots length equals to expected_elements
71 self.assertEqual(expected_elements, len(fetched_snap_list))
72
Chris Hoge7579c1a2015-02-26 14:12:15 -080073 @test.idempotent_id('b467b54c-07a4-446d-a1cf-651dedcc3ff1')
Matthew Treinish7ea69e62014-06-03 17:23:50 -040074 @test.services('compute')
Xiao Chen47fcbf42014-01-13 16:42:41 +080075 def test_snapshot_create_with_volume_in_use(self):
76 # Create a snapshot when volume status is in-use
77 # Create a test instance
zhuflc6ce5392016-08-17 14:34:37 +080078 server_name = data_utils.rand_name(
79 self.__class__.__name__ + '-instance')
Joseph Lanouxa074c012015-08-04 15:44:07 +000080 server = self.create_server(
81 name=server_name,
82 wait_until='ACTIVE')
Xiao Chen47fcbf42014-01-13 16:42:41 +080083 self.addCleanup(self.servers_client.delete_server, server['id'])
David Kranz3ebc7212015-02-10 12:19:19 -050084 self.servers_client.attach_volume(
Ken'ichi Ohmichidfc88de2015-08-13 05:12:20 +000085 server['id'], volumeId=self.volume_origin['id'],
bkopilovbc830d02016-03-27 14:09:47 +030086 device='/dev/%s' % CONF.compute.volume_device_name)
Yaroslav Lobankoved3a35b2016-03-24 22:41:30 -050087 waiters.wait_for_volume_status(self.volumes_client,
88 self.volume_origin['id'], 'in-use')
89 self.addCleanup(waiters.wait_for_volume_status, self.volumes_client,
Mitsuhiro Taninoab667962014-12-10 15:52:08 -050090 self.volume_origin['id'], 'available')
91 self.addCleanup(self.servers_client.detach_volume, server['id'],
92 self.volume_origin['id'])
Xiao Chen47fcbf42014-01-13 16:42:41 +080093 # Snapshot a volume even if it's attached to an instance
94 snapshot = self.create_snapshot(self.volume_origin['id'],
95 force=True)
96 # Delete the snapshot
Yuriy Nesenenko551e1a92015-09-11 18:26:05 +030097 self.cleanup_snapshot(snapshot)
Xiao Chen47fcbf42014-01-13 16:42:41 +080098
Chris Hoge7579c1a2015-02-26 14:12:15 -080099 @test.idempotent_id('2a8abbe4-d871-46db-b049-c41f5af8216e')
QingXin Mengdc95f5e2013-09-16 19:06:44 -0700100 def test_snapshot_create_get_list_update_delete(self):
Giulio Fidentef41b8ee2013-05-21 11:07:21 +0200101 # Create a snapshot
zhuflc6ce5392016-08-17 14:34:37 +0800102 s_name = data_utils.rand_name(self.__class__.__name__ + '-snap')
Zhi Kun Liu38641c62014-07-10 20:12:48 +0800103 params = {self.name_field: s_name}
104 snapshot = self.create_snapshot(self.volume_origin['id'], **params)
Giulio Fidente73332932013-05-03 18:04:09 +0200105
Giulio Fidentef41b8ee2013-05-21 11:07:21 +0200106 # Get the snap and check for some of its details
John Warrenff7faf62015-08-17 16:59:06 +0000107 snap_get = self.snapshots_client.show_snapshot(
108 snapshot['id'])['snapshot']
Giulio Fidentef41b8ee2013-05-21 11:07:21 +0200109 self.assertEqual(self.volume_origin['id'],
110 snap_get['volume_id'],
111 "Referred volume origin mismatch")
112
113 # Compare also with the output from the list action
Zhi Kun Liu38641c62014-07-10 20:12:48 +0800114 tracking_data = (snapshot['id'], snapshot[self.name_field])
John Warrenff7faf62015-08-17 16:59:06 +0000115 snaps_list = self.snapshots_client.list_snapshots()['snapshots']
Zhi Kun Liu38641c62014-07-10 20:12:48 +0800116 snaps_data = [(f['id'], f[self.name_field]) for f in snaps_list]
Giulio Fidentef41b8ee2013-05-21 11:07:21 +0200117 self.assertIn(tracking_data, snaps_data)
118
QingXin Mengdc95f5e2013-09-16 19:06:44 -0700119 # Updates snapshot with new values
zhuflc6ce5392016-08-17 14:34:37 +0800120 new_s_name = data_utils.rand_name(
121 self.__class__.__name__ + '-new-snap')
QingXin Mengdc95f5e2013-09-16 19:06:44 -0700122 new_desc = 'This is the new description of snapshot.'
Zhi Kun Liu38641c62014-07-10 20:12:48 +0800123 params = {self.name_field: new_s_name,
124 self.descrip_field: new_desc}
John Warrenff7faf62015-08-17 16:59:06 +0000125 update_snapshot = self.snapshots_client.update_snapshot(
126 snapshot['id'], **params)['snapshot']
QingXin Mengdc95f5e2013-09-16 19:06:44 -0700127 # Assert response body for update_snapshot method
Zhi Kun Liu38641c62014-07-10 20:12:48 +0800128 self.assertEqual(new_s_name, update_snapshot[self.name_field])
129 self.assertEqual(new_desc, update_snapshot[self.descrip_field])
Ken'ichi Ohmichi35798fb2015-04-06 01:22:41 +0000130 # Assert response body for show_snapshot method
John Warrenff7faf62015-08-17 16:59:06 +0000131 updated_snapshot = self.snapshots_client.show_snapshot(
132 snapshot['id'])['snapshot']
Zhi Kun Liu38641c62014-07-10 20:12:48 +0800133 self.assertEqual(new_s_name, updated_snapshot[self.name_field])
134 self.assertEqual(new_desc, updated_snapshot[self.descrip_field])
QingXin Mengdc95f5e2013-09-16 19:06:44 -0700135
Giulio Fidentef41b8ee2013-05-21 11:07:21 +0200136 # Delete the snapshot
Yuriy Nesenenko551e1a92015-09-11 18:26:05 +0300137 self.cleanup_snapshot(snapshot)
Giulio Fidentef41b8ee2013-05-21 11:07:21 +0200138
Chris Hoge7579c1a2015-02-26 14:12:15 -0800139 @test.idempotent_id('59f41f43-aebf-48a9-ab5d-d76340fab32b')
Abhijeet Malawade5945ffe2013-09-17 05:54:44 -0700140 def test_snapshots_list_with_params(self):
141 """list snapshots with params."""
142 # Create a snapshot
zhuflc6ce5392016-08-17 14:34:37 +0800143 display_name = data_utils.rand_name(self.__class__.__name__ + '-snap')
Zhi Kun Liu38641c62014-07-10 20:12:48 +0800144 params = {self.name_field: display_name}
145 snapshot = self.create_snapshot(self.volume_origin['id'], **params)
Yuriy Nesenenko551e1a92015-09-11 18:26:05 +0300146 self.addCleanup(self.cleanup_snapshot, snapshot)
Abhijeet Malawade5945ffe2013-09-17 05:54:44 -0700147
148 # Verify list snapshots by display_name filter
Zhi Kun Liu38641c62014-07-10 20:12:48 +0800149 params = {self.name_field: snapshot[self.name_field]}
Ghanshyam0b75b632015-12-11 15:08:28 +0900150 self._list_by_param_values_and_assert(**params)
Abhijeet Malawade5945ffe2013-09-17 05:54:44 -0700151
152 # Verify list snapshots by status filter
153 params = {'status': 'available'}
Ghanshyam0b75b632015-12-11 15:08:28 +0900154 self._list_by_param_values_and_assert(**params)
Abhijeet Malawade5945ffe2013-09-17 05:54:44 -0700155
156 # Verify list snapshots by status and display name filter
157 params = {'status': 'available',
Zhi Kun Liu38641c62014-07-10 20:12:48 +0800158 self.name_field: snapshot[self.name_field]}
Ghanshyam0b75b632015-12-11 15:08:28 +0900159 self._list_by_param_values_and_assert(**params)
Abhijeet Malawade5945ffe2013-09-17 05:54:44 -0700160
Chris Hoge7579c1a2015-02-26 14:12:15 -0800161 @test.idempotent_id('220a1022-1fcd-4a74-a7bd-6b859156cda2')
Abhijeet Malawade5945ffe2013-09-17 05:54:44 -0700162 def test_snapshots_list_details_with_params(self):
163 """list snapshot details with params."""
164 # Create a snapshot
zhuflc6ce5392016-08-17 14:34:37 +0800165 display_name = data_utils.rand_name(self.__class__.__name__ + '-snap')
Zhi Kun Liu38641c62014-07-10 20:12:48 +0800166 params = {self.name_field: display_name}
167 snapshot = self.create_snapshot(self.volume_origin['id'], **params)
Yuriy Nesenenko551e1a92015-09-11 18:26:05 +0300168 self.addCleanup(self.cleanup_snapshot, snapshot)
Abhijeet Malawade5945ffe2013-09-17 05:54:44 -0700169
170 # Verify list snapshot details by display_name filter
Zhi Kun Liu38641c62014-07-10 20:12:48 +0800171 params = {self.name_field: snapshot[self.name_field]}
Ghanshyam0b75b632015-12-11 15:08:28 +0900172 self._list_by_param_values_and_assert(with_detail=True, **params)
Abhijeet Malawade5945ffe2013-09-17 05:54:44 -0700173 # Verify list snapshot details by status filter
174 params = {'status': 'available'}
Ghanshyam0b75b632015-12-11 15:08:28 +0900175 self._list_by_param_values_and_assert(with_detail=True, **params)
Abhijeet Malawade5945ffe2013-09-17 05:54:44 -0700176 # Verify list snapshot details by status and display name filter
177 params = {'status': 'available',
Zhi Kun Liu38641c62014-07-10 20:12:48 +0800178 self.name_field: snapshot[self.name_field]}
Ghanshyam0b75b632015-12-11 15:08:28 +0900179 self._list_by_param_values_and_assert(with_detail=True, **params)
Abhijeet Malawade5945ffe2013-09-17 05:54:44 -0700180
Chris Hoge7579c1a2015-02-26 14:12:15 -0800181 @test.idempotent_id('677863d1-3142-456d-b6ac-9924f667a7f4')
Giulio Fidente73332932013-05-03 18:04:09 +0200182 def test_volume_from_snapshot(self):
Erlon R. Cruz8dbbc292016-06-17 15:40:36 -0300183 # Creates a volume a snapshot passing a size different from the source
184 src_size = CONF.volume.volume_size
185
186 src_vol = self.create_volume(size=src_size)
187 src_snap = self.create_snapshot(src_vol['id'])
188 # Destination volume bigger than source snapshot
189 dst_vol = self.create_volume(snapshot_id=src_snap['id'],
190 size=src_size + 1)
191
192 volume = self.volumes_client.show_volume(dst_vol['id'])['volume']
193 # Should allow
194 self.assertEqual(volume['snapshot_id'], src_snap['id'])
195 self.assertEqual(int(volume['size']), src_size + 1)
Yuriy Nesenenko551e1a92015-09-11 18:26:05 +0300196
lkuchlan755c6ee2016-03-30 15:55:35 +0300197 @test.idempotent_id('db4d8e0a-7a2e-41cc-a712-961f6844e896')
198 def test_snapshot_list_param_limit(self):
199 # List returns limited elements
200 self._list_snapshots_by_param_limit(limit=1, expected_elements=1)
201
202 @test.idempotent_id('a1427f61-420e-48a5-b6e3-0b394fa95400')
203 def test_snapshot_list_param_limit_equals_infinite(self):
204 # List returns all elements when request limit exceeded
205 # snapshots number
206 snap_list = self.snapshots_client.list_snapshots()['snapshots']
207 self._list_snapshots_by_param_limit(limit=100000,
208 expected_elements=len(snap_list))
209
210 @decorators.skip_because(bug='1540893')
211 @test.idempotent_id('e3b44b7f-ae87-45b5-8a8c-66110eb24d0a')
212 def test_snapshot_list_param_limit_equals_zero(self):
213 # List returns zero elements
214 self._list_snapshots_by_param_limit(limit=0, expected_elements=0)
215
Yuriy Nesenenko551e1a92015-09-11 18:26:05 +0300216 def cleanup_snapshot(self, snapshot):
217 # Delete the snapshot
218 self.snapshots_client.delete_snapshot(snapshot['id'])
219 self.snapshots_client.wait_for_resource_deletion(snapshot['id'])
220 self.snapshots.remove(snapshot)
Attila Fazekas36b1fcf2013-01-31 16:41:04 +0100221
222
Zhi Kun Liu38641c62014-07-10 20:12:48 +0800223class VolumesV1SnapshotTestJSON(VolumesV2SnapshotTestJSON):
224 _api_version = 1