blob: 6294cd996ec0445b8f534a9c45b529d7aa2648ba [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 Liubb363a22013-11-28 18:47:39 +080023class VolumesSnapshotTest(base.BaseVolumeV1Test):
Attila Fazekas3dcdae12013-02-14 12:50:04 +010024 _interface = "json"
Attila Fazekas36b1fcf2013-01-31 16:41:04 +010025
Giulio Fidente73332932013-05-03 18:04:09 +020026 @classmethod
Zhi Kun Liu43f9af12014-03-19 21:01:35 +080027 @test.safe_setup
Giulio Fidente73332932013-05-03 18:04:09 +020028 def setUpClass(cls):
29 super(VolumesSnapshotTest, cls).setUpClass()
Zhi Kun Liu43f9af12014-03-19 21:01:35 +080030 cls.volume_origin = cls.create_volume()
Giulio Fidente73332932013-05-03 18:04:09 +020031
JordanPbce55532014-03-19 12:10:32 +010032 if not CONF.volume_feature_enabled.snapshot:
33 raise cls.skipException("Cinder volume snapshots are disabled")
34
Giulio Fidente73332932013-05-03 18:04:09 +020035 @classmethod
36 def tearDownClass(cls):
37 super(VolumesSnapshotTest, cls).tearDownClass()
Giulio Fidente73332932013-05-03 18:04:09 +020038
Xiao Chen47fcbf42014-01-13 16:42:41 +080039 def _detach(self, volume_id):
40 """Detach volume."""
41 self.volumes_client.detach_volume(volume_id)
42 self.volumes_client.wait_for_volume_status(volume_id, 'available')
43
Abhijeet Malawade5945ffe2013-09-17 05:54:44 -070044 def _list_by_param_values_and_assert(self, params, with_detail=False):
45 """
46 Perform list or list_details action with given params
47 and validates result.
48 """
49 if with_detail:
50 resp, fetched_snap_list = \
51 self.snapshots_client.\
52 list_snapshots_with_detail(params=params)
53 else:
54 resp, fetched_snap_list = \
55 self.snapshots_client.list_snapshots(params=params)
56
57 self.assertEqual(200, resp.status)
58 # 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')
Xiao Chen47fcbf42014-01-13 16:42:41 +080066 def test_snapshot_create_with_volume_in_use(self):
67 # Create a snapshot when volume status is in-use
68 # Create a test instance
69 server_name = data_utils.rand_name('instance-')
70 resp, server = self.servers_client.create_server(server_name,
71 self.image_ref,
72 self.flavor_ref)
Xiao Chen47fcbf42014-01-13 16:42:41 +080073 self.addCleanup(self.servers_client.delete_server, server['id'])
Mauro S. M. Rodrigues253585d2014-03-19 12:08:39 -040074 self.servers_client.wait_for_server_status(server['id'], 'ACTIVE')
Xiao Chen47fcbf42014-01-13 16:42:41 +080075 mountpoint = '/dev/%s' % CONF.compute.volume_device_name
76 resp, body = self.volumes_client.attach_volume(
77 self.volume_origin['id'], server['id'], mountpoint)
78 self.assertEqual(202, resp.status)
79 self.volumes_client.wait_for_volume_status(self.volume_origin['id'],
80 'in-use')
81 self.addCleanup(self._detach, self.volume_origin['id'])
82 # Snapshot a volume even if it's attached to an instance
83 snapshot = self.create_snapshot(self.volume_origin['id'],
84 force=True)
85 # Delete the snapshot
86 self.snapshots_client.delete_snapshot(snapshot['id'])
87 self.assertEqual(202, resp.status)
88 self.snapshots_client.wait_for_resource_deletion(snapshot['id'])
89 self.snapshots.remove(snapshot)
90
Masayuki Igawa1edf94f2014-03-04 18:34:16 +090091 @test.attr(type='gate')
QingXin Mengdc95f5e2013-09-16 19:06:44 -070092 def test_snapshot_create_get_list_update_delete(self):
Giulio Fidentef41b8ee2013-05-21 11:07:21 +020093 # Create a snapshot
Masayuki Igawa259c1132013-10-31 17:48:44 +090094 s_name = data_utils.rand_name('snap')
Giulio Fidentef41b8ee2013-05-21 11:07:21 +020095 snapshot = self.create_snapshot(self.volume_origin['id'],
96 display_name=s_name)
Giulio Fidente73332932013-05-03 18:04:09 +020097
Giulio Fidentef41b8ee2013-05-21 11:07:21 +020098 # Get the snap and check for some of its details
99 resp, snap_get = self.snapshots_client.get_snapshot(snapshot['id'])
100 self.assertEqual(200, resp.status)
101 self.assertEqual(self.volume_origin['id'],
102 snap_get['volume_id'],
103 "Referred volume origin mismatch")
104
105 # Compare also with the output from the list action
106 tracking_data = (snapshot['id'], snapshot['display_name'])
107 resp, snaps_list = self.snapshots_client.list_snapshots()
108 self.assertEqual(200, resp.status)
109 snaps_data = [(f['id'], f['display_name']) for f in snaps_list]
110 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.'
115 resp, update_snapshot = \
116 self.snapshots_client.update_snapshot(snapshot['id'],
117 display_name=new_s_name,
118 display_description=new_desc)
119 # Assert response body for update_snapshot method
120 self.assertEqual(200, resp.status)
121 self.assertEqual(new_s_name, update_snapshot['display_name'])
122 self.assertEqual(new_desc, update_snapshot['display_description'])
123 # Assert response body for get_snapshot method
124 resp, updated_snapshot = \
125 self.snapshots_client.get_snapshot(snapshot['id'])
126 self.assertEqual(200, resp.status)
127 self.assertEqual(new_s_name, updated_snapshot['display_name'])
128 self.assertEqual(new_desc, updated_snapshot['display_description'])
129
Giulio Fidentef41b8ee2013-05-21 11:07:21 +0200130 # Delete the snapshot
131 self.snapshots_client.delete_snapshot(snapshot['id'])
132 self.assertEqual(200, resp.status)
133 self.snapshots_client.wait_for_resource_deletion(snapshot['id'])
134 self.snapshots.remove(snapshot)
135
Masayuki Igawa1edf94f2014-03-04 18:34:16 +0900136 @test.attr(type='gate')
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')
141 snapshot = self.create_snapshot(self.volume_origin['id'],
142 display_name=display_name)
143
144 # Verify list snapshots by display_name filter
145 params = {'display_name': snapshot['display_name']}
146 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',
154 'display_name': snapshot['display_name']}
155 self._list_by_param_values_and_assert(params)
156
Masayuki Igawa1edf94f2014-03-04 18:34:16 +0900157 @test.attr(type='gate')
Abhijeet Malawade5945ffe2013-09-17 05:54:44 -0700158 def test_snapshots_list_details_with_params(self):
159 """list snapshot details with params."""
160 # Create a snapshot
161 display_name = data_utils.rand_name('snap')
162 snapshot = self.create_snapshot(self.volume_origin['id'],
163 display_name=display_name)
164
165 # Verify list snapshot details by display_name filter
166 params = {'display_name': snapshot['display_name']}
167 self._list_by_param_values_and_assert(params, with_detail=True)
168 # Verify list snapshot details by status filter
169 params = {'status': 'available'}
170 self._list_by_param_values_and_assert(params, with_detail=True)
171 # Verify list snapshot details by status and display name filter
172 params = {'status': 'available',
173 'display_name': snapshot['display_name']}
174 self._list_by_param_values_and_assert(params, with_detail=True)
175
Masayuki Igawa1edf94f2014-03-04 18:34:16 +0900176 @test.attr(type='gate')
Giulio Fidente73332932013-05-03 18:04:09 +0200177 def test_volume_from_snapshot(self):
Giulio Fidente3a465e32013-05-07 13:38:18 +0200178 # Create a temporary snap using wrapper method from base, then
179 # create a snap based volume, check resp code and deletes it
Giulio Fidente73332932013-05-03 18:04:09 +0200180 snapshot = self.create_snapshot(self.volume_origin['id'])
Giulio Fidentef41b8ee2013-05-21 11:07:21 +0200181 # NOTE(gfidente): size is required also when passing snapshot_id
Giulio Fidente73332932013-05-03 18:04:09 +0200182 resp, volume = self.volumes_client.create_volume(
183 size=1,
184 snapshot_id=snapshot['id'])
185 self.assertEqual(200, resp.status)
186 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
Attila Fazekas3dcdae12013-02-14 12:50:04 +0100192class VolumesSnapshotTestXML(VolumesSnapshotTest):
193 _interface = "xml"