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

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