]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Catch additional type conversion errors
authorJamie Lennox <jamielennox@redhat.com>
Tue, 5 May 2015 01:50:21 +0000 (11:50 +1000)
committerJamie Lennox <jamielennox@redhat.com>
Tue, 5 May 2015 02:13:13 +0000 (12:13 +1000)
When converting strings to integers in quota we catch ValueError which
will handle an input which is not a valid number, eg 'abc'. Extend this
to covert TypeErrors which will handle things like a None value being
passed.

Partial-Bug: #1451637
Change-Id: I7e3e694d539113beeb99001aeb80012ac4c1124d

cinder/api/contrib/quotas.py
cinder/tests/unit/api/contrib/test_quotas.py

index 32667cad345b3d060416c63533aa055703039030..d1f9efca785410f2d3cb2c77d33e0d14f323aef4 100644 (file)
@@ -59,7 +59,7 @@ class QuotaSetsController(wsgi.Controller):
     def _validate_quota_limit(self, limit):
         try:
             limit = int(limit)
-        except ValueError:
+        except (ValueError, TypeError):
             msg = _("Quota limit must be specified as an integer value.")
             raise webob.exc.HTTPBadRequest(explanation=msg)
 
index fa01c1e711eef69da68538a77b4771384d32dc86..9e24657c0d4f1caec24573c2f2251cf0444006e0 100644 (file)
@@ -88,11 +88,16 @@ class QuotaSetsControllerTest(test.TestCase):
         self.assertRaises(webob.exc.HTTPBadRequest, self.controller.update,
                           self.req, 'foo', body)
 
-    def test_update_invalid_key_value(self):
+    def test_update_invalid_value_key_value(self):
         body = {'quota_set': {'gigabytes': "should_be_int"}}
         self.assertRaises(webob.exc.HTTPBadRequest, self.controller.update,
                           self.req, 'foo', body)
 
+    def test_update_invalid_type_key_value(self):
+        body = {'quota_set': {'gigabytes': None}}
+        self.assertRaises(webob.exc.HTTPBadRequest, self.controller.update,
+                          self.req, 'foo', body)
+
     def test_update_multi_value_with_bad_data(self):
         orig_quota = self.controller.show(self.req, 'foo')
         body = make_body(gigabytes=2000, snapshots=15, volumes="should_be_int",