blob: 78df1dfd9a3387d363a0dc4496a08999f4d6c8ba [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
Masayuki Igawa259c1132013-10-31 17:48:44 +090014from tempest.common.utils import data_utils
Xiao Chen47fcbf42014-01-13 16:42:41 +080015from tempest import config
Matthew Treinishf4a9b0f2013-07-26 16:58:26 -040016from tempest.openstack.common import log as logging
Masayuki Igawa1edf94f2014-03-04 18:34:16 +090017from tempest import test
Attila Fazekas36b1fcf2013-01-31 16:41:04 +010018
Giulio Fidente3a465e32013-05-07 13:38:18 +020019LOG = logging.getLogger(__name__)
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
Andrea Frittoli61a12e22014-09-15 13:14:54 +010026 def resource_setup(cls):
27 super(VolumesV2SnapshotTestJSON, cls).resource_setup()
Zhi Kun Liu43f9af12014-03-19 21:01:35 +080028 cls.volume_origin = cls.create_volume()
Giulio Fidente73332932013-05-03 18:04:09 +020029
JordanPbce55532014-03-19 12:10:32 +010030 if not CONF.volume_feature_enabled.snapshot:
31 raise cls.skipException("Cinder volume snapshots are disabled")
32
Zhi Kun Liu38641c62014-07-10 20:12:48 +080033 cls.name_field = cls.special_fields['name_field']
34 cls.descrip_field = cls.special_fields['descrip_field']
Giulio Fidente73332932013-05-03 18:04:09 +020035
Xiao Chen47fcbf42014-01-13 16:42:41 +080036 def _detach(self, volume_id):
37 """Detach volume."""
38 self.volumes_client.detach_volume(volume_id)
39 self.volumes_client.wait_for_volume_status(volume_id, 'available')
40
Abhijeet Malawade5945ffe2013-09-17 05:54:44 -070041 def _list_by_param_values_and_assert(self, params, with_detail=False):
42 """
43 Perform list or list_details action with given params
44 and validates result.
45 """
46 if with_detail:
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +000047 _, fetched_snap_list = \
Abhijeet Malawade5945ffe2013-09-17 05:54:44 -070048 self.snapshots_client.\
49 list_snapshots_with_detail(params=params)
50 else:
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +000051 _, fetched_snap_list = \
Abhijeet Malawade5945ffe2013-09-17 05:54:44 -070052 self.snapshots_client.list_snapshots(params=params)
53
Abhijeet Malawade5945ffe2013-09-17 05:54:44 -070054 # Validating params of fetched snapshots
55 for snap in fetched_snap_list:
56 for key in params:
57 msg = "Failed to list snapshots %s by %s" % \
58 ('details' if with_detail else '', key)
59 self.assertEqual(params[key], snap[key], msg)
60
Masayuki Igawa1edf94f2014-03-04 18:34:16 +090061 @test.attr(type='gate')
Matthew Treinish7ea69e62014-06-03 17:23:50 -040062 @test.services('compute')
Xiao Chen47fcbf42014-01-13 16:42:41 +080063 def test_snapshot_create_with_volume_in_use(self):
64 # Create a snapshot when volume status is in-use
65 # Create a test instance
66 server_name = data_utils.rand_name('instance-')
67 resp, server = self.servers_client.create_server(server_name,
68 self.image_ref,
69 self.flavor_ref)
Xiao Chen47fcbf42014-01-13 16:42:41 +080070 self.addCleanup(self.servers_client.delete_server, server['id'])
Mauro S. M. Rodrigues253585d2014-03-19 12:08:39 -040071 self.servers_client.wait_for_server_status(server['id'], 'ACTIVE')
Xiao Chen47fcbf42014-01-13 16:42:41 +080072 mountpoint = '/dev/%s' % CONF.compute.volume_device_name
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +000073 _, body = self.volumes_client.attach_volume(
Xiao Chen47fcbf42014-01-13 16:42:41 +080074 self.volume_origin['id'], server['id'], mountpoint)
Xiao Chen47fcbf42014-01-13 16:42:41 +080075 self.volumes_client.wait_for_volume_status(self.volume_origin['id'],
76 'in-use')
77 self.addCleanup(self._detach, self.volume_origin['id'])
78 # Snapshot a volume even if it's attached to an instance
79 snapshot = self.create_snapshot(self.volume_origin['id'],
80 force=True)
81 # Delete the snapshot
82 self.snapshots_client.delete_snapshot(snapshot['id'])
Xiao Chen47fcbf42014-01-13 16:42:41 +080083 self.snapshots_client.wait_for_resource_deletion(snapshot['id'])
84 self.snapshots.remove(snapshot)
85
Masayuki Igawa1edf94f2014-03-04 18:34:16 +090086 @test.attr(type='gate')
QingXin Mengdc95f5e2013-09-16 19:06:44 -070087 def test_snapshot_create_get_list_update_delete(self):
Giulio Fidentef41b8ee2013-05-21 11:07:21 +020088 # Create a snapshot
Masayuki Igawa259c1132013-10-31 17:48:44 +090089 s_name = data_utils.rand_name('snap')
Zhi Kun Liu38641c62014-07-10 20:12:48 +080090 params = {self.name_field: s_name}
91 snapshot = self.create_snapshot(self.volume_origin['id'], **params)
Giulio Fidente73332932013-05-03 18:04:09 +020092
Giulio Fidentef41b8ee2013-05-21 11:07:21 +020093 # Get the snap and check for some of its details
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +000094 _, snap_get = self.snapshots_client.get_snapshot(snapshot['id'])
Giulio Fidentef41b8ee2013-05-21 11:07:21 +020095 self.assertEqual(self.volume_origin['id'],
96 snap_get['volume_id'],
97 "Referred volume origin mismatch")
98
99 # Compare also with the output from the list action
Zhi Kun Liu38641c62014-07-10 20:12:48 +0800100 tracking_data = (snapshot['id'], snapshot[self.name_field])
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000101 _, snaps_list = self.snapshots_client.list_snapshots()
Zhi Kun Liu38641c62014-07-10 20:12:48 +0800102 snaps_data = [(f['id'], f[self.name_field]) for f in snaps_list]
Giulio Fidentef41b8ee2013-05-21 11:07:21 +0200103 self.assertIn(tracking_data, snaps_data)
104
QingXin Mengdc95f5e2013-09-16 19:06:44 -0700105 # Updates snapshot with new values
Masayuki Igawa259c1132013-10-31 17:48:44 +0900106 new_s_name = data_utils.rand_name('new-snap')
QingXin Mengdc95f5e2013-09-16 19:06:44 -0700107 new_desc = 'This is the new description of snapshot.'
Zhi Kun Liu38641c62014-07-10 20:12:48 +0800108 params = {self.name_field: new_s_name,
109 self.descrip_field: new_desc}
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000110 _, update_snapshot = \
Zhi Kun Liu38641c62014-07-10 20:12:48 +0800111 self.snapshots_client.update_snapshot(snapshot['id'], **params)
QingXin Mengdc95f5e2013-09-16 19:06:44 -0700112 # Assert response body for update_snapshot method
Zhi Kun Liu38641c62014-07-10 20:12:48 +0800113 self.assertEqual(new_s_name, update_snapshot[self.name_field])
114 self.assertEqual(new_desc, update_snapshot[self.descrip_field])
QingXin Mengdc95f5e2013-09-16 19:06:44 -0700115 # Assert response body for get_snapshot method
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000116 _, updated_snapshot = \
QingXin Mengdc95f5e2013-09-16 19:06:44 -0700117 self.snapshots_client.get_snapshot(snapshot['id'])
Zhi Kun Liu38641c62014-07-10 20:12:48 +0800118 self.assertEqual(new_s_name, updated_snapshot[self.name_field])
119 self.assertEqual(new_desc, updated_snapshot[self.descrip_field])
QingXin Mengdc95f5e2013-09-16 19:06:44 -0700120
Giulio Fidentef41b8ee2013-05-21 11:07:21 +0200121 # Delete the snapshot
122 self.snapshots_client.delete_snapshot(snapshot['id'])
Giulio Fidentef41b8ee2013-05-21 11:07:21 +0200123 self.snapshots_client.wait_for_resource_deletion(snapshot['id'])
124 self.snapshots.remove(snapshot)
125
Masayuki Igawa1edf94f2014-03-04 18:34:16 +0900126 @test.attr(type='gate')
Abhijeet Malawade5945ffe2013-09-17 05:54:44 -0700127 def test_snapshots_list_with_params(self):
128 """list snapshots with params."""
129 # Create a snapshot
130 display_name = data_utils.rand_name('snap')
Zhi Kun Liu38641c62014-07-10 20:12:48 +0800131 params = {self.name_field: display_name}
132 snapshot = self.create_snapshot(self.volume_origin['id'], **params)
Abhijeet Malawade5945ffe2013-09-17 05:54:44 -0700133
134 # Verify list snapshots by display_name filter
Zhi Kun Liu38641c62014-07-10 20:12:48 +0800135 params = {self.name_field: snapshot[self.name_field]}
Abhijeet Malawade5945ffe2013-09-17 05:54:44 -0700136 self._list_by_param_values_and_assert(params)
137
138 # Verify list snapshots by status filter
139 params = {'status': 'available'}
140 self._list_by_param_values_and_assert(params)
141
142 # Verify list snapshots by status and display name filter
143 params = {'status': 'available',
Zhi Kun Liu38641c62014-07-10 20:12:48 +0800144 self.name_field: snapshot[self.name_field]}
Abhijeet Malawade5945ffe2013-09-17 05:54:44 -0700145 self._list_by_param_values_and_assert(params)
146
Masayuki Igawa1edf94f2014-03-04 18:34:16 +0900147 @test.attr(type='gate')
Abhijeet Malawade5945ffe2013-09-17 05:54:44 -0700148 def test_snapshots_list_details_with_params(self):
149 """list snapshot details with params."""
150 # Create a snapshot
151 display_name = data_utils.rand_name('snap')
Zhi Kun Liu38641c62014-07-10 20:12:48 +0800152 params = {self.name_field: display_name}
153 snapshot = self.create_snapshot(self.volume_origin['id'], **params)
Abhijeet Malawade5945ffe2013-09-17 05:54:44 -0700154
155 # Verify list snapshot details by display_name filter
Zhi Kun Liu38641c62014-07-10 20:12:48 +0800156 params = {self.name_field: snapshot[self.name_field]}
Abhijeet Malawade5945ffe2013-09-17 05:54:44 -0700157 self._list_by_param_values_and_assert(params, with_detail=True)
158 # Verify list snapshot details by status filter
159 params = {'status': 'available'}
160 self._list_by_param_values_and_assert(params, with_detail=True)
161 # Verify list snapshot details by status and display name filter
162 params = {'status': 'available',
Zhi Kun Liu38641c62014-07-10 20:12:48 +0800163 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
Masayuki Igawa1edf94f2014-03-04 18:34:16 +0900166 @test.attr(type='gate')
Giulio Fidente73332932013-05-03 18:04:09 +0200167 def test_volume_from_snapshot(self):
Giulio Fidente3a465e32013-05-07 13:38:18 +0200168 # Create a temporary snap using wrapper method from base, then
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000169 # create a snap based volume and deletes it
Giulio Fidente73332932013-05-03 18:04:09 +0200170 snapshot = self.create_snapshot(self.volume_origin['id'])
Giulio Fidentef41b8ee2013-05-21 11:07:21 +0200171 # NOTE(gfidente): size is required also when passing snapshot_id
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000172 _, volume = self.volumes_client.create_volume(
Giulio Fidente73332932013-05-03 18:04:09 +0200173 size=1,
174 snapshot_id=snapshot['id'])
Giulio Fidente73332932013-05-03 18:04:09 +0200175 self.volumes_client.wait_for_volume_status(volume['id'], 'available')
176 self.volumes_client.delete_volume(volume['id'])
177 self.volumes_client.wait_for_resource_deletion(volume['id'])
178 self.clear_snapshots()
Attila Fazekas36b1fcf2013-01-31 16:41:04 +0100179
180
Zhi Kun Liu38641c62014-07-10 20:12:48 +0800181class VolumesV2SnapshotTestXML(VolumesV2SnapshotTestJSON):
182 _interface = "xml"
183
184
185class VolumesV1SnapshotTestJSON(VolumesV2SnapshotTestJSON):
186 _api_version = 1
187
188
189class VolumesV1SnapshotTestXML(VolumesV1SnapshotTestJSON):
Attila Fazekas3dcdae12013-02-14 12:50:04 +0100190 _interface = "xml"