From 7b4c1cb96bbb187bd7ce3e8714fcd010f5af3f85 Mon Sep 17 00:00:00 2001
From: Michael Hanselmann <hansmi@google.com>
Date: Thu, 8 Jul 2010 17:21:39 +0200
Subject: [PATCH] Provide feedback function for all LU methods
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

By exposing mcpu's _Feedback function (now renamed to β€œLog”) to LU's,
methods like ExpandNames can also write to the job execution log.

Signed-off-by: Michael Hanselmann <hansmi@google.com>
Reviewed-by: Iustin Pop <iustin@google.com>
---
 lib/cmdlib.py |  1 +
 lib/mcpu.py   | 16 ++++++++--------
 test/mocks.py |  3 +++
 3 files changed, 12 insertions(+), 8 deletions(-)

diff --git a/lib/cmdlib.py b/lib/cmdlib.py
index c25c52688..c853a96f5 100644
--- a/lib/cmdlib.py
+++ b/lib/cmdlib.py
@@ -278,6 +278,7 @@ class LogicalUnit(object):
     self.recalculate_locks = {}
     self.__ssh = None
     # logging
+    self.Log = processor.Log # pylint: disable-msg=C0103
     self.LogWarning = processor.LogWarning # pylint: disable-msg=C0103
     self.LogInfo = processor.LogInfo # pylint: disable-msg=C0103
     self.LogStep = processor.LogStep # pylint: disable-msg=C0103
diff --git a/lib/mcpu.py b/lib/mcpu.py
index 341014a44..e5c7922a4 100644
--- a/lib/mcpu.py
+++ b/lib/mcpu.py
@@ -321,7 +321,7 @@ class Processor(object):
     hm = HooksMaster(self.rpc.call_hooks_runner, lu)
     h_results = hm.RunPhase(constants.HOOKS_PHASE_PRE)
     lu.HooksCallBack(constants.HOOKS_PHASE_PRE, h_results,
-                     self._Feedback, None)
+                     self.Log, None)
 
     if getattr(lu.op, "dry_run", False):
       # in this mode, no post-hooks are run, and the config is not
@@ -332,10 +332,10 @@ class Processor(object):
       return lu.dry_run_result
 
     try:
-      result = lu.Exec(self._Feedback)
+      result = lu.Exec(self.Log)
       h_results = hm.RunPhase(constants.HOOKS_PHASE_POST)
       result = lu.HooksCallBack(constants.HOOKS_PHASE_POST, h_results,
-                                self._Feedback, result)
+                                self.Log, result)
     finally:
       # FIXME: This needs locks if not lu_class.REQ_BGL
       if write_count != self.context.cfg.write_count:
@@ -470,7 +470,7 @@ class Processor(object):
     finally:
       self._cbs = None
 
-  def _Feedback(self, *args):
+  def Log(self, *args):
     """Forward call to feedback callback function.
 
     """
@@ -482,7 +482,7 @@ class Processor(object):
 
     """
     logging.debug("Step %d/%d %s", current, total, message)
-    self._Feedback("STEP %d/%d %s" % (current, total, message))
+    self.Log("STEP %d/%d %s" % (current, total, message))
 
   def LogWarning(self, message, *args, **kwargs):
     """Log a warning to the logs and the user.
@@ -499,9 +499,9 @@ class Processor(object):
       message = message % tuple(args)
     if message:
       logging.warning(message)
-      self._Feedback(" - WARNING: %s" % message)
+      self.Log(" - WARNING: %s" % message)
     if "hint" in kwargs:
-      self._Feedback("      Hint: %s" % kwargs["hint"])
+      self.Log("      Hint: %s" % kwargs["hint"])
 
   def LogInfo(self, message, *args):
     """Log an informational message to the logs and the user.
@@ -510,7 +510,7 @@ class Processor(object):
     if args:
       message = message % tuple(args)
     logging.info(message)
-    self._Feedback(" - INFO: %s" % message)
+    self.Log(" - INFO: %s" % message)
 
   def GetECId(self):
     if not self._ec_id:
diff --git a/test/mocks.py b/test/mocks.py
index 8ea4f8d7e..1450ad156 100644
--- a/test/mocks.py
+++ b/test/mocks.py
@@ -59,6 +59,9 @@ class FakeConfig:
 class FakeProc:
     """Fake processor object"""
 
+    def Log(self, msg, *args, **kwargs):
+        pass
+
     def LogWarning(self, msg, *args, **kwargs):
         pass
 
-- 
GitLab