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 | |
Benny Kopilov | cdcf53c | 2017-03-29 07:25:05 +0300 | [diff] [blame] | 13 | import testtools |
lkuchlan | d827737 | 2017-02-22 15:07:52 +0200 | [diff] [blame] | 14 | from testtools import matchers |
| 15 | |
Sean Dague | 1937d09 | 2013-05-17 16:36:38 -0400 | [diff] [blame] | 16 | from tempest.api.volume import base |
Andrea Frittoli | cd36841 | 2017-08-14 21:37:56 +0100 | [diff] [blame] | 17 | from tempest.common import utils |
jeremy.zhang | d1be501 | 2018-06-06 17:25:39 +0800 | [diff] [blame] | 18 | from tempest.common import waiters |
Xiao Chen | 47fcbf4 | 2014-01-13 16:42:41 +0800 | [diff] [blame] | 19 | from tempest import config |
Ken'ichi Ohmichi | ef1c1ce | 2017-03-10 11:07:10 -0800 | [diff] [blame] | 20 | from tempest.lib.common.utils import data_utils |
Ken'ichi Ohmichi | 6b279c7 | 2017-01-27 18:26:59 -0800 | [diff] [blame] | 21 | from tempest.lib import decorators |
lianghao | 6c01199 | 2017-04-24 20:50:59 +0800 | [diff] [blame] | 22 | from tempest.lib import exceptions as lib_exc |
Attila Fazekas | 36b1fcf | 2013-01-31 16:41:04 +0100 | [diff] [blame] | 23 | |
Xiao Chen | 47fcbf4 | 2014-01-13 16:42:41 +0800 | [diff] [blame] | 24 | CONF = config.CONF |
Giulio Fidente | 3a465e3 | 2013-05-07 13:38:18 +0200 | [diff] [blame] | 25 | |
Attila Fazekas | 36b1fcf | 2013-01-31 16:41:04 +0100 | [diff] [blame] | 26 | |
Ken'ichi Ohmichi | e8afb8c | 2017-03-27 11:25:37 -0700 | [diff] [blame] | 27 | class VolumesSnapshotTestJSON(base.BaseVolumeTest): |
Attila Fazekas | 36b1fcf | 2013-01-31 16:41:04 +0100 | [diff] [blame] | 28 | |
Giulio Fidente | 7333293 | 2013-05-03 18:04:09 +0200 | [diff] [blame] | 29 | @classmethod |
Rohan Kanade | 0574915 | 2015-01-30 17:15:18 +0530 | [diff] [blame] | 30 | def skip_checks(cls): |
Ken'ichi Ohmichi | e8afb8c | 2017-03-27 11:25:37 -0700 | [diff] [blame] | 31 | super(VolumesSnapshotTestJSON, cls).skip_checks() |
Rohan Kanade | 0574915 | 2015-01-30 17:15:18 +0530 | [diff] [blame] | 32 | if not CONF.volume_feature_enabled.snapshot: |
| 33 | raise cls.skipException("Cinder volume snapshots are disabled") |
| 34 | |
| 35 | @classmethod |
Andrea Frittoli | 61a12e2 | 2014-09-15 13:14:54 +0100 | [diff] [blame] | 36 | def resource_setup(cls): |
Ken'ichi Ohmichi | e8afb8c | 2017-03-27 11:25:37 -0700 | [diff] [blame] | 37 | super(VolumesSnapshotTestJSON, cls).resource_setup() |
Zhi Kun Liu | 43f9af1 | 2014-03-19 21:01:35 +0800 | [diff] [blame] | 38 | cls.volume_origin = cls.create_volume() |
Giulio Fidente | 7333293 | 2013-05-03 18:04:09 +0200 | [diff] [blame] | 39 | |
zhufl | 529eefa | 2017-05-12 16:00:32 +0800 | [diff] [blame] | 40 | @decorators.idempotent_id('8567b54c-4455-446d-a1cf-651ddeaa3ff2') |
Andrea Frittoli | cd36841 | 2017-08-14 21:37:56 +0100 | [diff] [blame] | 41 | @utils.services('compute') |
zhufl | 529eefa | 2017-05-12 16:00:32 +0800 | [diff] [blame] | 42 | def test_snapshot_create_delete_with_volume_in_use(self): |
Xiao Chen | 47fcbf4 | 2014-01-13 16:42:41 +0800 | [diff] [blame] | 43 | # Create a test instance |
lkuchlan | d4ecd0e | 2017-06-11 12:01:27 +0300 | [diff] [blame] | 44 | server = self.create_server() |
zhufl | a2bffbd | 2018-03-02 15:04:06 +0800 | [diff] [blame] | 45 | # NOTE(zhufl) Here we create volume from self.image_ref for adding |
| 46 | # coverage for "creating snapshot from non-blank volume". |
| 47 | volume = self.create_volume(image_ref=self.image_ref) |
| 48 | self.attach_volume(server['id'], volume['id']) |
Erlon R. Cruz | ba19bc7 | 2016-09-28 14:32:11 -0300 | [diff] [blame] | 49 | |
lianghao | 6c01199 | 2017-04-24 20:50:59 +0800 | [diff] [blame] | 50 | # Snapshot a volume which attached to an instance with force=False |
| 51 | self.assertRaises(lib_exc.BadRequest, self.create_snapshot, |
zhufl | a2bffbd | 2018-03-02 15:04:06 +0800 | [diff] [blame] | 52 | volume['id'], force=False) |
lianghao | 6c01199 | 2017-04-24 20:50:59 +0800 | [diff] [blame] | 53 | |
Erlon R. Cruz | ba19bc7 | 2016-09-28 14:32:11 -0300 | [diff] [blame] | 54 | # Snapshot a volume attached to an instance |
zhufl | a2bffbd | 2018-03-02 15:04:06 +0800 | [diff] [blame] | 55 | snapshot1 = self.create_snapshot(volume['id'], force=True) |
| 56 | snapshot2 = self.create_snapshot(volume['id'], force=True) |
| 57 | snapshot3 = self.create_snapshot(volume['id'], force=True) |
Erlon R. Cruz | ba19bc7 | 2016-09-28 14:32:11 -0300 | [diff] [blame] | 58 | |
| 59 | # Delete the snapshots. Some snapshot implementations can take |
| 60 | # different paths according to order they are deleted. |
lkuchlan | 5b2b362 | 2017-02-14 15:48:36 +0200 | [diff] [blame] | 61 | self.delete_snapshot(snapshot1['id']) |
| 62 | self.delete_snapshot(snapshot3['id']) |
| 63 | self.delete_snapshot(snapshot2['id']) |
Erlon R. Cruz | ba19bc7 | 2016-09-28 14:32:11 -0300 | [diff] [blame] | 64 | |
Ken'ichi Ohmichi | 6b279c7 | 2017-01-27 18:26:59 -0800 | [diff] [blame] | 65 | @decorators.idempotent_id('5210a1de-85a0-11e6-bb21-641c676a5d61') |
Andrea Frittoli | cd36841 | 2017-08-14 21:37:56 +0100 | [diff] [blame] | 66 | @utils.services('compute') |
Erlon R. Cruz | ba19bc7 | 2016-09-28 14:32:11 -0300 | [diff] [blame] | 67 | def test_snapshot_create_offline_delete_online(self): |
| 68 | |
| 69 | # Create a snapshot while it is not attached |
| 70 | snapshot1 = self.create_snapshot(self.volume_origin['id']) |
| 71 | |
| 72 | # Create a server and attach it |
lkuchlan | d4ecd0e | 2017-06-11 12:01:27 +0300 | [diff] [blame] | 73 | server = self.create_server() |
Erlon R. Cruz | ba19bc7 | 2016-09-28 14:32:11 -0300 | [diff] [blame] | 74 | self.attach_volume(server['id'], self.volume_origin['id']) |
| 75 | |
| 76 | # Now that the volume is attached, create another snapshots |
| 77 | snapshot2 = self.create_snapshot(self.volume_origin['id'], force=True) |
| 78 | snapshot3 = self.create_snapshot(self.volume_origin['id'], force=True) |
| 79 | |
| 80 | # Delete the snapshots. Some snapshot implementations can take |
| 81 | # different paths according to order they are deleted. |
lkuchlan | 5b2b362 | 2017-02-14 15:48:36 +0200 | [diff] [blame] | 82 | self.delete_snapshot(snapshot3['id']) |
| 83 | self.delete_snapshot(snapshot1['id']) |
| 84 | self.delete_snapshot(snapshot2['id']) |
Erlon R. Cruz | ba19bc7 | 2016-09-28 14:32:11 -0300 | [diff] [blame] | 85 | |
Ken'ichi Ohmichi | 6b279c7 | 2017-01-27 18:26:59 -0800 | [diff] [blame] | 86 | @decorators.idempotent_id('2a8abbe4-d871-46db-b049-c41f5af8216e') |
QingXin Meng | dc95f5e | 2013-09-16 19:06:44 -0700 | [diff] [blame] | 87 | def test_snapshot_create_get_list_update_delete(self): |
lkuchlan | d827737 | 2017-02-22 15:07:52 +0200 | [diff] [blame] | 88 | # Create a snapshot with metadata |
| 89 | metadata = {"snap-meta1": "value1", |
| 90 | "snap-meta2": "value2", |
| 91 | "snap-meta3": "value3"} |
| 92 | snapshot = self.create_snapshot(self.volume_origin['id'], |
| 93 | metadata=metadata) |
Giulio Fidente | 7333293 | 2013-05-03 18:04:09 +0200 | [diff] [blame] | 94 | |
Giulio Fidente | f41b8ee | 2013-05-21 11:07:21 +0200 | [diff] [blame] | 95 | # Get the snap and check for some of its details |
John Warren | ff7faf6 | 2015-08-17 16:59:06 +0000 | [diff] [blame] | 96 | snap_get = self.snapshots_client.show_snapshot( |
| 97 | snapshot['id'])['snapshot'] |
Giulio Fidente | f41b8ee | 2013-05-21 11:07:21 +0200 | [diff] [blame] | 98 | self.assertEqual(self.volume_origin['id'], |
| 99 | snap_get['volume_id'], |
| 100 | "Referred volume origin mismatch") |
jeremy.zhang | 681dff8 | 2017-04-06 19:21:01 +0800 | [diff] [blame] | 101 | self.assertEqual(self.volume_origin['size'], snap_get['size']) |
Giulio Fidente | f41b8ee | 2013-05-21 11:07:21 +0200 | [diff] [blame] | 102 | |
lkuchlan | d827737 | 2017-02-22 15:07:52 +0200 | [diff] [blame] | 103 | # Verify snapshot metadata |
| 104 | self.assertThat(snap_get['metadata'].items(), |
| 105 | matchers.ContainsAll(metadata.items())) |
| 106 | |
Giulio Fidente | f41b8ee | 2013-05-21 11:07:21 +0200 | [diff] [blame] | 107 | # Compare also with the output from the list action |
zhufl | a57530c | 2017-03-23 11:38:12 +0800 | [diff] [blame] | 108 | tracking_data = (snapshot['id'], snapshot['name']) |
John Warren | ff7faf6 | 2015-08-17 16:59:06 +0000 | [diff] [blame] | 109 | snaps_list = self.snapshots_client.list_snapshots()['snapshots'] |
zhufl | a57530c | 2017-03-23 11:38:12 +0800 | [diff] [blame] | 110 | snaps_data = [(f['id'], f['name']) for f in snaps_list] |
Giulio Fidente | f41b8ee | 2013-05-21 11:07:21 +0200 | [diff] [blame] | 111 | self.assertIn(tracking_data, snaps_data) |
| 112 | |
QingXin Meng | dc95f5e | 2013-09-16 19:06:44 -0700 | [diff] [blame] | 113 | # Updates snapshot with new values |
zhufl | c6ce539 | 2016-08-17 14:34:37 +0800 | [diff] [blame] | 114 | new_s_name = data_utils.rand_name( |
| 115 | self.__class__.__name__ + '-new-snap') |
QingXin Meng | dc95f5e | 2013-09-16 19:06:44 -0700 | [diff] [blame] | 116 | new_desc = 'This is the new description of snapshot.' |
zhufl | a57530c | 2017-03-23 11:38:12 +0800 | [diff] [blame] | 117 | params = {'name': new_s_name, |
| 118 | 'description': new_desc} |
John Warren | ff7faf6 | 2015-08-17 16:59:06 +0000 | [diff] [blame] | 119 | update_snapshot = self.snapshots_client.update_snapshot( |
| 120 | snapshot['id'], **params)['snapshot'] |
QingXin Meng | dc95f5e | 2013-09-16 19:06:44 -0700 | [diff] [blame] | 121 | # Assert response body for update_snapshot method |
zhufl | a57530c | 2017-03-23 11:38:12 +0800 | [diff] [blame] | 122 | self.assertEqual(new_s_name, update_snapshot['name']) |
| 123 | self.assertEqual(new_desc, update_snapshot['description']) |
Ken'ichi Ohmichi | 35798fb | 2015-04-06 01:22:41 +0000 | [diff] [blame] | 124 | # Assert response body for show_snapshot method |
John Warren | ff7faf6 | 2015-08-17 16:59:06 +0000 | [diff] [blame] | 125 | updated_snapshot = self.snapshots_client.show_snapshot( |
| 126 | snapshot['id'])['snapshot'] |
zhufl | a57530c | 2017-03-23 11:38:12 +0800 | [diff] [blame] | 127 | self.assertEqual(new_s_name, updated_snapshot['name']) |
| 128 | self.assertEqual(new_desc, updated_snapshot['description']) |
QingXin Meng | dc95f5e | 2013-09-16 19:06:44 -0700 | [diff] [blame] | 129 | |
Giulio Fidente | f41b8ee | 2013-05-21 11:07:21 +0200 | [diff] [blame] | 130 | # Delete the snapshot |
lkuchlan | 5b2b362 | 2017-02-14 15:48:36 +0200 | [diff] [blame] | 131 | self.delete_snapshot(snapshot['id']) |
Giulio Fidente | f41b8ee | 2013-05-21 11:07:21 +0200 | [diff] [blame] | 132 | |
lkuchlan | 91d5fe0 | 2018-09-02 15:52:39 +0300 | [diff] [blame] | 133 | def _create_volume_from_snapshot(self, extra_size=0): |
| 134 | src_size = CONF.volume.volume_size |
| 135 | size = src_size + extra_size |
| 136 | |
| 137 | src_vol = self.create_volume(size=src_size) |
| 138 | src_snap = self.create_snapshot(src_vol['id']) |
| 139 | |
| 140 | dst_vol = self.create_volume(snapshot_id=src_snap['id'], |
| 141 | size=size) |
| 142 | # NOTE(zhufl): dst_vol is created based on snapshot, so dst_vol |
| 143 | # should be deleted before deleting snapshot, otherwise deleting |
| 144 | # snapshot will end with status 'error-deleting'. This depends on |
| 145 | # the implementation mechanism of vendors, generally speaking, |
| 146 | # some verdors will use "virtual disk clone" which will promote |
| 147 | # disk clone speed, and in this situation the "disk clone" |
| 148 | # is just a relationship between volume and snapshot. |
| 149 | self.addCleanup(self.delete_volume, self.volumes_client, dst_vol['id']) |
| 150 | |
| 151 | volume = self.volumes_client.show_volume(dst_vol['id'])['volume'] |
| 152 | # Should allow |
| 153 | self.assertEqual(volume['snapshot_id'], src_snap['id']) |
| 154 | self.assertEqual(volume['size'], size) |
| 155 | |
Ken'ichi Ohmichi | 6b279c7 | 2017-01-27 18:26:59 -0800 | [diff] [blame] | 156 | @decorators.idempotent_id('677863d1-3142-456d-b6ac-9924f667a7f4') |
Giulio Fidente | 7333293 | 2013-05-03 18:04:09 +0200 | [diff] [blame] | 157 | def test_volume_from_snapshot(self): |
jeremy.zhang | 681dff8 | 2017-04-06 19:21:01 +0800 | [diff] [blame] | 158 | # Creates a volume from a snapshot passing a size |
| 159 | # different from the source |
lkuchlan | 91d5fe0 | 2018-09-02 15:52:39 +0300 | [diff] [blame] | 160 | self._create_volume_from_snapshot(extra_size=1) |
Benny Kopilov | cdcf53c | 2017-03-29 07:25:05 +0300 | [diff] [blame] | 161 | |
Sean McGinnis | fde2167 | 2018-08-01 09:08:21 -0500 | [diff] [blame] | 162 | @decorators.idempotent_id('053d8870-8282-4fff-9dbb-99cb58bb5e0a') |
| 163 | def test_volume_from_snapshot_no_size(self): |
| 164 | # Creates a volume from a snapshot defaulting to original size |
lkuchlan | 91d5fe0 | 2018-09-02 15:52:39 +0300 | [diff] [blame] | 165 | self._create_volume_from_snapshot() |
Sean McGinnis | fde2167 | 2018-08-01 09:08:21 -0500 | [diff] [blame] | 166 | |
Benny Kopilov | cdcf53c | 2017-03-29 07:25:05 +0300 | [diff] [blame] | 167 | @decorators.idempotent_id('bbcfa285-af7f-479e-8c1a-8c34fc16543c') |
| 168 | @testtools.skipUnless(CONF.volume_feature_enabled.backup, |
| 169 | "Cinder backup is disabled") |
| 170 | def test_snapshot_backup(self): |
| 171 | # Create a snapshot |
| 172 | snapshot = self.create_snapshot(volume_id=self.volume_origin['id']) |
| 173 | |
| 174 | backup = self.create_backup(volume_id=self.volume_origin['id'], |
| 175 | snapshot_id=snapshot['id']) |
jeremy.zhang | d1be501 | 2018-06-06 17:25:39 +0800 | [diff] [blame] | 176 | waiters.wait_for_volume_resource_status(self.snapshots_client, |
| 177 | snapshot['id'], 'available') |
Benny Kopilov | cdcf53c | 2017-03-29 07:25:05 +0300 | [diff] [blame] | 178 | backup_info = self.backups_client.show_backup(backup['id'])['backup'] |
| 179 | self.assertEqual(self.volume_origin['id'], backup_info['volume_id']) |
| 180 | self.assertEqual(snapshot['id'], backup_info['snapshot_id']) |