blob: 0326f3c11292ab015970562495d39de69b0892c5 [file] [log] [blame]
huangtianhua1346d702013-12-09 18:42:35 +08001# vim: tabstop=4 shiftwidth=4 softtabstop=4
2
3# Copyright 2013 Huawei Technologies Co.,LTD
4# All Rights Reserved.
5#
6# Licensed under the Apache License, Version 2.0 (the "License"); you may
7# not use this file except in compliance with the License. You may obtain
8# a copy of the License at
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15# License for the specific language governing permissions and limitations
16# under the License.
17
18from tempest.api.volume import base
19from tempest import test
20
21
22class SnapshotMetadataTest(base.BaseVolumeV1Test):
23 _interface = "json"
24
25 @classmethod
26 def setUpClass(cls):
27 super(SnapshotMetadataTest, cls).setUpClass()
28 cls.client = cls.snapshots_client
29 # Create a volume
30 cls.volume = cls.create_volume()
31 # Create a snapshot
32 cls.snapshot = cls.create_snapshot(volume_id=cls.volume['id'])
33 cls.snapshot_id = cls.snapshot['id']
34
35 def tearDown(self):
36 # Update the metadata to {}
37 self.client.update_snapshot_metadata(self.snapshot_id, {})
38 super(SnapshotMetadataTest, self).tearDown()
39
40 @test.attr(type='gate')
41 def test_create_get_delete_snapshot_metadata(self):
42 # Create metadata for the snapshot
43 metadata = {"key1": "value1",
44 "key2": "value2",
45 "key3": "value3"}
46 expected = {"key2": "value2",
47 "key3": "value3"}
48 resp, body = self.client.create_snapshot_metadata(self.snapshot_id,
49 metadata)
50 self.assertEqual(200, resp.status)
51 # Get the metadata of the snapshot
52 resp, body = self.client.get_snapshot_metadata(self.snapshot_id)
53 self.assertEqual(200, resp.status)
54 self.assertEqual(metadata, body)
55 # Delete one item metadata of the snapshot
56 resp, body = self.client.delete_snapshot_metadata_item(
57 self.snapshot_id,
58 "key1")
59 self.assertEqual(200, resp.status)
60 resp, body = self.client.get_snapshot_metadata(self.snapshot_id)
61 self.assertEqual(expected, body)
62
63 @test.attr(type='gate')
64 def test_update_snapshot_metadata(self):
65 # Update metadata for the snapshot
66 metadata = {"key1": "value1",
67 "key2": "value2",
68 "key3": "value3"}
69 update = {"key3": "value3_update",
70 "key4": "value4"}
71 # Create metadata for the snapshot
72 resp, body = self.client.create_snapshot_metadata(self.snapshot_id,
73 metadata)
74 self.assertEqual(200, resp.status)
75 # Get the metadata of the snapshot
76 resp, body = self.client.get_snapshot_metadata(self.snapshot_id)
77 self.assertEqual(200, resp.status)
78 self.assertEqual(metadata, body)
79 # Update metadata item
80 resp, body = self.client.update_snapshot_metadata(
81 self.snapshot_id,
82 update)
83 self.assertEqual(200, resp.status)
84 # Get the metadata of the snapshot
85 resp, body = self.client.get_snapshot_metadata(self.snapshot_id)
86 self.assertEqual(200, resp.status)
87 self.assertEqual(update, body)
88
89 @test.attr(type='gate')
90 def test_update_snapshot_metadata_item(self):
91 # Update metadata item for the snapshot
92 metadata = {"key1": "value1",
93 "key2": "value2",
94 "key3": "value3"}
95 update_item = {"key3": "value3_update"}
96 expect = {"key1": "value1",
97 "key2": "value2",
98 "key3": "value3_update"}
99 # Create metadata for the snapshot
100 resp, body = self.client.create_snapshot_metadata(self.snapshot_id,
101 metadata)
102 self.assertEqual(200, resp.status)
103 # Get the metadata of the snapshot
104 resp, body = self.client.get_snapshot_metadata(self.snapshot_id)
105 self.assertEqual(metadata, body)
106 # Update metadata item
107 resp, body = self.client.update_snapshot_metadata_item(
108 self.snapshot_id,
109 "key3",
110 update_item)
111 self.assertEqual(200, resp.status)
112 # Get the metadata of the snapshot
113 resp, body = self.client.get_snapshot_metadata(self.snapshot_id)
114 self.assertEqual(200, resp.status)
115 self.assertEqual(expect, body)
116
117
118class SnapshotMetadataTestXML(SnapshotMetadataTest):
119 _interface = "xml"