]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Allow XML payload for volume creation.
authorEoghan Glynn <eglynn@redhat.com>
Mon, 30 Jul 2012 15:11:18 +0000 (16:11 +0100)
committerEoghan Glynn <eglynn@redhat.com>
Mon, 30 Jul 2012 15:14:29 +0000 (16:14 +0100)
Fixes cinder aspect of LP 1030330

Tolerate volume size attribute of type string as opposed to int.

Change-Id: I8d300a6c23c2e4e92187e26260ce49da35590545

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

index fb5cf137c788262fef1d2415efaf05f185d9054a..30efe991641d17da63681a34e323318fa5453cf4 100644 (file)
@@ -215,7 +215,17 @@ class VolumeController(object):
             raise exc.HTTPUnprocessableEntity()
 
         volume = body['volume']
-        size = volume['size']
+
+        def as_int(s):
+            try:
+                return int(s)
+            except ValueError:
+                return s
+
+        # NOTE(eglynn): we're tolerant of non-int sizes here, as type
+        # integrity is enforced later in the creation codepath
+        size = as_int(volume['size'])
+
         LOG.audit(_("Create volume of %s GB"), size, context=context)
 
         kwargs = {}
index 344ce57e7d7940bff49db354c29a2474b13f2c1d..1c5463b0ed1f0dcbfe97ce2dbfb467f6b6077a1c 100644 (file)
@@ -39,10 +39,10 @@ class VolumeApiTest(test.TestCase):
         self.stubs.Set(volume_api.API, 'get', fakes.stub_volume_get)
         self.stubs.Set(volume_api.API, 'delete', fakes.stub_volume_delete)
 
-    def test_volume_create(self):
+    def _do_test_volume_create(self, size):
         self.stubs.Set(volume_api.API, "create", fakes.stub_volume_create)
 
-        vol = {"size": 100,
+        vol = {"size": size,
                "display_name": "Volume Test Name",
                "display_description": "Volume Test Desc",
                "availability_zone": "zone1:host1"}
@@ -66,6 +66,12 @@ class VolumeApiTest(test.TestCase):
                                'size': 100}}
         self.assertEqual(res_dict, expected)
 
+    def test_volume_create_int_size(self):
+        self._do_test_volume_create(100)
+
+    def test_volume_create_str_size(self):
+        self._do_test_volume_create('100')
+
     def test_volume_creation_fails_with_bad_size(self):
         vol = {"size": '',
                "display_name": "Volume Test Name",