Validate 'is_public' when creating volume type

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
This commit is contained in:
liyingjun 2015-07-29 09:42:00 +08:00
parent b807ad524a
commit 95233d740a
2 changed files with 15 additions and 0 deletions

View 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,

View 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'