blob: 955fbcf3a60b2153b15481b009f073ef5ad5c828 [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 -050014from tempest_lib.common.utils import data_utils
15
Sean Dague1937d092013-05-17 16:36:38 -040016from tempest.api.volume import base
Xiao Chen47fcbf42014-01-13 16:42:41 +080017from tempest import config
Masayuki Igawa1edf94f2014-03-04 18:34:16 +090018from tempest import test
Attila Fazekas36b1fcf2013-01-31 16:41:04 +010019
Giulio Fidente3a465e32013-05-07 13:38:18 +020020LOG = logging.getLogger(__name__)
Xiao Chen47fcbf42014-01-13 16:42:41 +080021CONF = config.CONF
Giulio Fidente3a465e32013-05-07 13:38:18 +020022
Attila Fazekas36b1fcf2013-01-31 16:41:04 +010023
Zhi Kun Liu38641c62014-07-10 20:12:48 +080024class VolumesV2SnapshotTestJSON(base.BaseVolumeTest):
Attila Fazekas36b1fcf2013-01-31 16:41:04 +010025
Giulio Fidente73332932013-05-03 18:04:09 +020026 @classmethod
Rohan Kanade05749152015-01-30 17:15:18 +053027 def skip_checks(cls):
28 super(VolumesV2SnapshotTestJSON, cls).skip_checks()
29 if not CONF.volume_feature_enabled.snapshot:
30 raise cls.skipException("Cinder volume snapshots are disabled")
31
32 @classmethod
Andrea Frittoli61a12e22014-09-15 13:14:54 +010033 def resource_setup(cls):
34 super(VolumesV2SnapshotTestJSON, cls).resource_setup()
Zhi Kun Liu43f9af12014-03-19 21:01:35 +080035 cls.volume_origin = cls.create_volume()
Giulio Fidente73332932013-05-03 18:04:09 +020036
Zhi Kun Liu38641c62014-07-10 20:12:48 +080037 cls.name_field = cls.special_fields['name_field']
38 cls.descrip_field = cls.special_fields['descrip_field']
Giulio Fidente73332932013-05-03 18:04:09 +020039
Xiao Chen47fcbf42014-01-13 16:42:41 +080040 def _detach(self, volume_id):
41 """Detach volume."""
42 self.volumes_client.detach_volume(volume_id)
43 self.volumes_client.wait_for_volume_status(volume_id, 'available')
44
Abhijeet Malawade5945ffe2013-09-17 05:54:44 -070045 def _list_by_param_values_and_assert(self, params, with_detail=False):
46 """
47 Perform list or list_details action with given params
48 and validates result.
49 """
50 if with_detail:
Joseph Lanoux6809bab2014-12-18 14:57:18 +000051 fetched_snap_list = \
Abhijeet Malawade5945ffe2013-09-17 05:54:44 -070052 self.snapshots_client.\
53 list_snapshots_with_detail(params=params)
54 else:
Joseph Lanoux6809bab2014-12-18 14:57:18 +000055 fetched_snap_list = \
Abhijeet Malawade5945ffe2013-09-17 05:54:44 -070056 self.snapshots_client.list_snapshots(params=params)
57
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
Masayuki Igawa1edf94f2014-03-04 18:34:16 +090065 @test.attr(type='gate')
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
71 server_name = data_utils.rand_name('instance-')
David Kranz0fb14292015-02-11 15:55:20 -050072 server = self.servers_client.create_server(server_name,
73 self.image_ref,
74 self.flavor_ref)
Xiao Chen47fcbf42014-01-13 16:42:41 +080075 self.addCleanup(self.servers_client.delete_server, server['id'])
Mauro S. M. Rodrigues253585d2014-03-19 12:08:39 -040076 self.servers_client.wait_for_server_status(server['id'], 'ACTIVE')
Xiao Chen47fcbf42014-01-13 16:42:41 +080077 mountpoint = '/dev/%s' % CONF.compute.volume_device_name
David Kranz3ebc7212015-02-10 12:19:19 -050078 self.servers_client.attach_volume(
Mitsuhiro Taninoab667962014-12-10 15:52:08 -050079 server['id'], self.volume_origin['id'], mountpoint)
Xiao Chen47fcbf42014-01-13 16:42:41 +080080 self.volumes_client.wait_for_volume_status(self.volume_origin['id'],
81 'in-use')
Mitsuhiro Taninoab667962014-12-10 15:52:08 -050082 self.addCleanup(self.volumes_client.wait_for_volume_status,
83 self.volume_origin['id'], 'available')
84 self.addCleanup(self.servers_client.detach_volume, server['id'],
85 self.volume_origin['id'])
Xiao Chen47fcbf42014-01-13 16:42:41 +080086 # Snapshot a volume even if it's attached to an instance
87 snapshot = self.create_snapshot(self.volume_origin['id'],
88 force=True)
89 # Delete the snapshot
90 self.snapshots_client.delete_snapshot(snapshot['id'])
Xiao Chen47fcbf42014-01-13 16:42:41 +080091 self.snapshots_client.wait_for_resource_deletion(snapshot['id'])
92 self.snapshots.remove(snapshot)
93
Masayuki Igawa1edf94f2014-03-04 18:34:16 +090094 @test.attr(type='gate')
Chris Hoge7579c1a2015-02-26 14:12:15 -080095 @test.idempotent_id('2a8abbe4-d871-46db-b049-c41f5af8216e')
QingXin Mengdc95f5e2013-09-16 19:06:44 -070096 def test_snapshot_create_get_list_update_delete(self):
Giulio Fidentef41b8ee2013-05-21 11:07:21 +020097 # Create a snapshot
Masayuki Igawa259c1132013-10-31 17:48:44 +090098 s_name = data_utils.rand_name('snap')
Zhi Kun Liu38641c62014-07-10 20:12:48 +080099 params = {self.name_field: s_name}
100 snapshot = self.create_snapshot(self.volume_origin['id'], **params)
Giulio Fidente73332932013-05-03 18:04:09 +0200101
Giulio Fidentef41b8ee2013-05-21 11:07:21 +0200102 # Get the snap and check for some of its details
Joseph Lanoux6809bab2014-12-18 14:57:18 +0000103 snap_get = self.snapshots_client.get_snapshot(snapshot['id'])
Giulio Fidentef41b8ee2013-05-21 11:07:21 +0200104 self.assertEqual(self.volume_origin['id'],
105 snap_get['volume_id'],
106 "Referred volume origin mismatch")
107
108 # Compare also with the output from the list action
Zhi Kun Liu38641c62014-07-10 20:12:48 +0800109 tracking_data = (snapshot['id'], snapshot[self.name_field])
Joseph Lanoux6809bab2014-12-18 14:57:18 +0000110 snaps_list = self.snapshots_client.list_snapshots()
Zhi Kun Liu38641c62014-07-10 20:12:48 +0800111 snaps_data = [(f['id'], f[self.name_field]) for f in snaps_list]
Giulio Fidentef41b8ee2013-05-21 11:07:21 +0200112 self.assertIn(tracking_data, snaps_data)
113
QingXin Mengdc95f5e2013-09-16 19:06:44 -0700114 # Updates snapshot with new values
Masayuki Igawa259c1132013-10-31 17:48:44 +0900115 new_s_name = data_utils.rand_name('new-snap')
QingXin Mengdc95f5e2013-09-16 19:06:44 -0700116 new_desc = 'This is the new description of snapshot.'
Zhi Kun Liu38641c62014-07-10 20:12:48 +0800117 params = {self.name_field: new_s_name,
118 self.descrip_field: new_desc}
Joseph Lanoux6809bab2014-12-18 14:57:18 +0000119 update_snapshot = \
Zhi Kun Liu38641c62014-07-10 20:12:48 +0800120 self.snapshots_client.update_snapshot(snapshot['id'], **params)
QingXin Mengdc95f5e2013-09-16 19:06:44 -0700121 # Assert response body for update_snapshot method
Zhi Kun Liu38641c62014-07-10 20:12:48 +0800122 self.assertEqual(new_s_name, update_snapshot[self.name_field])
123 self.assertEqual(new_desc, update_snapshot[self.descrip_field])
QingXin Mengdc95f5e2013-09-16 19:06:44 -0700124 # Assert response body for get_snapshot method
Joseph Lanoux6809bab2014-12-18 14:57:18 +0000125 updated_snapshot = \
QingXin Mengdc95f5e2013-09-16 19:06:44 -0700126 self.snapshots_client.get_snapshot(snapshot['id'])
Zhi Kun Liu38641c62014-07-10 20:12:48 +0800127 self.assertEqual(new_s_name, updated_snapshot[self.name_field])
128 self.assertEqual(new_desc, updated_snapshot[self.descrip_field])
QingXin Mengdc95f5e2013-09-16 19:06:44 -0700129
Giulio Fidentef41b8ee2013-05-21 11:07:21 +0200130 # Delete the snapshot
131 self.snapshots_client.delete_snapshot(snapshot['id'])
Giulio Fidentef41b8ee2013-05-21 11:07:21 +0200132 self.snapshots_client.wait_for_resource_deletion(snapshot['id'])
133 self.snapshots.remove(snapshot)
134
Masayuki Igawa1edf94f2014-03-04 18:34:16 +0900135 @test.attr(type='gate')
Chris Hoge7579c1a2015-02-26 14:12:15 -0800136 @test.idempotent_id('59f41f43-aebf-48a9-ab5d-d76340fab32b')
Abhijeet Malawade5945ffe2013-09-17 05:54:44 -0700137 def test_snapshots_list_with_params(self):
138 """list snapshots with params."""
139 # Create a snapshot
140 display_name = data_utils.rand_name('snap')
Zhi Kun Liu38641c62014-07-10 20:12:48 +0800141 params = {self.name_field: display_name}
142 snapshot = self.create_snapshot(self.volume_origin['id'], **params)
Abhijeet Malawade5945ffe2013-09-17 05:54:44 -0700143
144 # Verify list snapshots by display_name filter
Zhi Kun Liu38641c62014-07-10 20:12:48 +0800145 params = {self.name_field: snapshot[self.name_field]}
Abhijeet Malawade5945ffe2013-09-17 05:54:44 -0700146 self._list_by_param_values_and_assert(params)
147
148 # Verify list snapshots by status filter
149 params = {'status': 'available'}
150 self._list_by_param_values_and_assert(params)
151
152 # Verify list snapshots by status and display name filter
153 params = {'status': 'available',
Zhi Kun Liu38641c62014-07-10 20:12:48 +0800154 self.name_field: snapshot[self.name_field]}
Abhijeet Malawade5945ffe2013-09-17 05:54:44 -0700155 self._list_by_param_values_and_assert(params)
156
Masayuki Igawa1edf94f2014-03-04 18:34:16 +0900157 @test.attr(type='gate')
Chris Hoge7579c1a2015-02-26 14:12:15 -0800158 @test.idempotent_id('220a1022-1fcd-4a74-a7bd-6b859156cda2')
Abhijeet Malawade5945ffe2013-09-17 05:54:44 -0700159 def test_snapshots_list_details_with_params(self):
160 """list snapshot details with params."""
161 # Create a snapshot
162 display_name = data_utils.rand_name('snap')
Zhi Kun Liu38641c62014-07-10 20:12:48 +0800163 params = {self.name_field: display_name}
164 snapshot = self.create_snapshot(self.volume_origin['id'], **params)
Abhijeet Malawade5945ffe2013-09-17 05:54:44 -0700165
166 # Verify list snapshot details by display_name filter
Zhi Kun Liu38641c62014-07-10 20:12:48 +0800167 params = {self.name_field: snapshot[self.name_field]}
Abhijeet Malawade5945ffe2013-09-17 05:54:44 -0700168 self._list_by_param_values_and_assert(params, with_detail=True)
169 # Verify list snapshot details by status filter
170 params = {'status': 'available'}
171 self._list_by_param_values_and_assert(params, with_detail=True)
172 # Verify list snapshot details by status and display name filter
173 params = {'status': 'available',
Zhi Kun Liu38641c62014-07-10 20:12:48 +0800174 self.name_field: snapshot[self.name_field]}
Abhijeet Malawade5945ffe2013-09-17 05:54:44 -0700175 self._list_by_param_values_and_assert(params, with_detail=True)
176
Masayuki Igawa1edf94f2014-03-04 18:34:16 +0900177 @test.attr(type='gate')
Chris Hoge7579c1a2015-02-26 14:12:15 -0800178 @test.idempotent_id('677863d1-3142-456d-b6ac-9924f667a7f4')
Giulio Fidente73332932013-05-03 18:04:09 +0200179 def test_volume_from_snapshot(self):
Giulio Fidente3a465e32013-05-07 13:38:18 +0200180 # Create a temporary snap using wrapper method from base, then
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000181 # create a snap based volume and deletes it
Giulio Fidente73332932013-05-03 18:04:09 +0200182 snapshot = self.create_snapshot(self.volume_origin['id'])
Giulio Fidentef41b8ee2013-05-21 11:07:21 +0200183 # NOTE(gfidente): size is required also when passing snapshot_id
Joseph Lanoux6809bab2014-12-18 14:57:18 +0000184 volume = self.volumes_client.create_volume(
Giulio Fidente73332932013-05-03 18:04:09 +0200185 snapshot_id=snapshot['id'])
Giulio Fidente73332932013-05-03 18:04:09 +0200186 self.volumes_client.wait_for_volume_status(volume['id'], 'available')
187 self.volumes_client.delete_volume(volume['id'])
188 self.volumes_client.wait_for_resource_deletion(volume['id'])
189 self.clear_snapshots()
Attila Fazekas36b1fcf2013-01-31 16:41:04 +0100190
191
Zhi Kun Liu38641c62014-07-10 20:12:48 +0800192class VolumesV1SnapshotTestJSON(VolumesV2SnapshotTestJSON):
193 _api_version = 1