Blame SOURCES/bz1205848-Do-not-set-two_node-in-corosync-if-auto_tie_breaker-is-on.patch

056f5b
From e751df5b0e5d6849fa5a8332c7a0fed53c5b5141 Mon Sep 17 00:00:00 2001
056f5b
From: Tomas Jelinek <tojeline@redhat.com>
056f5b
Date: Tue, 3 Mar 2015 15:21:29 +0100
056f5b
Subject: [PATCH] Do not set two_node in corosync if auto_tie_breaker is on
056f5b
056f5b
---
056f5b
 pcs/cluster.py           |  23 ++++++--
056f5b
 pcs/utils.py             |  26 +++++++--
056f5b
 3 files changed, 170 insertions(+), 14 deletions(-)
056f5b
056f5b
diff --git a/pcs/cluster.py b/pcs/cluster.py
056f5b
index 8569b92..c4a9b4c 100644
056f5b
--- a/pcs/cluster.py
056f5b
+++ b/pcs/cluster.py
056f5b
@@ -351,6 +351,20 @@ def corosync_setup(argv,returnConfig=False):
056f5b
             cib_path = os.path.join(settings.cib_dir, "cib.xml")
056f5b
             if os.path.exists(cib_path) and not "--force" in utils.pcs_options:
056f5b
                 utils.err("%s already exists, use --force to overwrite" % cib_path)
056f5b
+
056f5b
+        for opt in ["--wait_for_all", "--auto_tie_breaker", "--last_man_standing"]:
056f5b
+            if (
056f5b
+                opt in utils.pcs_options
056f5b
+                and
056f5b
+                utils.pcs_options[opt] not in ["0", "1"]
056f5b
+            ):
056f5b
+                utils.err(
056f5b
+                    "'%s' is not a valid value for %s, use 0 or 1"
056f5b
+                    % (utils.pcs_options[opt], opt)
056f5b
+                )
056f5b
+
056f5b
+        auto_tie_breaker = False
056f5b
+
056f5b
         if "--corosync_conf" not in utils.pcs_options:
056f5b
             cluster_destroy([])
056f5b
 
056f5b
@@ -372,20 +386,21 @@ def corosync_setup(argv,returnConfig=False):
056f5b
             new_nodes_section += "       }\n"
056f5b
             i = i+1
056f5b
 
056f5b
-        two_node_section = ""
056f5b
-        if len(nodes) == 2:
056f5b
-            two_node_section = "two_node: 1"
056f5b
-
056f5b
         quorum_options = ""
056f5b
         if "--wait_for_all" in utils.pcs_options:
056f5b
             quorum_options += "wait_for_all: " + utils.pcs_options["--wait_for_all"] + "\n"
056f5b
         if "--auto_tie_breaker" in utils.pcs_options:
056f5b
             quorum_options += "auto_tie_breaker: " + utils.pcs_options["--auto_tie_breaker"] + "\n"
056f5b
+            if utils.pcs_options["--auto_tie_breaker"] == "1":
056f5b
+                auto_tie_breaker = True
056f5b
         if "--last_man_standing" in utils.pcs_options:
056f5b
             quorum_options += "last_man_standing: " + utils.pcs_options["--last_man_standing"] + "\n"
056f5b
         if "--last_man_standing_window" in utils.pcs_options:
056f5b
             quorum_options += "last_man_standing_window: " + utils.pcs_options["--last_man_standing_window"] + "\n"
056f5b
 
056f5b
+        two_node_section = ""
056f5b
+        if len(nodes) == 2 and not auto_tie_breaker:
056f5b
+            two_node_section = "two_node: 1"
056f5b
 
056f5b
         transport = "udpu"
056f5b
         if "--transport" in utils.pcs_options:
056f5b
diff --git a/pcs/utils.py b/pcs/utils.py
056f5b
index d35db1d..6911f0c 100644
056f5b
--- a/pcs/utils.py
056f5b
+++ b/pcs/utils.py
056f5b
@@ -527,7 +527,8 @@ def removeNodeFromCorosync(node):
056f5b
         node0 = node
056f5b
         node1 = None
056f5b
 
056f5b
-    for c_node in getNodesFromCorosyncConf():
056f5b
+    corosync_conf = getCorosyncConf()
056f5b
+    for c_node in getNodesFromCorosyncConf(corosync_conf):
056f5b
         if c_node == node0:
056f5b
             node_found = True
056f5b
         num_nodes_in_conf = num_nodes_in_conf + 1
056f5b
@@ -539,7 +540,7 @@ def removeNodeFromCorosync(node):
056f5b
     in_node = False
056f5b
     node_match = False
056f5b
     node_buffer = []
056f5b
-    for line in getCorosyncConf().split("\n"):
056f5b
+    for line in corosync_conf.split("\n"):
056f5b
         if in_node:
056f5b
             node_buffer.append(line)
056f5b
             if (
056f5b
@@ -562,7 +563,8 @@ def removeNodeFromCorosync(node):
056f5b
     new_corosync_conf = "\n".join(new_corosync_conf_lines) + "\n"
056f5b
 
056f5b
     if removed_node:
056f5b
-        if num_nodes_in_conf == 3:
056f5b
+        auto_tie_breaker = getQuorumOption(corosync_conf, "auto_tie_breaker")
056f5b
+        if num_nodes_in_conf == 3 and auto_tie_breaker != "1":
056f5b
             new_corosync_conf = addQuorumOption(new_corosync_conf,("two_node","1"))
056f5b
         setCorosyncConf(new_corosync_conf)
056f5b
         reloadCorosync()
056f5b
@@ -640,6 +642,24 @@ def rmQuorumOption(corosync_conf,option):
056f5b
 
056f5b
     return output.rstrip('\n') + "\n"
056f5b
 
056f5b
+def getQuorumOption(corosync_conf, option):
056f5b
+    lines = corosync_conf.split("\n")
056f5b
+    value = None
056f5b
+
056f5b
+    inQuorum = False
056f5b
+    for line in lines:
056f5b
+        line = line.strip()
056f5b
+        if line.startswith("#"):
056f5b
+            continue
056f5b
+        if inQuorum and "}" in line:
056f5b
+            inQuorum = False
056f5b
+        elif inQuorum and line.split(":", 1)[0].strip() == option:
056f5b
+            value = line.split(":", 1)[1].strip()
056f5b
+        elif line.startswith("quorum {"):
056f5b
+            inQuorum = True
056f5b
+
056f5b
+    return value
056f5b
+
056f5b
 def getNextNodeID(corosync_conf):
056f5b
     currentNodes = []
056f5b
     highest = 0
056f5b
-- 
056f5b
1.9.1
056f5b