blob: 478bd160c3d47d4910106cf71933878597b8fe43 [file] [log] [blame]
lkuchlancb2f8592016-07-17 15:18:01 +03001# 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
lkuchlancb2f8592016-07-17 15:18:01 +030016from tempest.api.volume import base
lkuchlan724c6752023-06-20 15:04:12 +030017from tempest.common import utils
lkuchlancb2f8592016-07-17 15:18:01 +030018from tempest.common import waiters
19from tempest import config
lkuchlanda810bb2017-06-06 14:29:13 +030020from tempest.lib.common.utils import data_utils
Ken'ichi Ohmichi6b279c72017-01-27 18:26:59 -080021from tempest.lib import decorators
jeremy.zhangaa8c9312017-06-21 12:32:47 +080022from tempest.lib import exceptions
lkuchlancb2f8592016-07-17 15:18:01 +030023
24CONF = config.CONF
25
26
Ken'ichi Ohmichie8afb8c2017-03-27 11:25:37 -070027class SnapshotManageAdminTest(base.BaseVolumeAdminTest):
lkuchlancb2f8592016-07-17 15:18:01 +030028 """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
lkuchlan724c6752023-06-20 15:04:12 +030035 create_default_network = True
36
jeremy.zhangebc752b2017-06-14 13:58:37 +080037 @classmethod
38 def skip_checks(cls):
39 super(SnapshotManageAdminTest, cls).skip_checks()
40
jeremy.zhangb1345892017-12-16 17:21:17 +080041 if not CONF.volume_feature_enabled.snapshot:
42 raise cls.skipException("Cinder volume snapshots are disabled")
43
jeremy.zhangebc752b2017-06-14 13:58:37 +080044 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.zhangaa8c9312017-06-21 12:32:47 +080048 msg = ("Manage snapshot ref is not correctly configured, "
49 "it should be a list of two elements")
50 raise exceptions.InvalidConfiguration(msg)
jeremy.zhangebc752b2017-06-14 13:58:37 +080051
lkuchlan724c6752023-06-20 15:04:12 +030052 def _test_unmanage_manage_snapshot(self, attached_volume=False):
zhuflfcfb31b2020-04-20 15:41:07 +080053 """Test unmanaging and managing volume snapshot"""
lkuchlancb2f8592016-07-17 15:18:01 +030054 # Create a volume
55 volume = self.create_volume()
56
57 # Create a snapshot
58 snapshot = self.create_snapshot(volume_id=volume['id'])
59
lkuchlan724c6752023-06-20 15:04:12 +030060 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
lkuchlancb2f8592016-07-17 15:18:01 +030067 # 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.zhangebc752b2017-06-14 13:58:37 +080073 # Verify the original snapshot does not exist in snapshot list
74 params = {'all_tenants': 1}
75 all_snapshots = self.admin_snapshots_client.list_snapshots(
liangcuic4d1ad12018-01-02 10:51:03 +080076 detail=True, **params)['snapshots']
jeremy.zhangebc752b2017-06-14 13:58:37 +080077 self.assertNotIn(snapshot['id'], [v['id'] for v in all_snapshots])
lkuchlancb2f8592016-07-17 15:18:01 +030078
jeremy.zhangebc752b2017-06-14 13:58:37 +080079 # Manage the snapshot
lkuchlanda810bb2017-06-06 14:29:13 +030080 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.zhangebc752b2017-06-14 13:58:37 +080087 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 }
lkuchlancb2f8592016-07-17 15:18:01 +030095 new_snapshot = self.admin_snapshot_manage_client.manage_snapshot(
jeremy.zhangebc752b2017-06-14 13:58:37 +080096 **snapshot_ref)['snapshot']
lkuchlan5b2b3622017-02-14 15:48:36 +020097 self.addCleanup(self.delete_snapshot, new_snapshot['id'],
98 self.admin_snapshots_client)
lkuchlancb2f8592016-07-17 15:18:01 +030099
100 # Wait for the snapshot to be available after manage operation
lkuchlan52d7b0d2016-11-07 20:53:19 +0200101 waiters.wait_for_volume_resource_status(self.admin_snapshots_client,
102 new_snapshot['id'],
103 'available')
lkuchlancb2f8592016-07-17 15:18:01 +0300104
105 # Verify the managed snapshot has the expected parent volume
lkuchlanda810bb2017-06-06 14:29:13 +0300106 # and the expected field values.
jeremy.zhangebc752b2017-06-14 13:58:37 +0800107 new_snapshot_info = self.admin_snapshots_client.show_snapshot(
lkuchlanda810bb2017-06-06 14:29:13 +0300108 new_snapshot['id'])['snapshot']
jeremy.zhangebc752b2017-06-14 13:58:37 +0800109 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])
lkuchlan724c6752023-06-20 15:04:12 +0300112
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)