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"} |
| 47 | resp, body = self.client.create_snapshot_metadata(self.snapshot_id, |
| 48 | metadata) |
| 49 | self.assertEqual(200, resp.status) |
| 50 | # Get the metadata of the snapshot |
| 51 | resp, body = self.client.get_snapshot_metadata(self.snapshot_id) |
| 52 | self.assertEqual(200, resp.status) |
| 53 | self.assertEqual(metadata, body) |
| 54 | # Delete one item metadata of the snapshot |
| 55 | resp, body = self.client.delete_snapshot_metadata_item( |
| 56 | self.snapshot_id, |
| 57 | "key1") |
| 58 | self.assertEqual(200, resp.status) |
| 59 | resp, body = self.client.get_snapshot_metadata(self.snapshot_id) |
| 60 | self.assertEqual(expected, body) |
| 61 | |
| 62 | @test.attr(type='gate') |
| 63 | def test_update_snapshot_metadata(self): |
| 64 | # Update metadata for the snapshot |
| 65 | metadata = {"key1": "value1", |
| 66 | "key2": "value2", |
| 67 | "key3": "value3"} |
| 68 | update = {"key3": "value3_update", |
| 69 | "key4": "value4"} |
| 70 | # Create metadata for the snapshot |
| 71 | resp, body = self.client.create_snapshot_metadata(self.snapshot_id, |
| 72 | metadata) |
| 73 | self.assertEqual(200, resp.status) |
| 74 | # Get the metadata of the snapshot |
| 75 | resp, body = self.client.get_snapshot_metadata(self.snapshot_id) |
| 76 | self.assertEqual(200, resp.status) |
| 77 | self.assertEqual(metadata, body) |
| 78 | # Update metadata item |
| 79 | resp, body = self.client.update_snapshot_metadata( |
| 80 | self.snapshot_id, |
| 81 | update) |
| 82 | self.assertEqual(200, resp.status) |
| 83 | # Get the metadata of the snapshot |
| 84 | resp, body = self.client.get_snapshot_metadata(self.snapshot_id) |
| 85 | self.assertEqual(200, resp.status) |
| 86 | self.assertEqual(update, body) |
| 87 | |
| 88 | @test.attr(type='gate') |
| 89 | def test_update_snapshot_metadata_item(self): |
| 90 | # Update metadata item for the snapshot |
| 91 | metadata = {"key1": "value1", |
| 92 | "key2": "value2", |
| 93 | "key3": "value3"} |
| 94 | update_item = {"key3": "value3_update"} |
| 95 | expect = {"key1": "value1", |
| 96 | "key2": "value2", |
| 97 | "key3": "value3_update"} |
| 98 | # Create metadata for the snapshot |
| 99 | resp, body = self.client.create_snapshot_metadata(self.snapshot_id, |
| 100 | metadata) |
| 101 | self.assertEqual(200, resp.status) |
| 102 | # Get the metadata of the snapshot |
| 103 | resp, body = self.client.get_snapshot_metadata(self.snapshot_id) |
| 104 | self.assertEqual(metadata, body) |
| 105 | # Update metadata item |
| 106 | resp, body = self.client.update_snapshot_metadata_item( |
| 107 | self.snapshot_id, |
| 108 | "key3", |
| 109 | update_item) |
| 110 | self.assertEqual(200, resp.status) |
| 111 | # Get the metadata of the snapshot |
| 112 | resp, body = self.client.get_snapshot_metadata(self.snapshot_id) |
| 113 | self.assertEqual(200, resp.status) |
| 114 | self.assertEqual(expect, body) |
| 115 | |
| 116 | |
| 117 | class SnapshotMetadataTestXML(SnapshotMetadataTest): |
| 118 | _interface = "xml" |