blob: 7040891c872fe5c51de820871ec9c94ee2fd86ec [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
Masayuki Igawaa279a682014-03-14 13:29:42 +090023 @test.safe_setup
huangtianhua1346d702013-12-09 18:42:35 +080024 def setUpClass(cls):
Zhi Kun Liu38641c62014-07-10 20:12:48 +080025 super(SnapshotV2MetadataTestJSON, cls).setUpClass()
huangtianhua1346d702013-12-09 18:42:35 +080026 cls.client = cls.snapshots_client
27 # Create a volume
28 cls.volume = cls.create_volume()
29 # Create a snapshot
30 cls.snapshot = cls.create_snapshot(volume_id=cls.volume['id'])
31 cls.snapshot_id = cls.snapshot['id']
32
33 def tearDown(self):
34 # Update the metadata to {}
35 self.client.update_snapshot_metadata(self.snapshot_id, {})
Zhi Kun Liu38641c62014-07-10 20:12:48 +080036 super(SnapshotV2MetadataTestJSON, self).tearDown()
huangtianhua1346d702013-12-09 18:42:35 +080037
38 @test.attr(type='gate')
39 def test_create_get_delete_snapshot_metadata(self):
40 # Create metadata for the snapshot
41 metadata = {"key1": "value1",
42 "key2": "value2",
43 "key3": "value3"}
44 expected = {"key2": "value2",
45 "key3": "value3"}
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +000046 _, body = self.client.create_snapshot_metadata(self.snapshot_id,
47 metadata)
huangtianhua1346d702013-12-09 18:42:35 +080048 # Get the metadata of the snapshot
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +000049 _, body = self.client.get_snapshot_metadata(self.snapshot_id)
huangtianhua1346d702013-12-09 18:42:35 +080050 self.assertEqual(metadata, body)
51 # Delete one item metadata of the snapshot
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +000052 self.client.delete_snapshot_metadata_item(
53 self.snapshot_id, "key1")
54 _, body = self.client.get_snapshot_metadata(self.snapshot_id)
huangtianhua1346d702013-12-09 18:42:35 +080055 self.assertEqual(expected, body)
56
57 @test.attr(type='gate')
58 def test_update_snapshot_metadata(self):
59 # Update metadata for the snapshot
60 metadata = {"key1": "value1",
61 "key2": "value2",
62 "key3": "value3"}
63 update = {"key3": "value3_update",
64 "key4": "value4"}
65 # Create metadata for the snapshot
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +000066 _, body = self.client.create_snapshot_metadata(self.snapshot_id,
67 metadata)
huangtianhua1346d702013-12-09 18:42:35 +080068 # Get the metadata of the snapshot
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +000069 _, body = self.client.get_snapshot_metadata(self.snapshot_id)
huangtianhua1346d702013-12-09 18:42:35 +080070 self.assertEqual(metadata, body)
71 # Update metadata item
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +000072 _, body = self.client.update_snapshot_metadata(
73 self.snapshot_id, update)
huangtianhua1346d702013-12-09 18:42:35 +080074 # Get the metadata of the snapshot
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +000075 _, body = self.client.get_snapshot_metadata(self.snapshot_id)
huangtianhua1346d702013-12-09 18:42:35 +080076 self.assertEqual(update, body)
77
78 @test.attr(type='gate')
79 def test_update_snapshot_metadata_item(self):
80 # Update metadata item for the snapshot
81 metadata = {"key1": "value1",
82 "key2": "value2",
83 "key3": "value3"}
84 update_item = {"key3": "value3_update"}
85 expect = {"key1": "value1",
86 "key2": "value2",
87 "key3": "value3_update"}
88 # Create metadata for the snapshot
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +000089 _, body = self.client.create_snapshot_metadata(self.snapshot_id,
90 metadata)
huangtianhua1346d702013-12-09 18:42:35 +080091 # Get the metadata of the snapshot
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +000092 _, body = self.client.get_snapshot_metadata(self.snapshot_id)
huangtianhua1346d702013-12-09 18:42:35 +080093 self.assertEqual(metadata, body)
94 # Update metadata item
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +000095 _, body = self.client.update_snapshot_metadata_item(
96 self.snapshot_id, "key3", update_item)
huangtianhua1346d702013-12-09 18:42:35 +080097 # Get the metadata of the snapshot
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +000098 _, body = self.client.get_snapshot_metadata(self.snapshot_id)
huangtianhua1346d702013-12-09 18:42:35 +080099 self.assertEqual(expect, body)
100
101
Zhi Kun Liu38641c62014-07-10 20:12:48 +0800102class SnapshotV2MetadataTestXML(SnapshotV2MetadataTestJSON):
103 _interface = "xml"
104
105
106class SnapshotV1MetadataTestJSON(SnapshotV2MetadataTestJSON):
107 _api_version = 1
108
109
110class SnapshotV1MetadataTestXML(SnapshotV1MetadataTestJSON):
huangtianhua1346d702013-12-09 18:42:35 +0800111 _interface = "xml"