diff options
| author | Jenkins <jenkins@review.openstack.org> | 2012-08-15 07:55:40 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2012-08-15 07:55:40 +0000 |
| commit | 9f9f1a7aa46fad83fdda36be15d648dfa21cba2f (patch) | |
| tree | 2198e24faf3eb9f438c3d19238f63d384821cf47 /nova | |
| parent | 43261c0fe2973739ba1083e46f291db698cf5722 (diff) | |
| parent | 3b6207976a51d33ee2ec701d21fa2a0cc6eca2e8 (diff) | |
Merge "Allow XML payload for volume creation."
Diffstat (limited to 'nova')
| -rw-r--r-- | nova/api/openstack/volume/volumes.py | 12 | ||||
| -rw-r--r-- | nova/tests/api/openstack/volume/test_volumes.py | 10 |
2 files changed, 19 insertions, 3 deletions
diff --git a/nova/api/openstack/volume/volumes.py b/nova/api/openstack/volume/volumes.py index 4c12638b4..ec9a47a74 100644 --- a/nova/api/openstack/volume/volumes.py +++ b/nova/api/openstack/volume/volumes.py @@ -218,7 +218,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/nova/tests/api/openstack/volume/test_volumes.py b/nova/tests/api/openstack/volume/test_volumes.py index 6f9a6557b..1a51c8b67 100644 --- a/nova/tests/api/openstack/volume/test_volumes.py +++ b/nova/tests/api/openstack/volume/test_volumes.py @@ -42,10 +42,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"} @@ -71,6 +71,12 @@ class VolumeApiTest(test.TestCase): self.assertEqual(res.code, 200) self.assertTrue('location' in res.headers) + 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", |
