lkuchlan | cb2f859 | 2016-07-17 15:18:01 +0300 | [diff] [blame] | 1 | # Copyright 2016 Red Hat, Inc. |
| 2 | # All Rights Reserved. |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 5 | # not use this file except in compliance with the License. You may obtain |
| 6 | # a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 12 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 13 | # License for the specific language governing permissions and limitations |
| 14 | # under the License. |
| 15 | |
lkuchlan | cb2f859 | 2016-07-17 15:18:01 +0300 | [diff] [blame] | 16 | from tempest.api.volume import base |
| 17 | from tempest.common import waiters |
| 18 | from tempest import config |
lkuchlan | da810bb | 2017-06-06 14:29:13 +0300 | [diff] [blame] | 19 | from tempest.lib.common.utils import data_utils |
Ken'ichi Ohmichi | 6b279c7 | 2017-01-27 18:26:59 -0800 | [diff] [blame] | 20 | from tempest.lib import decorators |
jeremy.zhang | aa8c931 | 2017-06-21 12:32:47 +0800 | [diff] [blame] | 21 | from tempest.lib import exceptions |
lkuchlan | cb2f859 | 2016-07-17 15:18:01 +0300 | [diff] [blame] | 22 | |
| 23 | CONF = config.CONF |
| 24 | |
| 25 | |
Ken'ichi Ohmichi | e8afb8c | 2017-03-27 11:25:37 -0700 | [diff] [blame] | 26 | class SnapshotManageAdminTest(base.BaseVolumeAdminTest): |
lkuchlan | cb2f859 | 2016-07-17 15:18:01 +0300 | [diff] [blame] | 27 | """Unmanage & manage snapshots |
| 28 | |
| 29 | This feature provides the ability to import/export volume snapshot |
| 30 | from one Cinder to another and to import snapshots that have not been |
| 31 | managed by Cinder from a storage back end to Cinder |
| 32 | """ |
| 33 | |
jeremy.zhang | ebc752b | 2017-06-14 13:58:37 +0800 | [diff] [blame] | 34 | @classmethod |
| 35 | def skip_checks(cls): |
| 36 | super(SnapshotManageAdminTest, cls).skip_checks() |
| 37 | |
jeremy.zhang | b134589 | 2017-12-16 17:21:17 +0800 | [diff] [blame] | 38 | if not CONF.volume_feature_enabled.snapshot: |
| 39 | raise cls.skipException("Cinder volume snapshots are disabled") |
| 40 | |
jeremy.zhang | ebc752b | 2017-06-14 13:58:37 +0800 | [diff] [blame] | 41 | if not CONF.volume_feature_enabled.manage_snapshot: |
| 42 | raise cls.skipException("Manage snapshot tests are disabled") |
| 43 | |
| 44 | if len(CONF.volume.manage_snapshot_ref) != 2: |
jeremy.zhang | aa8c931 | 2017-06-21 12:32:47 +0800 | [diff] [blame] | 45 | msg = ("Manage snapshot ref is not correctly configured, " |
| 46 | "it should be a list of two elements") |
| 47 | raise exceptions.InvalidConfiguration(msg) |
jeremy.zhang | ebc752b | 2017-06-14 13:58:37 +0800 | [diff] [blame] | 48 | |
Ken'ichi Ohmichi | 6b279c7 | 2017-01-27 18:26:59 -0800 | [diff] [blame] | 49 | @decorators.idempotent_id('0132f42d-0147-4b45-8501-cc504bbf7810') |
lkuchlan | cb2f859 | 2016-07-17 15:18:01 +0300 | [diff] [blame] | 50 | def test_unmanage_manage_snapshot(self): |
zhufl | fcfb31b | 2020-04-20 15:41:07 +0800 | [diff] [blame] | 51 | """Test unmanaging and managing volume snapshot""" |
lkuchlan | cb2f859 | 2016-07-17 15:18:01 +0300 | [diff] [blame] | 52 | # Create a volume |
| 53 | volume = self.create_volume() |
| 54 | |
| 55 | # Create a snapshot |
| 56 | snapshot = self.create_snapshot(volume_id=volume['id']) |
| 57 | |
| 58 | # Unmanage the snapshot |
| 59 | # Unmanage snapshot function works almost the same as delete snapshot, |
| 60 | # but it does not delete the snapshot data |
| 61 | self.admin_snapshots_client.unmanage_snapshot(snapshot['id']) |
| 62 | self.admin_snapshots_client.wait_for_resource_deletion(snapshot['id']) |
| 63 | |
jeremy.zhang | ebc752b | 2017-06-14 13:58:37 +0800 | [diff] [blame] | 64 | # Verify the original snapshot does not exist in snapshot list |
| 65 | params = {'all_tenants': 1} |
| 66 | all_snapshots = self.admin_snapshots_client.list_snapshots( |
liangcui | c4d1ad1 | 2018-01-02 10:51:03 +0800 | [diff] [blame] | 67 | detail=True, **params)['snapshots'] |
jeremy.zhang | ebc752b | 2017-06-14 13:58:37 +0800 | [diff] [blame] | 68 | self.assertNotIn(snapshot['id'], [v['id'] for v in all_snapshots]) |
lkuchlan | cb2f859 | 2016-07-17 15:18:01 +0300 | [diff] [blame] | 69 | |
jeremy.zhang | ebc752b | 2017-06-14 13:58:37 +0800 | [diff] [blame] | 70 | # Manage the snapshot |
lkuchlan | da810bb | 2017-06-06 14:29:13 +0300 | [diff] [blame] | 71 | name = data_utils.rand_name(self.__class__.__name__ + |
| 72 | '-Managed-Snapshot') |
| 73 | description = data_utils.rand_name(self.__class__.__name__ + |
| 74 | '-Managed-Snapshot-Description') |
| 75 | metadata = {"manage-snap-meta1": "value1", |
| 76 | "manage-snap-meta2": "value2", |
| 77 | "manage-snap-meta3": "value3"} |
jeremy.zhang | ebc752b | 2017-06-14 13:58:37 +0800 | [diff] [blame] | 78 | snapshot_ref = { |
| 79 | 'volume_id': volume['id'], |
| 80 | 'ref': {CONF.volume.manage_snapshot_ref[0]: |
| 81 | CONF.volume.manage_snapshot_ref[1] % snapshot['id']}, |
| 82 | 'name': name, |
| 83 | 'description': description, |
| 84 | 'metadata': metadata |
| 85 | } |
lkuchlan | cb2f859 | 2016-07-17 15:18:01 +0300 | [diff] [blame] | 86 | new_snapshot = self.admin_snapshot_manage_client.manage_snapshot( |
jeremy.zhang | ebc752b | 2017-06-14 13:58:37 +0800 | [diff] [blame] | 87 | **snapshot_ref)['snapshot'] |
lkuchlan | 5b2b362 | 2017-02-14 15:48:36 +0200 | [diff] [blame] | 88 | self.addCleanup(self.delete_snapshot, new_snapshot['id'], |
| 89 | self.admin_snapshots_client) |
lkuchlan | cb2f859 | 2016-07-17 15:18:01 +0300 | [diff] [blame] | 90 | |
| 91 | # Wait for the snapshot to be available after manage operation |
lkuchlan | 52d7b0d | 2016-11-07 20:53:19 +0200 | [diff] [blame] | 92 | waiters.wait_for_volume_resource_status(self.admin_snapshots_client, |
| 93 | new_snapshot['id'], |
| 94 | 'available') |
lkuchlan | cb2f859 | 2016-07-17 15:18:01 +0300 | [diff] [blame] | 95 | |
| 96 | # Verify the managed snapshot has the expected parent volume |
lkuchlan | da810bb | 2017-06-06 14:29:13 +0300 | [diff] [blame] | 97 | # and the expected field values. |
jeremy.zhang | ebc752b | 2017-06-14 13:58:37 +0800 | [diff] [blame] | 98 | new_snapshot_info = self.admin_snapshots_client.show_snapshot( |
lkuchlan | da810bb | 2017-06-06 14:29:13 +0300 | [diff] [blame] | 99 | new_snapshot['id'])['snapshot'] |
jeremy.zhang | ebc752b | 2017-06-14 13:58:37 +0800 | [diff] [blame] | 100 | self.assertEqual(snapshot['size'], new_snapshot_info['size']) |
| 101 | for key in ['volume_id', 'name', 'description', 'metadata']: |
| 102 | self.assertEqual(snapshot_ref[key], new_snapshot_info[key]) |