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 | |
lkuchlan | d827737 | 2017-02-22 15:07:52 +0200 | [diff] [blame] | 13 | from testtools import matchers |
| 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 |
Ken'ichi Ohmichi | 6b279c7 | 2017-01-27 18:26:59 -0800 | [diff] [blame] | 18 | from tempest.lib import decorators |
Masayuki Igawa | 1edf94f | 2014-03-04 18:34:16 +0900 | [diff] [blame] | 19 | from tempest import test |
Attila Fazekas | 36b1fcf | 2013-01-31 16:41:04 +0100 | [diff] [blame] | 20 | |
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() |
Zhi Kun Liu | 38641c6 | 2014-07-10 20:12:48 +0800 | [diff] [blame] | 36 | cls.name_field = cls.special_fields['name_field'] |
| 37 | cls.descrip_field = cls.special_fields['descrip_field'] |
Giulio Fidente | 7333293 | 2013-05-03 18:04:09 +0200 | [diff] [blame] | 38 | |
Ken'ichi Ohmichi | 6b279c7 | 2017-01-27 18:26:59 -0800 | [diff] [blame] | 39 | @decorators.idempotent_id('b467b54c-07a4-446d-a1cf-651dedcc3ff1') |
Matthew Treinish | 7ea69e6 | 2014-06-03 17:23:50 -0400 | [diff] [blame] | 40 | @test.services('compute') |
Xiao Chen | 47fcbf4 | 2014-01-13 16:42:41 +0800 | [diff] [blame] | 41 | def test_snapshot_create_with_volume_in_use(self): |
| 42 | # Create a snapshot when volume status is in-use |
| 43 | # Create a test instance |
zhufl | 7867a6e | 2016-10-18 15:37:12 +0800 | [diff] [blame] | 44 | server = self.create_server(wait_until='ACTIVE') |
Erlon R. Cruz | ba19bc7 | 2016-09-28 14:32:11 -0300 | [diff] [blame] | 45 | self.attach_volume(server['id'], self.volume_origin['id']) |
| 46 | |
Xiao Chen | 47fcbf4 | 2014-01-13 16:42:41 +0800 | [diff] [blame] | 47 | # Snapshot a volume even if it's attached to an instance |
| 48 | snapshot = self.create_snapshot(self.volume_origin['id'], |
| 49 | force=True) |
| 50 | # Delete the snapshot |
lkuchlan | 5b2b362 | 2017-02-14 15:48:36 +0200 | [diff] [blame] | 51 | self.delete_snapshot(snapshot['id']) |
Xiao Chen | 47fcbf4 | 2014-01-13 16:42:41 +0800 | [diff] [blame] | 52 | |
Ken'ichi Ohmichi | 6b279c7 | 2017-01-27 18:26:59 -0800 | [diff] [blame] | 53 | @decorators.idempotent_id('8567b54c-4455-446d-a1cf-651ddeaa3ff2') |
Erlon R. Cruz | ba19bc7 | 2016-09-28 14:32:11 -0300 | [diff] [blame] | 54 | @test.services('compute') |
| 55 | def test_snapshot_delete_with_volume_in_use(self): |
| 56 | # Create a test instance |
| 57 | server = self.create_server(wait_until='ACTIVE') |
| 58 | self.attach_volume(server['id'], self.volume_origin['id']) |
| 59 | |
| 60 | # Snapshot a volume attached to an instance |
| 61 | snapshot1 = self.create_snapshot(self.volume_origin['id'], force=True) |
| 62 | snapshot2 = self.create_snapshot(self.volume_origin['id'], force=True) |
| 63 | snapshot3 = self.create_snapshot(self.volume_origin['id'], force=True) |
| 64 | |
| 65 | # Delete the snapshots. Some snapshot implementations can take |
| 66 | # different paths according to order they are deleted. |
lkuchlan | 5b2b362 | 2017-02-14 15:48:36 +0200 | [diff] [blame] | 67 | self.delete_snapshot(snapshot1['id']) |
| 68 | self.delete_snapshot(snapshot3['id']) |
| 69 | self.delete_snapshot(snapshot2['id']) |
Erlon R. Cruz | ba19bc7 | 2016-09-28 14:32:11 -0300 | [diff] [blame] | 70 | |
Ken'ichi Ohmichi | 6b279c7 | 2017-01-27 18:26:59 -0800 | [diff] [blame] | 71 | @decorators.idempotent_id('5210a1de-85a0-11e6-bb21-641c676a5d61') |
Erlon R. Cruz | ba19bc7 | 2016-09-28 14:32:11 -0300 | [diff] [blame] | 72 | @test.services('compute') |
| 73 | def test_snapshot_create_offline_delete_online(self): |
| 74 | |
| 75 | # Create a snapshot while it is not attached |
| 76 | snapshot1 = self.create_snapshot(self.volume_origin['id']) |
| 77 | |
| 78 | # Create a server and attach it |
| 79 | server = self.create_server(wait_until='ACTIVE') |
| 80 | self.attach_volume(server['id'], self.volume_origin['id']) |
| 81 | |
| 82 | # Now that the volume is attached, create another snapshots |
| 83 | snapshot2 = self.create_snapshot(self.volume_origin['id'], force=True) |
| 84 | snapshot3 = self.create_snapshot(self.volume_origin['id'], force=True) |
| 85 | |
| 86 | # Delete the snapshots. Some snapshot implementations can take |
| 87 | # different paths according to order they are deleted. |
lkuchlan | 5b2b362 | 2017-02-14 15:48:36 +0200 | [diff] [blame] | 88 | self.delete_snapshot(snapshot3['id']) |
| 89 | self.delete_snapshot(snapshot1['id']) |
| 90 | self.delete_snapshot(snapshot2['id']) |
Erlon R. Cruz | ba19bc7 | 2016-09-28 14:32:11 -0300 | [diff] [blame] | 91 | |
Ken'ichi Ohmichi | 6b279c7 | 2017-01-27 18:26:59 -0800 | [diff] [blame] | 92 | @decorators.idempotent_id('2a8abbe4-d871-46db-b049-c41f5af8216e') |
QingXin Meng | dc95f5e | 2013-09-16 19:06:44 -0700 | [diff] [blame] | 93 | def test_snapshot_create_get_list_update_delete(self): |
lkuchlan | d827737 | 2017-02-22 15:07:52 +0200 | [diff] [blame] | 94 | # Create a snapshot with metadata |
| 95 | metadata = {"snap-meta1": "value1", |
| 96 | "snap-meta2": "value2", |
| 97 | "snap-meta3": "value3"} |
| 98 | snapshot = self.create_snapshot(self.volume_origin['id'], |
| 99 | metadata=metadata) |
Giulio Fidente | 7333293 | 2013-05-03 18:04:09 +0200 | [diff] [blame] | 100 | |
Giulio Fidente | f41b8ee | 2013-05-21 11:07:21 +0200 | [diff] [blame] | 101 | # Get the snap and check for some of its details |
John Warren | ff7faf6 | 2015-08-17 16:59:06 +0000 | [diff] [blame] | 102 | snap_get = self.snapshots_client.show_snapshot( |
| 103 | snapshot['id'])['snapshot'] |
Giulio Fidente | f41b8ee | 2013-05-21 11:07:21 +0200 | [diff] [blame] | 104 | self.assertEqual(self.volume_origin['id'], |
| 105 | snap_get['volume_id'], |
| 106 | "Referred volume origin mismatch") |
| 107 | |
lkuchlan | d827737 | 2017-02-22 15:07:52 +0200 | [diff] [blame] | 108 | # Verify snapshot metadata |
| 109 | self.assertThat(snap_get['metadata'].items(), |
| 110 | matchers.ContainsAll(metadata.items())) |
| 111 | |
Giulio Fidente | f41b8ee | 2013-05-21 11:07:21 +0200 | [diff] [blame] | 112 | # Compare also with the output from the list action |
Zhi Kun Liu | 38641c6 | 2014-07-10 20:12:48 +0800 | [diff] [blame] | 113 | tracking_data = (snapshot['id'], snapshot[self.name_field]) |
John Warren | ff7faf6 | 2015-08-17 16:59:06 +0000 | [diff] [blame] | 114 | snaps_list = self.snapshots_client.list_snapshots()['snapshots'] |
Zhi Kun Liu | 38641c6 | 2014-07-10 20:12:48 +0800 | [diff] [blame] | 115 | 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] | 116 | self.assertIn(tracking_data, snaps_data) |
| 117 | |
QingXin Meng | dc95f5e | 2013-09-16 19:06:44 -0700 | [diff] [blame] | 118 | # Updates snapshot with new values |
zhufl | c6ce539 | 2016-08-17 14:34:37 +0800 | [diff] [blame] | 119 | new_s_name = data_utils.rand_name( |
| 120 | self.__class__.__name__ + '-new-snap') |
QingXin Meng | dc95f5e | 2013-09-16 19:06:44 -0700 | [diff] [blame] | 121 | new_desc = 'This is the new description of snapshot.' |
Zhi Kun Liu | 38641c6 | 2014-07-10 20:12:48 +0800 | [diff] [blame] | 122 | params = {self.name_field: new_s_name, |
| 123 | self.descrip_field: new_desc} |
John Warren | ff7faf6 | 2015-08-17 16:59:06 +0000 | [diff] [blame] | 124 | update_snapshot = self.snapshots_client.update_snapshot( |
| 125 | snapshot['id'], **params)['snapshot'] |
QingXin Meng | dc95f5e | 2013-09-16 19:06:44 -0700 | [diff] [blame] | 126 | # Assert response body for update_snapshot method |
Zhi Kun Liu | 38641c6 | 2014-07-10 20:12:48 +0800 | [diff] [blame] | 127 | self.assertEqual(new_s_name, update_snapshot[self.name_field]) |
| 128 | self.assertEqual(new_desc, update_snapshot[self.descrip_field]) |
Ken'ichi Ohmichi | 35798fb | 2015-04-06 01:22:41 +0000 | [diff] [blame] | 129 | # Assert response body for show_snapshot method |
John Warren | ff7faf6 | 2015-08-17 16:59:06 +0000 | [diff] [blame] | 130 | updated_snapshot = self.snapshots_client.show_snapshot( |
| 131 | snapshot['id'])['snapshot'] |
Zhi Kun Liu | 38641c6 | 2014-07-10 20:12:48 +0800 | [diff] [blame] | 132 | self.assertEqual(new_s_name, updated_snapshot[self.name_field]) |
| 133 | self.assertEqual(new_desc, updated_snapshot[self.descrip_field]) |
QingXin Meng | dc95f5e | 2013-09-16 19:06:44 -0700 | [diff] [blame] | 134 | |
Giulio Fidente | f41b8ee | 2013-05-21 11:07:21 +0200 | [diff] [blame] | 135 | # Delete the snapshot |
lkuchlan | 5b2b362 | 2017-02-14 15:48:36 +0200 | [diff] [blame] | 136 | self.delete_snapshot(snapshot['id']) |
Giulio Fidente | f41b8ee | 2013-05-21 11:07:21 +0200 | [diff] [blame] | 137 | |
Ken'ichi Ohmichi | 6b279c7 | 2017-01-27 18:26:59 -0800 | [diff] [blame] | 138 | @decorators.idempotent_id('677863d1-3142-456d-b6ac-9924f667a7f4') |
Giulio Fidente | 7333293 | 2013-05-03 18:04:09 +0200 | [diff] [blame] | 139 | def test_volume_from_snapshot(self): |
Erlon R. Cruz | 8dbbc29 | 2016-06-17 15:40:36 -0300 | [diff] [blame] | 140 | # Creates a volume a snapshot passing a size different from the source |
| 141 | src_size = CONF.volume.volume_size |
| 142 | |
| 143 | src_vol = self.create_volume(size=src_size) |
| 144 | src_snap = self.create_snapshot(src_vol['id']) |
| 145 | # Destination volume bigger than source snapshot |
| 146 | dst_vol = self.create_volume(snapshot_id=src_snap['id'], |
| 147 | size=src_size + 1) |
zhufl | d37b6a7 | 2016-11-29 16:56:01 +0800 | [diff] [blame] | 148 | # NOTE(zhufl): dst_vol is created based on snapshot, so dst_vol |
| 149 | # should be deleted before deleting snapshot, otherwise deleting |
| 150 | # snapshot will end with status 'error-deleting'. This depends on |
| 151 | # the implementation mechanism of vendors, generally speaking, |
| 152 | # some verdors will use "virtual disk clone" which will promote |
| 153 | # disk clone speed, and in this situation the "disk clone" |
| 154 | # is just a relationship between volume and snapshot. |
| 155 | self.addCleanup(self.delete_volume, self.volumes_client, dst_vol['id']) |
Erlon R. Cruz | 8dbbc29 | 2016-06-17 15:40:36 -0300 | [diff] [blame] | 156 | |
| 157 | volume = self.volumes_client.show_volume(dst_vol['id'])['volume'] |
| 158 | # Should allow |
| 159 | self.assertEqual(volume['snapshot_id'], src_snap['id']) |
Avi Avraham | d77d3d1 | 2017-02-15 16:45:25 +0200 | [diff] [blame] | 160 | self.assertEqual(volume['size'], src_size + 1) |
Yuriy Nesenenko | 551e1a9 | 2015-09-11 18:26:05 +0300 | [diff] [blame] | 161 | |
Attila Fazekas | 36b1fcf | 2013-01-31 16:41:04 +0100 | [diff] [blame] | 162 | |
Zhi Kun Liu | 38641c6 | 2014-07-10 20:12:48 +0800 | [diff] [blame] | 163 | class VolumesV1SnapshotTestJSON(VolumesV2SnapshotTestJSON): |
| 164 | _api_version = 1 |