Include volume_metadata with object on vol create

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
This commit is contained in:
John Griffith 2012-07-27 22:30:47 -06:00
parent 95262bb692
commit 5b605b6b8a
2 changed files with 29 additions and 2 deletions

View 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

View 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()