Addition of metadata for snapshot in VolumeSnapshot object

When accessing the snapshot object in Horizon codebase, we do not have
access to the metadata of the snapshot. This is because the
VolumeSnapshot object does not have metadata as a member. So added
'metadata' to the VolumeSnapshot object. The fix should provide access
to metadata.
Added test data and test cases for snapshot object with metadata.

Closes-Bug: 1542468

Change-Id: I4ae2e7a74d3ddbff8493b42f8f86c7002229cf8c
This commit is contained in:
Vivek Agrawal 2016-02-11 13:34:52 -08:00 committed by Timur Sufiev
parent fee1de02aa
commit a05883d88a
3 changed files with 26 additions and 1 deletions

View File

@ -93,7 +93,8 @@ class VolumeSnapshot(BaseCinderAPIResourceWrapper):
_attrs = ['id', 'name', 'description', 'size', 'status',
'created_at', 'volume_id',
'os-extended-snapshot-attributes:project_id']
'os-extended-snapshot-attributes:project_id',
'metadata']
class VolumeType(BaseCinderAPIResourceWrapper):

View File

@ -439,6 +439,20 @@ class CinderApiVersionTests(test.TestCase):
self.assertEqual(name, snapshot.name)
self.assertEqual(description, snapshot.description)
def test_get_v2_snapshot_metadata(self):
# Get a v2 snapshot with metadata
snapshot = self.cinder_volume_snapshots.get(
description="v2 volume snapshot with metadata description")
self.assertTrue(hasattr(snapshot._apiresource, 'metadata'))
self.assertFalse(hasattr(snapshot._apiresource, 'display_name'))
key_name = "snapshot_meta_key"
key_value = "snapshot_meta_value"
metadata_value = {key_name: key_value}
setattr(snapshot._apiresource, 'metadata', metadata_value)
self.assertTrue(key_name in snapshot.metadata.keys())
self.assertEqual(key_value, snapshot.metadata['snapshot_meta_key'])
def test_get_id_for_nameless_volume(self):
volume = self.cinder_volumes.first()
setattr(volume._apiresource, 'display_name', "")

View File

@ -200,6 +200,15 @@ def data(TEST):
'size': 80,
'status': 'available',
'volume_id': '31023e92-8008-4c8b-8059-7f2293ff1234'})
snapshot4 = vol_snaps.Snapshot(
vol_snaps.SnapshotManager(None),
{'id': 'cd6be1eb-82ca-4587-8036-13c37c00c2b1',
'name': '',
'description': 'v2 volume snapshot with metadata description',
'size': 80,
'status': 'available',
'volume_id': '31023e92-8008-4c8b-8059-7f2293ff1234',
'metadata': {'snapshot_meta_key': 'snapshot_meta_value'}})
snapshot.bootable = 'true'
snapshot2.bootable = 'true'
@ -207,6 +216,7 @@ def data(TEST):
TEST.cinder_volume_snapshots.add(api.cinder.VolumeSnapshot(snapshot))
TEST.cinder_volume_snapshots.add(api.cinder.VolumeSnapshot(snapshot2))
TEST.cinder_volume_snapshots.add(api.cinder.VolumeSnapshot(snapshot3))
TEST.cinder_volume_snapshots.add(api.cinder.VolumeSnapshot(snapshot4))
TEST.cinder_volume_snapshots.first()._volume = volume
# Volume Type Encryption