blob: ab0aa383a2d486780d59496c8f40d89900e262d2 [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
17from tempest.common import waiters
18from tempest import config
lkuchlanda810bb2017-06-06 14:29:13 +030019from tempest.lib.common.utils import data_utils
Ken'ichi Ohmichi6b279c72017-01-27 18:26:59 -080020from tempest.lib import decorators
jeremy.zhangaa8c9312017-06-21 12:32:47 +080021from tempest.lib import exceptions
lkuchlancb2f8592016-07-17 15:18:01 +030022
23CONF = config.CONF
24
25
Ken'ichi Ohmichie8afb8c2017-03-27 11:25:37 -070026class SnapshotManageAdminTest(base.BaseVolumeAdminTest):
lkuchlancb2f8592016-07-17 15:18:01 +030027 """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.zhangebc752b2017-06-14 13:58:37 +080034 @classmethod
35 def skip_checks(cls):
36 super(SnapshotManageAdminTest, cls).skip_checks()
37
jeremy.zhangb1345892017-12-16 17:21:17 +080038 if not CONF.volume_feature_enabled.snapshot:
39 raise cls.skipException("Cinder volume snapshots are disabled")
40
jeremy.zhangebc752b2017-06-14 13:58:37 +080041 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.zhangaa8c9312017-06-21 12:32:47 +080045 msg = ("Manage snapshot ref is not correctly configured, "
46 "it should be a list of two elements")
47 raise exceptions.InvalidConfiguration(msg)
jeremy.zhangebc752b2017-06-14 13:58:37 +080048
Ken'ichi Ohmichi6b279c72017-01-27 18:26:59 -080049 @decorators.idempotent_id('0132f42d-0147-4b45-8501-cc504bbf7810')
lkuchlancb2f8592016-07-17 15:18:01 +030050 def test_unmanage_manage_snapshot(self):
zhuflfcfb31b2020-04-20 15:41:07 +080051 """Test unmanaging and managing volume snapshot"""
lkuchlancb2f8592016-07-17 15:18:01 +030052 # 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.zhangebc752b2017-06-14 13:58:37 +080064 # Verify the original snapshot does not exist in snapshot list
65 params = {'all_tenants': 1}
66 all_snapshots = self.admin_snapshots_client.list_snapshots(
liangcuic4d1ad12018-01-02 10:51:03 +080067 detail=True, **params)['snapshots']
jeremy.zhangebc752b2017-06-14 13:58:37 +080068 self.assertNotIn(snapshot['id'], [v['id'] for v in all_snapshots])
lkuchlancb2f8592016-07-17 15:18:01 +030069
jeremy.zhangebc752b2017-06-14 13:58:37 +080070 # Manage the snapshot
lkuchlanda810bb2017-06-06 14:29:13 +030071 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.zhangebc752b2017-06-14 13:58:37 +080078 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 }
lkuchlancb2f8592016-07-17 15:18:01 +030086 new_snapshot = self.admin_snapshot_manage_client.manage_snapshot(
jeremy.zhangebc752b2017-06-14 13:58:37 +080087 **snapshot_ref)['snapshot']
lkuchlan5b2b3622017-02-14 15:48:36 +020088 self.addCleanup(self.delete_snapshot, new_snapshot['id'],
89 self.admin_snapshots_client)
lkuchlancb2f8592016-07-17 15:18:01 +030090
91 # Wait for the snapshot to be available after manage operation
lkuchlan52d7b0d2016-11-07 20:53:19 +020092 waiters.wait_for_volume_resource_status(self.admin_snapshots_client,
93 new_snapshot['id'],
94 'available')
lkuchlancb2f8592016-07-17 15:18:01 +030095
96 # Verify the managed snapshot has the expected parent volume
lkuchlanda810bb2017-06-06 14:29:13 +030097 # and the expected field values.
jeremy.zhangebc752b2017-06-14 13:58:37 +080098 new_snapshot_info = self.admin_snapshots_client.show_snapshot(
lkuchlanda810bb2017-06-06 14:29:13 +030099 new_snapshot['id'])['snapshot']
jeremy.zhangebc752b2017-06-14 13:58:37 +0800100 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])