From f362096fbd9ebec5f1d2b33d4ef914e136e2988a Mon Sep 17 00:00:00 2001
From: Iustin Pop <iustin@google.com>
Date: Thu, 29 Nov 2007 16:03:23 +0000
Subject: [PATCH] Make utils.RunCmd log failures when using debug

This patch adds logging of command failures to the debug log in case the
user either started the command (gnt-*) or the node daemon with the
debug flag.

Reviewed-by: imsnah
---
 daemons/ganeti-noded | 1 +
 lib/cli.py           | 1 +
 lib/utils.py         | 6 ++++++
 3 files changed, 8 insertions(+)

diff --git a/daemons/ganeti-noded b/daemons/ganeti-noded
index 30f3b54b9..1736904a2 100755
--- a/daemons/ganeti-noded
+++ b/daemons/ganeti-noded
@@ -519,6 +519,7 @@ def main():
 
   """
   options, args = ParseOptions()
+  utils.debug = options.debug
   for fname in (constants.SSL_CERT_FILE,):
     if not os.path.isfile(fname):
       print "config %s not there, will not run." % fname
diff --git a/lib/cli.py b/lib/cli.py
index 62fa111cc..7a4d56c05 100644
--- a/lib/cli.py
+++ b/lib/cli.py
@@ -453,6 +453,7 @@ def GenericMain(commands, override=None):
 
   logger.SetupLogging(debug=options.debug, program=binary)
 
+  utils.debug = options.debug
   try:
     utils.Lock('cmd', max_retries=options.lock_retries, debug=options.debug)
   except errors.LockError, err:
diff --git a/lib/utils.py b/lib/utils.py
index 450db6a32..68fac3e78 100644
--- a/lib/utils.py
+++ b/lib/utils.py
@@ -44,6 +44,8 @@ from ganeti import errors
 _locksheld = []
 _re_shell_unquoted = re.compile('^[-.,=:/_+@A-Za-z0-9]+$')
 
+debug = False
+
 class RunResult(object):
   """Simple class for holding the result of running external programs.
 
@@ -78,6 +80,10 @@ class RunResult(object):
     else:
       self.fail_reason = "unable to determine termination reason"
 
+    if debug and self.failed:
+      logger.Debug("Command '%s' failed (%s); output: %s" %
+                   (self.cmd, self.fail_reason, self.output))
+
   def _GetOutput(self):
     """Returns the combined stdout and stderr for easier usage.
 
-- 
GitLab