Attila Fazekas | 36b1fcf | 2013-01-31 16:41:04 +0100 | [diff] [blame] | 1 | # 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 Dague | 1937d09 | 2013-05-17 16:36:38 -0400 | [diff] [blame] | 15 | from tempest.api.volume import base |
Giulio Fidente | f41b8ee | 2013-05-21 11:07:21 +0200 | [diff] [blame] | 16 | from tempest.common.utils.data_utils import rand_name |
Matthew Treinish | f4a9b0f | 2013-07-26 16:58:26 -0400 | [diff] [blame] | 17 | from tempest.openstack.common import log as logging |
Giulio Fidente | 7333293 | 2013-05-03 18:04:09 +0200 | [diff] [blame] | 18 | from tempest.test import attr |
Attila Fazekas | 36b1fcf | 2013-01-31 16:41:04 +0100 | [diff] [blame] | 19 | |
Giulio Fidente | 3a465e3 | 2013-05-07 13:38:18 +0200 | [diff] [blame] | 20 | LOG = logging.getLogger(__name__) |
| 21 | |
Attila Fazekas | 36b1fcf | 2013-01-31 16:41:04 +0100 | [diff] [blame] | 22 | |
Attila Fazekas | 3dcdae1 | 2013-02-14 12:50:04 +0100 | [diff] [blame] | 23 | class VolumesSnapshotTest(base.BaseVolumeTest): |
| 24 | _interface = "json" |
Attila Fazekas | 36b1fcf | 2013-01-31 16:41:04 +0100 | [diff] [blame] | 25 | |
Giulio Fidente | 7333293 | 2013-05-03 18:04:09 +0200 | [diff] [blame] | 26 | @classmethod |
| 27 | def setUpClass(cls): |
| 28 | super(VolumesSnapshotTest, cls).setUpClass() |
| 29 | try: |
| 30 | cls.volume_origin = cls.create_volume() |
| 31 | except Exception: |
Giulio Fidente | 3a465e3 | 2013-05-07 13:38:18 +0200 | [diff] [blame] | 32 | LOG.exception("setup failed") |
Giulio Fidente | 7333293 | 2013-05-03 18:04:09 +0200 | [diff] [blame] | 33 | cls.tearDownClass() |
| 34 | raise |
| 35 | |
| 36 | @classmethod |
| 37 | def tearDownClass(cls): |
| 38 | super(VolumesSnapshotTest, cls).tearDownClass() |
Giulio Fidente | 7333293 | 2013-05-03 18:04:09 +0200 | [diff] [blame] | 39 | |
Giulio Fidente | f41b8ee | 2013-05-21 11:07:21 +0200 | [diff] [blame] | 40 | @attr(type='gate') |
QingXin Meng | dc95f5e | 2013-09-16 19:06:44 -0700 | [diff] [blame] | 41 | def test_snapshot_create_get_list_update_delete(self): |
Giulio Fidente | f41b8ee | 2013-05-21 11:07:21 +0200 | [diff] [blame] | 42 | # Create a snapshot |
| 43 | s_name = rand_name('snap') |
| 44 | snapshot = self.create_snapshot(self.volume_origin['id'], |
| 45 | display_name=s_name) |
Giulio Fidente | 7333293 | 2013-05-03 18:04:09 +0200 | [diff] [blame] | 46 | |
Giulio Fidente | f41b8ee | 2013-05-21 11:07:21 +0200 | [diff] [blame] | 47 | # 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 Meng | dc95f5e | 2013-09-16 19:06:44 -0700 | [diff] [blame] | 61 | # 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 Fidente | f41b8ee | 2013-05-21 11:07:21 +0200 | [diff] [blame] | 79 | # 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 Fidente | 7333293 | 2013-05-03 18:04:09 +0200 | [diff] [blame] | 86 | def test_volume_from_snapshot(self): |
Giulio Fidente | 3a465e3 | 2013-05-07 13:38:18 +0200 | [diff] [blame] | 87 | # Create a temporary snap using wrapper method from base, then |
| 88 | # create a snap based volume, check resp code and deletes it |
Giulio Fidente | 7333293 | 2013-05-03 18:04:09 +0200 | [diff] [blame] | 89 | snapshot = self.create_snapshot(self.volume_origin['id']) |
Giulio Fidente | f41b8ee | 2013-05-21 11:07:21 +0200 | [diff] [blame] | 90 | # NOTE(gfidente): size is required also when passing snapshot_id |
Giulio Fidente | 7333293 | 2013-05-03 18:04:09 +0200 | [diff] [blame] | 91 | 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 Fazekas | 36b1fcf | 2013-01-31 16:41:04 +0100 | [diff] [blame] | 99 | |
| 100 | |
Attila Fazekas | 3dcdae1 | 2013-02-14 12:50:04 +0100 | [diff] [blame] | 101 | class VolumesSnapshotTestXML(VolumesSnapshotTest): |
| 102 | _interface = "xml" |