blob: 179eb0965c3b2588f80f777db1eabfcc2b00eaab [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:
Joseph Lanoux6809bab2014-12-18 14:57:18 +000047 fetched_snap_list = \
Abhijeet Malawade5945ffe2013-09-17 05:54:44 -070048 self.snapshots_client.\
49 list_snapshots_with_detail(params=params)
50 else:
Joseph Lanoux6809bab2014-12-18 14:57:18 +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
Mitsuhiro Taninoab667962014-12-10 15:52:08 -050073 _, body = self.servers_client.attach_volume(
74 server['id'], self.volume_origin['id'], mountpoint)
Xiao Chen47fcbf42014-01-13 16:42:41 +080075 self.volumes_client.wait_for_volume_status(self.volume_origin['id'],
76 'in-use')
Mitsuhiro Taninoab667962014-12-10 15:52:08 -050077 self.addCleanup(self.volumes_client.wait_for_volume_status,
78 self.volume_origin['id'], 'available')
79 self.addCleanup(self.servers_client.detach_volume, server['id'],
80 self.volume_origin['id'])
Xiao Chen47fcbf42014-01-13 16:42:41 +080081 # Snapshot a volume even if it's attached to an instance
82 snapshot = self.create_snapshot(self.volume_origin['id'],
83 force=True)
84 # Delete the snapshot
85 self.snapshots_client.delete_snapshot(snapshot['id'])
Xiao Chen47fcbf42014-01-13 16:42:41 +080086 self.snapshots_client.wait_for_resource_deletion(snapshot['id'])
87 self.snapshots.remove(snapshot)
88
Masayuki Igawa1edf94f2014-03-04 18:34:16 +090089 @test.attr(type='gate')
QingXin Mengdc95f5e2013-09-16 19:06:44 -070090 def test_snapshot_create_get_list_update_delete(self):
Giulio Fidentef41b8ee2013-05-21 11:07:21 +020091 # Create a snapshot
Masayuki Igawa259c1132013-10-31 17:48:44 +090092 s_name = data_utils.rand_name('snap')
Zhi Kun Liu38641c62014-07-10 20:12:48 +080093 params = {self.name_field: s_name}
94 snapshot = self.create_snapshot(self.volume_origin['id'], **params)
Giulio Fidente73332932013-05-03 18:04:09 +020095
Giulio Fidentef41b8ee2013-05-21 11:07:21 +020096 # Get the snap and check for some of its details
Joseph Lanoux6809bab2014-12-18 14:57:18 +000097 snap_get = self.snapshots_client.get_snapshot(snapshot['id'])
Giulio Fidentef41b8ee2013-05-21 11:07:21 +020098 self.assertEqual(self.volume_origin['id'],
99 snap_get['volume_id'],
100 "Referred volume origin mismatch")
101
102 # Compare also with the output from the list action
Zhi Kun Liu38641c62014-07-10 20:12:48 +0800103 tracking_data = (snapshot['id'], snapshot[self.name_field])
Joseph Lanoux6809bab2014-12-18 14:57:18 +0000104 snaps_list = self.snapshots_client.list_snapshots()
Zhi Kun Liu38641c62014-07-10 20:12:48 +0800105 snaps_data = [(f['id'], f[self.name_field]) for f in snaps_list]
Giulio Fidentef41b8ee2013-05-21 11:07:21 +0200106 self.assertIn(tracking_data, snaps_data)
107
QingXin Mengdc95f5e2013-09-16 19:06:44 -0700108 # Updates snapshot with new values
Masayuki Igawa259c1132013-10-31 17:48:44 +0900109 new_s_name = data_utils.rand_name('new-snap')
QingXin Mengdc95f5e2013-09-16 19:06:44 -0700110 new_desc = 'This is the new description of snapshot.'
Zhi Kun Liu38641c62014-07-10 20:12:48 +0800111 params = {self.name_field: new_s_name,
112 self.descrip_field: new_desc}
Joseph Lanoux6809bab2014-12-18 14:57:18 +0000113 update_snapshot = \
Zhi Kun Liu38641c62014-07-10 20:12:48 +0800114 self.snapshots_client.update_snapshot(snapshot['id'], **params)
QingXin Mengdc95f5e2013-09-16 19:06:44 -0700115 # Assert response body for update_snapshot method
Zhi Kun Liu38641c62014-07-10 20:12:48 +0800116 self.assertEqual(new_s_name, update_snapshot[self.name_field])
117 self.assertEqual(new_desc, update_snapshot[self.descrip_field])
QingXin Mengdc95f5e2013-09-16 19:06:44 -0700118 # Assert response body for get_snapshot method
Joseph Lanoux6809bab2014-12-18 14:57:18 +0000119 updated_snapshot = \
QingXin Mengdc95f5e2013-09-16 19:06:44 -0700120 self.snapshots_client.get_snapshot(snapshot['id'])
Zhi Kun Liu38641c62014-07-10 20:12:48 +0800121 self.assertEqual(new_s_name, updated_snapshot[self.name_field])
122 self.assertEqual(new_desc, updated_snapshot[self.descrip_field])
QingXin Mengdc95f5e2013-09-16 19:06:44 -0700123
Giulio Fidentef41b8ee2013-05-21 11:07:21 +0200124 # Delete the snapshot
125 self.snapshots_client.delete_snapshot(snapshot['id'])
Giulio Fidentef41b8ee2013-05-21 11:07:21 +0200126 self.snapshots_client.wait_for_resource_deletion(snapshot['id'])
127 self.snapshots.remove(snapshot)
128
Masayuki Igawa1edf94f2014-03-04 18:34:16 +0900129 @test.attr(type='gate')
Abhijeet Malawade5945ffe2013-09-17 05:54:44 -0700130 def test_snapshots_list_with_params(self):
131 """list snapshots with params."""
132 # Create a snapshot
133 display_name = data_utils.rand_name('snap')
Zhi Kun Liu38641c62014-07-10 20:12:48 +0800134 params = {self.name_field: display_name}
135 snapshot = self.create_snapshot(self.volume_origin['id'], **params)
Abhijeet Malawade5945ffe2013-09-17 05:54:44 -0700136
137 # Verify list snapshots by display_name filter
Zhi Kun Liu38641c62014-07-10 20:12:48 +0800138 params = {self.name_field: snapshot[self.name_field]}
Abhijeet Malawade5945ffe2013-09-17 05:54:44 -0700139 self._list_by_param_values_and_assert(params)
140
141 # Verify list snapshots by status filter
142 params = {'status': 'available'}
143 self._list_by_param_values_and_assert(params)
144
145 # Verify list snapshots by status and display name filter
146 params = {'status': 'available',
Zhi Kun Liu38641c62014-07-10 20:12:48 +0800147 self.name_field: snapshot[self.name_field]}
Abhijeet Malawade5945ffe2013-09-17 05:54:44 -0700148 self._list_by_param_values_and_assert(params)
149
Masayuki Igawa1edf94f2014-03-04 18:34:16 +0900150 @test.attr(type='gate')
Abhijeet Malawade5945ffe2013-09-17 05:54:44 -0700151 def test_snapshots_list_details_with_params(self):
152 """list snapshot details with params."""
153 # Create a snapshot
154 display_name = data_utils.rand_name('snap')
Zhi Kun Liu38641c62014-07-10 20:12:48 +0800155 params = {self.name_field: display_name}
156 snapshot = self.create_snapshot(self.volume_origin['id'], **params)
Abhijeet Malawade5945ffe2013-09-17 05:54:44 -0700157
158 # Verify list snapshot details by display_name filter
Zhi Kun Liu38641c62014-07-10 20:12:48 +0800159 params = {self.name_field: snapshot[self.name_field]}
Abhijeet Malawade5945ffe2013-09-17 05:54:44 -0700160 self._list_by_param_values_and_assert(params, with_detail=True)
161 # Verify list snapshot details by status filter
162 params = {'status': 'available'}
163 self._list_by_param_values_and_assert(params, with_detail=True)
164 # Verify list snapshot details by status and display name filter
165 params = {'status': 'available',
Zhi Kun Liu38641c62014-07-10 20:12:48 +0800166 self.name_field: snapshot[self.name_field]}
Abhijeet Malawade5945ffe2013-09-17 05:54:44 -0700167 self._list_by_param_values_and_assert(params, with_detail=True)
168
Masayuki Igawa1edf94f2014-03-04 18:34:16 +0900169 @test.attr(type='gate')
Giulio Fidente73332932013-05-03 18:04:09 +0200170 def test_volume_from_snapshot(self):
Giulio Fidente3a465e32013-05-07 13:38:18 +0200171 # Create a temporary snap using wrapper method from base, then
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000172 # create a snap based volume and deletes it
Giulio Fidente73332932013-05-03 18:04:09 +0200173 snapshot = self.create_snapshot(self.volume_origin['id'])
Giulio Fidentef41b8ee2013-05-21 11:07:21 +0200174 # NOTE(gfidente): size is required also when passing snapshot_id
Joseph Lanoux6809bab2014-12-18 14:57:18 +0000175 volume = self.volumes_client.create_volume(
Giulio Fidente73332932013-05-03 18:04:09 +0200176 size=1,
177 snapshot_id=snapshot['id'])
Giulio Fidente73332932013-05-03 18:04:09 +0200178 self.volumes_client.wait_for_volume_status(volume['id'], 'available')
179 self.volumes_client.delete_volume(volume['id'])
180 self.volumes_client.wait_for_resource_deletion(volume['id'])
181 self.clear_snapshots()
Attila Fazekas36b1fcf2013-01-31 16:41:04 +0100182
183
Zhi Kun Liu38641c62014-07-10 20:12:48 +0800184class VolumesV1SnapshotTestJSON(VolumesV2SnapshotTestJSON):
185 _api_version = 1