Add strict Boolean checking for volume manage

There is no strict boolean checking for the parameter
"bootable" of API /os-volume-manage, so that any invalid
boolean value can be specified.
This patch adds a strict checking for it to prevent
invalid value, and adds a test for this change as well.

Change-Id: I0d79a0bb173aaeeea0fe6d735213c70c109ccd69
Partial-Bug: #1594261
This commit is contained in:
xiexs 2016-07-06 11:04:23 -04:00
parent afb81cd022
commit 28b5c7e101
2 changed files with 11 additions and 2 deletions

View File

@ -137,7 +137,7 @@ class VolumeManageController(wsgi.Controller):
kwargs['description'] = volume.get('description', None)
kwargs['metadata'] = volume.get('metadata', None)
kwargs['availability_zone'] = volume.get('availability_zone', None)
kwargs['bootable'] = volume.get('bootable', False)
kwargs['bootable'] = utils.get_bool_param('bootable', volume)
try:
new_volume = self.volume_api.manage_existing(context,
volume['host'],

View File

@ -202,6 +202,14 @@ class VolumeManageTest(test.TestCase):
self.assertEqual(400, res.status_int)
pass
def test_manage_volume_with_invalid_bootable(self):
"""Test correct failure when invalid bool value is specified."""
body = {'volume': {'host': 'host_ok',
'ref': 'fake_ref',
'bootable': 'InvalidBool'}}
res = self._get_resp_post(body)
self.assertEqual(400, res.status_int)
@mock.patch('cinder.volume.api.API.manage_existing', api_manage)
@mock.patch(
'cinder.api.openstack.wsgi.Controller.validate_name_and_description')
@ -213,7 +221,8 @@ class VolumeManageTest(test.TestCase):
"""
body = {'volume': {'host': 'host_ok',
'ref': 'fake_ref',
'volume_type': fake.VOLUME_TYPE_ID}}
'volume_type': fake.VOLUME_TYPE_ID,
'bootable': True}}
res = self._get_resp_post(body)
self.assertEqual(202, res.status_int, res)
self.assertTrue(mock_validate.called)