Add test for showing volume metadata item

This patch adds test for the missing API (volume v2):
show specific metadata item for a volume.

Including:

[1] Add show volume metadata item API to v2 volumes_client
[2] Add unit test for the API
[3] Modify test case: test_update_volume_metadata_item
[4] Add release note

According defcore(interop) patch is:
Ica8b57f5f5392e2bf47e368e9b10ef9fa5695c30

Change-Id: Idb9d198383ce93453707f1204806e4ae82c1e46a
This commit is contained in:
jeremy.zhang 2017-07-04 12:56:59 +08:00
parent 479863dd47
commit b40cb198ce
4 changed files with 42 additions and 1 deletions

View File

@ -0,0 +1,6 @@
---
features:
- |
Add show volume metadata item API to v2 volumes_client library.
This feature enables the possibility to show a volume's metadata for
a specific key.

View File

@ -70,7 +70,7 @@ class VolumesMetadataTest(base.BaseVolumeTest):
'Delete one item metadata of the volume failed')
@decorators.idempotent_id('862261c5-8df4-475a-8c21-946e50e36a20')
def test_update_volume_metadata_item(self):
def test_update_show_volume_metadata_item(self):
# Update metadata item for the volume
metadata = {"key1": "value1",
"key2": "value2",
@ -88,6 +88,12 @@ class VolumesMetadataTest(base.BaseVolumeTest):
body = self.volumes_client.update_volume_metadata_item(
self.volume['id'], "key3", update_item)['meta']
self.assertEqual(update_item, body)
# Get a specific metadata item of the volume
body = self.volumes_client.show_volume_metadata_item(
self.volume['id'], "key3")['meta']
self.assertEqual({"key3": expect['key3']}, body)
# Get the metadata of the volume
body = self.volumes_client.show_volume_metadata(
self.volume['id'])['metadata']

View File

@ -283,6 +283,14 @@ class VolumesClient(rest_client.RestClient):
self.expected_success(200, resp.status)
return rest_client.ResponseBody(resp, body)
def show_volume_metadata_item(self, volume_id, id):
"""Show metadata item for the volume."""
url = "volumes/%s/metadata/%s" % (volume_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_volume_metadata_item(self, volume_id, id, meta_item):
"""Update metadata item for the volume."""
put_body = json.dumps({'meta': meta_item})

View File

@ -20,6 +20,12 @@ from tempest.tests.lib.services import base
class TestVolumesClient(base.BaseServiceTest):
FAKE_VOLUME_METADATA_ITEM = {
"meta": {
"key1": "value1"
}
}
def setUp(self):
super(TestVolumesClient, self).setUp()
fake_auth = fake_auth_provider.FakeAuthProvider()
@ -45,8 +51,23 @@ class TestVolumesClient(base.BaseServiceTest):
**kwargs
)
def _test_show_volume_metadata_item(self, bytes_body=False):
self.check_service_client_function(
self.client.show_volume_metadata_item,
'tempest.lib.common.rest_client.RestClient.get',
self.FAKE_VOLUME_METADATA_ITEM,
to_utf=bytes_body,
volume_id="a3be971b-8de5-4bdf-bdb8-3d8eb0fb69f8",
id="key1")
def test_force_detach_volume_with_str_body(self):
self._test_force_detach_volume()
def test_force_detach_volume_with_bytes_body(self):
self._test_force_detach_volume(bytes_body=True)
def test_show_volume_metadata_item_with_str_body(self):
self._test_show_volume_metadata_item()
def test_show_volume_metadata_item_with_bytes_body(self):
self._test_show_volume_metadata_item(bytes_body=True)