]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Don't create volumes if an incorrect size was given
authorMike Perez <thingee@gmail.com>
Fri, 20 Jul 2012 06:35:32 +0000 (23:35 -0700)
committerMike Perez <thingee@gmail.com>
Fri, 20 Jul 2012 06:37:12 +0000 (23:37 -0700)
bug 1006875

Change-Id: Ied4c6f6d03c0a70838e1e483d69f3ed1ec08a9b5

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

diff --git a/Authors b/Authors
index 24eb71e78f10a9641d63e57a518f30375ca16c43..5af65cb45fb30f584810c60cea7a42752921a235 100644 (file)
--- a/Authors
+++ b/Authors
@@ -30,6 +30,7 @@ Kevin L. Mitchell <kevin.mitchell@rackspace.com>
 Liam Kelleher  <liam.kelleher@hp.com>
 Mandell Degerness <mandell@pistoncloud.com>
 Mark McLoughlin <markmc@redhat.com>
+Mike Perez <thingee@gmail.com>
 Monty Taylor <mordred@inaugust.com>
 Morita Kazutaka <morita.kazutaka@gmail.com>
 Muneyuki Noguchi <noguchimn@nttdata.co.jp>
index 28ce067e98254f74a926d6e761494f8016728d72..344ce57e7d7940bff49db354c29a2474b13f2c1d 100644 (file)
@@ -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')
index 699952223aa20f0c941ca587a6b8b79ed26018e1..412aee0987d5073501e6ffcd8e24da06b7281f0c 100644 (file)
@@ -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"