blob: 1493b3787986296748f45b9c643fc2abaad4ef34 [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
24 def setUpClass(cls):
25 super(SnapshotMetadataTest, cls).setUpClass()
26 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, {})
36 super(SnapshotMetadataTest, self).tearDown()
37
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"}
46 resp, body = self.client.create_snapshot_metadata(self.snapshot_id,
47 metadata)
48 self.assertEqual(200, resp.status)
49 # Get the metadata of the snapshot
50 resp, body = self.client.get_snapshot_metadata(self.snapshot_id)
51 self.assertEqual(200, resp.status)
52 self.assertEqual(metadata, body)
53 # Delete one item metadata of the snapshot
54 resp, body = self.client.delete_snapshot_metadata_item(
55 self.snapshot_id,
56 "key1")
57 self.assertEqual(200, resp.status)
58 resp, body = self.client.get_snapshot_metadata(self.snapshot_id)
59 self.assertEqual(expected, body)
60
61 @test.attr(type='gate')
62 def test_update_snapshot_metadata(self):
63 # Update metadata for the snapshot
64 metadata = {"key1": "value1",
65 "key2": "value2",
66 "key3": "value3"}
67 update = {"key3": "value3_update",
68 "key4": "value4"}
69 # Create metadata for the snapshot
70 resp, body = self.client.create_snapshot_metadata(self.snapshot_id,
71 metadata)
72 self.assertEqual(200, resp.status)
73 # Get the metadata of the snapshot
74 resp, body = self.client.get_snapshot_metadata(self.snapshot_id)
75 self.assertEqual(200, resp.status)
76 self.assertEqual(metadata, body)
77 # Update metadata item
78 resp, body = self.client.update_snapshot_metadata(
79 self.snapshot_id,
80 update)
81 self.assertEqual(200, resp.status)
82 # Get the metadata of the snapshot
83 resp, body = self.client.get_snapshot_metadata(self.snapshot_id)
84 self.assertEqual(200, resp.status)
85 self.assertEqual(update, body)
86
87 @test.attr(type='gate')
88 def test_update_snapshot_metadata_item(self):
89 # Update metadata item for the snapshot
90 metadata = {"key1": "value1",
91 "key2": "value2",
92 "key3": "value3"}
93 update_item = {"key3": "value3_update"}
94 expect = {"key1": "value1",
95 "key2": "value2",
96 "key3": "value3_update"}
97 # Create metadata for the snapshot
98 resp, body = self.client.create_snapshot_metadata(self.snapshot_id,
99 metadata)
100 self.assertEqual(200, resp.status)
101 # Get the metadata of the snapshot
102 resp, body = self.client.get_snapshot_metadata(self.snapshot_id)
103 self.assertEqual(metadata, body)
104 # Update metadata item
105 resp, body = self.client.update_snapshot_metadata_item(
106 self.snapshot_id,
107 "key3",
108 update_item)
109 self.assertEqual(200, resp.status)
110 # Get the metadata of the snapshot
111 resp, body = self.client.get_snapshot_metadata(self.snapshot_id)
112 self.assertEqual(200, resp.status)
113 self.assertEqual(expect, body)
114
115
116class SnapshotMetadataTestXML(SnapshotMetadataTest):
117 _interface = "xml"