blob: 2ec866750b2bfc572671dc396bbcfc3be1b6fb0d [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
36 @test.attr(type='gate')
37 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
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +000044 _, body = self.volumes_client.create_volume_metadata(self.volume_id,
45 metadata)
huangtianhua0ff41682013-12-16 14:49:31 +080046 # Get the metadata of the volume
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +000047 _, body = self.volumes_client.get_volume_metadata(self.volume_id)
Masayuki Igawaba7bcf62014-02-17 14:56:41 +090048 self.assertThat(body.items(), matchers.ContainsAll(metadata.items()))
huangtianhua0ff41682013-12-16 14:49:31 +080049 # Delete one item metadata of the volume
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +000050 self.volumes_client.delete_volume_metadata_item(
51 self.volume_id, "key1")
52 _, body = self.volumes_client.get_volume_metadata(self.volume_id)
huangtianhua0ff41682013-12-16 14:49:31 +080053 self.assertNotIn("key1", body)
Ryan McNair9acfcf72014-01-27 21:06:48 +000054 del metadata["key1"]
Masayuki Igawaba7bcf62014-02-17 14:56:41 +090055 self.assertThat(body.items(), matchers.ContainsAll(metadata.items()))
huangtianhua0ff41682013-12-16 14:49:31 +080056
57 @test.attr(type='gate')
58 def test_update_volume_metadata(self):
59 # Update metadata for the volume
60 metadata = {"key1": "value1",
61 "key2": "value2",
62 "key3": "value3"}
63
64 update = {"key4": "value4",
65 "key1": "value1_update"}
66
67 # Create metadata for the volume
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +000068 _, body = self.volumes_client.create_volume_metadata(
69 self.volume_id, metadata)
huangtianhua0ff41682013-12-16 14:49:31 +080070 # Get the metadata of the volume
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +000071 _, body = self.volumes_client.get_volume_metadata(self.volume_id)
Masayuki Igawaba7bcf62014-02-17 14:56:41 +090072 self.assertThat(body.items(), matchers.ContainsAll(metadata.items()))
huangtianhua0ff41682013-12-16 14:49:31 +080073 # Update metadata
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +000074 _, body = self.volumes_client.update_volume_metadata(
75 self.volume_id, update)
huangtianhua0ff41682013-12-16 14:49:31 +080076 # Get the metadata of the volume
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +000077 _, body = self.volumes_client.get_volume_metadata(self.volume_id)
Masayuki Igawaba7bcf62014-02-17 14:56:41 +090078 self.assertThat(body.items(), matchers.ContainsAll(update.items()))
huangtianhua0ff41682013-12-16 14:49:31 +080079
80 @test.attr(type='gate')
81 def test_update_volume_metadata_item(self):
82 # Update metadata item for the volume
83 metadata = {"key1": "value1",
84 "key2": "value2",
85 "key3": "value3"}
huangtianhua0ff41682013-12-16 14:49:31 +080086 update_item = {"key3": "value3_update"}
87 expect = {"key1": "value1",
88 "key2": "value2",
89 "key3": "value3_update"}
90 # Create metadata for the volume
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +000091 _, body = self.volumes_client.create_volume_metadata(
92 self.volume_id, metadata)
Masayuki Igawaba7bcf62014-02-17 14:56:41 +090093 self.assertThat(body.items(), matchers.ContainsAll(metadata.items()))
huangtianhua0ff41682013-12-16 14:49:31 +080094 # Update metadata item
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +000095 _, body = self.volumes_client.update_volume_metadata_item(
96 self.volume_id, "key3", update_item)
huangtianhua0ff41682013-12-16 14:49:31 +080097 # Get the metadata of the volume
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +000098 _, body = self.volumes_client.get_volume_metadata(self.volume_id)
Masayuki Igawaba7bcf62014-02-17 14:56:41 +090099 self.assertThat(body.items(), matchers.ContainsAll(expect.items()))
huangtianhua0ff41682013-12-16 14:49:31 +0800100
101
Zhi Kun Liu3d6d9862014-06-16 16:43:59 +0800102class VolumesV2MetadataTestXML(VolumesV2MetadataTest):
103 _interface = "xml"
104
105
106class VolumesV1MetadataTest(VolumesV2MetadataTest):
107 _api_version = 1
108
109
110class VolumesV1MetadataTestXML(VolumesV1MetadataTest):
huangtianhua0ff41682013-12-16 14:49:31 +0800111 _interface = "xml"