blob: 6b186e5e4749ed63c3174483dd6ef566b0a6235f [file] [log] [blame]
Attila Fazekas36b1fcf2013-01-31 16:41:04 +01001# vim: tabstop=4 shiftwidth=4 softtabstop=4
2
3# Licensed under the Apache License, Version 2.0 (the "License"); you may
4# not use this file except in compliance with the License. You may obtain
5# a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12# License for the specific language governing permissions and limitations
13# under the License.
14
Sean Dague1937d092013-05-17 16:36:38 -040015from tempest.api.volume import base
Giulio Fidentef41b8ee2013-05-21 11:07:21 +020016from tempest.common.utils.data_utils import rand_name
Matthew Treinishf4a9b0f2013-07-26 16:58:26 -040017from tempest.openstack.common import log as logging
Giulio Fidente73332932013-05-03 18:04:09 +020018from tempest.test import attr
Attila Fazekas36b1fcf2013-01-31 16:41:04 +010019
Giulio Fidente3a465e32013-05-07 13:38:18 +020020LOG = logging.getLogger(__name__)
21
Attila Fazekas36b1fcf2013-01-31 16:41:04 +010022
Attila Fazekas3dcdae12013-02-14 12:50:04 +010023class VolumesSnapshotTest(base.BaseVolumeTest):
24 _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
Giulio Fidentef41b8ee2013-05-21 11:07:21 +020040 @attr(type='gate')
QingXin Mengdc95f5e2013-09-16 19:06:44 -070041 def test_snapshot_create_get_list_update_delete(self):
Giulio Fidentef41b8ee2013-05-21 11:07:21 +020042 # Create a snapshot
43 s_name = rand_name('snap')
44 snapshot = self.create_snapshot(self.volume_origin['id'],
45 display_name=s_name)
Giulio Fidente73332932013-05-03 18:04:09 +020046
Giulio Fidentef41b8ee2013-05-21 11:07:21 +020047 # Get the snap and check for some of its details
48 resp, snap_get = self.snapshots_client.get_snapshot(snapshot['id'])
49 self.assertEqual(200, resp.status)
50 self.assertEqual(self.volume_origin['id'],
51 snap_get['volume_id'],
52 "Referred volume origin mismatch")
53
54 # Compare also with the output from the list action
55 tracking_data = (snapshot['id'], snapshot['display_name'])
56 resp, snaps_list = self.snapshots_client.list_snapshots()
57 self.assertEqual(200, resp.status)
58 snaps_data = [(f['id'], f['display_name']) for f in snaps_list]
59 self.assertIn(tracking_data, snaps_data)
60
QingXin Mengdc95f5e2013-09-16 19:06:44 -070061 # Updates snapshot with new values
62 new_s_name = rand_name('new-snap')
63 new_desc = 'This is the new description of snapshot.'
64 resp, update_snapshot = \
65 self.snapshots_client.update_snapshot(snapshot['id'],
66 display_name=new_s_name,
67 display_description=new_desc)
68 # Assert response body for update_snapshot method
69 self.assertEqual(200, resp.status)
70 self.assertEqual(new_s_name, update_snapshot['display_name'])
71 self.assertEqual(new_desc, update_snapshot['display_description'])
72 # Assert response body for get_snapshot method
73 resp, updated_snapshot = \
74 self.snapshots_client.get_snapshot(snapshot['id'])
75 self.assertEqual(200, resp.status)
76 self.assertEqual(new_s_name, updated_snapshot['display_name'])
77 self.assertEqual(new_desc, updated_snapshot['display_description'])
78
Giulio Fidentef41b8ee2013-05-21 11:07:21 +020079 # Delete the snapshot
80 self.snapshots_client.delete_snapshot(snapshot['id'])
81 self.assertEqual(200, resp.status)
82 self.snapshots_client.wait_for_resource_deletion(snapshot['id'])
83 self.snapshots.remove(snapshot)
84
85 @attr(type='gate')
Giulio Fidente73332932013-05-03 18:04:09 +020086 def test_volume_from_snapshot(self):
Giulio Fidente3a465e32013-05-07 13:38:18 +020087 # Create a temporary snap using wrapper method from base, then
88 # create a snap based volume, check resp code and deletes it
Giulio Fidente73332932013-05-03 18:04:09 +020089 snapshot = self.create_snapshot(self.volume_origin['id'])
Giulio Fidentef41b8ee2013-05-21 11:07:21 +020090 # NOTE(gfidente): size is required also when passing snapshot_id
Giulio Fidente73332932013-05-03 18:04:09 +020091 resp, volume = self.volumes_client.create_volume(
92 size=1,
93 snapshot_id=snapshot['id'])
94 self.assertEqual(200, resp.status)
95 self.volumes_client.wait_for_volume_status(volume['id'], 'available')
96 self.volumes_client.delete_volume(volume['id'])
97 self.volumes_client.wait_for_resource_deletion(volume['id'])
98 self.clear_snapshots()
Attila Fazekas36b1fcf2013-01-31 16:41:04 +010099
100
Attila Fazekas3dcdae12013-02-14 12:50:04 +0100101class VolumesSnapshotTestXML(VolumesSnapshotTest):
102 _interface = "xml"