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 | |
Doug Hellmann | 583ce2c | 2015-03-11 14:55:46 +0000 | [diff] [blame] | 13 | from oslo_log import log as logging |
Matthew Treinish | 01472ff | 2015-02-20 17:26:52 -0500 | [diff] [blame] | 14 | |
Sean Dague | 1937d09 | 2013-05-17 16:36:38 -0400 | [diff] [blame] | 15 | from tempest.api.volume import base |
Fei Long Wang | d39431f | 2015-05-14 11:30:48 +1200 | [diff] [blame] | 16 | from tempest.common.utils import data_utils |
Xiao Chen | 47fcbf4 | 2014-01-13 16:42:41 +0800 | [diff] [blame] | 17 | from tempest import config |
Masayuki Igawa | 1edf94f | 2014-03-04 18:34:16 +0900 | [diff] [blame] | 18 | from tempest import test |
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__) |
Xiao Chen | 47fcbf4 | 2014-01-13 16:42:41 +0800 | [diff] [blame] | 21 | CONF = config.CONF |
Giulio Fidente | 3a465e3 | 2013-05-07 13:38:18 +0200 | [diff] [blame] | 22 | |
Attila Fazekas | 36b1fcf | 2013-01-31 16:41:04 +0100 | [diff] [blame] | 23 | |
Zhi Kun Liu | 38641c6 | 2014-07-10 20:12:48 +0800 | [diff] [blame] | 24 | class VolumesV2SnapshotTestJSON(base.BaseVolumeTest): |
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 |
Rohan Kanade | 0574915 | 2015-01-30 17:15:18 +0530 | [diff] [blame] | 27 | def skip_checks(cls): |
| 28 | super(VolumesV2SnapshotTestJSON, cls).skip_checks() |
| 29 | if not CONF.volume_feature_enabled.snapshot: |
| 30 | raise cls.skipException("Cinder volume snapshots are disabled") |
| 31 | |
| 32 | @classmethod |
Andrea Frittoli | 61a12e2 | 2014-09-15 13:14:54 +0100 | [diff] [blame] | 33 | def resource_setup(cls): |
| 34 | super(VolumesV2SnapshotTestJSON, cls).resource_setup() |
Zhi Kun Liu | 43f9af1 | 2014-03-19 21:01:35 +0800 | [diff] [blame] | 35 | cls.volume_origin = cls.create_volume() |
Giulio Fidente | 7333293 | 2013-05-03 18:04:09 +0200 | [diff] [blame] | 36 | |
Zhi Kun Liu | 38641c6 | 2014-07-10 20:12:48 +0800 | [diff] [blame] | 37 | cls.name_field = cls.special_fields['name_field'] |
| 38 | cls.descrip_field = cls.special_fields['descrip_field'] |
Giulio Fidente | 7333293 | 2013-05-03 18:04:09 +0200 | [diff] [blame] | 39 | |
Xiao Chen | 47fcbf4 | 2014-01-13 16:42:41 +0800 | [diff] [blame] | 40 | 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 Malawade | 5945ffe | 2013-09-17 05:54:44 -0700 | [diff] [blame] | 45 | 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: |
John Warren | ff7faf6 | 2015-08-17 16:59:06 +0000 | [diff] [blame] | 51 | fetched_snap_list = self.snapshots_client.list_snapshots( |
| 52 | detail=True, params=params)['snapshots'] |
Abhijeet Malawade | 5945ffe | 2013-09-17 05:54:44 -0700 | [diff] [blame] | 53 | else: |
John Warren | ff7faf6 | 2015-08-17 16:59:06 +0000 | [diff] [blame] | 54 | fetched_snap_list = self.snapshots_client.list_snapshots( |
| 55 | params=params)['snapshots'] |
Abhijeet Malawade | 5945ffe | 2013-09-17 05:54:44 -0700 | [diff] [blame] | 56 | |
Abhijeet Malawade | 5945ffe | 2013-09-17 05:54:44 -0700 | [diff] [blame] | 57 | # Validating params of fetched snapshots |
| 58 | for snap in fetched_snap_list: |
| 59 | for key in params: |
| 60 | msg = "Failed to list snapshots %s by %s" % \ |
| 61 | ('details' if with_detail else '', key) |
| 62 | self.assertEqual(params[key], snap[key], msg) |
| 63 | |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 64 | @test.idempotent_id('b467b54c-07a4-446d-a1cf-651dedcc3ff1') |
Matthew Treinish | 7ea69e6 | 2014-06-03 17:23:50 -0400 | [diff] [blame] | 65 | @test.services('compute') |
Xiao Chen | 47fcbf4 | 2014-01-13 16:42:41 +0800 | [diff] [blame] | 66 | def test_snapshot_create_with_volume_in_use(self): |
| 67 | # Create a snapshot when volume status is in-use |
| 68 | # Create a test instance |
Ken'ichi Ohmichi | 07308f1 | 2015-03-23 00:24:28 +0000 | [diff] [blame] | 69 | server_name = data_utils.rand_name('instance') |
Joseph Lanoux | a074c01 | 2015-08-04 15:44:07 +0000 | [diff] [blame] | 70 | server = self.create_server( |
| 71 | name=server_name, |
| 72 | wait_until='ACTIVE') |
Xiao Chen | 47fcbf4 | 2014-01-13 16:42:41 +0800 | [diff] [blame] | 73 | self.addCleanup(self.servers_client.delete_server, server['id']) |
| 74 | mountpoint = '/dev/%s' % CONF.compute.volume_device_name |
David Kranz | 3ebc721 | 2015-02-10 12:19:19 -0500 | [diff] [blame] | 75 | self.servers_client.attach_volume( |
Ken'ichi Ohmichi | dfc88de | 2015-08-13 05:12:20 +0000 | [diff] [blame] | 76 | server['id'], volumeId=self.volume_origin['id'], |
| 77 | device=mountpoint) |
Xiao Chen | 47fcbf4 | 2014-01-13 16:42:41 +0800 | [diff] [blame] | 78 | self.volumes_client.wait_for_volume_status(self.volume_origin['id'], |
| 79 | 'in-use') |
Mitsuhiro Tanino | ab66796 | 2014-12-10 15:52:08 -0500 | [diff] [blame] | 80 | self.addCleanup(self.volumes_client.wait_for_volume_status, |
| 81 | self.volume_origin['id'], 'available') |
| 82 | self.addCleanup(self.servers_client.detach_volume, server['id'], |
| 83 | self.volume_origin['id']) |
Xiao Chen | 47fcbf4 | 2014-01-13 16:42:41 +0800 | [diff] [blame] | 84 | # Snapshot a volume even if it's attached to an instance |
| 85 | snapshot = self.create_snapshot(self.volume_origin['id'], |
| 86 | force=True) |
| 87 | # Delete the snapshot |
Yuriy Nesenenko | 551e1a9 | 2015-09-11 18:26:05 +0300 | [diff] [blame] | 88 | self.cleanup_snapshot(snapshot) |
Xiao Chen | 47fcbf4 | 2014-01-13 16:42:41 +0800 | [diff] [blame] | 89 | |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 90 | @test.idempotent_id('2a8abbe4-d871-46db-b049-c41f5af8216e') |
QingXin Meng | dc95f5e | 2013-09-16 19:06:44 -0700 | [diff] [blame] | 91 | def test_snapshot_create_get_list_update_delete(self): |
Giulio Fidente | f41b8ee | 2013-05-21 11:07:21 +0200 | [diff] [blame] | 92 | # Create a snapshot |
Masayuki Igawa | 259c113 | 2013-10-31 17:48:44 +0900 | [diff] [blame] | 93 | s_name = data_utils.rand_name('snap') |
Zhi Kun Liu | 38641c6 | 2014-07-10 20:12:48 +0800 | [diff] [blame] | 94 | params = {self.name_field: s_name} |
| 95 | snapshot = self.create_snapshot(self.volume_origin['id'], **params) |
Giulio Fidente | 7333293 | 2013-05-03 18:04:09 +0200 | [diff] [blame] | 96 | |
Giulio Fidente | f41b8ee | 2013-05-21 11:07:21 +0200 | [diff] [blame] | 97 | # Get the snap and check for some of its details |
John Warren | ff7faf6 | 2015-08-17 16:59:06 +0000 | [diff] [blame] | 98 | snap_get = self.snapshots_client.show_snapshot( |
| 99 | snapshot['id'])['snapshot'] |
Giulio Fidente | f41b8ee | 2013-05-21 11:07:21 +0200 | [diff] [blame] | 100 | self.assertEqual(self.volume_origin['id'], |
| 101 | snap_get['volume_id'], |
| 102 | "Referred volume origin mismatch") |
| 103 | |
| 104 | # Compare also with the output from the list action |
Zhi Kun Liu | 38641c6 | 2014-07-10 20:12:48 +0800 | [diff] [blame] | 105 | tracking_data = (snapshot['id'], snapshot[self.name_field]) |
John Warren | ff7faf6 | 2015-08-17 16:59:06 +0000 | [diff] [blame] | 106 | snaps_list = self.snapshots_client.list_snapshots()['snapshots'] |
Zhi Kun Liu | 38641c6 | 2014-07-10 20:12:48 +0800 | [diff] [blame] | 107 | snaps_data = [(f['id'], f[self.name_field]) for f in snaps_list] |
Giulio Fidente | f41b8ee | 2013-05-21 11:07:21 +0200 | [diff] [blame] | 108 | self.assertIn(tracking_data, snaps_data) |
| 109 | |
QingXin Meng | dc95f5e | 2013-09-16 19:06:44 -0700 | [diff] [blame] | 110 | # Updates snapshot with new values |
Masayuki Igawa | 259c113 | 2013-10-31 17:48:44 +0900 | [diff] [blame] | 111 | new_s_name = data_utils.rand_name('new-snap') |
QingXin Meng | dc95f5e | 2013-09-16 19:06:44 -0700 | [diff] [blame] | 112 | new_desc = 'This is the new description of snapshot.' |
Zhi Kun Liu | 38641c6 | 2014-07-10 20:12:48 +0800 | [diff] [blame] | 113 | params = {self.name_field: new_s_name, |
| 114 | self.descrip_field: new_desc} |
John Warren | ff7faf6 | 2015-08-17 16:59:06 +0000 | [diff] [blame] | 115 | update_snapshot = self.snapshots_client.update_snapshot( |
| 116 | snapshot['id'], **params)['snapshot'] |
QingXin Meng | dc95f5e | 2013-09-16 19:06:44 -0700 | [diff] [blame] | 117 | # Assert response body for update_snapshot method |
Zhi Kun Liu | 38641c6 | 2014-07-10 20:12:48 +0800 | [diff] [blame] | 118 | self.assertEqual(new_s_name, update_snapshot[self.name_field]) |
| 119 | self.assertEqual(new_desc, update_snapshot[self.descrip_field]) |
Ken'ichi Ohmichi | 35798fb | 2015-04-06 01:22:41 +0000 | [diff] [blame] | 120 | # Assert response body for show_snapshot method |
John Warren | ff7faf6 | 2015-08-17 16:59:06 +0000 | [diff] [blame] | 121 | updated_snapshot = self.snapshots_client.show_snapshot( |
| 122 | snapshot['id'])['snapshot'] |
Zhi Kun Liu | 38641c6 | 2014-07-10 20:12:48 +0800 | [diff] [blame] | 123 | self.assertEqual(new_s_name, updated_snapshot[self.name_field]) |
| 124 | self.assertEqual(new_desc, updated_snapshot[self.descrip_field]) |
QingXin Meng | dc95f5e | 2013-09-16 19:06:44 -0700 | [diff] [blame] | 125 | |
Giulio Fidente | f41b8ee | 2013-05-21 11:07:21 +0200 | [diff] [blame] | 126 | # Delete the snapshot |
Yuriy Nesenenko | 551e1a9 | 2015-09-11 18:26:05 +0300 | [diff] [blame] | 127 | self.cleanup_snapshot(snapshot) |
Giulio Fidente | f41b8ee | 2013-05-21 11:07:21 +0200 | [diff] [blame] | 128 | |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 129 | @test.idempotent_id('59f41f43-aebf-48a9-ab5d-d76340fab32b') |
Abhijeet Malawade | 5945ffe | 2013-09-17 05:54:44 -0700 | [diff] [blame] | 130 | def test_snapshots_list_with_params(self): |
| 131 | """list snapshots with params.""" |
| 132 | # Create a snapshot |
| 133 | display_name = data_utils.rand_name('snap') |
Zhi Kun Liu | 38641c6 | 2014-07-10 20:12:48 +0800 | [diff] [blame] | 134 | params = {self.name_field: display_name} |
| 135 | snapshot = self.create_snapshot(self.volume_origin['id'], **params) |
Yuriy Nesenenko | 551e1a9 | 2015-09-11 18:26:05 +0300 | [diff] [blame] | 136 | self.addCleanup(self.cleanup_snapshot, snapshot) |
Abhijeet Malawade | 5945ffe | 2013-09-17 05:54:44 -0700 | [diff] [blame] | 137 | |
| 138 | # Verify list snapshots by display_name filter |
Zhi Kun Liu | 38641c6 | 2014-07-10 20:12:48 +0800 | [diff] [blame] | 139 | params = {self.name_field: snapshot[self.name_field]} |
Abhijeet Malawade | 5945ffe | 2013-09-17 05:54:44 -0700 | [diff] [blame] | 140 | self._list_by_param_values_and_assert(params) |
| 141 | |
| 142 | # Verify list snapshots by status filter |
| 143 | params = {'status': 'available'} |
| 144 | self._list_by_param_values_and_assert(params) |
| 145 | |
| 146 | # Verify list snapshots by status and display name filter |
| 147 | params = {'status': 'available', |
Zhi Kun Liu | 38641c6 | 2014-07-10 20:12:48 +0800 | [diff] [blame] | 148 | self.name_field: snapshot[self.name_field]} |
Abhijeet Malawade | 5945ffe | 2013-09-17 05:54:44 -0700 | [diff] [blame] | 149 | self._list_by_param_values_and_assert(params) |
| 150 | |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 151 | @test.idempotent_id('220a1022-1fcd-4a74-a7bd-6b859156cda2') |
Abhijeet Malawade | 5945ffe | 2013-09-17 05:54:44 -0700 | [diff] [blame] | 152 | def test_snapshots_list_details_with_params(self): |
| 153 | """list snapshot details with params.""" |
| 154 | # Create a snapshot |
| 155 | display_name = data_utils.rand_name('snap') |
Zhi Kun Liu | 38641c6 | 2014-07-10 20:12:48 +0800 | [diff] [blame] | 156 | params = {self.name_field: display_name} |
| 157 | snapshot = self.create_snapshot(self.volume_origin['id'], **params) |
Yuriy Nesenenko | 551e1a9 | 2015-09-11 18:26:05 +0300 | [diff] [blame] | 158 | self.addCleanup(self.cleanup_snapshot, snapshot) |
Abhijeet Malawade | 5945ffe | 2013-09-17 05:54:44 -0700 | [diff] [blame] | 159 | |
| 160 | # Verify list snapshot details by display_name filter |
Zhi Kun Liu | 38641c6 | 2014-07-10 20:12:48 +0800 | [diff] [blame] | 161 | params = {self.name_field: snapshot[self.name_field]} |
Abhijeet Malawade | 5945ffe | 2013-09-17 05:54:44 -0700 | [diff] [blame] | 162 | self._list_by_param_values_and_assert(params, with_detail=True) |
| 163 | # Verify list snapshot details by status filter |
| 164 | params = {'status': 'available'} |
| 165 | self._list_by_param_values_and_assert(params, with_detail=True) |
| 166 | # Verify list snapshot details by status and display name filter |
| 167 | params = {'status': 'available', |
Zhi Kun Liu | 38641c6 | 2014-07-10 20:12:48 +0800 | [diff] [blame] | 168 | self.name_field: snapshot[self.name_field]} |
Abhijeet Malawade | 5945ffe | 2013-09-17 05:54:44 -0700 | [diff] [blame] | 169 | self._list_by_param_values_and_assert(params, with_detail=True) |
| 170 | |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 171 | @test.idempotent_id('677863d1-3142-456d-b6ac-9924f667a7f4') |
Giulio Fidente | 7333293 | 2013-05-03 18:04:09 +0200 | [diff] [blame] | 172 | def test_volume_from_snapshot(self): |
Giulio Fidente | 3a465e3 | 2013-05-07 13:38:18 +0200 | [diff] [blame] | 173 | # Create a temporary snap using wrapper method from base, then |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 174 | # create a snap based volume and deletes it |
Giulio Fidente | 7333293 | 2013-05-03 18:04:09 +0200 | [diff] [blame] | 175 | snapshot = self.create_snapshot(self.volume_origin['id']) |
Giulio Fidente | f41b8ee | 2013-05-21 11:07:21 +0200 | [diff] [blame] | 176 | # NOTE(gfidente): size is required also when passing snapshot_id |
Joseph Lanoux | 6809bab | 2014-12-18 14:57:18 +0000 | [diff] [blame] | 177 | volume = self.volumes_client.create_volume( |
John Warren | 6177c9e | 2015-08-19 20:00:17 +0000 | [diff] [blame] | 178 | snapshot_id=snapshot['id'])['volume'] |
Giulio Fidente | 7333293 | 2013-05-03 18:04:09 +0200 | [diff] [blame] | 179 | self.volumes_client.wait_for_volume_status(volume['id'], 'available') |
| 180 | self.volumes_client.delete_volume(volume['id']) |
| 181 | self.volumes_client.wait_for_resource_deletion(volume['id']) |
Yuriy Nesenenko | 551e1a9 | 2015-09-11 18:26:05 +0300 | [diff] [blame] | 182 | self.cleanup_snapshot(snapshot) |
| 183 | |
| 184 | def cleanup_snapshot(self, snapshot): |
| 185 | # Delete the snapshot |
| 186 | self.snapshots_client.delete_snapshot(snapshot['id']) |
| 187 | self.snapshots_client.wait_for_resource_deletion(snapshot['id']) |
| 188 | self.snapshots.remove(snapshot) |
Attila Fazekas | 36b1fcf | 2013-01-31 16:41:04 +0100 | [diff] [blame] | 189 | |
| 190 | |
Zhi Kun Liu | 38641c6 | 2014-07-10 20:12:48 +0800 | [diff] [blame] | 191 | class VolumesV1SnapshotTestJSON(VolumesV2SnapshotTestJSON): |
| 192 | _api_version = 1 |