From 58dd2385365e7f5b79dc0c151092795d02bfe802 Mon Sep 17 00:00:00 2001 From: John Griffith Date: Mon, 17 Sep 2012 15:36:10 -0600 Subject: [PATCH] Clean up db.volume_create() 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 | 11 +---------- cinder/tests/test_volume.py | 7 +++---- 2 files changed, 4 insertions(+), 14 deletions(-) diff --git a/cinder/db/sqlalchemy/api.py b/cinder/db/sqlalchemy/api.py index 55834ed0b..be29b30bd 100644 --- a/cinder/db/sqlalchemy/api.py +++ b/cinder/db/sqlalchemy/api.py @@ -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 diff --git a/cinder/tests/test_volume.py b/cinder/tests/test_volume.py index 23b462a2c..b4d126758 100644 --- a/cinder/tests/test_volume.py +++ b/cinder/tests/test_volume.py @@ -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: -- 2.45.2