From d09872d13a37556bb2754c7e15f0f69023c1fc04 Mon Sep 17 00:00:00 2001 From: Ryan Petrello Date: Mon, 31 Jul 2017 18:16:19 -0400 Subject: [PATCH] fix a bug which breaks inventory update stdout downloads see: https://github.com/ansible/ansible-tower/issues/7363 see: https://github.com/ansible/ansible-tower/issues/7337 --- awx/api/views.py | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/awx/api/views.py b/awx/api/views.py index 4fee59a14b..40cedd426d 100644 --- a/awx/api/views.py +++ b/awx/api/views.py @@ -4382,18 +4382,25 @@ class UnifiedJobStdout(RetrieveAPIView): tablename, related_name = { Job: ('main_jobevent', 'job_id'), AdHocCommand: ('main_adhoccommandevent', 'ad_hoc_command_id'), - }[unified_job.__class__] - cursor.copy_expert( - "copy (select stdout from {} where {}={} order by start_line) to stdout".format( - tablename, - related_name, - unified_job.id - ), - write_fd - ) - write_fd.close() - subprocess.Popen("sed -i 's/\\\\r\\\\n/\\n/g' {}".format(unified_job.result_stdout_file), - shell=True).wait() + }.get(unified_job.__class__, (None, None)) + if tablename is None: + # stdout job event reconstruction isn't supported + # for certain job types (such as inventory syncs), + # so just grab the raw stdout from the DB + write_fd.write(unified_job.result_stdout_text) + write_fd.close() + else: + cursor.copy_expert( + "copy (select stdout from {} where {}={} order by start_line) to stdout".format( + tablename, + related_name, + unified_job.id + ), + write_fd + ) + write_fd.close() + subprocess.Popen("sed -i 's/\\\\r\\\\n/\\n/g' {}".format(unified_job.result_stdout_file), + shell=True).wait() except Exception as e: return Response({"error": _("Error generating stdout download file: {}".format(e))}) try: