blob: 84c95016a75d9d376baa615fe4d34ba74f7cd896 [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
27 def setUpClass(cls):
28 super(VolumesSnapshotTest, cls).setUpClass()
29 try:
30 cls.volume_origin = cls.create_volume()
31 except Exception:
Giulio Fidente3a465e32013-05-07 13:38:18 +020032 LOG.exception("setup failed")
Giulio Fidente73332932013-05-03 18:04:09 +020033 cls.tearDownClass()
34 raise
35
36 @classmethod
37 def tearDownClass(cls):
38 super(VolumesSnapshotTest, cls).tearDownClass()
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:
51 resp, fetched_snap_list = \
52 self.snapshots_client.\
53 list_snapshots_with_detail(params=params)
54 else:
55 resp, fetched_snap_list = \
56 self.snapshots_client.list_snapshots(params=params)
57
58 self.assertEqual(200, resp.status)
59 # 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
Masayuki Igawa1edf94f2014-03-04 18:34:16 +090066 @test.attr(type='gate')
Xiao Chen47fcbf42014-01-13 16:42:41 +080067 def test_snapshot_create_with_volume_in_use(self):
68 # Create a snapshot when volume status is in-use
69 # Create a test instance
70 server_name = data_utils.rand_name('instance-')
71 resp, server = self.servers_client.create_server(server_name,
72 self.image_ref,
73 self.flavor_ref)
Xiao Chen47fcbf42014-01-13 16:42:41 +080074 self.addCleanup(self.servers_client.delete_server, server['id'])
Mauro S. M. Rodrigues253585d2014-03-19 12:08:39 -040075 self.servers_client.wait_for_server_status(server['id'], 'ACTIVE')
Xiao Chen47fcbf42014-01-13 16:42:41 +080076 mountpoint = '/dev/%s' % CONF.compute.volume_device_name
77 resp, body = self.volumes_client.attach_volume(
78 self.volume_origin['id'], server['id'], mountpoint)
79 self.assertEqual(202, resp.status)
80 self.volumes_client.wait_for_volume_status(self.volume_origin['id'],
81 'in-use')
82 self.addCleanup(self._detach, self.volume_origin['id'])
83 # Snapshot a volume even if it's attached to an instance
84 snapshot = self.create_snapshot(self.volume_origin['id'],
85 force=True)
86 # Delete the snapshot
87 self.snapshots_client.delete_snapshot(snapshot['id'])
88 self.assertEqual(202, resp.status)
89 self.snapshots_client.wait_for_resource_deletion(snapshot['id'])
90 self.snapshots.remove(snapshot)
91
Masayuki Igawa1edf94f2014-03-04 18:34:16 +090092 @test.attr(type='gate')
QingXin Mengdc95f5e2013-09-16 19:06:44 -070093 def test_snapshot_create_get_list_update_delete(self):
Giulio Fidentef41b8ee2013-05-21 11:07:21 +020094 # Create a snapshot
Masayuki Igawa259c1132013-10-31 17:48:44 +090095 s_name = data_utils.rand_name('snap')
Giulio Fidentef41b8ee2013-05-21 11:07:21 +020096 snapshot = self.create_snapshot(self.volume_origin['id'],
97 display_name=s_name)
Giulio Fidente73332932013-05-03 18:04:09 +020098
Giulio Fidentef41b8ee2013-05-21 11:07:21 +020099 # Get the snap and check for some of its details
100 resp, snap_get = self.snapshots_client.get_snapshot(snapshot['id'])
101 self.assertEqual(200, resp.status)
102 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
107 tracking_data = (snapshot['id'], snapshot['display_name'])
108 resp, snaps_list = self.snapshots_client.list_snapshots()
109 self.assertEqual(200, resp.status)
110 snaps_data = [(f['id'], f['display_name']) for f in snaps_list]
111 self.assertIn(tracking_data, snaps_data)
112
QingXin Mengdc95f5e2013-09-16 19:06:44 -0700113 # Updates snapshot with new values
Masayuki Igawa259c1132013-10-31 17:48:44 +0900114 new_s_name = data_utils.rand_name('new-snap')
QingXin Mengdc95f5e2013-09-16 19:06:44 -0700115 new_desc = 'This is the new description of snapshot.'
116 resp, update_snapshot = \
117 self.snapshots_client.update_snapshot(snapshot['id'],
118 display_name=new_s_name,
119 display_description=new_desc)
120 # Assert response body for update_snapshot method
121 self.assertEqual(200, resp.status)
122 self.assertEqual(new_s_name, update_snapshot['display_name'])
123 self.assertEqual(new_desc, update_snapshot['display_description'])
124 # Assert response body for get_snapshot method
125 resp, updated_snapshot = \
126 self.snapshots_client.get_snapshot(snapshot['id'])
127 self.assertEqual(200, resp.status)
128 self.assertEqual(new_s_name, updated_snapshot['display_name'])
129 self.assertEqual(new_desc, updated_snapshot['display_description'])
130
Giulio Fidentef41b8ee2013-05-21 11:07:21 +0200131 # Delete the snapshot
132 self.snapshots_client.delete_snapshot(snapshot['id'])
133 self.assertEqual(200, resp.status)
134 self.snapshots_client.wait_for_resource_deletion(snapshot['id'])
135 self.snapshots.remove(snapshot)
136
Masayuki Igawa1edf94f2014-03-04 18:34:16 +0900137 @test.attr(type='gate')
Abhijeet Malawade5945ffe2013-09-17 05:54:44 -0700138 def test_snapshots_list_with_params(self):
139 """list snapshots with params."""
140 # Create a snapshot
141 display_name = data_utils.rand_name('snap')
142 snapshot = self.create_snapshot(self.volume_origin['id'],
143 display_name=display_name)
144
145 # Verify list snapshots by display_name filter
146 params = {'display_name': snapshot['display_name']}
147 self._list_by_param_values_and_assert(params)
148
149 # Verify list snapshots by status filter
150 params = {'status': 'available'}
151 self._list_by_param_values_and_assert(params)
152
153 # Verify list snapshots by status and display name filter
154 params = {'status': 'available',
155 'display_name': snapshot['display_name']}
156 self._list_by_param_values_and_assert(params)
157
Masayuki Igawa1edf94f2014-03-04 18:34:16 +0900158 @test.attr(type='gate')
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')
163 snapshot = self.create_snapshot(self.volume_origin['id'],
164 display_name=display_name)
165
166 # Verify list snapshot details by display_name filter
167 params = {'display_name': snapshot['display_name']}
168 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',
174 'display_name': snapshot['display_name']}
175 self._list_by_param_values_and_assert(params, with_detail=True)
176
Masayuki Igawa1edf94f2014-03-04 18:34:16 +0900177 @test.attr(type='gate')
Giulio Fidente73332932013-05-03 18:04:09 +0200178 def test_volume_from_snapshot(self):
Giulio Fidente3a465e32013-05-07 13:38:18 +0200179 # Create a temporary snap using wrapper method from base, then
180 # create a snap based volume, check resp code and deletes it
Giulio Fidente73332932013-05-03 18:04:09 +0200181 snapshot = self.create_snapshot(self.volume_origin['id'])
Giulio Fidentef41b8ee2013-05-21 11:07:21 +0200182 # NOTE(gfidente): size is required also when passing snapshot_id
Giulio Fidente73332932013-05-03 18:04:09 +0200183 resp, volume = self.volumes_client.create_volume(
184 size=1,
185 snapshot_id=snapshot['id'])
186 self.assertEqual(200, resp.status)
187 self.volumes_client.wait_for_volume_status(volume['id'], 'available')
188 self.volumes_client.delete_volume(volume['id'])
189 self.volumes_client.wait_for_resource_deletion(volume['id'])
190 self.clear_snapshots()
Attila Fazekas36b1fcf2013-01-31 16:41:04 +0100191
192
Attila Fazekas3dcdae12013-02-14 12:50:04 +0100193class VolumesSnapshotTestXML(VolumesSnapshotTest):
194 _interface = "xml"