blob: 641317a59bf000b10c856f6b656b121a28f41436 [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"}
Joseph Lanoux6809bab2014-12-18 14:57:18 +000051 body = self.client.create_snapshot_metadata(self.snapshot_id,
52 metadata)
huangtianhua1346d702013-12-09 18:42:35 +080053 # Get the metadata of the snapshot
Ken'ichi Ohmichi35798fb2015-04-06 01:22:41 +000054 body = self.client.show_snapshot_metadata(self.snapshot_id)
Earle F. Philhower, III568865f2015-05-18 14:36:55 -070055 self.assertThat(body.items(), matchers.ContainsAll(metadata.items()))
56
huangtianhua1346d702013-12-09 18:42:35 +080057 # Delete one item metadata of the snapshot
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +000058 self.client.delete_snapshot_metadata_item(
59 self.snapshot_id, "key1")
Ken'ichi Ohmichi35798fb2015-04-06 01:22:41 +000060 body = self.client.show_snapshot_metadata(self.snapshot_id)
Earle F. Philhower, III568865f2015-05-18 14:36:55 -070061 self.assertThat(body.items(), matchers.ContainsAll(expected.items()))
62 self.assertNotIn("key1", body)
huangtianhua1346d702013-12-09 18:42:35 +080063
Chris Hoge7579c1a2015-02-26 14:12:15 -080064 @test.idempotent_id('bd2363bc-de92-48a4-bc98-28943c6e4be1')
huangtianhua1346d702013-12-09 18:42:35 +080065 def test_update_snapshot_metadata(self):
66 # Update metadata for the snapshot
67 metadata = {"key1": "value1",
68 "key2": "value2",
69 "key3": "value3"}
70 update = {"key3": "value3_update",
71 "key4": "value4"}
72 # Create metadata for the snapshot
Joseph Lanoux6809bab2014-12-18 14:57:18 +000073 body = self.client.create_snapshot_metadata(self.snapshot_id,
74 metadata)
huangtianhua1346d702013-12-09 18:42:35 +080075 # Get the metadata of the snapshot
Ken'ichi Ohmichi35798fb2015-04-06 01:22:41 +000076 body = self.client.show_snapshot_metadata(self.snapshot_id)
Earle F. Philhower, III568865f2015-05-18 14:36:55 -070077 self.assertThat(body.items(), matchers.ContainsAll(metadata.items()))
78
huangtianhua1346d702013-12-09 18:42:35 +080079 # Update metadata item
Joseph Lanoux6809bab2014-12-18 14:57:18 +000080 body = self.client.update_snapshot_metadata(
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +000081 self.snapshot_id, update)
huangtianhua1346d702013-12-09 18:42:35 +080082 # Get the metadata of the snapshot
Ken'ichi Ohmichi35798fb2015-04-06 01:22:41 +000083 body = self.client.show_snapshot_metadata(self.snapshot_id)
huangtianhua1346d702013-12-09 18:42:35 +080084 self.assertEqual(update, body)
85
Chris Hoge7579c1a2015-02-26 14:12:15 -080086 @test.idempotent_id('e8ff85c5-8f97-477f-806a-3ac364a949ed')
huangtianhua1346d702013-12-09 18:42:35 +080087 def test_update_snapshot_metadata_item(self):
88 # Update metadata item for the snapshot
89 metadata = {"key1": "value1",
90 "key2": "value2",
91 "key3": "value3"}
92 update_item = {"key3": "value3_update"}
93 expect = {"key1": "value1",
94 "key2": "value2",
95 "key3": "value3_update"}
96 # Create metadata for the snapshot
Joseph Lanoux6809bab2014-12-18 14:57:18 +000097 body = self.client.create_snapshot_metadata(self.snapshot_id,
98 metadata)
huangtianhua1346d702013-12-09 18:42:35 +080099 # Get the metadata of the snapshot
Ken'ichi Ohmichi35798fb2015-04-06 01:22:41 +0000100 body = self.client.show_snapshot_metadata(self.snapshot_id)
Earle F. Philhower, III568865f2015-05-18 14:36:55 -0700101 self.assertThat(body.items(), matchers.ContainsAll(metadata.items()))
huangtianhua1346d702013-12-09 18:42:35 +0800102 # Update metadata item
Joseph Lanoux6809bab2014-12-18 14:57:18 +0000103 body = self.client.update_snapshot_metadata_item(
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000104 self.snapshot_id, "key3", update_item)
huangtianhua1346d702013-12-09 18:42:35 +0800105 # Get the metadata of the snapshot
Ken'ichi Ohmichi35798fb2015-04-06 01:22:41 +0000106 body = self.client.show_snapshot_metadata(self.snapshot_id)
Earle F. Philhower, III568865f2015-05-18 14:36:55 -0700107 self.assertThat(body.items(), matchers.ContainsAll(expect.items()))
huangtianhua1346d702013-12-09 18:42:35 +0800108
109
Zhi Kun Liu38641c62014-07-10 20:12:48 +0800110class SnapshotV1MetadataTestJSON(SnapshotV2MetadataTestJSON):
111 _api_version = 1