From: Clay Gerrard Date: Wed, 31 Oct 2012 20:25:55 +0000 (-0500) Subject: Return volume type name on volume create X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=ecc664dca2c6844a7963da63d3495281ef5866c8;p=openstack-build%2Fcinder-build.git Return volume type name on volume create Update openstack api controller for volumes to fully inflate the returned volume model on create to populate the volume_type fields so the response serializer will return the name of the volume_type instead of the id on volume create requests. Returning the name on create is consistent with the show and index commands. fixes bug #1071436 Change-Id: Ie091cf824a2df40211d8bcfa7f177fc851d737f5 --- diff --git a/cinder/api/openstack/volume/volumes.py b/cinder/api/openstack/volume/volumes.py index 5b80d4922..cc11df1ea 100644 --- a/cinder/api/openstack/volume/volumes.py +++ b/cinder/api/openstack/volume/volumes.py @@ -330,7 +330,8 @@ class VolumeController(wsgi.Controller): # TODO(vish): Instance should be None at db layer instead of # trying to lazy load, but for now we turn it into # a dict to avoid an error. - retval = _translate_volume_detail_view(context, dict(new_volume), + retval = _translate_volume_detail_view(context, + dict(new_volume.iteritems()), image_uuid) return {'volume': retval} diff --git a/cinder/tests/api/openstack/volume/test_volumes.py b/cinder/tests/api/openstack/volume/test_volumes.py index f5141f631..47c2a611e 100644 --- a/cinder/tests/api/openstack/volume/test_volumes.py +++ b/cinder/tests/api/openstack/volume/test_volumes.py @@ -19,6 +19,7 @@ from lxml import etree import webob from cinder.api.openstack.volume import volumes +from cinder import context from cinder import db from cinder.api.openstack.volume import extensions from cinder import exception @@ -91,6 +92,26 @@ class VolumeApiTest(test.TestCase): 'size': 100}} self.assertEqual(res_dict, expected) + def test_volume_create_with_type(self): + vol_type = FLAGS.default_volume_type + db.volume_type_create(context.get_admin_context(), + dict(name=vol_type, extra_specs={})) + + db_vol_type = db.volume_type_get_by_name(context.get_admin_context(), + vol_type) + + vol = {"size": 100, + "display_name": "Volume Test Name", + "display_description": "Volume Test Desc", + "availability_zone": "zone1:host1", + "volume_type": db_vol_type['name'], + } + body = {"volume": vol} + req = fakes.HTTPRequest.blank('/v1/volumes') + res_dict = self.controller.create(req, body) + self.assertEquals(res_dict['volume']['volume_type'], + db_vol_type['name']) + def test_volume_creation_fails_with_bad_size(self): vol = {"size": '', "display_name": "Volume Test Name",