Correctly send to master, by mostly doing complicated things in logs, buildout errors.

parent e63444fc
......@@ -379,7 +379,8 @@ class Partition(object):
env=utils.getCleanEnvironment(pwd.getpwuid(uid).pw_dir), **kw)
if process_handler.returncode is None or process_handler.returncode != 0:
message = 'Failed to bootstrap buildout in %r.' % (self.instance_path)
raise BuildoutFailedError(message)
self.logger.error(message)
raise BuildoutFailedError('%s:\n%s\n' % (message, process_handler.output))
buildout_binary = os.path.join(self.instance_path, 'sbin', 'buildout')
if not os.path.exists(buildout_binary):
......@@ -479,7 +480,8 @@ class Partition(object):
if process_handler.returncode is None or process_handler.returncode != 0:
message = 'Failed to destroy Computer Partition in %r.' % \
self.instance_path
raise subprocess.CalledProcessError(message)
self.logger.error(message)
raise subprocess.CalledProcessError(message, process_handler.output)
# Manually cleans what remains
try:
for f in [self.key_file, self.cert_file]:
......
......@@ -29,6 +29,7 @@
import argparse
import ConfigParser
from exception import BuildoutFailedError
from hashlib import md5
from lxml import etree
import logging
......@@ -562,10 +563,25 @@ class Slapgrid(object):
logger.info('Destroying %r...' % software_release_uri)
software.destroy()
logger.info('Destroyed %r.' % software_release_uri)
# Send log before exiting
except (SystemExit, KeyboardInterrupt):
exception = traceback.format_exc()
software_release.error(exception)
raise
# Buildout failed: send log but don't print it to output (already done)
except BuildoutFailedError, exception:
clean_run = False
try:
software_release.error(exception)
except (SystemExit, KeyboardInterrupt):
raise
except Exception:
exception = traceback.format_exc()
logger.error('Problem during reporting error, continuing:\n' +
exception)
# For everything else: log it, send it, continue.
except Exception:
exception = traceback.format_exc()
logger.error(exception)
......@@ -800,10 +816,25 @@ class Slapgrid(object):
# Process the partition itself
self.processComputerPartition(computer_partition)
# Send log before exiting
except (SystemExit, KeyboardInterrupt):
exception = traceback.format_exc()
computer_partition.error(exception)
raise
# Buildout failed: send log but don't print it to output (already done)
except BuildoutFailedError, exception:
clean_run = False
try:
computer_partition.error(exception)
except (SystemExit, KeyboardInterrupt):
raise
except Exception:
exception = traceback.format_exc()
logger.error('Problem during reporting error, continuing:\n' +
exception)
# For everything else: log it, send it, continue.
except Exception as exception:
clean_run = False
logger.error(traceback.format_exc())
......
......@@ -92,6 +92,8 @@ class AlreadyRunning(Exception):
class SlapPopen(subprocess.Popen):
"""
Almost normal subprocess with greedish features and logging.
Each line is logged "live", and self.output is a string containing the whole
log.
"""
def __init__(self, *args, **kwargs):
kwargs.update(stdin=subprocess.PIPE)
......@@ -101,15 +103,17 @@ class SlapPopen(subprocess.Popen):
self.stdin = None
logger = logging.getLogger('SlapProcessManager')
# XXX-Cedric: this algorithm looks overkill for simple logging.
self.output = ''
while True:
line = self.stdout.readline()
if line == '' and self.poll() != None:
break
self.output = self.output + line
if line[-1:] == '\n':
line = line[:-1]
logger.info(line)
def getSoftwareUrlHash(url):
return md5(url).hexdigest()
......@@ -275,10 +279,10 @@ def bootstrapBuildout(path, buildout=None,
process_handler = SlapPopen(invocation_list,
preexec_fn=lambda: dropPrivileges(uid, gid),
cwd=path, **kw)
if process_handler.returncode is None or process_handler.returncode != 0:
message = 'Failed to run buildout profile in directory %r.\n' % (path)
raise BuildoutFailedError(message)
message = 'Failed to run buildout profile in directory %r' % (path)
logger.error(message)
raise BuildoutFailedError('%s:\n%s\n' % (message, process_handler.output))
except OSError as error:
raise BuildoutFailedError(error)
finally:
......@@ -318,8 +322,9 @@ def launchBuildout(path, buildout_binary,
preexec_fn=lambda: dropPrivileges(uid, gid), cwd=path,
env=getCleanEnvironment(pwd.getpwuid(uid).pw_dir), **kw)
if process_handler.returncode is None or process_handler.returncode != 0:
message = 'Failed to run buildout profile in directory %r\n' % (path)
raise BuildoutFailedError(message)
message = 'Failed to run buildout profile in directory %r' % (path)
logger.error(message)
raise BuildoutFailedError('%s:\n%s\n' % (message, process_handler.output))
except OSError as error:
raise BuildoutFailedError(error)
finally:
......
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