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 ...@@ -59,7 +59,11 @@ from slapos import manager as slapmanager
from slapos.slap.slap import NotFoundError from slapos.slap.slap import NotFoundError
from slapos.slap.slap import ServerError from slapos.slap.slap import ServerError
from slapos.slap.slap import COMPUTER_PARTITION_REQUEST_LIST_TEMPLATE_FILENAME 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.exception import BuildoutFailedError
from slapos.grid.SlapObject import Software, Partition from slapos.grid.SlapObject import Software, Partition
from slapos.grid.svcbackend import (launchSupervisord, from slapos.grid.svcbackend import (launchSupervisord,
...@@ -68,7 +72,6 @@ from slapos.grid.svcbackend import (launchSupervisord, ...@@ -68,7 +72,6 @@ from slapos.grid.svcbackend import (launchSupervisord,
_getSupervisordSocketPath) _getSupervisordSocketPath)
from slapos.grid.utils import (md5digest, from slapos.grid.utils import (md5digest,
dropPrivileges, dropPrivileges,
killProcessTree,
SlapPopen, SlapPopen,
updateFile) updateFile)
from slapos.grid.promise import PromiseLauncher, PromiseError from slapos.grid.promise import PromiseLauncher, PromiseError
...@@ -738,28 +741,22 @@ stderr_logfile_backups=1 ...@@ -738,28 +741,22 @@ stderr_logfile_backups=1
os.dup2(1, 2) os.dup2(1, 2)
dropPrivileges(uid, gid, logger=self.logger) dropPrivileges(uid, gid, logger=self.logger)
os.dup2(err, 2) os.dup2(err, 2)
try: process = SlapPopen(
process = SlapPopen( command,
command, preexec_fn=preexec_fn,
preexec_fn=preexec_fn, cwd=instance_path,
cwd=instance_path, universal_newlines=True,
universal_newlines=True, stdout=subprocess.PIPE,
stdout=subprocess.PIPE, stderr=subprocess.PIPE,
stderr=subprocess.PIPE, logger=self.logger,
logger=self.logger, timeout=timeout,
timeout=timeout, )
) if process.returncode == 2:
stderr = process.stderr.read() raise PromiseError(unicode2str(process.error))
if process.returncode == 2: elif process.returncode:
raise PromiseError(stderr) raise Exception(unicode2str(process.error))
elif process.returncode: elif process.error:
raise Exception(stderr) self.logger.warn('Unexpected promise runner output:\n%s', process.error)
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')
else: else:
return PromiseLauncher(config=promise_config, logger=self.logger).run() 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