From b183c4a832f63021a94edf2fa017d4b7c634d7ff Mon Sep 17 00:00:00 2001 From: Iustin Pop <iustin@google.com> Date: Tue, 23 Oct 2012 16:01:18 +0200 Subject: [PATCH] Improve logging of AssertionErrors Currently, when we have an assertion error raised from cmdlib, it looks like this: [cluster] root@node4:~# gnt-instance grow-disk instance1 0 1G Failure: command execution error: This is very very confusing. This patch adds a bit of traceback formatting to improve this as follows: [cluster] root@node4:~# gnt-instance grow-disk instance1 0 1G Failure: command execution error: Internal assertion error: please report this as a bug. Error message: ''; location: File "/usr/lib/python2.6/dist-packages/ganeti/cmdlib.py", line 11954, in CheckPrereq assert False This is not perfect, but at least it shows better what the problem is. Signed-off-by: Iustin Pop <iustin@google.com> Reviewed-by: Michael Hanselmann <hansmi@google.com> --- lib/mcpu.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/mcpu.py b/lib/mcpu.py index a7ea80cbd..b807b911b 100644 --- a/lib/mcpu.py +++ b/lib/mcpu.py @@ -28,10 +28,12 @@ are two kinds of classes defined: """ +import sys import logging import random import time import itertools +import traceback from ganeti import opcodes from ganeti import constants @@ -354,7 +356,19 @@ class Processor(object): if self._cbs: self._cbs.NotifyStart() - result = self._ExecLU(lu) + try: + result = self._ExecLU(lu) + except AssertionError, err: + # this is a bit ugly, as we don't know from which phase + # (prereq, exec) this comes; but it's better than an exception + # with no information + (_, _, tb) = sys.exc_info() + err_info = traceback.format_tb(tb) + del tb + logging.exception("Detected AssertionError") + raise errors.OpExecError("Internal assertion error: please report" + " this as a bug.\nError message: '%s';" + " location:\n%s" % (str(err), err_info[-1])) elif adding_locks and acquiring_locks: # We could both acquire and add locks at the same level, but for now we -- GitLab