From: Mike Perez Date: Fri, 20 Jul 2012 06:35:32 +0000 (-0700) Subject: Don't create volumes if an incorrect size was given X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=635f1498757d5ab8a0a8957d6e5aafaf3ceee022;p=openstack-build%2Fcinder-build.git Don't create volumes if an incorrect size was given bug 1006875 Change-Id: Ied4c6f6d03c0a70838e1e483d69f3ed1ec08a9b5 --- diff --git a/Authors b/Authors index 24eb71e78..5af65cb45 100644 --- a/Authors +++ b/Authors @@ -30,6 +30,7 @@ Kevin L. Mitchell Liam Kelleher Mandell Degerness Mark McLoughlin +Mike Perez Monty Taylor Morita Kazutaka Muneyuki Noguchi diff --git a/cinder/tests/api/openstack/volume/test_volumes.py b/cinder/tests/api/openstack/volume/test_volumes.py index 28ce067e9..344ce57e7 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 exception from cinder import flags from cinder import test from cinder.tests.api.openstack import fakes @@ -65,6 +66,18 @@ class VolumeApiTest(test.TestCase): 'size': 100}} self.assertEqual(res_dict, expected) + def test_volume_creation_fails_with_bad_size(self): + vol = {"size": '', + "display_name": "Volume Test Name", + "display_description": "Volume Test Desc", + "availability_zone": "zone1:host1"} + body = {"volume": vol} + req = fakes.HTTPRequest.blank('/v1/volumes') + self.assertRaises(exception.InvalidInput, + self.controller.create, + req, + body) + def test_volume_create_no_body(self): body = {} req = fakes.HTTPRequest.blank('/v1/volumes') diff --git a/cinder/volume/api.py b/cinder/volume/api.py index 699952223..412aee098 100644 --- a/cinder/volume/api.py +++ b/cinder/volume/api.py @@ -81,6 +81,9 @@ class API(base.Base): else: snapshot_id = None + if not isinstance(size, int) or size <= 0: + msg = _('Volume size must be an integer and greater than 0') + raise exception.InvalidInput(reason=msg) if quota.allowed_volumes(context, 1, size) < 1: pid = context.project_id LOG.warn(_("Quota exceeded for %(pid)s, tried to create"