Fix stderr false return value (#22845)
* ensure exit_json does not fail from stderr=False - do a little bit of safety-checking in exit_json to not try to .splitlines() on a boolean - remove the stderr=boolean from uri.py, this is the only spot that uses it (at least so obviously) - add unit tests that call exit_json. These are useless because the stderr parsing is in _execute_module and is difficult to mock; deleting these tests after the commit. * remove added unit tests per prev commit exit_json doesn't do the param parsing, that is buried deep inside _execute_module.
This commit is contained in:
parent
5beb27ef5e
commit
887456ab8e
2 changed files with 9 additions and 6 deletions
|
@ -425,15 +425,14 @@ def main():
|
|||
# and the filename already exists. This allows idempotence
|
||||
# of uri executions.
|
||||
if os.path.exists(creates):
|
||||
module.exit_json(stdout="skipped, since %s exists" % creates,
|
||||
changed=False, stderr=False, rc=0)
|
||||
module.exit_json(stdout="skipped, since %s exists" % creates, changed=False, rc=0)
|
||||
|
||||
if removes is not None:
|
||||
# do not run the command if the line contains removes=filename
|
||||
# and the filename do not exists. This allows idempotence
|
||||
# of uri executions.
|
||||
if not os.path.exists(removes):
|
||||
module.exit_json(stdout="skipped, since %s does not exist" % removes, changed=False, stderr=False, rc=0)
|
||||
module.exit_json(stdout="skipped, since %s does not exist" % removes, changed=False, rc=0)
|
||||
|
||||
# Make the request
|
||||
resp, content, dest = uri(module, url, dest, body, body_format, method,
|
||||
|
|
|
@ -514,7 +514,7 @@ class ActionBase(with_metaclass(ABCMeta, object)):
|
|||
3 = its a directory, not a file
|
||||
4 = stat module failed, likely due to not finding python
|
||||
'''
|
||||
x = "0" # unknown error has occured
|
||||
x = "0" # unknown error has occurred
|
||||
try:
|
||||
remote_stat = self._execute_remote_stat(path, all_vars, follow=follow)
|
||||
if remote_stat['exists'] and remote_stat['isdir']:
|
||||
|
@ -754,9 +754,13 @@ class ActionBase(with_metaclass(ABCMeta, object)):
|
|||
|
||||
# pre-split stdout/stderr into lines if needed
|
||||
if 'stdout' in data and 'stdout_lines' not in data:
|
||||
data['stdout_lines'] = data.get('stdout', u'').splitlines()
|
||||
# if the value is 'False', a default won't catch it.
|
||||
txt = data.get('stdout', None) or u''
|
||||
data['stdout_lines'] = txt.splitlines()
|
||||
if 'stderr' in data and 'stderr_lines' not in data:
|
||||
data['stderr_lines'] = data.get('stderr', u'').splitlines()
|
||||
# if the value is 'False', a default won't catch it.
|
||||
txt = data.get('stderr', None) or u''
|
||||
data['stderr_lines'] = txt.splitlines()
|
||||
|
||||
display.debug("done with _execute_module (%s, %s)" % (module_name, module_args))
|
||||
return data
|
||||
|
|
Loading…
Reference in a new issue