Merge pull request #131 from ryanpetrello/fix-7337

fix a bug which breaks inventory update stdout downloads
This commit is contained in:
Ryan Petrello
2017-08-01 11:03:01 -04:00
committed by GitHub

View File

@@ -4376,18 +4376,25 @@ class UnifiedJobStdout(RetrieveAPIView):
tablename, related_name = { tablename, related_name = {
Job: ('main_jobevent', 'job_id'), Job: ('main_jobevent', 'job_id'),
AdHocCommand: ('main_adhoccommandevent', 'ad_hoc_command_id'), AdHocCommand: ('main_adhoccommandevent', 'ad_hoc_command_id'),
}[unified_job.__class__] }.get(unified_job.__class__, (None, None))
cursor.copy_expert( if tablename is None:
"copy (select stdout from {} where {}={} order by start_line) to stdout".format( # stdout job event reconstruction isn't supported
tablename, # for certain job types (such as inventory syncs),
related_name, # so just grab the raw stdout from the DB
unified_job.id write_fd.write(unified_job.result_stdout_text)
), write_fd.close()
write_fd else:
) cursor.copy_expert(
write_fd.close() "copy (select stdout from {} where {}={} order by start_line) to stdout".format(
subprocess.Popen("sed -i 's/\\\\r\\\\n/\\n/g' {}".format(unified_job.result_stdout_file), tablename,
shell=True).wait() 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: except Exception as e:
return Response({"error": _("Error generating stdout download file: {}".format(e))}) return Response({"error": _("Error generating stdout download file: {}".format(e))})
try: try: