]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Validate 'is_public' when creating volume type
authorliyingjun <yingjun.li@kylin-cloud.com>
Wed, 29 Jul 2015 01:42:00 +0000 (09:42 +0800)
committerliyingjun <yingjun.li@kylin-cloud.com>
Mon, 10 Aug 2015 00:51:52 +0000 (08:51 +0800)
is_public should be checked when creating volume type, otherwise DBError
will be raised in cinder-api, and the user will receive a 500 Internal
server error.

Change-Id: Id0695fbb05613f3655a7af5b5ab10e08ed5e606b
Closes-bug: #1479170

cinder/api/contrib/types_manage.py
cinder/tests/unit/api/contrib/test_types_manage.py

index 5a908933aaa79ad96efc474c18b69c386cabdc92..9c32528d7972b39bade862f64fb42fcf35f2678d 100644 (file)
@@ -73,6 +73,11 @@ class VolumeTypesManageController(wsgi.Controller):
             utils.check_string_length(description, 'Type description',
                                       min_length=0, max_length=255)
 
+        if not utils.is_valid_boolstr(is_public):
+            msg = _("Invalid value '%s' for is_public. Accepted values: "
+                    "True or False.") % is_public
+            raise webob.exc.HTTPBadRequest(explanation=msg)
+
         try:
             volume_types.create(context,
                                 name,
index 3bdaa5d168ad5e318769211d8681eae841c57a09..f613f7487da3aeee6a5e0879559bc056ec71b9b5 100644 (file)
@@ -186,6 +186,7 @@ class VolumeTypesManageApiTest(test.TestCase):
                        return_volume_types_get_by_name)
 
         body = {"volume_type": {"name": "vol_type_1",
+                                "os-volume-type-access:is_public": True,
                                 "extra_specs": {"key1": "value1"}}}
         req = fakes.HTTPRequest.blank('/v2/fake/types')
 
@@ -246,6 +247,15 @@ class VolumeTypesManageApiTest(test.TestCase):
         self.assertRaises(webob.exc.HTTPConflict,
                           self.controller._create, req, body)
 
+    def test_create_type_with_invalid_is_public(self):
+        body = {"volume_type": {"name": "vol_type_1",
+                                "os-volume-type-access:is_public": "fake",
+                                "description": "test description",
+                                "extra_specs": {"key1": "value1"}}}
+        req = fakes.HTTPRequest.blank('/v2/fake/types')
+        self.assertRaises(webob.exc.HTTPBadRequest,
+                          self.controller._create, req, body)
+
     def _create_volume_type_bad_body(self, body):
         req = fakes.HTTPRequest.blank('/v2/fake/types')
         req.method = 'POST'