blob: 6c09042f6c119617dbc02ed7f3d270402cbd0e99 [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
lkuchlancb2f8592016-07-17 15:18:01 +030021
22CONF = config.CONF
23
24
Ken'ichi Ohmichie8afb8c2017-03-27 11:25:37 -070025class SnapshotManageAdminTest(base.BaseVolumeAdminTest):
lkuchlancb2f8592016-07-17 15:18:01 +030026 """Unmanage & manage snapshots
27
28 This feature provides the ability to import/export volume snapshot
29 from one Cinder to another and to import snapshots that have not been
30 managed by Cinder from a storage back end to Cinder
31 """
32
jeremy.zhangebc752b2017-06-14 13:58:37 +080033 @classmethod
34 def skip_checks(cls):
35 super(SnapshotManageAdminTest, cls).skip_checks()
36
37 if not CONF.volume_feature_enabled.manage_snapshot:
38 raise cls.skipException("Manage snapshot tests are disabled")
39
40 if len(CONF.volume.manage_snapshot_ref) != 2:
41 raise cls.skipException("Manage snapshot ref is not correctly "
42 "configured")
43
Ken'ichi Ohmichi6b279c72017-01-27 18:26:59 -080044 @decorators.idempotent_id('0132f42d-0147-4b45-8501-cc504bbf7810')
lkuchlancb2f8592016-07-17 15:18:01 +030045 def test_unmanage_manage_snapshot(self):
46 # Create a volume
47 volume = self.create_volume()
48
49 # Create a snapshot
50 snapshot = self.create_snapshot(volume_id=volume['id'])
51
52 # Unmanage the snapshot
53 # Unmanage snapshot function works almost the same as delete snapshot,
54 # but it does not delete the snapshot data
55 self.admin_snapshots_client.unmanage_snapshot(snapshot['id'])
56 self.admin_snapshots_client.wait_for_resource_deletion(snapshot['id'])
57
jeremy.zhangebc752b2017-06-14 13:58:37 +080058 # Verify the original snapshot does not exist in snapshot list
59 params = {'all_tenants': 1}
60 all_snapshots = self.admin_snapshots_client.list_snapshots(
61 detail=True, params=params)['snapshots']
62 self.assertNotIn(snapshot['id'], [v['id'] for v in all_snapshots])
lkuchlancb2f8592016-07-17 15:18:01 +030063
jeremy.zhangebc752b2017-06-14 13:58:37 +080064 # Manage the snapshot
lkuchlanda810bb2017-06-06 14:29:13 +030065 name = data_utils.rand_name(self.__class__.__name__ +
66 '-Managed-Snapshot')
67 description = data_utils.rand_name(self.__class__.__name__ +
68 '-Managed-Snapshot-Description')
69 metadata = {"manage-snap-meta1": "value1",
70 "manage-snap-meta2": "value2",
71 "manage-snap-meta3": "value3"}
jeremy.zhangebc752b2017-06-14 13:58:37 +080072 snapshot_ref = {
73 'volume_id': volume['id'],
74 'ref': {CONF.volume.manage_snapshot_ref[0]:
75 CONF.volume.manage_snapshot_ref[1] % snapshot['id']},
76 'name': name,
77 'description': description,
78 'metadata': metadata
79 }
lkuchlancb2f8592016-07-17 15:18:01 +030080 new_snapshot = self.admin_snapshot_manage_client.manage_snapshot(
jeremy.zhangebc752b2017-06-14 13:58:37 +080081 **snapshot_ref)['snapshot']
lkuchlan5b2b3622017-02-14 15:48:36 +020082 self.addCleanup(self.delete_snapshot, new_snapshot['id'],
83 self.admin_snapshots_client)
lkuchlancb2f8592016-07-17 15:18:01 +030084
85 # Wait for the snapshot to be available after manage operation
lkuchlan52d7b0d2016-11-07 20:53:19 +020086 waiters.wait_for_volume_resource_status(self.admin_snapshots_client,
87 new_snapshot['id'],
88 'available')
lkuchlancb2f8592016-07-17 15:18:01 +030089
90 # Verify the managed snapshot has the expected parent volume
lkuchlanda810bb2017-06-06 14:29:13 +030091 # and the expected field values.
jeremy.zhangebc752b2017-06-14 13:58:37 +080092 new_snapshot_info = self.admin_snapshots_client.show_snapshot(
lkuchlanda810bb2017-06-06 14:29:13 +030093 new_snapshot['id'])['snapshot']
jeremy.zhangebc752b2017-06-14 13:58:37 +080094 self.assertEqual(snapshot['size'], new_snapshot_info['size'])
95 for key in ['volume_id', 'name', 'description', 'metadata']:
96 self.assertEqual(snapshot_ref[key], new_snapshot_info[key])