]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Include volume_metadata with object on vol create
authorJohn Griffith <john.griffith@solidfire.com>
Sat, 28 Jul 2012 04:30:47 +0000 (22:30 -0600)
committerJohn Griffith <john.griffith@solidfire.com>
Sat, 28 Jul 2012 04:43:22 +0000 (22:43 -0600)
Fix for Bug 1029762

The symptom of this bug is that the response data of an
OSAPI create call always shows and empty dict for volume_metadata
regardless of what was passed in to created and actually used.

Upon the db create_volume call a reference to the volume
object is all that was being returned.  Since metadata is
specified and set, it should also be returned with the
create reference object.

This will result in the the osapi create call returning
a body with correct metdata info rather than always showing
and empty dict as it was previously.

Change-Id: I9ae9c737bd2aa5bfa14c19fe8b8b2a7a5aa4d43a

cinder/db/sqlalchemy/api.py
cinder/tests/test_volume.py

index a9d07414138312155cbae5bca8842fc27070a42f..6249e01d7cb7da49b69bb702e08937c2227fa97f 100644 (file)
@@ -434,7 +434,16 @@ def volume_create(context, values):
     with session.begin():
         volume_ref.save(session=session)
 
-    return volume_ref
+    meta = volume_metadata_get(context, volume_ref.id)
+    volume_ref.metadata = meta
+
+    result = model_query(context, models.Volume, read_deleted="no").\
+                         options(joinedload('volume_metadata')).\
+                         filter_by(id=volume_ref['id']).first()
+    if not result:
+        raise exception.VolumeNotFound(volume_id=volume_ref['id'])
+
+    return result
 
 
 @require_admin_context
index 065272382134527ea238ab248437415e2a4231ce..33271b8d964da8e032dd360f6e3f15c8dd53e6e6 100644 (file)
@@ -53,7 +53,7 @@ class VolumeTestCase(test.TestCase):
         super(VolumeTestCase, self).tearDown()
 
     @staticmethod
-    def _create_volume(size='0', snapshot_id=None):
+    def _create_volume(size='0', snapshot_id=None, metadata=None):
         """Create a volume object."""
         vol = {}
         vol['size'] = size
@@ -63,6 +63,8 @@ class VolumeTestCase(test.TestCase):
         vol['availability_zone'] = FLAGS.storage_availability_zone
         vol['status'] = "creating"
         vol['attach_status'] = "detached"
+        if metadata is not None:
+            vol['metadata'] = metadata
         return db.volume_create(context.get_admin_context(), vol)
 
     def test_create_delete_volume(self):
@@ -79,6 +81,22 @@ class VolumeTestCase(test.TestCase):
                           self.context,
                           volume_id)
 
+    def test_create_delete_volume_with_metadata(self):
+        """Test volume can be created and deleted."""
+        test_meta = {'fake_key': 'fake_value'}
+        volume = self._create_volume('0', None, test_meta)
+        volume_id = volume['id']
+        self.volume.create_volume(self.context, volume_id)
+        result_meta = {
+            volume.volume_metadata[0].key: volume.volume_metadata[0].value}
+        self.assertEqual(result_meta, test_meta)
+
+        self.volume.delete_volume(self.context, volume_id)
+        self.assertRaises(exception.NotFound,
+                          db.volume_get,
+                          self.context,
+                          volume_id)
+
     def test_delete_busy_volume(self):
         """Test volume survives deletion if driver reports it as busy."""
         volume = self._create_volume()