From 62af23cff67791781e5851ad83334857752eae36 Mon Sep 17 00:00:00 2001 From: Eoghan Glynn Date: Mon, 30 Jul 2012 16:11:18 +0100 Subject: [PATCH] Allow XML payload for volume creation. 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 | 12 +++++++++++- cinder/tests/api/openstack/volume/test_volumes.py | 10 ++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/cinder/api/openstack/volume/volumes.py b/cinder/api/openstack/volume/volumes.py index fb5cf137c..30efe9916 100644 --- a/cinder/api/openstack/volume/volumes.py +++ b/cinder/api/openstack/volume/volumes.py @@ -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 = {} diff --git a/cinder/tests/api/openstack/volume/test_volumes.py b/cinder/tests/api/openstack/volume/test_volumes.py index 344ce57e7..1c5463b0e 100644 --- a/cinder/tests/api/openstack/volume/test_volumes.py +++ b/cinder/tests/api/openstack/volume/test_volumes.py @@ -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", -- 2.45.2