Add parameter validation for policy-create

This patch adds parameter validation for policy-create API calls.

Closes-Bug: #1467826
Change-Id: I3e32aa0a0eacf770ab0cfb9ddef78f17e8cdd4e8
This commit is contained in:
tengqm 2015-11-26 02:30:36 -05:00
parent be7e5beb84
commit 0369f6beb7
3 changed files with 21 additions and 2 deletions

View File

@ -0,0 +1,3 @@
---
fixes:
- Added parameter checking for policy-create API calls.

View File

@ -41,10 +41,16 @@ class PolicyData(object):
return self.data[consts.POLICY_SPEC]
def level(self):
return self.data.get(consts.POLICY_LEVEL, None)
value = self.data.get(consts.POLICY_LEVEL, None)
if value is not None:
value = utils.parse_int_param('level', value)
return value
def cooldown(self):
return self.data.get(consts.POLICY_COOLDOWN, None)
value = self.data.get(consts.POLICY_COOLDOWN, None)
if value is not None:
value = utils.parse_int_param('cooldown', value)
return value
class PolicyController(object):

View File

@ -57,6 +57,16 @@ class PolicyDataTest(base.SenlinTestCase):
self.assertIsNone(data.level())
self.assertIsNone(data.cooldown())
def test_level_invalid(self):
body = {
'name': 'test_policy',
'level': -1,
'cooldown': 'long',
}
data = policies.PolicyData(body)
self.assertRaises(senlin_exc.InvalidParameter, data.level)
self.assertRaises(senlin_exc.InvalidParameter, data.cooldown)
@mock.patch.object(policy, 'enforce')
class PolicyControllerTest(shared.ControllerTest, base.SenlinTestCase):