]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Return volume type name on volume create
authorClay Gerrard <clay.gerrard@gmail.com>
Wed, 31 Oct 2012 20:25:55 +0000 (15:25 -0500)
committerClay Gerrard <clay.gerrard@gmail.com>
Wed, 31 Oct 2012 20:39:59 +0000 (15:39 -0500)
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

cinder/api/openstack/volume/volumes.py
cinder/tests/api/openstack/volume/test_volumes.py

index 5b80d4922bdcf6ffa1f26cd165d7d190d1cc9b70..cc11df1eac895e16f2a123c0702c33db9dbc4469 100644 (file)
@@ -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}
index f5141f631f7d0d0fba1664910a420fc3b6089535..47c2a611ed16c8e88558e911acec3f0804519b40 100644 (file)
@@ -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",