blob: 487ada6ac90b39ecae7c5fd8ac04d7d539edd7df [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
Matthew Treinishf4a9b0f2013-07-26 16:58:26 -040015from tempest.openstack.common import log as logging
Giulio Fidente73332932013-05-03 18:04:09 +020016from tempest.test import attr
Attila Fazekas36b1fcf2013-01-31 16:41:04 +010017
Giulio Fidente3a465e32013-05-07 13:38:18 +020018LOG = logging.getLogger(__name__)
19
Attila Fazekas36b1fcf2013-01-31 16:41:04 +010020
Zhi Kun Liubb363a22013-11-28 18:47:39 +080021class VolumesSnapshotTest(base.BaseVolumeV1Test):
Attila Fazekas3dcdae12013-02-14 12:50:04 +010022 _interface = "json"
Attila Fazekas36b1fcf2013-01-31 16:41:04 +010023
Giulio Fidente73332932013-05-03 18:04:09 +020024 @classmethod
25 def setUpClass(cls):
26 super(VolumesSnapshotTest, cls).setUpClass()
27 try:
28 cls.volume_origin = cls.create_volume()
29 except Exception:
Giulio Fidente3a465e32013-05-07 13:38:18 +020030 LOG.exception("setup failed")
Giulio Fidente73332932013-05-03 18:04:09 +020031 cls.tearDownClass()
32 raise
33
34 @classmethod
35 def tearDownClass(cls):
36 super(VolumesSnapshotTest, cls).tearDownClass()
Giulio Fidente73332932013-05-03 18:04:09 +020037
Abhijeet Malawade5945ffe2013-09-17 05:54:44 -070038 def _list_by_param_values_and_assert(self, params, with_detail=False):
39 """
40 Perform list or list_details action with given params
41 and validates result.
42 """
43 if with_detail:
44 resp, fetched_snap_list = \
45 self.snapshots_client.\
46 list_snapshots_with_detail(params=params)
47 else:
48 resp, fetched_snap_list = \
49 self.snapshots_client.list_snapshots(params=params)
50
51 self.assertEqual(200, resp.status)
52 # Validating params of fetched snapshots
53 for snap in fetched_snap_list:
54 for key in params:
55 msg = "Failed to list snapshots %s by %s" % \
56 ('details' if with_detail else '', key)
57 self.assertEqual(params[key], snap[key], msg)
58
Giulio Fidentef41b8ee2013-05-21 11:07:21 +020059 @attr(type='gate')
QingXin Mengdc95f5e2013-09-16 19:06:44 -070060 def test_snapshot_create_get_list_update_delete(self):
Giulio Fidentef41b8ee2013-05-21 11:07:21 +020061 # Create a snapshot
Masayuki Igawa259c1132013-10-31 17:48:44 +090062 s_name = data_utils.rand_name('snap')
Giulio Fidentef41b8ee2013-05-21 11:07:21 +020063 snapshot = self.create_snapshot(self.volume_origin['id'],
64 display_name=s_name)
Giulio Fidente73332932013-05-03 18:04:09 +020065
Giulio Fidentef41b8ee2013-05-21 11:07:21 +020066 # Get the snap and check for some of its details
67 resp, snap_get = self.snapshots_client.get_snapshot(snapshot['id'])
68 self.assertEqual(200, resp.status)
69 self.assertEqual(self.volume_origin['id'],
70 snap_get['volume_id'],
71 "Referred volume origin mismatch")
72
73 # Compare also with the output from the list action
74 tracking_data = (snapshot['id'], snapshot['display_name'])
75 resp, snaps_list = self.snapshots_client.list_snapshots()
76 self.assertEqual(200, resp.status)
77 snaps_data = [(f['id'], f['display_name']) for f in snaps_list]
78 self.assertIn(tracking_data, snaps_data)
79
QingXin Mengdc95f5e2013-09-16 19:06:44 -070080 # Updates snapshot with new values
Masayuki Igawa259c1132013-10-31 17:48:44 +090081 new_s_name = data_utils.rand_name('new-snap')
QingXin Mengdc95f5e2013-09-16 19:06:44 -070082 new_desc = 'This is the new description of snapshot.'
83 resp, update_snapshot = \
84 self.snapshots_client.update_snapshot(snapshot['id'],
85 display_name=new_s_name,
86 display_description=new_desc)
87 # Assert response body for update_snapshot method
88 self.assertEqual(200, resp.status)
89 self.assertEqual(new_s_name, update_snapshot['display_name'])
90 self.assertEqual(new_desc, update_snapshot['display_description'])
91 # Assert response body for get_snapshot method
92 resp, updated_snapshot = \
93 self.snapshots_client.get_snapshot(snapshot['id'])
94 self.assertEqual(200, resp.status)
95 self.assertEqual(new_s_name, updated_snapshot['display_name'])
96 self.assertEqual(new_desc, updated_snapshot['display_description'])
97
Giulio Fidentef41b8ee2013-05-21 11:07:21 +020098 # Delete the snapshot
99 self.snapshots_client.delete_snapshot(snapshot['id'])
100 self.assertEqual(200, resp.status)
101 self.snapshots_client.wait_for_resource_deletion(snapshot['id'])
102 self.snapshots.remove(snapshot)
103
104 @attr(type='gate')
Abhijeet Malawade5945ffe2013-09-17 05:54:44 -0700105 def test_snapshots_list_with_params(self):
106 """list snapshots with params."""
107 # Create a snapshot
108 display_name = data_utils.rand_name('snap')
109 snapshot = self.create_snapshot(self.volume_origin['id'],
110 display_name=display_name)
111
112 # Verify list snapshots by display_name filter
113 params = {'display_name': snapshot['display_name']}
114 self._list_by_param_values_and_assert(params)
115
116 # Verify list snapshots by status filter
117 params = {'status': 'available'}
118 self._list_by_param_values_and_assert(params)
119
120 # Verify list snapshots by status and display name filter
121 params = {'status': 'available',
122 'display_name': snapshot['display_name']}
123 self._list_by_param_values_and_assert(params)
124
125 @attr(type='gate')
126 def test_snapshots_list_details_with_params(self):
127 """list snapshot details with params."""
128 # Create a snapshot
129 display_name = data_utils.rand_name('snap')
130 snapshot = self.create_snapshot(self.volume_origin['id'],
131 display_name=display_name)
132
133 # Verify list snapshot details by display_name filter
134 params = {'display_name': snapshot['display_name']}
135 self._list_by_param_values_and_assert(params, with_detail=True)
136 # Verify list snapshot details by status filter
137 params = {'status': 'available'}
138 self._list_by_param_values_and_assert(params, with_detail=True)
139 # Verify list snapshot details by status and display name filter
140 params = {'status': 'available',
141 'display_name': snapshot['display_name']}
142 self._list_by_param_values_and_assert(params, with_detail=True)
143
144 @attr(type='gate')
Giulio Fidente73332932013-05-03 18:04:09 +0200145 def test_volume_from_snapshot(self):
Giulio Fidente3a465e32013-05-07 13:38:18 +0200146 # Create a temporary snap using wrapper method from base, then
147 # create a snap based volume, check resp code and deletes it
Giulio Fidente73332932013-05-03 18:04:09 +0200148 snapshot = self.create_snapshot(self.volume_origin['id'])
Giulio Fidentef41b8ee2013-05-21 11:07:21 +0200149 # NOTE(gfidente): size is required also when passing snapshot_id
Giulio Fidente73332932013-05-03 18:04:09 +0200150 resp, volume = self.volumes_client.create_volume(
151 size=1,
152 snapshot_id=snapshot['id'])
153 self.assertEqual(200, resp.status)
154 self.volumes_client.wait_for_volume_status(volume['id'], 'available')
155 self.volumes_client.delete_volume(volume['id'])
156 self.volumes_client.wait_for_resource_deletion(volume['id'])
157 self.clear_snapshots()
Attila Fazekas36b1fcf2013-01-31 16:41:04 +0100158
159
Attila Fazekas3dcdae12013-02-14 12:50:04 +0100160class VolumesSnapshotTestXML(VolumesSnapshotTest):
161 _interface = "xml"