]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Clean up db.volume_create()
authorJohn Griffith <john.griffith@solidfire.com>
Mon, 17 Sep 2012 21:36:10 +0000 (15:36 -0600)
committerJohn Griffith <john.griffith@solidfire.com>
Mon, 17 Sep 2012 21:58:39 +0000 (15:58 -0600)
 Adding the metadata return to db.volume_create() introduced some
 messy and unnecessary repitition in the code.  This patch
 cleans that up and makes use of existing volume_get functions rather
 than duplicating the code in volume_create.

 This syncs cinder up with the patch as it's been submitted for nova
 in https://review.openstack.org/#/c/10461/

 Addresses bug #1052176

Change-Id: I17aca069fbb0240770613f176430a1b2fcf2b25a

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

index 55834ed0b8b8e8793a8d57f2fe7cf50dfccdb25c..be29b30bdbde0890875b93a54ae1a22f86fcada3 100644 (file)
@@ -948,16 +948,7 @@ def volume_create(context, values):
     with session.begin():
         volume_ref.save(session=session)
 
-    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
+    return volume_get(context, values['id'], session=session)
 
 
 @require_admin_context
index 23b462a2ca7c781aba2d005731ea905563ac2c6e..b4d12675887220159ca32c66250f5fe359dff5e2 100644 (file)
@@ -72,9 +72,8 @@ class VolumeTestCase(test.TestCase):
         return 1
 
     @staticmethod
-    def _create_volume(size='0', snapshot_id=None, image_id=None,
+    def _create_volume(size=0, snapshot_id=None, image_id=None,
                        metadata=None):
-        #def _create_volume(size=0, snapshot_id=None):
         """Create a volume object."""
         vol = {}
         vol['size'] = size
@@ -123,7 +122,7 @@ class VolumeTestCase(test.TestCase):
     def test_create_delete_volume_with_metadata(self):
         """Test volume can be created with metadata and deleted."""
         test_meta = {'fake_key': 'fake_value'}
-        volume = self._create_volume('0', None, metadata=test_meta)
+        volume = self._create_volume(0, None, metadata=test_meta)
         volume_id = volume['id']
         self.volume.create_volume(self.context, volume_id)
         result_meta = {
@@ -182,7 +181,7 @@ class VolumeTestCase(test.TestCase):
         #              volume_create
         return True
         try:
-            volume = self._create_volume('1001')
+            volume = self._create_volume(1001)
             self.volume.create_volume(self.context, volume)
             self.fail("Should have thrown TypeError")
         except TypeError: