Merge pull request #652 from rjeffman/ipaansiblemodule_fail_if_invalid

Standardize algorithm to verify if invalid argument was used.
This commit is contained in:
Thomas Woerner
2021-10-04 16:37:04 +02:00
committed by GitHub
26 changed files with 95 additions and 204 deletions

View File

@@ -699,6 +699,30 @@ else:
"""
return module_params_get(self, name)
def params_fail_used_invalid(self, invalid_params, state, action=None):
"""
Fail module execution if one of the invalid parameters is not None.
Parameters
----------
invalid_params:
List of parameters that must value 'None'.
state:
State being tested.
action:
Action being tested (optional).
"""
if action is None:
msg = "Argument '{0}' can not be used with state '{1}'"
else:
msg = "Argument '{0}' can not be used with action "\
"'{2}' and state '{1}'"
for param in invalid_params:
if self.params.get(param) is not None:
self.fail_json(msg=msg.format(param, state, action))
def ipa_command(self, command, name, args):
"""
Execute an IPA API command with a required `name` argument.