Commit 3ff4a916 authored by Xavier Thompson's avatar Xavier Thompson

slapgrid: Fix promise logging with instance python

See merge request nexedi/slapos.core!373
parents dc8272b5 ad06784b
Pipeline #20586 failed with stage
in 0 seconds
......@@ -726,16 +726,21 @@ stderr_logfile_backups=1
else:
command.append('--' + option)
command.append(str(value))
# Compute timeout as the sum of all promise timeouts + empirical margin.
promises = plugins + len(listifdir(legacy_promise_dir))
# Add a timeout margin to let the process kill the promises and cleanup
timeout = promises * self.promise_timeout + 10
# The runpromise script uses stderr exclusively to propagate exception
# messages. It otherwise redirects stderr to stdout so that all outputs
# from the promises go to stdout.
def preexec_fn():
err = os.dup(2)
os.dup2(1, 2)
dropPrivileges(uid, gid, logger=self.logger)
os.dup2(err, 2)
try:
process = SlapPopen(
command,
preexec_fn=lambda: dropPrivileges(uid, gid, logger=self.logger),
preexec_fn=preexec_fn,
cwd=instance_path,
universal_newlines=True,
stdout=subprocess.PIPE,
......@@ -749,10 +754,10 @@ stderr_logfile_backups=1
elif process.returncode:
raise Exception(stderr)
elif stderr:
self.logger.warn('Promise runner unexpected output:\n%s', stderr)
self.logger.warn('Unexpected promise runner output:\n%s', stderr)
except subprocess.TimeoutExpired:
killProcessTree(process.pid, self.logger)
# The timeout margin was exceeded but this should be infrequent
# If this happens, it might be that the timeout margin is too small.
raise Exception('Promise runner timed out')
else:
......
......@@ -299,7 +299,7 @@ def dropPrivileges(uid, gid, logger):
else:
raise ValueError('%s it was possible to go back to uid = %r and gid = '
'%r which is fatal.' % (message_pre, current_uid, current_gid))
logger.debug('Succesfully dropped privileges to uid=%r gid=%r' % (uid, gid))
logger.debug('Successfully dropped privileges to uid=%r gid=%r' % (uid, gid))
def bootstrapBuildout(path, logger, buildout=None,
......
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