Commit 5591f894 authored by Xavier Thompson's avatar Xavier Thompson

slapgrid: Adapt launching promise with SlapPopen

parent 0fe309cd
......@@ -59,7 +59,11 @@ from slapos import manager as slapmanager
from slapos.slap.slap import NotFoundError
from slapos.slap.slap import ServerError
from slapos.slap.slap import COMPUTER_PARTITION_REQUEST_LIST_TEMPLATE_FILENAME
from slapos.util import mkdir_p, chownDirectory, string_to_boolean, listifdir
from slapos.util import (mkdir_p,
chownDirectory,
string_to_boolean,
listifdir,
unicode2str)
from slapos.grid.exception import BuildoutFailedError
from slapos.grid.SlapObject import Software, Partition
from slapos.grid.svcbackend import (launchSupervisord,
......@@ -68,7 +72,6 @@ from slapos.grid.svcbackend import (launchSupervisord,
_getSupervisordSocketPath)
from slapos.grid.utils import (md5digest,
dropPrivileges,
killProcessTree,
SlapPopen,
updateFile)
from slapos.grid.promise import PromiseLauncher, PromiseError
......@@ -738,28 +741,22 @@ stderr_logfile_backups=1
os.dup2(1, 2)
dropPrivileges(uid, gid, logger=self.logger)
os.dup2(err, 2)
try:
process = SlapPopen(
command,
preexec_fn=preexec_fn,
cwd=instance_path,
universal_newlines=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
logger=self.logger,
timeout=timeout,
)
stderr = process.stderr.read()
if process.returncode == 2:
raise PromiseError(stderr)
elif process.returncode:
raise Exception(stderr)
elif stderr:
self.logger.warn('Unexpected promise runner output:\n%s', stderr)
except subprocess.TimeoutExpired:
killProcessTree(process.pid, self.logger)
# If this happens, it might be that the timeout margin is too small.
raise Exception('Promise runner timed out')
process = SlapPopen(
command,
preexec_fn=preexec_fn,
cwd=instance_path,
universal_newlines=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
logger=self.logger,
timeout=timeout,
)
if process.returncode == 2:
raise PromiseError(unicode2str(process.error))
elif process.returncode:
raise Exception(unicode2str(process.error))
elif process.error:
self.logger.warn('Unexpected promise runner output:\n%s', process.error)
else:
return PromiseLauncher(config=promise_config, logger=self.logger).run()
......
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