Improve cfgupgrade output in case of errors
authorHrvoje Ribicic <riba@google.com>
Wed, 28 Oct 2015 14:21:06 +0000 (15:21 +0100)
committerHrvoje Ribicic <riba@google.com>
Wed, 28 Oct 2015 15:34:41 +0000 (16:34 +0100)
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 <gjo@google.com>
Signed-off-by: Hrvoje Ribicic <riba@google.com>
Reviewed-by: Klaus Aehlig <aehlig@google.com>

lib/tools/cfgupgrade.py
tools/cfgupgrade

index d70f59d..eb7028c 100644 (file)
@@ -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")
index ce18108..31da116 100755 (executable)
@@ -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)