huangtianhua | 0ff4168 | 2013-12-16 14:49:31 +0800 | [diff] [blame] | 1 | # 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 Igawa | ba7bcf6 | 2014-02-17 14:56:41 +0900 | [diff] [blame] | 16 | from testtools import matchers |
Giulio Fidente | 5ed48ce | 2014-01-09 18:28:28 +0100 | [diff] [blame] | 17 | |
Zhi Kun Liu | 02a9906 | 2014-01-02 19:00:08 +0800 | [diff] [blame] | 18 | from tempest.api.volume import base |
huangtianhua | 0ff4168 | 2013-12-16 14:49:31 +0800 | [diff] [blame] | 19 | from tempest import test |
| 20 | |
| 21 | |
Zhi Kun Liu | 3d6d986 | 2014-06-16 16:43:59 +0800 | [diff] [blame] | 22 | class VolumesV2MetadataTest(base.BaseVolumeTest): |
huangtianhua | 0ff4168 | 2013-12-16 14:49:31 +0800 | [diff] [blame] | 23 | |
| 24 | @classmethod |
Andrea Frittoli | 61a12e2 | 2014-09-15 13:14:54 +0100 | [diff] [blame] | 25 | def resource_setup(cls): |
| 26 | super(VolumesV2MetadataTest, cls).resource_setup() |
huangtianhua | 0ff4168 | 2013-12-16 14:49:31 +0800 | [diff] [blame] | 27 | # Create a volume |
| 28 | cls.volume = cls.create_volume() |
| 29 | cls.volume_id = cls.volume['id'] |
| 30 | |
huangtianhua | 0ff4168 | 2013-12-16 14:49:31 +0800 | [diff] [blame] | 31 | def tearDown(self): |
| 32 | # Update the metadata to {} |
| 33 | self.volumes_client.update_volume_metadata(self.volume_id, {}) |
Zhi Kun Liu | 3d6d986 | 2014-06-16 16:43:59 +0800 | [diff] [blame] | 34 | super(VolumesV2MetadataTest, self).tearDown() |
huangtianhua | 0ff4168 | 2013-12-16 14:49:31 +0800 | [diff] [blame] | 35 | |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 36 | @test.idempotent_id('6f5b125b-f664-44bf-910f-751591fe5769') |
huangtianhua | 0ff4168 | 2013-12-16 14:49:31 +0800 | [diff] [blame] | 37 | def test_create_get_delete_volume_metadata(self): |
| 38 | # Create metadata for the volume |
| 39 | metadata = {"key1": "value1", |
| 40 | "key2": "value2", |
Ryan McNair | 9acfcf7 | 2014-01-27 21:06:48 +0000 | [diff] [blame] | 41 | "key3": "value3", |
| 42 | "key4": "<value&special_chars>"} |
huangtianhua | 0ff4168 | 2013-12-16 14:49:31 +0800 | [diff] [blame] | 43 | |
Joseph Lanoux | 6809bab | 2014-12-18 14:57:18 +0000 | [diff] [blame] | 44 | body = self.volumes_client.create_volume_metadata(self.volume_id, |
John Warren | 6177c9e | 2015-08-19 20:00:17 +0000 | [diff] [blame] | 45 | metadata)['metadata'] |
huangtianhua | 0ff4168 | 2013-12-16 14:49:31 +0800 | [diff] [blame] | 46 | # Get the metadata of the volume |
John Warren | 6177c9e | 2015-08-19 20:00:17 +0000 | [diff] [blame] | 47 | body = self.volumes_client.show_volume_metadata( |
| 48 | self.volume_id)['metadata'] |
Masayuki Igawa | ba7bcf6 | 2014-02-17 14:56:41 +0900 | [diff] [blame] | 49 | self.assertThat(body.items(), matchers.ContainsAll(metadata.items())) |
huangtianhua | 0ff4168 | 2013-12-16 14:49:31 +0800 | [diff] [blame] | 50 | # Delete one item metadata of the volume |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 51 | self.volumes_client.delete_volume_metadata_item( |
| 52 | self.volume_id, "key1") |
John Warren | 6177c9e | 2015-08-19 20:00:17 +0000 | [diff] [blame] | 53 | body = self.volumes_client.show_volume_metadata( |
| 54 | self.volume_id)['metadata'] |
huangtianhua | 0ff4168 | 2013-12-16 14:49:31 +0800 | [diff] [blame] | 55 | self.assertNotIn("key1", body) |
Ryan McNair | 9acfcf7 | 2014-01-27 21:06:48 +0000 | [diff] [blame] | 56 | del metadata["key1"] |
Masayuki Igawa | ba7bcf6 | 2014-02-17 14:56:41 +0900 | [diff] [blame] | 57 | self.assertThat(body.items(), matchers.ContainsAll(metadata.items())) |
huangtianhua | 0ff4168 | 2013-12-16 14:49:31 +0800 | [diff] [blame] | 58 | |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 59 | @test.idempotent_id('774d2918-9beb-4f30-b3d1-2a4e8179ec0a') |
huangtianhua | 0ff4168 | 2013-12-16 14:49:31 +0800 | [diff] [blame] | 60 | 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 Lanoux | 6809bab | 2014-12-18 14:57:18 +0000 | [diff] [blame] | 70 | body = self.volumes_client.create_volume_metadata( |
John Warren | 6177c9e | 2015-08-19 20:00:17 +0000 | [diff] [blame] | 71 | self.volume_id, metadata)['metadata'] |
huangtianhua | 0ff4168 | 2013-12-16 14:49:31 +0800 | [diff] [blame] | 72 | # Get the metadata of the volume |
John Warren | 6177c9e | 2015-08-19 20:00:17 +0000 | [diff] [blame] | 73 | body = self.volumes_client.show_volume_metadata( |
| 74 | self.volume_id)['metadata'] |
Masayuki Igawa | ba7bcf6 | 2014-02-17 14:56:41 +0900 | [diff] [blame] | 75 | self.assertThat(body.items(), matchers.ContainsAll(metadata.items())) |
huangtianhua | 0ff4168 | 2013-12-16 14:49:31 +0800 | [diff] [blame] | 76 | # Update metadata |
Joseph Lanoux | 6809bab | 2014-12-18 14:57:18 +0000 | [diff] [blame] | 77 | body = self.volumes_client.update_volume_metadata( |
John Warren | 6177c9e | 2015-08-19 20:00:17 +0000 | [diff] [blame] | 78 | self.volume_id, update)['metadata'] |
huangtianhua | 0ff4168 | 2013-12-16 14:49:31 +0800 | [diff] [blame] | 79 | # Get the metadata of the volume |
John Warren | 6177c9e | 2015-08-19 20:00:17 +0000 | [diff] [blame] | 80 | body = self.volumes_client.show_volume_metadata( |
| 81 | self.volume_id)['metadata'] |
Earle F. Philhower, III | 7cc84e6 | 2015-05-27 09:54:16 -0700 | [diff] [blame] | 82 | self.assertEqual(update, body) |
huangtianhua | 0ff4168 | 2013-12-16 14:49:31 +0800 | [diff] [blame] | 83 | |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 84 | @test.idempotent_id('862261c5-8df4-475a-8c21-946e50e36a20') |
huangtianhua | 0ff4168 | 2013-12-16 14:49:31 +0800 | [diff] [blame] | 85 | def test_update_volume_metadata_item(self): |
| 86 | # Update metadata item for the volume |
| 87 | metadata = {"key1": "value1", |
| 88 | "key2": "value2", |
| 89 | "key3": "value3"} |
huangtianhua | 0ff4168 | 2013-12-16 14:49:31 +0800 | [diff] [blame] | 90 | update_item = {"key3": "value3_update"} |
| 91 | expect = {"key1": "value1", |
| 92 | "key2": "value2", |
| 93 | "key3": "value3_update"} |
| 94 | # Create metadata for the volume |
Joseph Lanoux | 6809bab | 2014-12-18 14:57:18 +0000 | [diff] [blame] | 95 | body = self.volumes_client.create_volume_metadata( |
John Warren | 6177c9e | 2015-08-19 20:00:17 +0000 | [diff] [blame] | 96 | self.volume_id, metadata)['metadata'] |
Masayuki Igawa | ba7bcf6 | 2014-02-17 14:56:41 +0900 | [diff] [blame] | 97 | self.assertThat(body.items(), matchers.ContainsAll(metadata.items())) |
huangtianhua | 0ff4168 | 2013-12-16 14:49:31 +0800 | [diff] [blame] | 98 | # Update metadata item |
Joseph Lanoux | 6809bab | 2014-12-18 14:57:18 +0000 | [diff] [blame] | 99 | body = self.volumes_client.update_volume_metadata_item( |
John Warren | 6177c9e | 2015-08-19 20:00:17 +0000 | [diff] [blame] | 100 | self.volume_id, "key3", update_item)['meta'] |
huangtianhua | 0ff4168 | 2013-12-16 14:49:31 +0800 | [diff] [blame] | 101 | # Get the metadata of the volume |
John Warren | 6177c9e | 2015-08-19 20:00:17 +0000 | [diff] [blame] | 102 | body = self.volumes_client.show_volume_metadata( |
| 103 | self.volume_id)['metadata'] |
Masayuki Igawa | ba7bcf6 | 2014-02-17 14:56:41 +0900 | [diff] [blame] | 104 | self.assertThat(body.items(), matchers.ContainsAll(expect.items())) |
huangtianhua | 0ff4168 | 2013-12-16 14:49:31 +0800 | [diff] [blame] | 105 | |
| 106 | |
Zhi Kun Liu | 3d6d986 | 2014-06-16 16:43:59 +0800 | [diff] [blame] | 107 | class VolumesV1MetadataTest(VolumesV2MetadataTest): |
| 108 | _api_version = 1 |