mirror of
https://github.com/ansible/awx.git
synced 2026-03-08 05:01:09 -02:30
Print module standard out in test failure scenarios
This commit is contained in:
@@ -127,15 +127,22 @@ def run_module(request, collection_import):
|
|||||||
else:
|
else:
|
||||||
tower_cli_mgr = suppress()
|
tower_cli_mgr = suppress()
|
||||||
with tower_cli_mgr:
|
with tower_cli_mgr:
|
||||||
# Ansible modules return data to the mothership over stdout
|
try:
|
||||||
with redirect_stdout(stdout_buffer):
|
# Ansible modules return data to the mothership over stdout
|
||||||
try:
|
with redirect_stdout(stdout_buffer):
|
||||||
resource_module.main()
|
resource_module.main()
|
||||||
except SystemExit:
|
except SystemExit:
|
||||||
pass # A system exit indicates successful execution
|
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()
|
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
|
# A module exception should never be a test expectation
|
||||||
if 'exception' in result:
|
if 'exception' in result:
|
||||||
raise Exception('Module encountered error:\n{0}'.format(result['exception']))
|
raise Exception('Module encountered error:\n{0}'.format(result['exception']))
|
||||||
|
|||||||
Reference in New Issue
Block a user