Move hook execution decision to HooksMaster
authorIustin Pop <iustin@google.com>
Thu, 11 Oct 2007 15:00:16 +0000 (15:00 +0000)
committerIustin Pop <iustin@google.com>
Thu, 11 Oct 2007 15:00:16 +0000 (15:00 +0000)
Currently, the HooksMaster creation and execution decision is in the
Processor class. This is not optimal, so we change to always create a
hooks master and instead make the decision inside that class, by
creating empty node lists for both pre and post if the lu doesn't
support hooks. This way, hooks decisions are moved to HooksMaster (where
they belong).

Reviewed-by: imsnah

lib/mcpu.py

index 1875741..874658a 100644 (file)
@@ -114,13 +114,10 @@ class Processor(object):
       self.sstore = ssconf.SimpleStore()
     lu = lu_class(self, op, self.cfg, self.sstore)
     lu.CheckPrereq()
-    do_hooks = lu_class.HPATH is not None
-    if do_hooks:
-      hm = HooksMaster(rpc.call_hooks_runner, lu)
-      hm.RunPhase(constants.HOOKS_PHASE_PRE)
+    hm = HooksMaster(rpc.call_hooks_runner, lu)
+    hm.RunPhase(constants.HOOKS_PHASE_PRE)
     result = lu.Exec(feedback_fn)
-    if do_hooks:
-      hm.RunPhase(constants.HOOKS_PHASE_POST)
+    hm.RunPhase(constants.HOOKS_PHASE_POST)
     return result
 
   def ChainOpCode(self, op, feedback_fn):
@@ -193,10 +190,13 @@ class HooksMaster(object):
       "GANETI_OBJECT_TYPE": self.lu.HTYPE,
       }
 
-    lu_env, lu_nodes_pre, lu_nodes_post = self.lu.BuildHooksEnv()
-    if lu_env:
-      for key in lu_env:
-        env["GANETI_" + key] = lu_env[key]
+    if self.lu.HPATH is not None:
+      lu_env, lu_nodes_pre, lu_nodes_post = self.lu.BuildHooksEnv()
+      if lu_env:
+        for key in lu_env:
+          env["GANETI_" + key] = lu_env[key]
+    else:
+      lu_nodes_pre = lu_nodes_post = []
 
     if self.lu.sstore is not None:
       env["GANETI_CLUSTER"] = self.lu.sstore.GetClusterName()
@@ -215,9 +215,9 @@ class HooksMaster(object):
 
     """
     if not self.node_list[phase]:
-      # empty node list, we should not attempt to run this
-      # as most probably we're in the cluster init phase and the rpc client
-      # part can't even attempt to run
+      # empty node list, we should not attempt to run this as either
+      # we're in the cluster init phase and the rpc client part can't
+      # even attempt to run, or this LU doesn't do hooks at all
       return
     self.env["GANETI_HOOKS_PHASE"] = str(phase)
     results = self.callfn(self.node_list[phase], self.hpath, phase, self.env)