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 |
lkuchlan | 724c675 | 2023-06-20 15:04:12 +0300 | [diff] [blame] | 17 | from tempest.common import utils |
lkuchlan | cb2f859 | 2016-07-17 15:18:01 +0300 | [diff] [blame] | 18 | from tempest.common import waiters |
| 19 | from tempest import config |
lkuchlan | da810bb | 2017-06-06 14:29:13 +0300 | [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 |
jeremy.zhang | aa8c931 | 2017-06-21 12:32:47 +0800 | [diff] [blame] | 22 | from tempest.lib import exceptions |
lkuchlan | cb2f859 | 2016-07-17 15:18:01 +0300 | [diff] [blame] | 23 | |
| 24 | CONF = config.CONF |
| 25 | |
| 26 | |
Ken'ichi Ohmichi | e8afb8c | 2017-03-27 11:25:37 -0700 | [diff] [blame] | 27 | class SnapshotManageAdminTest(base.BaseVolumeAdminTest): |
lkuchlan | cb2f859 | 2016-07-17 15:18:01 +0300 | [diff] [blame] | 28 | """Unmanage & manage snapshots |
| 29 | |
| 30 | This feature provides the ability to import/export volume snapshot |
| 31 | from one Cinder to another and to import snapshots that have not been |
| 32 | managed by Cinder from a storage back end to Cinder |
| 33 | """ |
| 34 | |
lkuchlan | 724c675 | 2023-06-20 15:04:12 +0300 | [diff] [blame] | 35 | create_default_network = True |
| 36 | |
jeremy.zhang | ebc752b | 2017-06-14 13:58:37 +0800 | [diff] [blame] | 37 | @classmethod |
| 38 | def skip_checks(cls): |
| 39 | super(SnapshotManageAdminTest, cls).skip_checks() |
| 40 | |
jeremy.zhang | b134589 | 2017-12-16 17:21:17 +0800 | [diff] [blame] | 41 | if not CONF.volume_feature_enabled.snapshot: |
| 42 | raise cls.skipException("Cinder volume snapshots are disabled") |
| 43 | |
jeremy.zhang | ebc752b | 2017-06-14 13:58:37 +0800 | [diff] [blame] | 44 | if not CONF.volume_feature_enabled.manage_snapshot: |
| 45 | raise cls.skipException("Manage snapshot tests are disabled") |
| 46 | |
| 47 | if len(CONF.volume.manage_snapshot_ref) != 2: |
jeremy.zhang | aa8c931 | 2017-06-21 12:32:47 +0800 | [diff] [blame] | 48 | msg = ("Manage snapshot ref is not correctly configured, " |
| 49 | "it should be a list of two elements") |
| 50 | raise exceptions.InvalidConfiguration(msg) |
jeremy.zhang | ebc752b | 2017-06-14 13:58:37 +0800 | [diff] [blame] | 51 | |
lkuchlan | 724c675 | 2023-06-20 15:04:12 +0300 | [diff] [blame] | 52 | def _test_unmanage_manage_snapshot(self, attached_volume=False): |
zhufl | fcfb31b | 2020-04-20 15:41:07 +0800 | [diff] [blame] | 53 | """Test unmanaging and managing volume snapshot""" |
lkuchlan | cb2f859 | 2016-07-17 15:18:01 +0300 | [diff] [blame] | 54 | # Create a volume |
| 55 | volume = self.create_volume() |
| 56 | |
| 57 | # Create a snapshot |
| 58 | snapshot = self.create_snapshot(volume_id=volume['id']) |
| 59 | |
lkuchlan | 724c675 | 2023-06-20 15:04:12 +0300 | [diff] [blame] | 60 | if attached_volume: |
| 61 | # Create a server |
| 62 | server = self.create_server(wait_until='SSHABLE') |
| 63 | # Attach volume to instance |
| 64 | self.attach_volume(server['id'], volume['id'], |
| 65 | wait_for_detach=False) |
| 66 | |
lkuchlan | cb2f859 | 2016-07-17 15:18:01 +0300 | [diff] [blame] | 67 | # Unmanage the snapshot |
| 68 | # Unmanage snapshot function works almost the same as delete snapshot, |
| 69 | # but it does not delete the snapshot data |
| 70 | self.admin_snapshots_client.unmanage_snapshot(snapshot['id']) |
| 71 | self.admin_snapshots_client.wait_for_resource_deletion(snapshot['id']) |
| 72 | |
jeremy.zhang | ebc752b | 2017-06-14 13:58:37 +0800 | [diff] [blame] | 73 | # Verify the original snapshot does not exist in snapshot list |
| 74 | params = {'all_tenants': 1} |
| 75 | all_snapshots = self.admin_snapshots_client.list_snapshots( |
liangcui | c4d1ad1 | 2018-01-02 10:51:03 +0800 | [diff] [blame] | 76 | detail=True, **params)['snapshots'] |
jeremy.zhang | ebc752b | 2017-06-14 13:58:37 +0800 | [diff] [blame] | 77 | self.assertNotIn(snapshot['id'], [v['id'] for v in all_snapshots]) |
lkuchlan | cb2f859 | 2016-07-17 15:18:01 +0300 | [diff] [blame] | 78 | |
jeremy.zhang | ebc752b | 2017-06-14 13:58:37 +0800 | [diff] [blame] | 79 | # Manage the snapshot |
lkuchlan | da810bb | 2017-06-06 14:29:13 +0300 | [diff] [blame] | 80 | name = data_utils.rand_name(self.__class__.__name__ + |
| 81 | '-Managed-Snapshot') |
| 82 | description = data_utils.rand_name(self.__class__.__name__ + |
| 83 | '-Managed-Snapshot-Description') |
| 84 | metadata = {"manage-snap-meta1": "value1", |
| 85 | "manage-snap-meta2": "value2", |
| 86 | "manage-snap-meta3": "value3"} |
jeremy.zhang | ebc752b | 2017-06-14 13:58:37 +0800 | [diff] [blame] | 87 | snapshot_ref = { |
| 88 | 'volume_id': volume['id'], |
| 89 | 'ref': {CONF.volume.manage_snapshot_ref[0]: |
| 90 | CONF.volume.manage_snapshot_ref[1] % snapshot['id']}, |
| 91 | 'name': name, |
| 92 | 'description': description, |
| 93 | 'metadata': metadata |
| 94 | } |
lkuchlan | cb2f859 | 2016-07-17 15:18:01 +0300 | [diff] [blame] | 95 | new_snapshot = self.admin_snapshot_manage_client.manage_snapshot( |
jeremy.zhang | ebc752b | 2017-06-14 13:58:37 +0800 | [diff] [blame] | 96 | **snapshot_ref)['snapshot'] |
lkuchlan | 5b2b362 | 2017-02-14 15:48:36 +0200 | [diff] [blame] | 97 | self.addCleanup(self.delete_snapshot, new_snapshot['id'], |
| 98 | self.admin_snapshots_client) |
lkuchlan | cb2f859 | 2016-07-17 15:18:01 +0300 | [diff] [blame] | 99 | |
| 100 | # Wait for the snapshot to be available after manage operation |
lkuchlan | 52d7b0d | 2016-11-07 20:53:19 +0200 | [diff] [blame] | 101 | waiters.wait_for_volume_resource_status(self.admin_snapshots_client, |
| 102 | new_snapshot['id'], |
| 103 | 'available') |
lkuchlan | cb2f859 | 2016-07-17 15:18:01 +0300 | [diff] [blame] | 104 | |
| 105 | # Verify the managed snapshot has the expected parent volume |
lkuchlan | da810bb | 2017-06-06 14:29:13 +0300 | [diff] [blame] | 106 | # and the expected field values. |
jeremy.zhang | ebc752b | 2017-06-14 13:58:37 +0800 | [diff] [blame] | 107 | new_snapshot_info = self.admin_snapshots_client.show_snapshot( |
lkuchlan | da810bb | 2017-06-06 14:29:13 +0300 | [diff] [blame] | 108 | new_snapshot['id'])['snapshot'] |
jeremy.zhang | ebc752b | 2017-06-14 13:58:37 +0800 | [diff] [blame] | 109 | self.assertEqual(snapshot['size'], new_snapshot_info['size']) |
| 110 | for key in ['volume_id', 'name', 'description', 'metadata']: |
| 111 | self.assertEqual(snapshot_ref[key], new_snapshot_info[key]) |
lkuchlan | 724c675 | 2023-06-20 15:04:12 +0300 | [diff] [blame] | 112 | |
| 113 | @decorators.idempotent_id('0132f42d-0147-4b45-8501-cc504bbf7810') |
| 114 | def test_unmanage_manage_snapshot(self): |
| 115 | self._test_unmanage_manage_snapshot() |
| 116 | |
| 117 | @decorators.idempotent_id('7c735385-e953-4198-8534-68137f72dbdc') |
| 118 | @utils.services('compute') |
| 119 | def test_snapshot_manage_with_attached_volume(self): |
| 120 | """Test manage a snapshot with an attached volume. |
| 121 | |
| 122 | The case validates manage snapshot operation while |
| 123 | the parent volume is attached to an instance. |
| 124 | """ |
| 125 | self._test_unmanage_manage_snapshot(attached_volume=True) |