Add test for showing snapshot metadata item
This patch adds test for the missing API (volume v2):
show specific metadata item for a snapshot.
Including:
[1] Add show snapshot metadata item API to v2 snapshots_client
[2] Add unit test for the API
[3] Modify test case: test_update_snapshot_metadata_item
[4] Add release note
According defcore(interop) patch is:
I672bbcb9983e7a3ace7769722d6ff97f7bc0ccc8
Change-Id: I3697406e5541bbdb191e4d6e63831be31b471e78
diff --git a/releasenotes/notes/add-show-snapshot-metadata-item-api-to-v2-snapshots-client-bd3cbab3c7f0e0b3.yaml b/releasenotes/notes/add-show-snapshot-metadata-item-api-to-v2-snapshots-client-bd3cbab3c7f0e0b3.yaml
new file mode 100644
index 0000000..140df60
--- /dev/null
+++ b/releasenotes/notes/add-show-snapshot-metadata-item-api-to-v2-snapshots-client-bd3cbab3c7f0e0b3.yaml
@@ -0,0 +1,6 @@
+---
+features:
+ - |
+ Add show snapshot metadata item API to v2 snapshots_client library.
+ This feature enables the possibility to show a snapshot's metadata for
+ a specific key.
diff --git a/tempest/api/volume/test_snapshot_metadata.py b/tempest/api/volume/test_snapshot_metadata.py
index e54cd65..e6fe25d 100644
--- a/tempest/api/volume/test_snapshot_metadata.py
+++ b/tempest/api/volume/test_snapshot_metadata.py
@@ -81,7 +81,7 @@
self.assertNotIn("key3", body)
@decorators.idempotent_id('e8ff85c5-8f97-477f-806a-3ac364a949ed')
- def test_update_snapshot_metadata_item(self):
+ def test_update_show_snapshot_metadata_item(self):
# Update metadata item for the snapshot
metadata = {"key1": "value1",
"key2": "value2",
@@ -101,6 +101,12 @@
body = self.snapshots_client.update_snapshot_metadata_item(
self.snapshot['id'], "key3", meta=update_item)['meta']
self.assertEqual(update_item, body)
+
+ # Get a specific metadata item of the snapshot
+ body = self.snapshots_client.show_snapshot_metadata_item(
+ self.snapshot['id'], "key3")['meta']
+ self.assertEqual({"key3": expect['key3']}, body)
+
# Get the metadata of the snapshot
body = self.snapshots_client.show_snapshot_metadata(
self.snapshot['id'])['metadata']
diff --git a/tempest/lib/services/volume/v2/snapshots_client.py b/tempest/lib/services/volume/v2/snapshots_client.py
index 5f4e7de..4bc2842 100644
--- a/tempest/lib/services/volume/v2/snapshots_client.py
+++ b/tempest/lib/services/volume/v2/snapshots_client.py
@@ -164,6 +164,14 @@
self.expected_success(200, resp.status)
return rest_client.ResponseBody(resp, body)
+ def show_snapshot_metadata_item(self, snapshot_id, id):
+ """Show metadata item for the snapshot."""
+ url = "snapshots/%s/metadata/%s" % (snapshot_id, id)
+ resp, body = self.get(url)
+ body = json.loads(body)
+ self.expected_success(200, resp.status)
+ return rest_client.ResponseBody(resp, body)
+
def update_snapshot_metadata_item(self, snapshot_id, id, **kwargs):
"""Update metadata item for the snapshot."""
# TODO(piyush): Current api-site doesn't contain this API description.
diff --git a/tempest/tests/lib/services/volume/v2/test_snapshots_client.py b/tempest/tests/lib/services/volume/v2/test_snapshots_client.py
index 7d656f1..c9f57a0 100644
--- a/tempest/tests/lib/services/volume/v2/test_snapshots_client.py
+++ b/tempest/tests/lib/services/volume/v2/test_snapshots_client.py
@@ -72,6 +72,12 @@
]
}
+ FAKE_SNAPSHOT_METADATA_ITEM = {
+ "meta": {
+ "key1": "value1"
+ }
+ }
+
def setUp(self):
super(TestSnapshotsClient, self).setUp()
fake_auth = fake_auth_provider.FakeAuthProvider()
@@ -142,6 +148,15 @@
self.FAKE_INFO_SNAPSHOT,
bytes_body, volume_type_id="cbc36478b0bd8e67e89")
+ def _test_show_snapshot_metadata_item(self, bytes_body=False):
+ self.check_service_client_function(
+ self.client.show_snapshot_metadata_item,
+ 'tempest.lib.common.rest_client.RestClient.get',
+ self.FAKE_SNAPSHOT_METADATA_ITEM,
+ bytes_body,
+ snapshot_id="3fbbcccf-d058-4502-8844-6feeffdf4cb5",
+ id="key1")
+
def test_create_snapshot_with_str_body(self):
self._test_create_snapshot()
@@ -184,6 +199,12 @@
def test_update_snapshot_metadata_with_bytes_body(self):
self._test_update_snapshot_metadata(bytes_body=True)
+ def test_show_snapshot_metadata_item_with_str_body(self):
+ self._test_show_snapshot_metadata_item()
+
+ def test_show_snapshot_metadata_item_with_bytes_body(self):
+ self._test_show_snapshot_metadata_item(bytes_body=True)
+
def test_force_delete_snapshot(self):
self.check_service_client_function(
self.client.force_delete_snapshot,