blob: ce6ba90a11f61490fba102bda864054b616c3c5d [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
Earle F. Philhower, III568865f2015-05-18 14:36:55 -070016from testtools import matchers
17
huangtianhua1346d702013-12-09 18:42:35 +080018from tempest.api.volume import base
19from tempest import test
20
21
Zhi Kun Liu38641c62014-07-10 20:12:48 +080022class SnapshotV2MetadataTestJSON(base.BaseVolumeTest):
huangtianhua1346d702013-12-09 18:42:35 +080023
24 @classmethod
Rohan Kanade05749152015-01-30 17:15:18 +053025 def setup_clients(cls):
26 super(SnapshotV2MetadataTestJSON, cls).setup_clients()
27 cls.client = cls.snapshots_client
28
29 @classmethod
Andrea Frittoli61a12e22014-09-15 13:14:54 +010030 def resource_setup(cls):
31 super(SnapshotV2MetadataTestJSON, cls).resource_setup()
huangtianhua1346d702013-12-09 18:42:35 +080032 # Create a volume
33 cls.volume = cls.create_volume()
34 # Create a snapshot
35 cls.snapshot = cls.create_snapshot(volume_id=cls.volume['id'])
36 cls.snapshot_id = cls.snapshot['id']
37
38 def tearDown(self):
39 # Update the metadata to {}
40 self.client.update_snapshot_metadata(self.snapshot_id, {})
Zhi Kun Liu38641c62014-07-10 20:12:48 +080041 super(SnapshotV2MetadataTestJSON, self).tearDown()
huangtianhua1346d702013-12-09 18:42:35 +080042
Chris Hoge7579c1a2015-02-26 14:12:15 -080043 @test.idempotent_id('a2f20f99-e363-4584-be97-bc33afb1a56c')
huangtianhua1346d702013-12-09 18:42:35 +080044 def test_create_get_delete_snapshot_metadata(self):
45 # Create metadata for the snapshot
46 metadata = {"key1": "value1",
47 "key2": "value2",
48 "key3": "value3"}
49 expected = {"key2": "value2",
50 "key3": "value3"}
John Warrenff7faf62015-08-17 16:59:06 +000051 body = self.client.create_snapshot_metadata(
52 self.snapshot_id, metadata)['metadata']
huangtianhua1346d702013-12-09 18:42:35 +080053 # Get the metadata of the snapshot
John Warrenff7faf62015-08-17 16:59:06 +000054 body = self.client.show_snapshot_metadata(
55 self.snapshot_id)['metadata']
Earle F. Philhower, III568865f2015-05-18 14:36:55 -070056 self.assertThat(body.items(), matchers.ContainsAll(metadata.items()))
57
huangtianhua1346d702013-12-09 18:42:35 +080058 # Delete one item metadata of the snapshot
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +000059 self.client.delete_snapshot_metadata_item(
60 self.snapshot_id, "key1")
John Warrenff7faf62015-08-17 16:59:06 +000061 body = self.client.show_snapshot_metadata(
62 self.snapshot_id)['metadata']
Earle F. Philhower, III568865f2015-05-18 14:36:55 -070063 self.assertThat(body.items(), matchers.ContainsAll(expected.items()))
64 self.assertNotIn("key1", body)
huangtianhua1346d702013-12-09 18:42:35 +080065
Chris Hoge7579c1a2015-02-26 14:12:15 -080066 @test.idempotent_id('bd2363bc-de92-48a4-bc98-28943c6e4be1')
huangtianhua1346d702013-12-09 18:42:35 +080067 def test_update_snapshot_metadata(self):
68 # Update metadata for the snapshot
69 metadata = {"key1": "value1",
70 "key2": "value2",
71 "key3": "value3"}
72 update = {"key3": "value3_update",
73 "key4": "value4"}
74 # Create metadata for the snapshot
John Warrenff7faf62015-08-17 16:59:06 +000075 body = self.client.create_snapshot_metadata(
76 self.snapshot_id, metadata)['metadata']
huangtianhua1346d702013-12-09 18:42:35 +080077 # Get the metadata of the snapshot
John Warrenff7faf62015-08-17 16:59:06 +000078 body = self.client.show_snapshot_metadata(
79 self.snapshot_id)['metadata']
Earle F. Philhower, III568865f2015-05-18 14:36:55 -070080 self.assertThat(body.items(), matchers.ContainsAll(metadata.items()))
81
huangtianhua1346d702013-12-09 18:42:35 +080082 # Update metadata item
Joseph Lanoux6809bab2014-12-18 14:57:18 +000083 body = self.client.update_snapshot_metadata(
John Warrenff7faf62015-08-17 16:59:06 +000084 self.snapshot_id, update)['metadata']
huangtianhua1346d702013-12-09 18:42:35 +080085 # Get the metadata of the snapshot
John Warrenff7faf62015-08-17 16:59:06 +000086 body = self.client.show_snapshot_metadata(
87 self.snapshot_id)['metadata']
huangtianhua1346d702013-12-09 18:42:35 +080088 self.assertEqual(update, body)
89
Chris Hoge7579c1a2015-02-26 14:12:15 -080090 @test.idempotent_id('e8ff85c5-8f97-477f-806a-3ac364a949ed')
huangtianhua1346d702013-12-09 18:42:35 +080091 def test_update_snapshot_metadata_item(self):
92 # Update metadata item for the snapshot
93 metadata = {"key1": "value1",
94 "key2": "value2",
95 "key3": "value3"}
96 update_item = {"key3": "value3_update"}
97 expect = {"key1": "value1",
98 "key2": "value2",
99 "key3": "value3_update"}
100 # Create metadata for the snapshot
John Warrenff7faf62015-08-17 16:59:06 +0000101 body = self.client.create_snapshot_metadata(
102 self.snapshot_id, metadata)['metadata']
huangtianhua1346d702013-12-09 18:42:35 +0800103 # Get the metadata of the snapshot
John Warrenff7faf62015-08-17 16:59:06 +0000104 body = self.client.show_snapshot_metadata(
105 self.snapshot_id)['metadata']
Earle F. Philhower, III568865f2015-05-18 14:36:55 -0700106 self.assertThat(body.items(), matchers.ContainsAll(metadata.items()))
huangtianhua1346d702013-12-09 18:42:35 +0800107 # Update metadata item
Joseph Lanoux6809bab2014-12-18 14:57:18 +0000108 body = self.client.update_snapshot_metadata_item(
John Warrenff7faf62015-08-17 16:59:06 +0000109 self.snapshot_id, "key3", update_item)['meta']
huangtianhua1346d702013-12-09 18:42:35 +0800110 # Get the metadata of the snapshot
John Warrenff7faf62015-08-17 16:59:06 +0000111 body = self.client.show_snapshot_metadata(
112 self.snapshot_id)['metadata']
Earle F. Philhower, III568865f2015-05-18 14:36:55 -0700113 self.assertThat(body.items(), matchers.ContainsAll(expect.items()))
huangtianhua1346d702013-12-09 18:42:35 +0800114
115
Zhi Kun Liu38641c62014-07-10 20:12:48 +0800116class SnapshotV1MetadataTestJSON(SnapshotV2MetadataTestJSON):
117 _api_version = 1