From bf76eb25224a012776fd2017140df1cb539bad29 Mon Sep 17 00:00:00 2001 From: xiexs Date: Tue, 28 Jun 2016 07:51:28 -0400 Subject: [PATCH] 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 --- cinder/api/contrib/scheduler_stats.py | 3 ++- cinder/tests/unit/api/contrib/test_scheduler_stats.py | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/cinder/api/contrib/scheduler_stats.py b/cinder/api/contrib/scheduler_stats.py index b8c82348d..23778f3d1 100644 --- a/cinder/api/contrib/scheduler_stats.py +++ b/cinder/api/contrib/scheduler_stats.py @@ -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) diff --git a/cinder/tests/unit/api/contrib/test_scheduler_stats.py b/cinder/tests/unit/api/contrib/test_scheduler_stats.py index 2a5ae2751..74c8b583b 100644 --- a/cinder/tests/unit/api/contrib/test_scheduler_stats.py +++ b/cinder/tests/unit/api/contrib/test_scheduler_stats.py @@ -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)