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.
pull/22843/head
Ted Timmons 8 years ago committed by Brian Coca
parent 5beb27ef5e
commit 887456ab8e

@ -425,15 +425,14 @@ def main():
# and the filename already exists. This allows idempotence # and the filename already exists. This allows idempotence
# of uri executions. # of uri executions.
if os.path.exists(creates): if os.path.exists(creates):
module.exit_json(stdout="skipped, since %s exists" % creates, module.exit_json(stdout="skipped, since %s exists" % creates, changed=False, rc=0)
changed=False, stderr=False, rc=0)
if removes is not None: if removes is not None:
# do not run the command if the line contains removes=filename # do not run the command if the line contains removes=filename
# and the filename do not exists. This allows idempotence # and the filename do not exists. This allows idempotence
# of uri executions. # of uri executions.
if not os.path.exists(removes): 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 # Make the request
resp, content, dest = uri(module, url, dest, body, body_format, method, 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 3 = its a directory, not a file
4 = stat module failed, likely due to not finding python 4 = stat module failed, likely due to not finding python
''' '''
x = "0" # unknown error has occured x = "0" # unknown error has occurred
try: try:
remote_stat = self._execute_remote_stat(path, all_vars, follow=follow) remote_stat = self._execute_remote_stat(path, all_vars, follow=follow)
if remote_stat['exists'] and remote_stat['isdir']: 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 # pre-split stdout/stderr into lines if needed
if 'stdout' in data and 'stdout_lines' not in data: 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: 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)) display.debug("done with _execute_module (%s, %s)" % (module_name, module_args))
return data return data

Loading…
Cancel
Save