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:
parent
be7e5beb84
commit
0369f6beb7
|
@ -0,0 +1,3 @@
|
|||
---
|
||||
fixes:
|
||||
- Added parameter checking for policy-create API calls.
|
|
@ -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):
|
||||
|
|
|
@ -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):
|
||||
|
|
Loading…
Reference in New Issue