Commit 6d7e1f20 authored by Guido Trotter's avatar Guido Trotter
Browse files

Abstract self-promotion decision



During node add we decide whether to self promote to an MC. Abstract
this decision making to a separate function.
Signed-off-by: default avatarGuido Trotter <ultrotter@google.com>
Reviewed-by: default avatarOlivier Tharan <olive@google.com>
parent 44485f49
...@@ -686,6 +686,17 @@ def _AdjustCandidatePool(lu, exceptions): ...@@ -686,6 +686,17 @@ def _AdjustCandidatePool(lu, exceptions):
(mc_now, mc_max)) (mc_now, mc_max))
def _DecideSelfPromotion(lu, exceptions=None):
"""Decide whether I should promote myself as a master candidate.
"""
cp_size = lu.cfg.GetClusterInfo().candidate_pool_size
mc_now, mc_should, _ = lu.cfg.GetMasterCandidateStats(exceptions)
# the new node will increase mc_max with one, so:
mc_should = min(mc_should + 1, cp_size)
return mc_now < mc_should
def _CheckNicsBridgesExist(lu, target_nics, target_node, def _CheckNicsBridgesExist(lu, target_nics, target_node,
profile=constants.PP_DEFAULT): profile=constants.PP_DEFAULT):
"""Check that the brigdes needed by a list of nics exist. """Check that the brigdes needed by a list of nics exist.
...@@ -2793,15 +2804,12 @@ class LUAddNode(LogicalUnit): ...@@ -2793,15 +2804,12 @@ class LUAddNode(LogicalUnit):
raise errors.OpPrereqError("Node secondary ip not reachable by TCP" raise errors.OpPrereqError("Node secondary ip not reachable by TCP"
" based ping to noded port") " based ping to noded port")
cp_size = self.cfg.GetClusterInfo().candidate_pool_size
if self.op.readd: if self.op.readd:
exceptions = [node] exceptions = [node]
else: else:
exceptions = [] exceptions = []
mc_now, mc_max, _ = self.cfg.GetMasterCandidateStats(exceptions)
# the new node will increase mc_max with one, so: self.master_candidate = _DecideSelfPromotion(self, exceptions=exceptions)
mc_max = min(mc_max + 1, cp_size)
self.master_candidate = mc_now < mc_max
if self.op.readd: if self.op.readd:
self.new_node = self.cfg.GetNodeInfo(node) self.new_node = self.cfg.GetNodeInfo(node)
......
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