blob: e50ca957c4f8a377fe8c9932a0496639bc53a18c [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
Takeaki Matsumotoa08e2e52015-09-02 13:52:26 +090019from tempest import config
huangtianhua1346d702013-12-09 18:42:35 +080020from tempest import test
21
Takeaki Matsumotoa08e2e52015-09-02 13:52:26 +090022CONF = config.CONF
23
huangtianhua1346d702013-12-09 18:42:35 +080024
Zhi Kun Liu38641c62014-07-10 20:12:48 +080025class SnapshotV2MetadataTestJSON(base.BaseVolumeTest):
Takeaki Matsumotoa08e2e52015-09-02 13:52:26 +090026 @classmethod
27 def skip_checks(cls):
28 super(SnapshotV2MetadataTestJSON, cls).skip_checks()
29 if not CONF.volume_feature_enabled.snapshot:
30 raise cls.skipException("Cinder snapshot feature disabled")
huangtianhua1346d702013-12-09 18:42:35 +080031
32 @classmethod
Rohan Kanade05749152015-01-30 17:15:18 +053033 def setup_clients(cls):
34 super(SnapshotV2MetadataTestJSON, cls).setup_clients()
35 cls.client = cls.snapshots_client
36
37 @classmethod
Andrea Frittoli61a12e22014-09-15 13:14:54 +010038 def resource_setup(cls):
39 super(SnapshotV2MetadataTestJSON, cls).resource_setup()
huangtianhua1346d702013-12-09 18:42:35 +080040 # Create a volume
41 cls.volume = cls.create_volume()
42 # Create a snapshot
43 cls.snapshot = cls.create_snapshot(volume_id=cls.volume['id'])
44 cls.snapshot_id = cls.snapshot['id']
45
46 def tearDown(self):
47 # Update the metadata to {}
48 self.client.update_snapshot_metadata(self.snapshot_id, {})
Zhi Kun Liu38641c62014-07-10 20:12:48 +080049 super(SnapshotV2MetadataTestJSON, self).tearDown()
huangtianhua1346d702013-12-09 18:42:35 +080050
Chris Hoge7579c1a2015-02-26 14:12:15 -080051 @test.idempotent_id('a2f20f99-e363-4584-be97-bc33afb1a56c')
huangtianhua1346d702013-12-09 18:42:35 +080052 def test_create_get_delete_snapshot_metadata(self):
53 # Create metadata for the snapshot
54 metadata = {"key1": "value1",
55 "key2": "value2",
56 "key3": "value3"}
57 expected = {"key2": "value2",
58 "key3": "value3"}
John Warrenff7faf62015-08-17 16:59:06 +000059 body = self.client.create_snapshot_metadata(
60 self.snapshot_id, metadata)['metadata']
huangtianhua1346d702013-12-09 18:42:35 +080061 # Get the metadata of the snapshot
John Warrenff7faf62015-08-17 16:59:06 +000062 body = self.client.show_snapshot_metadata(
63 self.snapshot_id)['metadata']
Earle F. Philhower, III568865f2015-05-18 14:36:55 -070064 self.assertThat(body.items(), matchers.ContainsAll(metadata.items()))
65
huangtianhua1346d702013-12-09 18:42:35 +080066 # Delete one item metadata of the snapshot
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +000067 self.client.delete_snapshot_metadata_item(
68 self.snapshot_id, "key1")
John Warrenff7faf62015-08-17 16:59:06 +000069 body = self.client.show_snapshot_metadata(
70 self.snapshot_id)['metadata']
Earle F. Philhower, III568865f2015-05-18 14:36:55 -070071 self.assertThat(body.items(), matchers.ContainsAll(expected.items()))
72 self.assertNotIn("key1", body)
huangtianhua1346d702013-12-09 18:42:35 +080073
Chris Hoge7579c1a2015-02-26 14:12:15 -080074 @test.idempotent_id('bd2363bc-de92-48a4-bc98-28943c6e4be1')
huangtianhua1346d702013-12-09 18:42:35 +080075 def test_update_snapshot_metadata(self):
76 # Update metadata for the snapshot
77 metadata = {"key1": "value1",
78 "key2": "value2",
79 "key3": "value3"}
80 update = {"key3": "value3_update",
81 "key4": "value4"}
82 # Create metadata for the snapshot
John Warrenff7faf62015-08-17 16:59:06 +000083 body = self.client.create_snapshot_metadata(
84 self.snapshot_id, metadata)['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']
Earle F. Philhower, III568865f2015-05-18 14:36:55 -070088 self.assertThat(body.items(), matchers.ContainsAll(metadata.items()))
89
huangtianhua1346d702013-12-09 18:42:35 +080090 # Update metadata item
Joseph Lanoux6809bab2014-12-18 14:57:18 +000091 body = self.client.update_snapshot_metadata(
John Warrenff7faf62015-08-17 16:59:06 +000092 self.snapshot_id, update)['metadata']
huangtianhua1346d702013-12-09 18:42:35 +080093 # Get the metadata of the snapshot
John Warrenff7faf62015-08-17 16:59:06 +000094 body = self.client.show_snapshot_metadata(
95 self.snapshot_id)['metadata']
huangtianhua1346d702013-12-09 18:42:35 +080096 self.assertEqual(update, body)
97
Chris Hoge7579c1a2015-02-26 14:12:15 -080098 @test.idempotent_id('e8ff85c5-8f97-477f-806a-3ac364a949ed')
huangtianhua1346d702013-12-09 18:42:35 +080099 def test_update_snapshot_metadata_item(self):
100 # Update metadata item for the snapshot
101 metadata = {"key1": "value1",
102 "key2": "value2",
103 "key3": "value3"}
104 update_item = {"key3": "value3_update"}
105 expect = {"key1": "value1",
106 "key2": "value2",
107 "key3": "value3_update"}
108 # Create metadata for the snapshot
John Warrenff7faf62015-08-17 16:59:06 +0000109 body = self.client.create_snapshot_metadata(
110 self.snapshot_id, metadata)['metadata']
huangtianhua1346d702013-12-09 18:42:35 +0800111 # Get the metadata of the snapshot
John Warrenff7faf62015-08-17 16:59:06 +0000112 body = self.client.show_snapshot_metadata(
113 self.snapshot_id)['metadata']
Earle F. Philhower, III568865f2015-05-18 14:36:55 -0700114 self.assertThat(body.items(), matchers.ContainsAll(metadata.items()))
huangtianhua1346d702013-12-09 18:42:35 +0800115 # Update metadata item
Joseph Lanoux6809bab2014-12-18 14:57:18 +0000116 body = self.client.update_snapshot_metadata_item(
John Warrenff7faf62015-08-17 16:59:06 +0000117 self.snapshot_id, "key3", update_item)['meta']
huangtianhua1346d702013-12-09 18:42:35 +0800118 # Get the metadata of the snapshot
John Warrenff7faf62015-08-17 16:59:06 +0000119 body = self.client.show_snapshot_metadata(
120 self.snapshot_id)['metadata']
Earle F. Philhower, III568865f2015-05-18 14:36:55 -0700121 self.assertThat(body.items(), matchers.ContainsAll(expect.items()))
huangtianhua1346d702013-12-09 18:42:35 +0800122
123
Zhi Kun Liu38641c62014-07-10 20:12:48 +0800124class SnapshotV1MetadataTestJSON(SnapshotV2MetadataTestJSON):
125 _api_version = 1