blob: 164ed378b895f03993b9113f0bcc54f3c3909147 [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
Ken'ichi Ohmichi6b279c72017-01-27 18:26:59 -080020from tempest.lib import decorators
huangtianhua1346d702013-12-09 18:42:35 +080021
Takeaki Matsumotoa08e2e52015-09-02 13:52:26 +090022CONF = config.CONF
23
huangtianhua1346d702013-12-09 18:42:35 +080024
Ken'ichi Ohmichie8afb8c2017-03-27 11:25:37 -070025class SnapshotMetadataTestJSON(base.BaseVolumeTest):
Takeaki Matsumotoa08e2e52015-09-02 13:52:26 +090026 @classmethod
27 def skip_checks(cls):
Ken'ichi Ohmichie8afb8c2017-03-27 11:25:37 -070028 super(SnapshotMetadataTestJSON, cls).skip_checks()
Takeaki Matsumotoa08e2e52015-09-02 13:52:26 +090029 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):
Ken'ichi Ohmichie8afb8c2017-03-27 11:25:37 -070034 super(SnapshotMetadataTestJSON, 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={})
Ken'ichi Ohmichie8afb8c2017-03-27 11:25:37 -070044 super(SnapshotMetadataTestJSON, self).tearDown()
huangtianhua1346d702013-12-09 18:42:35 +080045
Ken'ichi Ohmichi6b279c72017-01-27 18:26:59 -080046 @decorators.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
Ken'ichi Ohmichi6b279c72017-01-27 18:26:59 -080081 @decorators.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()))