parameters: handle blank values when argument is a list (#77119)

Fixes: #77108

Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
pull/77140/head
Abhijeet Kasurde 3 years ago committed by GitHub
parent d60efd9768
commit 4f48f375a0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,3 @@
---
bugfixes:
- parameters - handle blank values when argument is a list (https://github.com/ansible/ansible/issues/77108).

@ -651,10 +651,11 @@ def _validate_argument_values(argument_spec, parameters, options_context=None, e
if param in parameters:
# Allow one or more when type='list' param with choices
if isinstance(parameters[param], list):
diff_list = ", ".join([item for item in parameters[param] if item not in choices])
diff_list = [item for item in parameters[param] if item not in choices]
if diff_list:
choices_str = ", ".join([to_native(c) for c in choices])
msg = "value of %s must be one or more of: %s. Got no match for: %s" % (param, choices_str, diff_list)
diff_str = ", ".join(diff_list)
msg = "value of %s must be one or more of: %s. Got no match for: %s" % (param, choices_str, diff_str)
if options_context:
msg = "{0} found in {1}".format(msg, " -> ".join(options_context))
errors.append(ArgumentValueError(msg))

@ -100,6 +100,14 @@ INVALID_SPECS = [
{'req': None},
set(),
"missing required arguments: req"
),
(
'blank_values',
{'ch_param': {'elements': 'str', 'type': 'list', 'choices': ['a', 'b']}},
{'ch_param': ['']},
{'ch_param': ['']},
set(),
"value of ch_param must be one or more of"
)
]

Loading…
Cancel
Save