LU execution: implement dry-run framework
[ganeti-local] / lib / mcpu.py
index 2e75f56..0844b74 100644 (file)
@@ -113,6 +113,15 @@ class Processor(object):
     h_results = hm.RunPhase(constants.HOOKS_PHASE_PRE)
     lu.HooksCallBack(constants.HOOKS_PHASE_PRE, h_results,
                      self._feedback_fn, None)
+
+    if getattr(lu.op, "dry_run", False):
+      # in this mode, no post-hooks are run, and the config is not
+      # written (as it might have been modified by another LU, and we
+      # shouldn't do writeout on behalf of other threads
+      self.LogInfo("dry-run mode requested, not actually executing"
+                   " the operation")
+      return lu.dry_run_result
+
     try:
       result = lu.Exec(self._feedback_fn)
       h_results = hm.RunPhase(constants.HOOKS_PHASE_POST)
@@ -340,12 +349,14 @@ class HooksMaster(object):
         raise errors.HooksFailure("Communication failure")
       for node_name in results:
         res = results[node_name]
-        if res.failed or res.data is False or not isinstance(res.data, list):
-          if not res.offline:
-            self.proc.LogWarning("Communication failure to node %s" %
-                                 node_name)
+        if res.offline:
+          continue
+        msg = res.RemoteFailMsg()
+        if msg:
+          self.proc.LogWarning("Communication failure to node %s: %s",
+                               node_name, msg)
           continue
-        for script, hkr, output in res.data:
+        for script, hkr, output in res.payload:
           if hkr == constants.HKR_FAIL:
             errs.append((node_name, script, output))
       if errs:
@@ -362,4 +373,4 @@ class HooksMaster(object):
     phase = constants.HOOKS_PHASE_POST
     hpath = constants.HOOKS_NAME_CFGUPDATE
     nodes = [self.lu.cfg.GetMasterNode()]
-    results = self._RunWrapper(nodes, hpath, phase)
+    self._RunWrapper(nodes, hpath, phase)