Commit 39d99e60 authored by Ad Schellevis's avatar Ad Schellevis

(configd) flush script output to tempfile to avoid the use of...

(configd) flush script output to tempfile to avoid the use of subprocess.check_output which can be slow on some platforms.
parent 952e010b
...@@ -45,6 +45,7 @@ import glob ...@@ -45,6 +45,7 @@ import glob
import time import time
import uuid import uuid
import shlex import shlex
import tempfile
import ph_inline_actions import ph_inline_actions
from modules import singleton from modules import singleton
...@@ -429,8 +430,12 @@ class Action(object): ...@@ -429,8 +430,12 @@ class Action(object):
return 'Execute error' return 'Execute error'
elif self.type.lower() == 'script_output': elif self.type.lower() == 'script_output':
try: try:
script_output = subprocess.check_output(script_command, env=self.config_environment, shell=True) with tempfile.NamedTemporaryFile() as output_stream:
return script_output subprocess.check_call(script_command, env=self.config_environment, shell=True,
stdout=output_stream, stderr=subprocess.STDOUT)
output_stream.seek(0)
script_output = output_stream.read()
return script_output
except: except:
syslog.syslog(syslog.LOG_ERR, '[%s] Script action failed at %s' % (message_uuid, syslog.syslog(syslog.LOG_ERR, '[%s] Script action failed at %s' % (message_uuid,
traceback.format_exc())) traceback.format_exc()))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment