Attila Fazekas | 36b1fcf | 2013-01-31 16:41:04 +0100 | [diff] [blame] | 1 | # 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 Dague | 1937d09 | 2013-05-17 16:36:38 -0400 | [diff] [blame] | 13 | from tempest.api.volume import base |
Masayuki Igawa | 259c113 | 2013-10-31 17:48:44 +0900 | [diff] [blame] | 14 | from tempest.common.utils import data_utils |
Matthew Treinish | f4a9b0f | 2013-07-26 16:58:26 -0400 | [diff] [blame] | 15 | from tempest.openstack.common import log as logging |
Giulio Fidente | 7333293 | 2013-05-03 18:04:09 +0200 | [diff] [blame] | 16 | from tempest.test import attr |
Attila Fazekas | 36b1fcf | 2013-01-31 16:41:04 +0100 | [diff] [blame] | 17 | |
Giulio Fidente | 3a465e3 | 2013-05-07 13:38:18 +0200 | [diff] [blame] | 18 | LOG = logging.getLogger(__name__) |
| 19 | |
Attila Fazekas | 36b1fcf | 2013-01-31 16:41:04 +0100 | [diff] [blame] | 20 | |
Zhi Kun Liu | bb363a2 | 2013-11-28 18:47:39 +0800 | [diff] [blame] | 21 | class VolumesSnapshotTest(base.BaseVolumeV1Test): |
Attila Fazekas | 3dcdae1 | 2013-02-14 12:50:04 +0100 | [diff] [blame] | 22 | _interface = "json" |
Attila Fazekas | 36b1fcf | 2013-01-31 16:41:04 +0100 | [diff] [blame] | 23 | |
Giulio Fidente | 7333293 | 2013-05-03 18:04:09 +0200 | [diff] [blame] | 24 | @classmethod |
| 25 | def setUpClass(cls): |
| 26 | super(VolumesSnapshotTest, cls).setUpClass() |
| 27 | try: |
| 28 | cls.volume_origin = cls.create_volume() |
| 29 | except Exception: |
Giulio Fidente | 3a465e3 | 2013-05-07 13:38:18 +0200 | [diff] [blame] | 30 | LOG.exception("setup failed") |
Giulio Fidente | 7333293 | 2013-05-03 18:04:09 +0200 | [diff] [blame] | 31 | cls.tearDownClass() |
| 32 | raise |
| 33 | |
| 34 | @classmethod |
| 35 | def tearDownClass(cls): |
| 36 | super(VolumesSnapshotTest, cls).tearDownClass() |
Giulio Fidente | 7333293 | 2013-05-03 18:04:09 +0200 | [diff] [blame] | 37 | |
Abhijeet Malawade | 5945ffe | 2013-09-17 05:54:44 -0700 | [diff] [blame] | 38 | 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 Fidente | f41b8ee | 2013-05-21 11:07:21 +0200 | [diff] [blame] | 59 | @attr(type='gate') |
QingXin Meng | dc95f5e | 2013-09-16 19:06:44 -0700 | [diff] [blame] | 60 | def test_snapshot_create_get_list_update_delete(self): |
Giulio Fidente | f41b8ee | 2013-05-21 11:07:21 +0200 | [diff] [blame] | 61 | # Create a snapshot |
Masayuki Igawa | 259c113 | 2013-10-31 17:48:44 +0900 | [diff] [blame] | 62 | s_name = data_utils.rand_name('snap') |
Giulio Fidente | f41b8ee | 2013-05-21 11:07:21 +0200 | [diff] [blame] | 63 | snapshot = self.create_snapshot(self.volume_origin['id'], |
| 64 | display_name=s_name) |
Giulio Fidente | 7333293 | 2013-05-03 18:04:09 +0200 | [diff] [blame] | 65 | |
Giulio Fidente | f41b8ee | 2013-05-21 11:07:21 +0200 | [diff] [blame] | 66 | # 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 Meng | dc95f5e | 2013-09-16 19:06:44 -0700 | [diff] [blame] | 80 | # Updates snapshot with new values |
Masayuki Igawa | 259c113 | 2013-10-31 17:48:44 +0900 | [diff] [blame] | 81 | new_s_name = data_utils.rand_name('new-snap') |
QingXin Meng | dc95f5e | 2013-09-16 19:06:44 -0700 | [diff] [blame] | 82 | 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 Fidente | f41b8ee | 2013-05-21 11:07:21 +0200 | [diff] [blame] | 98 | # 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 Malawade | 5945ffe | 2013-09-17 05:54:44 -0700 | [diff] [blame] | 105 | 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 Fidente | 7333293 | 2013-05-03 18:04:09 +0200 | [diff] [blame] | 145 | def test_volume_from_snapshot(self): |
Giulio Fidente | 3a465e3 | 2013-05-07 13:38:18 +0200 | [diff] [blame] | 146 | # Create a temporary snap using wrapper method from base, then |
| 147 | # create a snap based volume, check resp code and deletes it |
Giulio Fidente | 7333293 | 2013-05-03 18:04:09 +0200 | [diff] [blame] | 148 | snapshot = self.create_snapshot(self.volume_origin['id']) |
Giulio Fidente | f41b8ee | 2013-05-21 11:07:21 +0200 | [diff] [blame] | 149 | # NOTE(gfidente): size is required also when passing snapshot_id |
Giulio Fidente | 7333293 | 2013-05-03 18:04:09 +0200 | [diff] [blame] | 150 | 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 Fazekas | 36b1fcf | 2013-01-31 16:41:04 +0100 | [diff] [blame] | 158 | |
| 159 | |
Attila Fazekas | 3dcdae1 | 2013-02-14 12:50:04 +0100 | [diff] [blame] | 160 | class VolumesSnapshotTestXML(VolumesSnapshotTest): |
| 161 | _interface = "xml" |