mirror of
https://github.com/linux-system-roles/network.git
synced 2026-07-20 17:59:00 +00:00
arg_validator: reject bool arguments from ArgValidatorNum
`ArgValidatorNum` would normalize boolean into int when `self.numeric_type` is int, then `self.numeric_type(False)` is 0 and `self.numeric_type(True)` is 1. Therefore, we need to fix `ArgValidatorNum()` to reject boolean values when integer values are expected for the setting. This bug fix potentially breaks previously "working" playbooks (but realistically, they were not working, because setting 0 or 1 was unlikely intended). Signed-off-by: Wen Liang <liangwen12year@gmail.com>
This commit is contained in:
parent
dfacbf72f7
commit
a6c98bd660
2 changed files with 7 additions and 1 deletions
|
|
@ -271,7 +271,11 @@ class ArgValidatorNum(ArgValidator):
|
|||
def _validate_impl(self, value, name):
|
||||
v = None
|
||||
try:
|
||||
if isinstance(value, self.numeric_type):
|
||||
if isinstance(value, bool):
|
||||
# bool can (probably) be converted to self.numeric_type,
|
||||
# but here we don't want to accept a boolean value.
|
||||
pass
|
||||
elif isinstance(value, self.numeric_type):
|
||||
# ArgValidatorNum should normalize the input values to be of type
|
||||
# self.numeric_type, except the default_value
|
||||
v = self.numeric_type(value)
|
||||
|
|
|
|||
|
|
@ -384,6 +384,8 @@ class TestValidator(unittest.TestCase):
|
|||
|
||||
v = network_lsr.argument_validator.ArgValidatorNum("state", required=True)
|
||||
self.assertValidationError(v, None)
|
||||
self.assertValidationError(v, False)
|
||||
self.assertValidationError(v, True)
|
||||
|
||||
def test_validate_bool(self):
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue