blob: d0fa07e40b4668263e1176b152900be8d40672fc [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
Andrea Frittoli61a12e22014-09-15 13:14:54 +010033 def resource_setup(cls):
34 super(SnapshotV2MetadataTestJSON, cls).resource_setup()
huangtianhua1346d702013-12-09 18:42:35 +080035 # Create a volume
36 cls.volume = cls.create_volume()
37 # Create a snapshot
38 cls.snapshot = cls.create_snapshot(volume_id=cls.volume['id'])
huangtianhua1346d702013-12-09 18:42:35 +080039
40 def tearDown(self):
41 # Update the metadata to {}
lkuchlanb21fc572016-11-28 12:25:22 +020042 self.snapshots_client.update_snapshot_metadata(
guo yunxian07322542016-11-10 19:55:37 +080043 self.snapshot['id'], metadata={})
Zhi Kun Liu38641c62014-07-10 20:12:48 +080044 super(SnapshotV2MetadataTestJSON, self).tearDown()
huangtianhua1346d702013-12-09 18:42:35 +080045
Chris Hoge7579c1a2015-02-26 14:12:15 -080046 @test.idempotent_id('a2f20f99-e363-4584-be97-bc33afb1a56c')
guo yunxian07322542016-11-10 19:55:37 +080047 def test_crud_snapshot_metadata(self):
huangtianhua1346d702013-12-09 18:42:35 +080048 # Create metadata for the snapshot
49 metadata = {"key1": "value1",
50 "key2": "value2",
51 "key3": "value3"}
huangtianhua1346d702013-12-09 18:42:35 +080052 update = {"key3": "value3_update",
53 "key4": "value4"}
guo yunxian07322542016-11-10 19:55:37 +080054 expect = {"key4": "value4"}
55 # Create metadata
lkuchlanb21fc572016-11-28 12:25:22 +020056 body = self.snapshots_client.create_snapshot_metadata(
guo yunxian07322542016-11-10 19:55:37 +080057 self.snapshot['id'], metadata)['metadata']
Earle F. Philhower, III568865f2015-05-18 14:36:55 -070058
huangtianhua1346d702013-12-09 18:42:35 +080059 # Get the metadata of the snapshot
lkuchlanb21fc572016-11-28 12:25:22 +020060 body = self.snapshots_client.show_snapshot_metadata(
guo yunxian07322542016-11-10 19:55:37 +080061 self.snapshot['id'])['metadata']
62 self.assertThat(body.items(), matchers.ContainsAll(metadata.items()),
63 'Create snapshot metadata failed')
64
65 # Update metadata
66 body = self.snapshots_client.update_snapshot_metadata(
67 self.snapshot['id'], metadata=update)['metadata']
68 body = self.snapshots_client.show_snapshot_metadata(
69 self.snapshot['id'])['metadata']
70 self.assertEqual(update, body, 'Update snapshot metadata failed')
71
72 # Delete one item metadata of the snapshot
73 self.snapshots_client.delete_snapshot_metadata_item(
74 self.snapshot['id'], "key3")
75 body = self.snapshots_client.show_snapshot_metadata(
76 self.snapshot['id'])['metadata']
77 self.assertThat(body.items(), matchers.ContainsAll(expect.items()),
78 'Delete one item metadata of the snapshot failed')
79 self.assertNotIn("key3", body)
huangtianhua1346d702013-12-09 18:42:35 +080080
Chris Hoge7579c1a2015-02-26 14:12:15 -080081 @test.idempotent_id('e8ff85c5-8f97-477f-806a-3ac364a949ed')
huangtianhua1346d702013-12-09 18:42:35 +080082 def test_update_snapshot_metadata_item(self):
83 # Update metadata item for the snapshot
84 metadata = {"key1": "value1",
85 "key2": "value2",
86 "key3": "value3"}
87 update_item = {"key3": "value3_update"}
88 expect = {"key1": "value1",
89 "key2": "value2",
90 "key3": "value3_update"}
91 # Create metadata for the snapshot
lkuchlanb21fc572016-11-28 12:25:22 +020092 body = self.snapshots_client.create_snapshot_metadata(
guo yunxian07322542016-11-10 19:55:37 +080093 self.snapshot['id'], metadata)['metadata']
huangtianhua1346d702013-12-09 18:42:35 +080094 # Get the metadata of the snapshot
lkuchlanb21fc572016-11-28 12:25:22 +020095 body = self.snapshots_client.show_snapshot_metadata(
guo yunxian07322542016-11-10 19:55:37 +080096 self.snapshot['id'])['metadata']
Earle F. Philhower, III568865f2015-05-18 14:36:55 -070097 self.assertThat(body.items(), matchers.ContainsAll(metadata.items()))
huangtianhua1346d702013-12-09 18:42:35 +080098 # Update metadata item
lkuchlanb21fc572016-11-28 12:25:22 +020099 body = self.snapshots_client.update_snapshot_metadata_item(
guo yunxian07322542016-11-10 19:55:37 +0800100 self.snapshot['id'], "key3", meta=update_item)['meta']
huangtianhua1346d702013-12-09 18:42:35 +0800101 # Get the metadata of the snapshot
lkuchlanb21fc572016-11-28 12:25:22 +0200102 body = self.snapshots_client.show_snapshot_metadata(
guo yunxian07322542016-11-10 19:55:37 +0800103 self.snapshot['id'])['metadata']
Earle F. Philhower, III568865f2015-05-18 14:36:55 -0700104 self.assertThat(body.items(), matchers.ContainsAll(expect.items()))
huangtianhua1346d702013-12-09 18:42:35 +0800105
106
Zhi Kun Liu38641c62014-07-10 20:12:48 +0800107class SnapshotV1MetadataTestJSON(SnapshotV2MetadataTestJSON):
108 _api_version = 1