From 8c4b9364902fb44a62d13ae3a5bf6de8450da5b3 Mon Sep 17 00:00:00 2001
From: Luca Bigliardi <shammash@google.com>
Date: Tue, 25 Aug 2009 15:11:53 +0100
Subject: [PATCH] HooksMaster: logging hooks in RunPhase

Extend RunPhase so it will log hooks results in POST phase.

Signed-off-by: Luca Bigliardi <shammash@google.com>
Reviewed-by: Iustin Pop <iustin@google.com>
---
 lib/mcpu.py | 43 ++++++++++++++++++++++++++-----------------
 1 file changed, 26 insertions(+), 17 deletions(-)

diff --git a/lib/mcpu.py b/lib/mcpu.py
index 5cd356679..630f8775b 100644
--- a/lib/mcpu.py
+++ b/lib/mcpu.py
@@ -357,24 +357,33 @@ class HooksMaster(object):
       results = self._RunWrapper(nodes, hpath, phase)
     else:
       results = self._RunWrapper(self.node_list[phase], hpath, phase)
-    if phase == constants.HOOKS_PHASE_PRE:
-      errs = []
-      if not results:
-        raise errors.HooksFailure("Communication failure")
-      for node_name in results:
-        res = results[node_name]
-        if res.offline:
-          continue
-        msg = res.RemoteFailMsg()
-        if msg:
-          self.lu.LogWarning("Communication failure to node %s: %s",
-                             node_name, msg)
-          continue
-        for script, hkr, output in res.payload:
-          if hkr == constants.HKR_FAIL:
+    errs = []
+    if not results:
+      msg = "Communication Failure"
+      if phase == constants.HOOKS_PHASE_PRE:
+        raise errors.HooksFailure(msg)
+      else:
+        self.lu.LogWarning(msg)
+    for node_name in results:
+      res = results[node_name]
+      if res.offline:
+        continue
+      msg = res.RemoteFailMsg()
+      if msg:
+        self.lu.LogWarning("Communication failure to node %s: %s",
+                           node_name, msg)
+        continue
+      for script, hkr, output in res.payload:
+        if hkr == constants.HKR_FAIL:
+          if phase == constants.HOOKS_PHASE_PRE:
             errs.append((node_name, script, output))
-      if errs:
-        raise errors.HooksAbort(errs)
+          else:
+            if not output:
+	      output = "(no output)"
+            self.lu.LogWarning("On %s script %s failed, output: %s" %
+                               (node_name, script, output))
+    if errs and phase == constants.HOOKS_PHASE_PRE:
+      raise errors.HooksAbort(errs)
     return results
 
   def RunConfigUpdate(self):
-- 
GitLab