diff --git a/lib/cmdlib.py b/lib/cmdlib.py index e1056903c119538410197022a1b2e5a602137fd8..3ce419c950dc02fb39a73f03e4a2df5a05b140ef 100644 --- a/lib/cmdlib.py +++ b/lib/cmdlib.py @@ -670,17 +670,17 @@ def _BuildInstanceHookEnvByObject(lu, instance, override=None): return _BuildInstanceHookEnv(**args) -def _AdjustCandidatePool(lu): +def _AdjustCandidatePool(lu, exceptions): """Adjust the candidate pool after node operations. """ - mod_list = lu.cfg.MaintainCandidatePool() + mod_list = lu.cfg.MaintainCandidatePool(exceptions) if mod_list: lu.LogInfo("Promoted nodes to master candidate role: %s", ", ".join(node.name for node in mod_list)) for name in mod_list: lu.context.ReaddNode(name) - mc_now, mc_max, _ = lu.cfg.GetMasterCandidateStats() + mc_now, mc_max, _ = lu.cfg.GetMasterCandidateStats(exceptions) if mc_now > mc_max: lu.LogInfo("Note: more nodes are candidates (%d) than desired (%d)" % (mc_now, mc_max)) @@ -1946,7 +1946,7 @@ class LUSetClusterParams(LogicalUnit): if self.op.candidate_pool_size is not None: self.cluster.candidate_pool_size = self.op.candidate_pool_size # we need to update the pool size here, otherwise the save will fail - _AdjustCandidatePool(self) + _AdjustCandidatePool(self, []) self.cfg.Update(self.cluster) @@ -2282,6 +2282,8 @@ class LURemoveNode(LogicalUnit): logging.info("Stopping the node daemon and removing configs from node %s", node.name) + # Promote nodes to master candidate as needed + _AdjustCandidatePool(self, exceptions=[node.name]) self.context.RemoveNode(node.name) # Run post hooks on the node before it's removed @@ -2297,9 +2299,6 @@ class LURemoveNode(LogicalUnit): self.LogWarning("Errors encountered on the remote node while leaving" " the cluster: %s", msg) - # Promote nodes to master candidate as needed - _AdjustCandidatePool(self) - class LUQueryNodes(NoHooksLU): """Logical unit for querying nodes. diff --git a/lib/config.py b/lib/config.py index 41fcf094db04a6e913900667e209aba42456ff9d..54f80702ae4fa2a55fda519b98a870a34934a309 100644 --- a/lib/config.py +++ b/lib/config.py @@ -1044,14 +1044,16 @@ class ConfigWriter: return self._UnlockedGetMasterCandidateStats(exceptions) @locking.ssynchronized(_config_lock) - def MaintainCandidatePool(self): + def MaintainCandidatePool(self, exceptions): """Try to grow the candidate pool to the desired size. + @type exceptions: list + @param exceptions: if passed, list of nodes that should be ignored @rtype: list @return: list with the adjusted nodes (L{objects.Node} instances) """ - mc_now, mc_max, _ = self._UnlockedGetMasterCandidateStats() + mc_now, mc_max, _ = self._UnlockedGetMasterCandidateStats(exceptions) mod_list = [] if mc_now < mc_max: node_list = self._config_data.nodes.keys() @@ -1060,7 +1062,8 @@ class ConfigWriter: if mc_now >= mc_max: break node = self._config_data.nodes[name] - if node.master_candidate or node.offline or node.drained: + if (node.master_candidate or node.offline or node.drained or + node.name in exceptions): continue mod_list.append(node) node.master_candidate = True