Commit 8135a2db authored by Iustin Pop's avatar Iustin Pop
Browse files

Prevent master failover to a non candidate node

Reviewed-by: imsnah
parent f56618e0
......@@ -323,11 +323,11 @@ def MasterFailover():
new master.
"""
cfg = ssconf.SimpleConfigWriter()
sstore = ssconf.SimpleStore()
new_master = utils.HostInfo().name
old_master = cfg.GetMasterNode()
node_list = cfg.GetNodeList()
old_master, new_master = ssconf.GetMasterAndMyself(sstore)
node_list = sstore.GetNodeList()
mc_list = sstore.GetMasterCandidates()
if old_master == new_master:
raise errors.OpPrereqError("This commands must be run on the node"
......@@ -335,6 +335,14 @@ def MasterFailover():
" %s is already the master" %
old_master)
if new_master not in mc_list:
mc_no_master = [name for name in mc_list if name != old_master]
raise errors.OpPrereqError("This node is not among the nodes marked"
" as master candidates. Only these nodes"
" can become masters. Current list of"
" master candidates is:\n"
"%s" % ('\n'.join(mc_no_master)))
vote_list = GatherMasterVotes(node_list)
if vote_list:
......@@ -349,6 +357,10 @@ def MasterFailover():
" this node." % (old_master, voted_master))
# end checks
# instantiate a real config writer, as we now know we have the
# configuration data
cfg = ssconf.SimpleConfigWriter()
rcode = 0
logging.info("Setting master to %s, old master: %s", new_master, old_master)
......
......@@ -255,6 +255,11 @@ def GetMasterAndMyself(ss=None):
The function does not handle any errors, these should be handled in
the caller (errors.ConfigurationError, errors.ResolverError).
@param ss: either a sstore.SimpleConfigReader or a
sstore.SimpleStore instance
@rtype: tuple
@return: a tuple (master node name, my own name)
"""
if ss is None:
ss = SimpleStore()
......
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