From 99a6f4f9e5b13cd9a3e5c90a5ff11eab9ad92642 Mon Sep 17 00:00:00 2001 From: Ollie Leahy Date: Wed, 24 Jul 2013 10:06:41 +0000 Subject: [PATCH] get_snapshot should populate the snapshot metadata Update the query in db api snapshot_get() to join with the table snapshot_metadata, so that snapshot metadata is returned. This makes the api snapshot_get() function in the same way as volume_get(). Fixes: bug #1204446 Change-Id: I37004140f6a11b96aaeb3af6c631028a44541d3a --- cinder/db/sqlalchemy/api.py | 1 + cinder/tests/test_volume.py | 8 +++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/cinder/db/sqlalchemy/api.py b/cinder/db/sqlalchemy/api.py index 25fb2ae97..3c9d0c0dc 100644 --- a/cinder/db/sqlalchemy/api.py +++ b/cinder/db/sqlalchemy/api.py @@ -1313,6 +1313,7 @@ def _snapshot_get(context, snapshot_id, session=None): result = model_query(context, models.Snapshot, session=session, project_only=True).\ options(joinedload('volume')).\ + options(joinedload('snapshot_metadata')).\ filter_by(id=snapshot_id).\ first() diff --git a/cinder/tests/test_volume.py b/cinder/tests/test_volume.py index 41c389b6e..ed4b9409f 100644 --- a/cinder/tests/test_volume.py +++ b/cinder/tests/test_volume.py @@ -563,12 +563,14 @@ class VolumeTestCase(test.TestCase): test_meta = {'fake_key': 'fake_value'} volume = self._create_volume(0, None) volume_id = volume['id'] - self.volume.create_volume(self.context, volume_id) snapshot = self._create_snapshot(volume['id'], metadata=test_meta) snapshot_id = snapshot['id'] + + snap = db.snapshot_get(context.get_admin_context(), snapshot_id) + result_dict = dict(snap.iteritems()) result_meta = { - snapshot.snapshot_metadata[0].key: - snapshot.snapshot_metadata[0].value} + result_dict['snapshot_metadata'][0].key: + result_dict['snapshot_metadata'][0].value} self.assertEqual(result_meta, test_meta) self.volume.delete_snapshot(self.context, snapshot_id) -- 2.45.2