Commit 7b4c1cb9 authored by Michael Hanselmann's avatar Michael Hanselmann
Browse files

Provide feedback function for all LU methods



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: default avatarMichael Hanselmann <hansmi@google.com>
Reviewed-by: default avatarIustin Pop <iustin@google.com>
parent 2034c70d
...@@ -278,6 +278,7 @@ class LogicalUnit(object): ...@@ -278,6 +278,7 @@ class LogicalUnit(object):
self.recalculate_locks = {} self.recalculate_locks = {}
self.__ssh = None self.__ssh = None
# logging # logging
self.Log = processor.Log # pylint: disable-msg=C0103
self.LogWarning = processor.LogWarning # pylint: disable-msg=C0103 self.LogWarning = processor.LogWarning # pylint: disable-msg=C0103
self.LogInfo = processor.LogInfo # pylint: disable-msg=C0103 self.LogInfo = processor.LogInfo # pylint: disable-msg=C0103
self.LogStep = processor.LogStep # pylint: disable-msg=C0103 self.LogStep = processor.LogStep # pylint: disable-msg=C0103
......
...@@ -321,7 +321,7 @@ class Processor(object): ...@@ -321,7 +321,7 @@ class Processor(object):
hm = HooksMaster(self.rpc.call_hooks_runner, lu) hm = HooksMaster(self.rpc.call_hooks_runner, lu)
h_results = hm.RunPhase(constants.HOOKS_PHASE_PRE) h_results = hm.RunPhase(constants.HOOKS_PHASE_PRE)
lu.HooksCallBack(constants.HOOKS_PHASE_PRE, h_results, lu.HooksCallBack(constants.HOOKS_PHASE_PRE, h_results,
self._Feedback, None) self.Log, None)
if getattr(lu.op, "dry_run", False): if getattr(lu.op, "dry_run", False):
# in this mode, no post-hooks are run, and the config is not # in this mode, no post-hooks are run, and the config is not
...@@ -332,10 +332,10 @@ class Processor(object): ...@@ -332,10 +332,10 @@ class Processor(object):
return lu.dry_run_result return lu.dry_run_result
try: try:
result = lu.Exec(self._Feedback) result = lu.Exec(self.Log)
h_results = hm.RunPhase(constants.HOOKS_PHASE_POST) h_results = hm.RunPhase(constants.HOOKS_PHASE_POST)
result = lu.HooksCallBack(constants.HOOKS_PHASE_POST, h_results, result = lu.HooksCallBack(constants.HOOKS_PHASE_POST, h_results,
self._Feedback, result) self.Log, result)
finally: finally:
# FIXME: This needs locks if not lu_class.REQ_BGL # FIXME: This needs locks if not lu_class.REQ_BGL
if write_count != self.context.cfg.write_count: if write_count != self.context.cfg.write_count:
...@@ -470,7 +470,7 @@ class Processor(object): ...@@ -470,7 +470,7 @@ class Processor(object):
finally: finally:
self._cbs = None self._cbs = None
def _Feedback(self, *args): def Log(self, *args):
"""Forward call to feedback callback function. """Forward call to feedback callback function.
""" """
...@@ -482,7 +482,7 @@ class Processor(object): ...@@ -482,7 +482,7 @@ class Processor(object):
""" """
logging.debug("Step %d/%d %s", current, total, message) 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): def LogWarning(self, message, *args, **kwargs):
"""Log a warning to the logs and the user. """Log a warning to the logs and the user.
...@@ -499,9 +499,9 @@ class Processor(object): ...@@ -499,9 +499,9 @@ class Processor(object):
message = message % tuple(args) message = message % tuple(args)
if message: if message:
logging.warning(message) logging.warning(message)
self._Feedback(" - WARNING: %s" % message) self.Log(" - WARNING: %s" % message)
if "hint" in kwargs: if "hint" in kwargs:
self._Feedback(" Hint: %s" % kwargs["hint"]) self.Log(" Hint: %s" % kwargs["hint"])
def LogInfo(self, message, *args): def LogInfo(self, message, *args):
"""Log an informational message to the logs and the user. """Log an informational message to the logs and the user.
...@@ -510,7 +510,7 @@ class Processor(object): ...@@ -510,7 +510,7 @@ class Processor(object):
if args: if args:
message = message % tuple(args) message = message % tuple(args)
logging.info(message) logging.info(message)
self._Feedback(" - INFO: %s" % message) self.Log(" - INFO: %s" % message)
def GetECId(self): def GetECId(self):
if not self._ec_id: if not self._ec_id:
......
...@@ -59,6 +59,9 @@ class FakeConfig: ...@@ -59,6 +59,9 @@ class FakeConfig:
class FakeProc: class FakeProc:
"""Fake processor object""" """Fake processor object"""
def Log(self, msg, *args, **kwargs):
pass
def LogWarning(self, msg, *args, **kwargs): def LogWarning(self, msg, *args, **kwargs):
pass pass
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment