Skip to content
Snippets Groups Projects
Commit 9a395a76 authored by Iustin Pop's avatar Iustin Pop
Browse files

Move hook execution decision to HooksMaster

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
parent f97a6b10
No related branches found
No related tags found
No related merge requests found
...@@ -114,13 +114,10 @@ class Processor(object): ...@@ -114,13 +114,10 @@ class Processor(object):
self.sstore = ssconf.SimpleStore() self.sstore = ssconf.SimpleStore()
lu = lu_class(self, op, self.cfg, self.sstore) lu = lu_class(self, op, self.cfg, self.sstore)
lu.CheckPrereq() lu.CheckPrereq()
do_hooks = lu_class.HPATH is not None hm = HooksMaster(rpc.call_hooks_runner, lu)
if do_hooks: hm.RunPhase(constants.HOOKS_PHASE_PRE)
hm = HooksMaster(rpc.call_hooks_runner, lu)
hm.RunPhase(constants.HOOKS_PHASE_PRE)
result = lu.Exec(feedback_fn) result = lu.Exec(feedback_fn)
if do_hooks: hm.RunPhase(constants.HOOKS_PHASE_POST)
hm.RunPhase(constants.HOOKS_PHASE_POST)
return result return result
def ChainOpCode(self, op, feedback_fn): def ChainOpCode(self, op, feedback_fn):
...@@ -193,10 +190,13 @@ class HooksMaster(object): ...@@ -193,10 +190,13 @@ class HooksMaster(object):
"GANETI_OBJECT_TYPE": self.lu.HTYPE, "GANETI_OBJECT_TYPE": self.lu.HTYPE,
} }
lu_env, lu_nodes_pre, lu_nodes_post = self.lu.BuildHooksEnv() if self.lu.HPATH is not None:
if lu_env: lu_env, lu_nodes_pre, lu_nodes_post = self.lu.BuildHooksEnv()
for key in lu_env: if lu_env:
env["GANETI_" + key] = lu_env[key] 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: if self.lu.sstore is not None:
env["GANETI_CLUSTER"] = self.lu.sstore.GetClusterName() env["GANETI_CLUSTER"] = self.lu.sstore.GetClusterName()
...@@ -215,9 +215,9 @@ class HooksMaster(object): ...@@ -215,9 +215,9 @@ class HooksMaster(object):
""" """
if not self.node_list[phase]: if not self.node_list[phase]:
# empty node list, we should not attempt to run this # empty node list, we should not attempt to run this as either
# as most probably we're in the cluster init phase and the rpc client # we're in the cluster init phase and the rpc client part can't
# part can't even attempt to run # even attempt to run, or this LU doesn't do hooks at all
return return
self.env["GANETI_HOOKS_PHASE"] = str(phase) self.env["GANETI_HOOKS_PHASE"] = str(phase)
results = self.callfn(self.node_list[phase], self.hpath, phase, self.env) results = self.callfn(self.node_list[phase], self.hpath, phase, self.env)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment