Merge pull request #6273 from AlanCoding/failure_verbosity

Print module standard out in test failure scenarios

Reviewed-by: https://github.com/apps/softwarefactory-project-zuul
This commit is contained in:
softwarefactory-project-zuul[bot] 2020-03-18 17:50:16 +00:00 committed by GitHub
commit afa3b500d3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -140,15 +140,22 @@ def run_module(request, collection_import):
else:
tower_cli_mgr = suppress()
with tower_cli_mgr:
# Ansible modules return data to the mothership over stdout
with redirect_stdout(stdout_buffer):
try:
try:
# Ansible modules return data to the mothership over stdout
with redirect_stdout(stdout_buffer):
resource_module.main()
except SystemExit:
pass # A system exit indicates successful execution
except SystemExit:
pass # A system exit indicates successful execution
except Exception:
# dump the stdout back to console for debugging
print(stdout_buffer.getvalue())
raise
module_stdout = stdout_buffer.getvalue().strip()
result = json.loads(module_stdout)
try:
result = json.loads(module_stdout)
except Exception as e:
raise Exception('Module did not write valid JSON, error: {}, stdout:\n{}'.format(str(e), module_stdout))
# A module exception should never be a test expectation
if 'exception' in result:
raise Exception('Module encountered error:\n{0}'.format(result['exception']))