blob: 94ba095190a98b230755dabb6598430f93db33ce [file] [log] [blame]
huangtianhua1346d702013-12-09 18:42:35 +08001# Copyright 2013 Huawei Technologies Co.,LTD
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
16from tempest.api.volume import base
17from tempest import test
18
19
20class SnapshotMetadataTest(base.BaseVolumeV1Test):
21 _interface = "json"
22
23 @classmethod
Masayuki Igawaa279a682014-03-14 13:29:42 +090024 @test.safe_setup
huangtianhua1346d702013-12-09 18:42:35 +080025 def setUpClass(cls):
26 super(SnapshotMetadataTest, cls).setUpClass()
27 cls.client = cls.snapshots_client
28 # Create a volume
29 cls.volume = cls.create_volume()
30 # Create a snapshot
31 cls.snapshot = cls.create_snapshot(volume_id=cls.volume['id'])
32 cls.snapshot_id = cls.snapshot['id']
33
34 def tearDown(self):
35 # Update the metadata to {}
36 self.client.update_snapshot_metadata(self.snapshot_id, {})
37 super(SnapshotMetadataTest, self).tearDown()
38
39 @test.attr(type='gate')
40 def test_create_get_delete_snapshot_metadata(self):
41 # Create metadata for the snapshot
42 metadata = {"key1": "value1",
43 "key2": "value2",
44 "key3": "value3"}
45 expected = {"key2": "value2",
46 "key3": "value3"}
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +000047 _, body = self.client.create_snapshot_metadata(self.snapshot_id,
48 metadata)
huangtianhua1346d702013-12-09 18:42:35 +080049 # Get the metadata of the snapshot
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +000050 _, body = self.client.get_snapshot_metadata(self.snapshot_id)
huangtianhua1346d702013-12-09 18:42:35 +080051 self.assertEqual(metadata, body)
52 # Delete one item metadata of the snapshot
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +000053 self.client.delete_snapshot_metadata_item(
54 self.snapshot_id, "key1")
55 _, body = self.client.get_snapshot_metadata(self.snapshot_id)
huangtianhua1346d702013-12-09 18:42:35 +080056 self.assertEqual(expected, body)
57
58 @test.attr(type='gate')
59 def test_update_snapshot_metadata(self):
60 # Update metadata for the snapshot
61 metadata = {"key1": "value1",
62 "key2": "value2",
63 "key3": "value3"}
64 update = {"key3": "value3_update",
65 "key4": "value4"}
66 # Create metadata for the snapshot
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +000067 _, body = self.client.create_snapshot_metadata(self.snapshot_id,
68 metadata)
huangtianhua1346d702013-12-09 18:42:35 +080069 # Get the metadata of the snapshot
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +000070 _, body = self.client.get_snapshot_metadata(self.snapshot_id)
huangtianhua1346d702013-12-09 18:42:35 +080071 self.assertEqual(metadata, body)
72 # Update metadata item
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +000073 _, body = self.client.update_snapshot_metadata(
74 self.snapshot_id, update)
huangtianhua1346d702013-12-09 18:42:35 +080075 # Get the metadata of the snapshot
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +000076 _, body = self.client.get_snapshot_metadata(self.snapshot_id)
huangtianhua1346d702013-12-09 18:42:35 +080077 self.assertEqual(update, body)
78
79 @test.attr(type='gate')
80 def test_update_snapshot_metadata_item(self):
81 # Update metadata item for the snapshot
82 metadata = {"key1": "value1",
83 "key2": "value2",
84 "key3": "value3"}
85 update_item = {"key3": "value3_update"}
86 expect = {"key1": "value1",
87 "key2": "value2",
88 "key3": "value3_update"}
89 # Create metadata for the snapshot
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +000090 _, body = self.client.create_snapshot_metadata(self.snapshot_id,
91 metadata)
huangtianhua1346d702013-12-09 18:42:35 +080092 # Get the metadata of the snapshot
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +000093 _, body = self.client.get_snapshot_metadata(self.snapshot_id)
huangtianhua1346d702013-12-09 18:42:35 +080094 self.assertEqual(metadata, body)
95 # Update metadata item
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +000096 _, body = self.client.update_snapshot_metadata_item(
97 self.snapshot_id, "key3", update_item)
huangtianhua1346d702013-12-09 18:42:35 +080098 # Get the metadata of the snapshot
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +000099 _, body = self.client.get_snapshot_metadata(self.snapshot_id)
huangtianhua1346d702013-12-09 18:42:35 +0800100 self.assertEqual(expect, body)
101
102
103class SnapshotMetadataTestXML(SnapshotMetadataTest):
104 _interface = "xml"