Add strict Boolean checking for storage pools
There is no strict boolean checking for the parameter "detail" of API /scheduler-states/get_pools, 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: Ic24850e5a0e206548de81529179cd182d9eabb7f Partial-Bug: #1594261
This commit is contained in:
parent
9af8e7125b
commit
bf76eb2522
@ -18,6 +18,7 @@ from cinder.api import extensions
|
||||
from cinder.api.openstack import wsgi
|
||||
from cinder.api.views import scheduler_stats as scheduler_stats_view
|
||||
from cinder.scheduler import rpcapi
|
||||
from cinder import utils
|
||||
|
||||
|
||||
def authorize(context, action_name):
|
||||
@ -40,7 +41,7 @@ class SchedulerStatsController(wsgi.Controller):
|
||||
authorize(context, 'get_pools')
|
||||
|
||||
# TODO(zhiteng) Add filters support
|
||||
detail = req.params.get('detail', False)
|
||||
detail = utils.get_bool_param('detail', req.params)
|
||||
pools = self.scheduler_api.get_pools(context, filters=None)
|
||||
|
||||
return self._view_builder.pools(req, pools, detail)
|
||||
|
@ -18,6 +18,7 @@ import mock
|
||||
|
||||
from cinder.api.contrib import scheduler_stats
|
||||
from cinder import context
|
||||
from cinder import exception
|
||||
from cinder import test
|
||||
from cinder.tests.unit.api import fakes
|
||||
from cinder.tests.unit import fake_constants as fake
|
||||
@ -111,3 +112,12 @@ class SchedulerStatsAPITest(test.TestCase):
|
||||
}
|
||||
|
||||
self.assertDictMatch(expected, res)
|
||||
|
||||
def test_get_pools_detail_invalid_bool(self):
|
||||
req = fakes.HTTPRequest.blank(
|
||||
'/v2/%s/scheduler_stats?detail=InvalidBool' %
|
||||
fake.PROJECT_ID)
|
||||
req.environ['cinder.context'] = self.ctxt
|
||||
self.assertRaises(exception.InvalidParameterValue,
|
||||
self.controller.get_pools,
|
||||
req)
|
||||
|
Loading…
Reference in New Issue
Block a user