blob: 6707121ef994ed4204120f9faeadb7b35984cc60 [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
Ken'ichi Ohmichi07308f12015-03-23 00:24:28 +000078 server_name = data_utils.rand_name('instance')
Joseph Lanouxa074c012015-08-04 15:44:07 +000079 server = self.create_server(
80 name=server_name,
81 wait_until='ACTIVE')
Xiao Chen47fcbf42014-01-13 16:42:41 +080082 self.addCleanup(self.servers_client.delete_server, server['id'])
David Kranz3ebc7212015-02-10 12:19:19 -050083 self.servers_client.attach_volume(
Ken'ichi Ohmichidfc88de2015-08-13 05:12:20 +000084 server['id'], volumeId=self.volume_origin['id'],
bkopilovbc830d02016-03-27 14:09:47 +030085 device='/dev/%s' % CONF.compute.volume_device_name)
Yaroslav Lobankoved3a35b2016-03-24 22:41:30 -050086 waiters.wait_for_volume_status(self.volumes_client,
87 self.volume_origin['id'], 'in-use')
88 self.addCleanup(waiters.wait_for_volume_status, self.volumes_client,
Mitsuhiro Taninoab667962014-12-10 15:52:08 -050089 self.volume_origin['id'], 'available')
90 self.addCleanup(self.servers_client.detach_volume, server['id'],
91 self.volume_origin['id'])
Xiao Chen47fcbf42014-01-13 16:42:41 +080092 # Snapshot a volume even if it's attached to an instance
93 snapshot = self.create_snapshot(self.volume_origin['id'],
94 force=True)
95 # Delete the snapshot
Yuriy Nesenenko551e1a92015-09-11 18:26:05 +030096 self.cleanup_snapshot(snapshot)
Xiao Chen47fcbf42014-01-13 16:42:41 +080097
Chris Hoge7579c1a2015-02-26 14:12:15 -080098 @test.idempotent_id('2a8abbe4-d871-46db-b049-c41f5af8216e')
QingXin Mengdc95f5e2013-09-16 19:06:44 -070099 def test_snapshot_create_get_list_update_delete(self):
Giulio Fidentef41b8ee2013-05-21 11:07:21 +0200100 # Create a snapshot
Masayuki Igawa259c1132013-10-31 17:48:44 +0900101 s_name = data_utils.rand_name('snap')
Zhi Kun Liu38641c62014-07-10 20:12:48 +0800102 params = {self.name_field: s_name}
103 snapshot = self.create_snapshot(self.volume_origin['id'], **params)
Giulio Fidente73332932013-05-03 18:04:09 +0200104
Giulio Fidentef41b8ee2013-05-21 11:07:21 +0200105 # Get the snap and check for some of its details
John Warrenff7faf62015-08-17 16:59:06 +0000106 snap_get = self.snapshots_client.show_snapshot(
107 snapshot['id'])['snapshot']
Giulio Fidentef41b8ee2013-05-21 11:07:21 +0200108 self.assertEqual(self.volume_origin['id'],
109 snap_get['volume_id'],
110 "Referred volume origin mismatch")
111
112 # Compare also with the output from the list action
Zhi Kun Liu38641c62014-07-10 20:12:48 +0800113 tracking_data = (snapshot['id'], snapshot[self.name_field])
John Warrenff7faf62015-08-17 16:59:06 +0000114 snaps_list = self.snapshots_client.list_snapshots()['snapshots']
Zhi Kun Liu38641c62014-07-10 20:12:48 +0800115 snaps_data = [(f['id'], f[self.name_field]) for f in snaps_list]
Giulio Fidentef41b8ee2013-05-21 11:07:21 +0200116 self.assertIn(tracking_data, snaps_data)
117
QingXin Mengdc95f5e2013-09-16 19:06:44 -0700118 # Updates snapshot with new values
Masayuki Igawa259c1132013-10-31 17:48:44 +0900119 new_s_name = data_utils.rand_name('new-snap')
QingXin Mengdc95f5e2013-09-16 19:06:44 -0700120 new_desc = 'This is the new description of snapshot.'
Zhi Kun Liu38641c62014-07-10 20:12:48 +0800121 params = {self.name_field: new_s_name,
122 self.descrip_field: 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
Zhi Kun Liu38641c62014-07-10 20:12:48 +0800126 self.assertEqual(new_s_name, update_snapshot[self.name_field])
127 self.assertEqual(new_desc, update_snapshot[self.descrip_field])
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']
Zhi Kun Liu38641c62014-07-10 20:12:48 +0800131 self.assertEqual(new_s_name, updated_snapshot[self.name_field])
132 self.assertEqual(new_desc, updated_snapshot[self.descrip_field])
QingXin Mengdc95f5e2013-09-16 19:06:44 -0700133
Giulio Fidentef41b8ee2013-05-21 11:07:21 +0200134 # Delete the snapshot
Yuriy Nesenenko551e1a92015-09-11 18:26:05 +0300135 self.cleanup_snapshot(snapshot)
Giulio Fidentef41b8ee2013-05-21 11:07:21 +0200136
Chris Hoge7579c1a2015-02-26 14:12:15 -0800137 @test.idempotent_id('59f41f43-aebf-48a9-ab5d-d76340fab32b')
Abhijeet Malawade5945ffe2013-09-17 05:54:44 -0700138 def test_snapshots_list_with_params(self):
139 """list snapshots with params."""
140 # Create a snapshot
141 display_name = data_utils.rand_name('snap')
Zhi Kun Liu38641c62014-07-10 20:12:48 +0800142 params = {self.name_field: display_name}
143 snapshot = self.create_snapshot(self.volume_origin['id'], **params)
Yuriy Nesenenko551e1a92015-09-11 18:26:05 +0300144 self.addCleanup(self.cleanup_snapshot, snapshot)
Abhijeet Malawade5945ffe2013-09-17 05:54:44 -0700145
146 # Verify list snapshots by display_name filter
Zhi Kun Liu38641c62014-07-10 20:12:48 +0800147 params = {self.name_field: snapshot[self.name_field]}
Ghanshyam0b75b632015-12-11 15:08:28 +0900148 self._list_by_param_values_and_assert(**params)
Abhijeet Malawade5945ffe2013-09-17 05:54:44 -0700149
150 # Verify list snapshots by status filter
151 params = {'status': 'available'}
Ghanshyam0b75b632015-12-11 15:08:28 +0900152 self._list_by_param_values_and_assert(**params)
Abhijeet Malawade5945ffe2013-09-17 05:54:44 -0700153
154 # Verify list snapshots by status and display name filter
155 params = {'status': 'available',
Zhi Kun Liu38641c62014-07-10 20:12:48 +0800156 self.name_field: snapshot[self.name_field]}
Ghanshyam0b75b632015-12-11 15:08:28 +0900157 self._list_by_param_values_and_assert(**params)
Abhijeet Malawade5945ffe2013-09-17 05:54:44 -0700158
Chris Hoge7579c1a2015-02-26 14:12:15 -0800159 @test.idempotent_id('220a1022-1fcd-4a74-a7bd-6b859156cda2')
Abhijeet Malawade5945ffe2013-09-17 05:54:44 -0700160 def test_snapshots_list_details_with_params(self):
161 """list snapshot details with params."""
162 # Create a snapshot
163 display_name = data_utils.rand_name('snap')
Zhi Kun Liu38641c62014-07-10 20:12:48 +0800164 params = {self.name_field: display_name}
165 snapshot = self.create_snapshot(self.volume_origin['id'], **params)
Yuriy Nesenenko551e1a92015-09-11 18:26:05 +0300166 self.addCleanup(self.cleanup_snapshot, snapshot)
Abhijeet Malawade5945ffe2013-09-17 05:54:44 -0700167
168 # Verify list snapshot details by display_name filter
Zhi Kun Liu38641c62014-07-10 20:12:48 +0800169 params = {self.name_field: snapshot[self.name_field]}
Ghanshyam0b75b632015-12-11 15:08:28 +0900170 self._list_by_param_values_and_assert(with_detail=True, **params)
Abhijeet Malawade5945ffe2013-09-17 05:54:44 -0700171 # Verify list snapshot details by status filter
172 params = {'status': 'available'}
Ghanshyam0b75b632015-12-11 15:08:28 +0900173 self._list_by_param_values_and_assert(with_detail=True, **params)
Abhijeet Malawade5945ffe2013-09-17 05:54:44 -0700174 # Verify list snapshot details by status and display name filter
175 params = {'status': 'available',
Zhi Kun Liu38641c62014-07-10 20:12:48 +0800176 self.name_field: snapshot[self.name_field]}
Ghanshyam0b75b632015-12-11 15:08:28 +0900177 self._list_by_param_values_and_assert(with_detail=True, **params)
Abhijeet Malawade5945ffe2013-09-17 05:54:44 -0700178
Chris Hoge7579c1a2015-02-26 14:12:15 -0800179 @test.idempotent_id('677863d1-3142-456d-b6ac-9924f667a7f4')
Giulio Fidente73332932013-05-03 18:04:09 +0200180 def test_volume_from_snapshot(self):
Giulio Fidente3a465e32013-05-07 13:38:18 +0200181 # Create a temporary snap using wrapper method from base, then
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000182 # create a snap based volume and deletes it
Giulio Fidente73332932013-05-03 18:04:09 +0200183 snapshot = self.create_snapshot(self.volume_origin['id'])
Giulio Fidentef41b8ee2013-05-21 11:07:21 +0200184 # NOTE(gfidente): size is required also when passing snapshot_id
Joseph Lanoux6809bab2014-12-18 14:57:18 +0000185 volume = self.volumes_client.create_volume(
John Warren6177c9e2015-08-19 20:00:17 +0000186 snapshot_id=snapshot['id'])['volume']
Yaroslav Lobankoved3a35b2016-03-24 22:41:30 -0500187 waiters.wait_for_volume_status(self.volumes_client,
188 volume['id'], 'available')
Giulio Fidente73332932013-05-03 18:04:09 +0200189 self.volumes_client.delete_volume(volume['id'])
190 self.volumes_client.wait_for_resource_deletion(volume['id'])
Yuriy Nesenenko551e1a92015-09-11 18:26:05 +0300191 self.cleanup_snapshot(snapshot)
192
lkuchlan755c6ee2016-03-30 15:55:35 +0300193 @test.idempotent_id('db4d8e0a-7a2e-41cc-a712-961f6844e896')
194 def test_snapshot_list_param_limit(self):
195 # List returns limited elements
196 self._list_snapshots_by_param_limit(limit=1, expected_elements=1)
197
198 @test.idempotent_id('a1427f61-420e-48a5-b6e3-0b394fa95400')
199 def test_snapshot_list_param_limit_equals_infinite(self):
200 # List returns all elements when request limit exceeded
201 # snapshots number
202 snap_list = self.snapshots_client.list_snapshots()['snapshots']
203 self._list_snapshots_by_param_limit(limit=100000,
204 expected_elements=len(snap_list))
205
206 @decorators.skip_because(bug='1540893')
207 @test.idempotent_id('e3b44b7f-ae87-45b5-8a8c-66110eb24d0a')
208 def test_snapshot_list_param_limit_equals_zero(self):
209 # List returns zero elements
210 self._list_snapshots_by_param_limit(limit=0, expected_elements=0)
211
Yuriy Nesenenko551e1a92015-09-11 18:26:05 +0300212 def cleanup_snapshot(self, snapshot):
213 # Delete the snapshot
214 self.snapshots_client.delete_snapshot(snapshot['id'])
215 self.snapshots_client.wait_for_resource_deletion(snapshot['id'])
216 self.snapshots.remove(snapshot)
Attila Fazekas36b1fcf2013-01-31 16:41:04 +0100217
218
Zhi Kun Liu38641c62014-07-10 20:12:48 +0800219class VolumesV1SnapshotTestJSON(VolumesV2SnapshotTestJSON):
220 _api_version = 1