By logging with the exception function instead of the error function, and showing the error content without the stack trace unless explicitly debugging.
Signed-off-by: Gerard Oskamp <[email protected]> Signed-off-by: Hrvoje Ribicic <[email protected]> --- lib/tools/cfgupgrade.py | 4 ++-- tools/cfgupgrade | 12 ++++++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/tools/cfgupgrade.py b/lib/tools/cfgupgrade.py index d70f59d..eb7028c 100644 --- a/lib/tools/cfgupgrade.py +++ b/lib/tools/cfgupgrade.py @@ -115,7 +115,7 @@ def OrFail(description=None): f(self) except BaseException, e: msg = "%s failed:\n%s" % (description or f.func_name, e) - logging.error(msg) + logging.exception(msg) self.config_data = safety self.errors.append(msg) return wrapped @@ -188,7 +188,7 @@ class CfgUpgrade(object): if config_revision != 0: logging.warning("Config revision is %s, not 0", config_revision) if not self.UpgradeAll(): - raise Error("Upgrade failed:\n%s", '\n'.join(self.errors)) + raise Error("Upgrade failed:\n%s" % '\n'.join(self.errors)) elif config_major == TARGET_MAJOR and config_minor == TARGET_MINOR: logging.info("No changes necessary") diff --git a/tools/cfgupgrade b/tools/cfgupgrade index ce18108..31da116 100755 --- a/tools/cfgupgrade +++ b/tools/cfgupgrade @@ -35,9 +35,17 @@ example, 'set' is a 'list'. """ -from ganeti.tools.cfgupgrade import CfgUpgrade, ParseOptions +from ganeti.tools.cfgupgrade import CfgUpgrade, Error, ParseOptions if __name__ == "__main__": opts, args = ParseOptions() - CfgUpgrade(opts, args).Run() + try: + CfgUpgrade(opts, args).Run() + except Error as e: + if opts.debug: + # If debugging, we want to see the original stack trace. + raise + else: + # Else silence it for the sake of convenience. + raise SystemExit(e) -- 2.1.4
