mirror of
https://github.com/linux-system-roles/network.git
synced 2026-01-23 02:15:17 +00:00
arg_validator: accept None as valid input for ArgValidatorList
Users might want to use jinja2 templates to set properties. As such,
it's convenient to accept None as an alias for an empty list.
For exmaple, setting like `"match": {"path": None}` will be allowed by
the role:
network_connections:
- name: enp0s8
type: ethernet
persistent_state: present
state: up
match:
path:
ip:
route_metric4: 10
Signed-off-by: Wen Liang <liangwen12year@gmail.com>
This commit is contained in:
parent
71b4ff9357
commit
af07c2a58d
2 changed files with 6 additions and 0 deletions
|
|
@ -407,6 +407,11 @@ class ArgValidatorList(ArgValidator):
|
|||
# not supported. If you need that, define a proper list.
|
||||
value = [s for s in value.split(" ") if s]
|
||||
|
||||
if value is None:
|
||||
# Users might want to use jinja2 templates to set properties. As such,
|
||||
# it's convenient to accept None as an alias for an empty list
|
||||
# e.g. setting like `"match": {"path": None}` will be allowed by the role
|
||||
return []
|
||||
result = []
|
||||
for (idx, v) in enumerate(value):
|
||||
try:
|
||||
|
|
|
|||
|
|
@ -445,6 +445,7 @@ class TestValidator(unittest.TestCase):
|
|||
)
|
||||
self.assertEqual([1, 5], v.validate(["1", 5]))
|
||||
self.assertValidationError(v, [1, "s"])
|
||||
self.assertEqual(v.validate(None), [])
|
||||
|
||||
def test_empty(self):
|
||||
self.maxDiff = None
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue