blob: 777d3de8003c84ce1c18661d7267dcb5e687a2db [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
Zhi Kun Liu38641c62014-07-10 20:12:48 +080020class SnapshotV2MetadataTestJSON(base.BaseVolumeTest):
huangtianhua1346d702013-12-09 18:42:35 +080021
22 @classmethod
Andrea Frittoli61a12e22014-09-15 13:14:54 +010023 def resource_setup(cls):
24 super(SnapshotV2MetadataTestJSON, cls).resource_setup()
huangtianhua1346d702013-12-09 18:42:35 +080025 cls.client = cls.snapshots_client
26 # Create a volume
27 cls.volume = cls.create_volume()
28 # Create a snapshot
29 cls.snapshot = cls.create_snapshot(volume_id=cls.volume['id'])
30 cls.snapshot_id = cls.snapshot['id']
31
32 def tearDown(self):
33 # Update the metadata to {}
34 self.client.update_snapshot_metadata(self.snapshot_id, {})
Zhi Kun Liu38641c62014-07-10 20:12:48 +080035 super(SnapshotV2MetadataTestJSON, self).tearDown()
huangtianhua1346d702013-12-09 18:42:35 +080036
37 @test.attr(type='gate')
38 def test_create_get_delete_snapshot_metadata(self):
39 # Create metadata for the snapshot
40 metadata = {"key1": "value1",
41 "key2": "value2",
42 "key3": "value3"}
43 expected = {"key2": "value2",
44 "key3": "value3"}
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +000045 _, body = self.client.create_snapshot_metadata(self.snapshot_id,
46 metadata)
huangtianhua1346d702013-12-09 18:42:35 +080047 # Get the metadata of the snapshot
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +000048 _, body = self.client.get_snapshot_metadata(self.snapshot_id)
huangtianhua1346d702013-12-09 18:42:35 +080049 self.assertEqual(metadata, body)
50 # Delete one item metadata of the snapshot
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +000051 self.client.delete_snapshot_metadata_item(
52 self.snapshot_id, "key1")
53 _, body = self.client.get_snapshot_metadata(self.snapshot_id)
huangtianhua1346d702013-12-09 18:42:35 +080054 self.assertEqual(expected, body)
55
56 @test.attr(type='gate')
57 def test_update_snapshot_metadata(self):
58 # Update metadata for the snapshot
59 metadata = {"key1": "value1",
60 "key2": "value2",
61 "key3": "value3"}
62 update = {"key3": "value3_update",
63 "key4": "value4"}
64 # Create metadata for the snapshot
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +000065 _, body = self.client.create_snapshot_metadata(self.snapshot_id,
66 metadata)
huangtianhua1346d702013-12-09 18:42:35 +080067 # Get the metadata of the snapshot
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +000068 _, body = self.client.get_snapshot_metadata(self.snapshot_id)
huangtianhua1346d702013-12-09 18:42:35 +080069 self.assertEqual(metadata, body)
70 # Update metadata item
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +000071 _, body = self.client.update_snapshot_metadata(
72 self.snapshot_id, update)
huangtianhua1346d702013-12-09 18:42:35 +080073 # Get the metadata of the snapshot
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +000074 _, body = self.client.get_snapshot_metadata(self.snapshot_id)
huangtianhua1346d702013-12-09 18:42:35 +080075 self.assertEqual(update, body)
76
77 @test.attr(type='gate')
78 def test_update_snapshot_metadata_item(self):
79 # Update metadata item for the snapshot
80 metadata = {"key1": "value1",
81 "key2": "value2",
82 "key3": "value3"}
83 update_item = {"key3": "value3_update"}
84 expect = {"key1": "value1",
85 "key2": "value2",
86 "key3": "value3_update"}
87 # Create metadata for the snapshot
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +000088 _, body = self.client.create_snapshot_metadata(self.snapshot_id,
89 metadata)
huangtianhua1346d702013-12-09 18:42:35 +080090 # Get the metadata of the snapshot
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +000091 _, body = self.client.get_snapshot_metadata(self.snapshot_id)
huangtianhua1346d702013-12-09 18:42:35 +080092 self.assertEqual(metadata, body)
93 # Update metadata item
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +000094 _, body = self.client.update_snapshot_metadata_item(
95 self.snapshot_id, "key3", update_item)
huangtianhua1346d702013-12-09 18:42:35 +080096 # Get the metadata of the snapshot
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +000097 _, body = self.client.get_snapshot_metadata(self.snapshot_id)
huangtianhua1346d702013-12-09 18:42:35 +080098 self.assertEqual(expect, body)
99
100
Zhi Kun Liu38641c62014-07-10 20:12:48 +0800101class SnapshotV2MetadataTestXML(SnapshotV2MetadataTestJSON):
102 _interface = "xml"
103
104
105class SnapshotV1MetadataTestJSON(SnapshotV2MetadataTestJSON):
106 _api_version = 1
107
108
109class SnapshotV1MetadataTestXML(SnapshotV1MetadataTestJSON):
huangtianhua1346d702013-12-09 18:42:35 +0800110 _interface = "xml"