blob: 536648d24883b973e637d21390b881300783296c [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
Rohan Kanade05749152015-01-30 17:15:18 +053023 def setup_clients(cls):
24 super(SnapshotV2MetadataTestJSON, cls).setup_clients()
25 cls.client = cls.snapshots_client
26
27 @classmethod
Andrea Frittoli61a12e22014-09-15 13:14:54 +010028 def resource_setup(cls):
29 super(SnapshotV2MetadataTestJSON, cls).resource_setup()
huangtianhua1346d702013-12-09 18:42:35 +080030 # Create a volume
31 cls.volume = cls.create_volume()
32 # Create a snapshot
33 cls.snapshot = cls.create_snapshot(volume_id=cls.volume['id'])
34 cls.snapshot_id = cls.snapshot['id']
35
36 def tearDown(self):
37 # Update the metadata to {}
38 self.client.update_snapshot_metadata(self.snapshot_id, {})
Zhi Kun Liu38641c62014-07-10 20:12:48 +080039 super(SnapshotV2MetadataTestJSON, self).tearDown()
huangtianhua1346d702013-12-09 18:42:35 +080040
41 @test.attr(type='gate')
Chris Hoge7579c1a2015-02-26 14:12:15 -080042 @test.idempotent_id('a2f20f99-e363-4584-be97-bc33afb1a56c')
huangtianhua1346d702013-12-09 18:42:35 +080043 def test_create_get_delete_snapshot_metadata(self):
44 # Create metadata for the snapshot
45 metadata = {"key1": "value1",
46 "key2": "value2",
47 "key3": "value3"}
48 expected = {"key2": "value2",
49 "key3": "value3"}
Joseph Lanoux6809bab2014-12-18 14:57:18 +000050 body = self.client.create_snapshot_metadata(self.snapshot_id,
51 metadata)
huangtianhua1346d702013-12-09 18:42:35 +080052 # Get the metadata of the snapshot
Ken'ichi Ohmichi35798fb2015-04-06 01:22:41 +000053 body = self.client.show_snapshot_metadata(self.snapshot_id)
huangtianhua1346d702013-12-09 18:42:35 +080054 self.assertEqual(metadata, body)
55 # Delete one item metadata of the snapshot
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +000056 self.client.delete_snapshot_metadata_item(
57 self.snapshot_id, "key1")
Ken'ichi Ohmichi35798fb2015-04-06 01:22:41 +000058 body = self.client.show_snapshot_metadata(self.snapshot_id)
huangtianhua1346d702013-12-09 18:42:35 +080059 self.assertEqual(expected, body)
60
61 @test.attr(type='gate')
Chris Hoge7579c1a2015-02-26 14:12:15 -080062 @test.idempotent_id('bd2363bc-de92-48a4-bc98-28943c6e4be1')
huangtianhua1346d702013-12-09 18:42:35 +080063 def test_update_snapshot_metadata(self):
64 # Update metadata for the snapshot
65 metadata = {"key1": "value1",
66 "key2": "value2",
67 "key3": "value3"}
68 update = {"key3": "value3_update",
69 "key4": "value4"}
70 # Create metadata for the snapshot
Joseph Lanoux6809bab2014-12-18 14:57:18 +000071 body = self.client.create_snapshot_metadata(self.snapshot_id,
72 metadata)
huangtianhua1346d702013-12-09 18:42:35 +080073 # Get the metadata of the snapshot
Ken'ichi Ohmichi35798fb2015-04-06 01:22:41 +000074 body = self.client.show_snapshot_metadata(self.snapshot_id)
huangtianhua1346d702013-12-09 18:42:35 +080075 self.assertEqual(metadata, body)
76 # Update metadata item
Joseph Lanoux6809bab2014-12-18 14:57:18 +000077 body = self.client.update_snapshot_metadata(
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +000078 self.snapshot_id, update)
huangtianhua1346d702013-12-09 18:42:35 +080079 # Get the metadata of the snapshot
Ken'ichi Ohmichi35798fb2015-04-06 01:22:41 +000080 body = self.client.show_snapshot_metadata(self.snapshot_id)
huangtianhua1346d702013-12-09 18:42:35 +080081 self.assertEqual(update, body)
82
83 @test.attr(type='gate')
Chris Hoge7579c1a2015-02-26 14:12:15 -080084 @test.idempotent_id('e8ff85c5-8f97-477f-806a-3ac364a949ed')
huangtianhua1346d702013-12-09 18:42:35 +080085 def test_update_snapshot_metadata_item(self):
86 # Update metadata item for the snapshot
87 metadata = {"key1": "value1",
88 "key2": "value2",
89 "key3": "value3"}
90 update_item = {"key3": "value3_update"}
91 expect = {"key1": "value1",
92 "key2": "value2",
93 "key3": "value3_update"}
94 # Create metadata for the snapshot
Joseph Lanoux6809bab2014-12-18 14:57:18 +000095 body = self.client.create_snapshot_metadata(self.snapshot_id,
96 metadata)
huangtianhua1346d702013-12-09 18:42:35 +080097 # Get the metadata of the snapshot
Ken'ichi Ohmichi35798fb2015-04-06 01:22:41 +000098 body = self.client.show_snapshot_metadata(self.snapshot_id)
huangtianhua1346d702013-12-09 18:42:35 +080099 self.assertEqual(metadata, body)
100 # Update metadata item
Joseph Lanoux6809bab2014-12-18 14:57:18 +0000101 body = self.client.update_snapshot_metadata_item(
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000102 self.snapshot_id, "key3", update_item)
huangtianhua1346d702013-12-09 18:42:35 +0800103 # Get the metadata of the snapshot
Ken'ichi Ohmichi35798fb2015-04-06 01:22:41 +0000104 body = self.client.show_snapshot_metadata(self.snapshot_id)
huangtianhua1346d702013-12-09 18:42:35 +0800105 self.assertEqual(expect, body)
106
107
Zhi Kun Liu38641c62014-07-10 20:12:48 +0800108class SnapshotV1MetadataTestJSON(SnapshotV2MetadataTestJSON):
109 _api_version = 1