argspec validation - fix apply_defaults (#74029)

* Add test
This commit is contained in:
Felix Fontein 2021-03-25 00:17:07 +01:00 committed by GitHub
parent 3bccfb1615
commit 940b7af7d8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 46 additions and 2 deletions

View file

@ -0,0 +1,2 @@
bugfixes:
- "argument spec validation - fix behavior of ``apply_defaults=True`` when an empty dictionary is specified for such an option (https://github.com/ansible/ansible/pull/74029)."

View file

@ -702,8 +702,8 @@ def _validate_sub_spec(argument_spec, parameters, prefix='', options_context=Non
if sub_spec is not None:
if parameters.get(param) is None:
parameters[param] = {}
else:
continue
else:
continue
elif sub_spec is None or param not in parameters or parameters[param] is None:
continue

View file

@ -126,6 +126,19 @@ def main():
'int': {
'type': 'int',
},
'apply_defaults': {
'type': 'dict',
'apply_defaults': True,
'options': {
'foo': {
'type': 'str',
},
'bar': {
'type': 'str',
'default': 'baz',
},
},
},
},
required_if=(
('state', 'present', ('path', 'content'), True),

View file

@ -342,6 +342,30 @@
register: argspec_int_invalid
ignore_errors: true
- argspec:
required: value
required_one_of_one: value
register: argspec_apply_defaults_not_specified
- argspec:
required: value
required_one_of_one: value
apply_defaults: ~
register: argspec_apply_defaults_none
- argspec:
required: value
required_one_of_one: value
apply_defaults: {}
register: argspec_apply_defaults_empty
- argspec:
required: value
required_one_of_one: value
apply_defaults:
foo: bar
register: argspec_apply_defaults_one
- assert:
that:
- argspec_required_fail is failed
@ -417,3 +441,8 @@
- argspec_password_no_log.stdout|regex_findall('VALUE_SPECIFIED_IN_NO_LOG_PARAMETER')|length == 1
- argspec_int_invalid is failed
- "argspec_apply_defaults_not_specified.apply_defaults == {'foo': none, 'bar': 'baz'}"
- "argspec_apply_defaults_none.apply_defaults == {'foo': none, 'bar': 'baz'}"
- "argspec_apply_defaults_empty.apply_defaults == {'foo': none, 'bar': 'baz'}"
- "argspec_apply_defaults_one.apply_defaults == {'foo': 'bar', 'bar': 'baz'}"