Commit 4167825b authored by Iustin Pop's avatar Iustin Pop
Browse files

Split the hooks env building in two parts

This patch moves some of the environment processing from _BuildEnv to a
new _RunWrapper command which does the stringification and adds the
sstore variables.

The reasoning is that the sstore can be fresher than before the
execution (e.g.  in case of cluster init).

In order to support thise, we also need to modify cmdlib.LUInitCluster:
  - memorize the sstore and cfgw newly created in the Exec function
  - no need to build the custom environment in the BuildHooks
parent 9a395a76
......@@ -545,11 +545,7 @@ class LUInitCluster(LogicalUnit):
ourselves in the post-run node list.
"""
env = {
"CLUSTER": self.op.cluster_name,
"MASTER": self.hostname.name,
}
return env, [], [self.hostname.name]
return {}, [], [self.hostname.name]
def CheckPrereq(self):
"""Verify that the passed name is a valid one.
......@@ -615,7 +611,7 @@ class LUInitCluster(LogicalUnit):
hostname = self.hostname
# set up the simple store
ss = ssconf.SimpleStore()
self.sstore = ss = ssconf.SimpleStore()
ss.SetKey(ss.SS_HYPERVISOR, self.op.hypervisor_type)
ss.SetKey(ss.SS_MASTER_NODE, hostname.name)
ss.SetKey(ss.SS_MASTER_IP, clustername.ip)
......@@ -643,7 +639,7 @@ class LUInitCluster(LogicalUnit):
_InitSSHSetup(hostname.name)
# init of cluster config file
cfgw = config.ConfigWriter()
self.cfg = cfgw = config.ConfigWriter()
cfgw.InitConfig(hostname.name, hostname.ip, self.secondary_ip,
sshkey, self.op.mac_prefix,
self.op.vg_name, self.op.def_bridge)
......
......@@ -170,9 +170,7 @@ class HooksMaster(object):
self.callfn = callfn
self.lu = lu
self.op = lu.op
self.hpath = self.lu.HPATH
self.env, node_list_pre, node_list_post = self._BuildEnv()
self.node_list = {constants.HOOKS_PHASE_PRE: node_list_pre,
constants.HOOKS_PHASE_POST: node_list_post}
......@@ -198,15 +196,24 @@ class HooksMaster(object):
else:
lu_nodes_pre = lu_nodes_post = []
return env, frozenset(lu_nodes_pre), frozenset(lu_nodes_post)
def _RunWrapper(self, node_list, hpath, phase):
"""Simple wrapper over self.callfn.
This method fixes the environment before doing the rpc call.
"""
env = self.env.copy()
env["GANETI_HOOKS_PHASE"] = phase
env["GANETI_HOOKS_PATH"] = hpath
if self.lu.sstore is not None:
env["GANETI_CLUSTER"] = self.lu.sstore.GetClusterName()
env["GANETI_MASTER"] = self.lu.sstore.GetMasterNode()
for key in env:
if not isinstance(env[key], str):
env[key] = str(env[key])
env = dict([(str(key), str(val)) for key, val in env.iteritems()])
return env, frozenset(lu_nodes_pre), frozenset(lu_nodes_post)
return self.callfn(node_list, hpath, phase, env)
def RunPhase(self, phase):
"""Run all the scripts for a phase.
......@@ -219,8 +226,8 @@ class HooksMaster(object):
# 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)
hpath = self.lu.HPATH
results = self._RunWrapper(self.node_list[phase], hpath, phase)
if phase == constants.HOOKS_PHASE_PRE:
errs = []
if not results:
......
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