huangtianhua | 1346d70 | 2013-12-09 18:42:35 +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 | |
| 16 | from tempest.api.volume import base |
| 17 | from tempest import test |
| 18 | |
| 19 | |
| 20 | class SnapshotMetadataTest(base.BaseVolumeV1Test): |
| 21 | _interface = "json" |
| 22 | |
| 23 | @classmethod |
Masayuki Igawa | a279a68 | 2014-03-14 13:29:42 +0900 | [diff] [blame] | 24 | @test.safe_setup |
huangtianhua | 1346d70 | 2013-12-09 18:42:35 +0800 | [diff] [blame] | 25 | def setUpClass(cls): |
| 26 | super(SnapshotMetadataTest, cls).setUpClass() |
| 27 | cls.client = cls.snapshots_client |
| 28 | # Create a volume |
| 29 | cls.volume = cls.create_volume() |
| 30 | # Create a snapshot |
| 31 | cls.snapshot = cls.create_snapshot(volume_id=cls.volume['id']) |
| 32 | cls.snapshot_id = cls.snapshot['id'] |
| 33 | |
| 34 | def tearDown(self): |
| 35 | # Update the metadata to {} |
| 36 | self.client.update_snapshot_metadata(self.snapshot_id, {}) |
| 37 | super(SnapshotMetadataTest, self).tearDown() |
| 38 | |
| 39 | @test.attr(type='gate') |
| 40 | def test_create_get_delete_snapshot_metadata(self): |
| 41 | # Create metadata for the snapshot |
| 42 | metadata = {"key1": "value1", |
| 43 | "key2": "value2", |
| 44 | "key3": "value3"} |
| 45 | expected = {"key2": "value2", |
| 46 | "key3": "value3"} |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame^] | 47 | _, body = self.client.create_snapshot_metadata(self.snapshot_id, |
| 48 | metadata) |
huangtianhua | 1346d70 | 2013-12-09 18:42:35 +0800 | [diff] [blame] | 49 | # Get the metadata of the snapshot |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame^] | 50 | _, body = self.client.get_snapshot_metadata(self.snapshot_id) |
huangtianhua | 1346d70 | 2013-12-09 18:42:35 +0800 | [diff] [blame] | 51 | self.assertEqual(metadata, body) |
| 52 | # Delete one item metadata of the snapshot |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame^] | 53 | self.client.delete_snapshot_metadata_item( |
| 54 | self.snapshot_id, "key1") |
| 55 | _, body = self.client.get_snapshot_metadata(self.snapshot_id) |
huangtianhua | 1346d70 | 2013-12-09 18:42:35 +0800 | [diff] [blame] | 56 | self.assertEqual(expected, body) |
| 57 | |
| 58 | @test.attr(type='gate') |
| 59 | def test_update_snapshot_metadata(self): |
| 60 | # Update metadata for the snapshot |
| 61 | metadata = {"key1": "value1", |
| 62 | "key2": "value2", |
| 63 | "key3": "value3"} |
| 64 | update = {"key3": "value3_update", |
| 65 | "key4": "value4"} |
| 66 | # Create metadata for the snapshot |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame^] | 67 | _, body = self.client.create_snapshot_metadata(self.snapshot_id, |
| 68 | metadata) |
huangtianhua | 1346d70 | 2013-12-09 18:42:35 +0800 | [diff] [blame] | 69 | # Get the metadata of the snapshot |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame^] | 70 | _, body = self.client.get_snapshot_metadata(self.snapshot_id) |
huangtianhua | 1346d70 | 2013-12-09 18:42:35 +0800 | [diff] [blame] | 71 | self.assertEqual(metadata, body) |
| 72 | # Update metadata item |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame^] | 73 | _, body = self.client.update_snapshot_metadata( |
| 74 | self.snapshot_id, update) |
huangtianhua | 1346d70 | 2013-12-09 18:42:35 +0800 | [diff] [blame] | 75 | # Get the metadata of the snapshot |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame^] | 76 | _, body = self.client.get_snapshot_metadata(self.snapshot_id) |
huangtianhua | 1346d70 | 2013-12-09 18:42:35 +0800 | [diff] [blame] | 77 | self.assertEqual(update, body) |
| 78 | |
| 79 | @test.attr(type='gate') |
| 80 | def test_update_snapshot_metadata_item(self): |
| 81 | # Update metadata item for the snapshot |
| 82 | metadata = {"key1": "value1", |
| 83 | "key2": "value2", |
| 84 | "key3": "value3"} |
| 85 | update_item = {"key3": "value3_update"} |
| 86 | expect = {"key1": "value1", |
| 87 | "key2": "value2", |
| 88 | "key3": "value3_update"} |
| 89 | # Create metadata for the snapshot |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame^] | 90 | _, body = self.client.create_snapshot_metadata(self.snapshot_id, |
| 91 | metadata) |
huangtianhua | 1346d70 | 2013-12-09 18:42:35 +0800 | [diff] [blame] | 92 | # Get the metadata of the snapshot |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame^] | 93 | _, body = self.client.get_snapshot_metadata(self.snapshot_id) |
huangtianhua | 1346d70 | 2013-12-09 18:42:35 +0800 | [diff] [blame] | 94 | self.assertEqual(metadata, body) |
| 95 | # Update metadata item |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame^] | 96 | _, body = self.client.update_snapshot_metadata_item( |
| 97 | self.snapshot_id, "key3", update_item) |
huangtianhua | 1346d70 | 2013-12-09 18:42:35 +0800 | [diff] [blame] | 98 | # Get the metadata of the snapshot |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame^] | 99 | _, body = self.client.get_snapshot_metadata(self.snapshot_id) |
huangtianhua | 1346d70 | 2013-12-09 18:42:35 +0800 | [diff] [blame] | 100 | self.assertEqual(expect, body) |
| 101 | |
| 102 | |
| 103 | class SnapshotMetadataTestXML(SnapshotMetadataTest): |
| 104 | _interface = "xml" |