if hasattr(manager, '__enter__'):
manager.__enter__()
stack.append(manager)
- except:
+ except Exception, e:
ctx.summary['success'] = False
+ if 'failure_reason' not in ctx.summary:
+ ctx.summary['failure_reason'] = str(e)
log.exception('Saw exception from tasks')
if ctx.config.get('interactive-on-error'):
from .task import interactive
log.debug('Unwinding manager %s', manager)
try:
suppress = manager.__exit__(*exc_info)
- except:
+ except Exception, e:
ctx.summary['success'] = False
+ if 'failure_reason' not in ctx.summary:
+ ctx.summary['failure_reason'] = str(e)
log.exception('Manager failed: %s', manager)
else:
if suppress:
)
log.info('Checking cluster ceph.log for badness...')
- r = mon0_remote.run(args=[
- 'if', run.Raw('!'),
- 'egrep', '-q', '\[ERR\]|\[WRN\]|\[SEC\]',
- '/tmp/cephtest/data/%s/log' % firstmon,
- run.Raw(';'), 'then', 'echo', 'OK', run.Raw(';'),
- 'fi',
- ],
+ def first_in_ceph_log(pattern):
+ r = mon0_remote.run(
+ args=[
+ 'if', run.Raw('!'),
+ 'egrep', '-q', pattern,
+ '/tmp/cephtest/data/%s/log' % firstmon,
+ run.Raw(';'), 'then', 'echo', 'OK', run.Raw(';'),
+ 'else',
+ 'egrep', pattern,
+ '/tmp/cephtest/data/%s/log' % firstmon,
+ run.Raw('|'),
+ 'head', '-n', '1', run.Raw(';'),
+ 'fi',
+ ],
stdout=StringIO(),
)
- if r.stdout.getvalue() != "OK\n":
+ stdout = r.stdout.getvalue()
+ if stdout != "OK\n":
+ return stdout
+ return None
+
+ if first_in_ceph_log('\[ERR\]|\[WRN\]|\[SEC\]') is not None:
log.warning('Found errors (ERR|WRN|SEC) in cluster log')
ctx.summary['success'] = False
+ # use the most severe problem as the failure reason
+ if 'failure_reason' not in ctx.summary:
+ for pattern in ['\[SEC\]', '\[ERR\]', '\[WRN\]']:
+ match = first_in_ceph_log(pattern)
+ if match is not None:
+ ctx.summary['failure_reason'] = \
+ '"{match}" in cluster log'.format(
+ match=match.rstrip('\n'),
+ )
+ break
for remote, dirs in devs_to_clean.iteritems():
for dir_ in dirs:
if r.stdout.getvalue() != 'OK\n':
log.warning('Found coredumps on %s, flagging run as failed', remote)
ctx.summary['success'] = False
+ if 'failure_reason' not in ctx.summary:
+ ctx.summary['failure_reason'] = \
+ 'Found coredumps on {remote}'.format(remote=remote)
@contextlib.contextmanager
def syslog(ctx, config):