]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
get_snapshot should populate the snapshot metadata
authorOllie Leahy <oliver.leahy@hp.com>
Wed, 24 Jul 2013 10:06:41 +0000 (10:06 +0000)
committerOllie Leahy <oliver.leahy@hp.com>
Wed, 24 Jul 2013 10:15:53 +0000 (10:15 +0000)
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
cinder/tests/test_volume.py

index 25fb2ae9715dac3bce727ff654dbd0cb08b0ef91..3c9d0c0dc6390cdf0978a20a19c62ba943df44cf 100644 (file)
@@ -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()
 
index 41c389b6e6e0a769257da4a801cbca85e61b6936..ed4b9409fb0c5869953ed3295555b59e6de12085 100644 (file)
@@ -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)