mirror of
https://github.com/linux-system-roles/network.git
synced 2026-07-20 17:59:00 +00:00
arg_validator: accept None as valid input for ArgValidatorDict
Users might want to use jinja2 templates to set properties. As such,
it's convenient to accept None as an alias for an empty dictionary.
For exmaple, setting like `"match": None` will be allowed by the role:
e.g.
network_connections:
- name: enp0s8
type: ethernet
persistent_state: present
state: up
match:
ip:
route_metric4: 10
Signed-off-by: Wen Liang <liangwen12year@gmail.com>
This commit is contained in:
parent
af07c2a58d
commit
b569704c72
2 changed files with 6 additions and 0 deletions
|
|
@ -350,6 +350,11 @@ class ArgValidatorDict(ArgValidator):
|
|||
def _validate_impl(self, value, name):
|
||||
result = {}
|
||||
seen_keys = set()
|
||||
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 dictionary
|
||||
# e.g. setting like `"match": None` will be allowed by the role
|
||||
return {}
|
||||
try:
|
||||
items = list(value.items())
|
||||
except AttributeError:
|
||||
|
|
|
|||
|
|
@ -437,6 +437,7 @@ class TestValidator(unittest.TestCase):
|
|||
{"i": 5, "s": "s_default", "l": "6"}, v.validate({"i": "5", "l": "6"})
|
||||
)
|
||||
self.assertValidationError(v, {"k": 1})
|
||||
self.assertEqual(v.validate(None), {})
|
||||
|
||||
def test_validate_list(self):
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue