blob: 1df1896d8b1bdf089efe7ea3e786c78db97659ca [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
Doug Hellmann583ce2c2015-03-11 14:55:46 +000013from oslo_log import log as logging
Matthew Treinish01472ff2015-02-20 17:26:52 -050014
Sean Dague1937d092013-05-17 16:36:38 -040015from tempest.api.volume import base
Fei Long Wangd39431f2015-05-14 11:30:48 +120016from tempest.common.utils import data_utils
Ken'ichi Ohmichi0eb153c2015-07-13 02:18:25 +000017from tempest.common import waiters
Xiao Chen47fcbf42014-01-13 16:42:41 +080018from tempest import config
Masayuki Igawa1edf94f2014-03-04 18:34:16 +090019from tempest import test
Attila Fazekas36b1fcf2013-01-31 16:41:04 +010020
Giulio Fidente3a465e32013-05-07 13:38:18 +020021LOG = logging.getLogger(__name__)
Xiao Chen47fcbf42014-01-13 16:42:41 +080022CONF = config.CONF
Giulio Fidente3a465e32013-05-07 13:38:18 +020023
Attila Fazekas36b1fcf2013-01-31 16:41:04 +010024
Zhi Kun Liu38641c62014-07-10 20:12:48 +080025class VolumesV2SnapshotTestJSON(base.BaseVolumeTest):
Attila Fazekas36b1fcf2013-01-31 16:41:04 +010026
Giulio Fidente73332932013-05-03 18:04:09 +020027 @classmethod
Rohan Kanade05749152015-01-30 17:15:18 +053028 def skip_checks(cls):
29 super(VolumesV2SnapshotTestJSON, cls).skip_checks()
30 if not CONF.volume_feature_enabled.snapshot:
31 raise cls.skipException("Cinder volume snapshots are disabled")
32
33 @classmethod
Andrea Frittoli61a12e22014-09-15 13:14:54 +010034 def resource_setup(cls):
35 super(VolumesV2SnapshotTestJSON, cls).resource_setup()
Zhi Kun Liu43f9af12014-03-19 21:01:35 +080036 cls.volume_origin = cls.create_volume()
Giulio Fidente73332932013-05-03 18:04:09 +020037
Zhi Kun Liu38641c62014-07-10 20:12:48 +080038 cls.name_field = cls.special_fields['name_field']
39 cls.descrip_field = cls.special_fields['descrip_field']
Giulio Fidente73332932013-05-03 18:04:09 +020040
Xiao Chen47fcbf42014-01-13 16:42:41 +080041 def _detach(self, volume_id):
42 """Detach volume."""
43 self.volumes_client.detach_volume(volume_id)
44 self.volumes_client.wait_for_volume_status(volume_id, 'available')
45
Abhijeet Malawade5945ffe2013-09-17 05:54:44 -070046 def _list_by_param_values_and_assert(self, params, with_detail=False):
47 """
48 Perform list or list_details action with given params
49 and validates result.
50 """
51 if with_detail:
Joseph Lanoux6809bab2014-12-18 14:57:18 +000052 fetched_snap_list = \
Abhijeet Malawade5945ffe2013-09-17 05:54:44 -070053 self.snapshots_client.\
Ken'ichi Ohmichi35798fb2015-04-06 01:22:41 +000054 list_snapshots(detail=True, params=params)
Abhijeet Malawade5945ffe2013-09-17 05:54:44 -070055 else:
Joseph Lanoux6809bab2014-12-18 14:57:18 +000056 fetched_snap_list = \
Abhijeet Malawade5945ffe2013-09-17 05:54:44 -070057 self.snapshots_client.list_snapshots(params=params)
58
Abhijeet Malawade5945ffe2013-09-17 05:54:44 -070059 # Validating params of fetched snapshots
60 for snap in fetched_snap_list:
61 for key in params:
62 msg = "Failed to list snapshots %s by %s" % \
63 ('details' if with_detail else '', key)
64 self.assertEqual(params[key], snap[key], msg)
65
Chris Hoge7579c1a2015-02-26 14:12:15 -080066 @test.idempotent_id('b467b54c-07a4-446d-a1cf-651dedcc3ff1')
Matthew Treinish7ea69e62014-06-03 17:23:50 -040067 @test.services('compute')
Xiao Chen47fcbf42014-01-13 16:42:41 +080068 def test_snapshot_create_with_volume_in_use(self):
69 # Create a snapshot when volume status is in-use
70 # Create a test instance
Ken'ichi Ohmichi07308f12015-03-23 00:24:28 +000071 server_name = data_utils.rand_name('instance')
Rohan Kanade9ce97df2013-12-10 18:59:35 +053072 server = self.create_server(server_name)
Xiao Chen47fcbf42014-01-13 16:42:41 +080073 self.addCleanup(self.servers_client.delete_server, server['id'])
Ken'ichi Ohmichi0eb153c2015-07-13 02:18:25 +000074 waiters.wait_for_server_status(self.servers_client, server['id'],
75 'ACTIVE')
Xiao Chen47fcbf42014-01-13 16:42:41 +080076 mountpoint = '/dev/%s' % CONF.compute.volume_device_name
David Kranz3ebc7212015-02-10 12:19:19 -050077 self.servers_client.attach_volume(
Mitsuhiro Taninoab667962014-12-10 15:52:08 -050078 server['id'], self.volume_origin['id'], mountpoint)
Xiao Chen47fcbf42014-01-13 16:42:41 +080079 self.volumes_client.wait_for_volume_status(self.volume_origin['id'],
80 'in-use')
Mitsuhiro Taninoab667962014-12-10 15:52:08 -050081 self.addCleanup(self.volumes_client.wait_for_volume_status,
82 self.volume_origin['id'], 'available')
83 self.addCleanup(self.servers_client.detach_volume, server['id'],
84 self.volume_origin['id'])
Xiao Chen47fcbf42014-01-13 16:42:41 +080085 # Snapshot a volume even if it's attached to an instance
86 snapshot = self.create_snapshot(self.volume_origin['id'],
87 force=True)
88 # Delete the snapshot
89 self.snapshots_client.delete_snapshot(snapshot['id'])
Xiao Chen47fcbf42014-01-13 16:42:41 +080090 self.snapshots_client.wait_for_resource_deletion(snapshot['id'])
91 self.snapshots.remove(snapshot)
92
Chris Hoge7579c1a2015-02-26 14:12:15 -080093 @test.idempotent_id('2a8abbe4-d871-46db-b049-c41f5af8216e')
QingXin Mengdc95f5e2013-09-16 19:06:44 -070094 def test_snapshot_create_get_list_update_delete(self):
Giulio Fidentef41b8ee2013-05-21 11:07:21 +020095 # Create a snapshot
Masayuki Igawa259c1132013-10-31 17:48:44 +090096 s_name = data_utils.rand_name('snap')
Zhi Kun Liu38641c62014-07-10 20:12:48 +080097 params = {self.name_field: s_name}
98 snapshot = self.create_snapshot(self.volume_origin['id'], **params)
Giulio Fidente73332932013-05-03 18:04:09 +020099
Giulio Fidentef41b8ee2013-05-21 11:07:21 +0200100 # Get the snap and check for some of its details
Ken'ichi Ohmichi35798fb2015-04-06 01:22:41 +0000101 snap_get = self.snapshots_client.show_snapshot(snapshot['id'])
Giulio Fidentef41b8ee2013-05-21 11:07:21 +0200102 self.assertEqual(self.volume_origin['id'],
103 snap_get['volume_id'],
104 "Referred volume origin mismatch")
105
106 # Compare also with the output from the list action
Zhi Kun Liu38641c62014-07-10 20:12:48 +0800107 tracking_data = (snapshot['id'], snapshot[self.name_field])
Joseph Lanoux6809bab2014-12-18 14:57:18 +0000108 snaps_list = self.snapshots_client.list_snapshots()
Zhi Kun Liu38641c62014-07-10 20:12:48 +0800109 snaps_data = [(f['id'], f[self.name_field]) for f in snaps_list]
Giulio Fidentef41b8ee2013-05-21 11:07:21 +0200110 self.assertIn(tracking_data, snaps_data)
111
QingXin Mengdc95f5e2013-09-16 19:06:44 -0700112 # Updates snapshot with new values
Masayuki Igawa259c1132013-10-31 17:48:44 +0900113 new_s_name = data_utils.rand_name('new-snap')
QingXin Mengdc95f5e2013-09-16 19:06:44 -0700114 new_desc = 'This is the new description of snapshot.'
Zhi Kun Liu38641c62014-07-10 20:12:48 +0800115 params = {self.name_field: new_s_name,
116 self.descrip_field: new_desc}
Joseph Lanoux6809bab2014-12-18 14:57:18 +0000117 update_snapshot = \
Zhi Kun Liu38641c62014-07-10 20:12:48 +0800118 self.snapshots_client.update_snapshot(snapshot['id'], **params)
QingXin Mengdc95f5e2013-09-16 19:06:44 -0700119 # Assert response body for update_snapshot method
Zhi Kun Liu38641c62014-07-10 20:12:48 +0800120 self.assertEqual(new_s_name, update_snapshot[self.name_field])
121 self.assertEqual(new_desc, update_snapshot[self.descrip_field])
Ken'ichi Ohmichi35798fb2015-04-06 01:22:41 +0000122 # Assert response body for show_snapshot method
Joseph Lanoux6809bab2014-12-18 14:57:18 +0000123 updated_snapshot = \
Ken'ichi Ohmichi35798fb2015-04-06 01:22:41 +0000124 self.snapshots_client.show_snapshot(snapshot['id'])
Zhi Kun Liu38641c62014-07-10 20:12:48 +0800125 self.assertEqual(new_s_name, updated_snapshot[self.name_field])
126 self.assertEqual(new_desc, updated_snapshot[self.descrip_field])
QingXin Mengdc95f5e2013-09-16 19:06:44 -0700127
Giulio Fidentef41b8ee2013-05-21 11:07:21 +0200128 # Delete the snapshot
129 self.snapshots_client.delete_snapshot(snapshot['id'])
Giulio Fidentef41b8ee2013-05-21 11:07:21 +0200130 self.snapshots_client.wait_for_resource_deletion(snapshot['id'])
131 self.snapshots.remove(snapshot)
132
Chris Hoge7579c1a2015-02-26 14:12:15 -0800133 @test.idempotent_id('59f41f43-aebf-48a9-ab5d-d76340fab32b')
Abhijeet Malawade5945ffe2013-09-17 05:54:44 -0700134 def test_snapshots_list_with_params(self):
135 """list snapshots with params."""
136 # Create a snapshot
137 display_name = data_utils.rand_name('snap')
Zhi Kun Liu38641c62014-07-10 20:12:48 +0800138 params = {self.name_field: display_name}
139 snapshot = self.create_snapshot(self.volume_origin['id'], **params)
Abhijeet Malawade5945ffe2013-09-17 05:54:44 -0700140
141 # Verify list snapshots by display_name filter
Zhi Kun Liu38641c62014-07-10 20:12:48 +0800142 params = {self.name_field: snapshot[self.name_field]}
Abhijeet Malawade5945ffe2013-09-17 05:54:44 -0700143 self._list_by_param_values_and_assert(params)
144
145 # Verify list snapshots by status filter
146 params = {'status': 'available'}
147 self._list_by_param_values_and_assert(params)
148
149 # Verify list snapshots by status and display name filter
150 params = {'status': 'available',
Zhi Kun Liu38641c62014-07-10 20:12:48 +0800151 self.name_field: snapshot[self.name_field]}
Abhijeet Malawade5945ffe2013-09-17 05:54:44 -0700152 self._list_by_param_values_and_assert(params)
153
Chris Hoge7579c1a2015-02-26 14:12:15 -0800154 @test.idempotent_id('220a1022-1fcd-4a74-a7bd-6b859156cda2')
Abhijeet Malawade5945ffe2013-09-17 05:54:44 -0700155 def test_snapshots_list_details_with_params(self):
156 """list snapshot details with params."""
157 # Create a snapshot
158 display_name = data_utils.rand_name('snap')
Zhi Kun Liu38641c62014-07-10 20:12:48 +0800159 params = {self.name_field: display_name}
160 snapshot = self.create_snapshot(self.volume_origin['id'], **params)
Abhijeet Malawade5945ffe2013-09-17 05:54:44 -0700161
162 # Verify list snapshot details by display_name filter
Zhi Kun Liu38641c62014-07-10 20:12:48 +0800163 params = {self.name_field: snapshot[self.name_field]}
Abhijeet Malawade5945ffe2013-09-17 05:54:44 -0700164 self._list_by_param_values_and_assert(params, with_detail=True)
165 # Verify list snapshot details by status filter
166 params = {'status': 'available'}
167 self._list_by_param_values_and_assert(params, with_detail=True)
168 # Verify list snapshot details by status and display name filter
169 params = {'status': 'available',
Zhi Kun Liu38641c62014-07-10 20:12:48 +0800170 self.name_field: snapshot[self.name_field]}
Abhijeet Malawade5945ffe2013-09-17 05:54:44 -0700171 self._list_by_param_values_and_assert(params, with_detail=True)
172
Chris Hoge7579c1a2015-02-26 14:12:15 -0800173 @test.idempotent_id('677863d1-3142-456d-b6ac-9924f667a7f4')
Giulio Fidente73332932013-05-03 18:04:09 +0200174 def test_volume_from_snapshot(self):
Giulio Fidente3a465e32013-05-07 13:38:18 +0200175 # Create a temporary snap using wrapper method from base, then
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000176 # create a snap based volume and deletes it
Giulio Fidente73332932013-05-03 18:04:09 +0200177 snapshot = self.create_snapshot(self.volume_origin['id'])
Giulio Fidentef41b8ee2013-05-21 11:07:21 +0200178 # NOTE(gfidente): size is required also when passing snapshot_id
Joseph Lanoux6809bab2014-12-18 14:57:18 +0000179 volume = self.volumes_client.create_volume(
Giulio Fidente73332932013-05-03 18:04:09 +0200180 snapshot_id=snapshot['id'])
Giulio Fidente73332932013-05-03 18:04:09 +0200181 self.volumes_client.wait_for_volume_status(volume['id'], 'available')
182 self.volumes_client.delete_volume(volume['id'])
183 self.volumes_client.wait_for_resource_deletion(volume['id'])
184 self.clear_snapshots()
Attila Fazekas36b1fcf2013-01-31 16:41:04 +0100185
186
Zhi Kun Liu38641c62014-07-10 20:12:48 +0800187class VolumesV1SnapshotTestJSON(VolumesV2SnapshotTestJSON):
188 _api_version = 1