blob: e529538cf3397c0287513c1751c7bb139144d93c [file] [log] [blame]
huangtianhua0ff41682013-12-16 14:49:31 +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
Masayuki Igawaba7bcf62014-02-17 14:56:41 +090016from testtools import matchers
Giulio Fidente5ed48ce2014-01-09 18:28:28 +010017
Zhi Kun Liu02a99062014-01-02 19:00:08 +080018from tempest.api.volume import base
huangtianhua0ff41682013-12-16 14:49:31 +080019from tempest import test
20
21
Zhi Kun Liu3d6d9862014-06-16 16:43:59 +080022class VolumesV2MetadataTest(base.BaseVolumeTest):
huangtianhua0ff41682013-12-16 14:49:31 +080023
24 @classmethod
Andrea Frittoli61a12e22014-09-15 13:14:54 +010025 def resource_setup(cls):
26 super(VolumesV2MetadataTest, cls).resource_setup()
huangtianhua0ff41682013-12-16 14:49:31 +080027 # Create a volume
28 cls.volume = cls.create_volume()
29 cls.volume_id = cls.volume['id']
30
huangtianhua0ff41682013-12-16 14:49:31 +080031 def tearDown(self):
32 # Update the metadata to {}
33 self.volumes_client.update_volume_metadata(self.volume_id, {})
Zhi Kun Liu3d6d9862014-06-16 16:43:59 +080034 super(VolumesV2MetadataTest, self).tearDown()
huangtianhua0ff41682013-12-16 14:49:31 +080035
Chris Hoge7579c1a2015-02-26 14:12:15 -080036 @test.idempotent_id('6f5b125b-f664-44bf-910f-751591fe5769')
huangtianhua0ff41682013-12-16 14:49:31 +080037 def test_create_get_delete_volume_metadata(self):
38 # Create metadata for the volume
39 metadata = {"key1": "value1",
40 "key2": "value2",
Ryan McNair9acfcf72014-01-27 21:06:48 +000041 "key3": "value3",
42 "key4": "<value&special_chars>"}
huangtianhua0ff41682013-12-16 14:49:31 +080043
Joseph Lanoux6809bab2014-12-18 14:57:18 +000044 body = self.volumes_client.create_volume_metadata(self.volume_id,
John Warren6177c9e2015-08-19 20:00:17 +000045 metadata)['metadata']
huangtianhua0ff41682013-12-16 14:49:31 +080046 # Get the metadata of the volume
John Warren6177c9e2015-08-19 20:00:17 +000047 body = self.volumes_client.show_volume_metadata(
48 self.volume_id)['metadata']
Masayuki Igawaba7bcf62014-02-17 14:56:41 +090049 self.assertThat(body.items(), matchers.ContainsAll(metadata.items()))
huangtianhua0ff41682013-12-16 14:49:31 +080050 # Delete one item metadata of the volume
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +000051 self.volumes_client.delete_volume_metadata_item(
52 self.volume_id, "key1")
John Warren6177c9e2015-08-19 20:00:17 +000053 body = self.volumes_client.show_volume_metadata(
54 self.volume_id)['metadata']
huangtianhua0ff41682013-12-16 14:49:31 +080055 self.assertNotIn("key1", body)
Ryan McNair9acfcf72014-01-27 21:06:48 +000056 del metadata["key1"]
Masayuki Igawaba7bcf62014-02-17 14:56:41 +090057 self.assertThat(body.items(), matchers.ContainsAll(metadata.items()))
huangtianhua0ff41682013-12-16 14:49:31 +080058
Chris Hoge7579c1a2015-02-26 14:12:15 -080059 @test.idempotent_id('774d2918-9beb-4f30-b3d1-2a4e8179ec0a')
huangtianhua0ff41682013-12-16 14:49:31 +080060 def test_update_volume_metadata(self):
61 # Update metadata for the volume
62 metadata = {"key1": "value1",
63 "key2": "value2",
64 "key3": "value3"}
65
66 update = {"key4": "value4",
67 "key1": "value1_update"}
68
69 # Create metadata for the volume
Joseph Lanoux6809bab2014-12-18 14:57:18 +000070 body = self.volumes_client.create_volume_metadata(
John Warren6177c9e2015-08-19 20:00:17 +000071 self.volume_id, metadata)['metadata']
huangtianhua0ff41682013-12-16 14:49:31 +080072 # Get the metadata of the volume
John Warren6177c9e2015-08-19 20:00:17 +000073 body = self.volumes_client.show_volume_metadata(
74 self.volume_id)['metadata']
Masayuki Igawaba7bcf62014-02-17 14:56:41 +090075 self.assertThat(body.items(), matchers.ContainsAll(metadata.items()))
huangtianhua0ff41682013-12-16 14:49:31 +080076 # Update metadata
Joseph Lanoux6809bab2014-12-18 14:57:18 +000077 body = self.volumes_client.update_volume_metadata(
John Warren6177c9e2015-08-19 20:00:17 +000078 self.volume_id, update)['metadata']
huangtianhua0ff41682013-12-16 14:49:31 +080079 # Get the metadata of the volume
John Warren6177c9e2015-08-19 20:00:17 +000080 body = self.volumes_client.show_volume_metadata(
81 self.volume_id)['metadata']
Earle F. Philhower, III7cc84e62015-05-27 09:54:16 -070082 self.assertEqual(update, body)
huangtianhua0ff41682013-12-16 14:49:31 +080083
Chris Hoge7579c1a2015-02-26 14:12:15 -080084 @test.idempotent_id('862261c5-8df4-475a-8c21-946e50e36a20')
huangtianhua0ff41682013-12-16 14:49:31 +080085 def test_update_volume_metadata_item(self):
86 # Update metadata item for the volume
87 metadata = {"key1": "value1",
88 "key2": "value2",
89 "key3": "value3"}
huangtianhua0ff41682013-12-16 14:49:31 +080090 update_item = {"key3": "value3_update"}
91 expect = {"key1": "value1",
92 "key2": "value2",
93 "key3": "value3_update"}
94 # Create metadata for the volume
Joseph Lanoux6809bab2014-12-18 14:57:18 +000095 body = self.volumes_client.create_volume_metadata(
John Warren6177c9e2015-08-19 20:00:17 +000096 self.volume_id, metadata)['metadata']
Masayuki Igawaba7bcf62014-02-17 14:56:41 +090097 self.assertThat(body.items(), matchers.ContainsAll(metadata.items()))
huangtianhua0ff41682013-12-16 14:49:31 +080098 # Update metadata item
Joseph Lanoux6809bab2014-12-18 14:57:18 +000099 body = self.volumes_client.update_volume_metadata_item(
John Warren6177c9e2015-08-19 20:00:17 +0000100 self.volume_id, "key3", update_item)['meta']
huangtianhua0ff41682013-12-16 14:49:31 +0800101 # Get the metadata of the volume
John Warren6177c9e2015-08-19 20:00:17 +0000102 body = self.volumes_client.show_volume_metadata(
103 self.volume_id)['metadata']
Masayuki Igawaba7bcf62014-02-17 14:56:41 +0900104 self.assertThat(body.items(), matchers.ContainsAll(expect.items()))
huangtianhua0ff41682013-12-16 14:49:31 +0800105
106
Zhi Kun Liu3d6d9862014-06-16 16:43:59 +0800107class VolumesV1MetadataTest(VolumesV2MetadataTest):
108 _api_version = 1