Blame SOURCES/bz1940363-2-bundle-disable-validate-with.patch

0c4b27
From 716db89c1ab02ce4fed8ba0916ff1f6d01b4b636 Mon Sep 17 00:00:00 2001
0c4b27
From: Damien Ciabrini <damien.ciabrini@gmail.com>
0c4b27
Date: Thu, 18 Mar 2021 14:11:11 +0100
0c4b27
Subject: [PATCH] bundle: run crm_mon without performing validation
0c4b27
0c4b27
We have a use case in OpenStack where the resource agents run
0c4b27
inside bundles (containerized pacemaker remotes), and we cannot
0c4b27
always guarantee an exact match of pacemaker version on the host
0c4b27
and in containers. This can make crm_mon fail to run because
0c4b27
it may not have the latest version of the schema to validate the
0c4b27
CIB that it's getting.
0c4b27
0c4b27
Add a function crm_mon_no_validation to allow clustered services
0c4b27
like galera, redis and rabbitmq to work when there is a minor
0c4b27
version mismatch between host and containers. This doesn't
0c4b27
impact non-containerized use cases, there is a single version
0c4b27
of pacemaker binaries in this case.
0c4b27
0c4b27
Related-Bug: rhbz#1940363
0c4b27
---
0c4b27
 configure.ac                                     |  2 ++
0c4b27
 heartbeat/{galera => galera.in}                  | 10 +++++-----
0c4b27
 heartbeat/ocf-shellfuncs.in                      | 16 ++++++++++++++++
0c4b27
 .../{rabbitmq-cluster => rabbitmq-cluster.in}    |  4 ++--
0c4b27
 heartbeat/redis.in                               |  4 ++--
0c4b27
 5 files changed, 27 insertions(+), 9 deletions(-)
0c4b27
 rename heartbeat/{galera => galera.in} (98%)
0c4b27
 rename heartbeat/{rabbitmq-cluster => rabbitmq-cluster.in} (98%)
0c4b27
0c4b27
diff --git a/configure.ac b/configure.ac
0c4b27
index ed9dc09bf..11c1b786b 100644
0c4b27
--- a/configure.ac
0c4b27
+++ b/configure.ac
0c4b27
@@ -979,6 +979,7 @@ AC_CONFIG_FILES([heartbeat/dnsupdate], [chmod +x heartbeat/dnsupdate])
0c4b27
 AC_CONFIG_FILES([heartbeat/dnsupdate], [chmod +x heartbeat/dnsupdate])
0c4b27
 AC_CONFIG_FILES([heartbeat/eDir88], [chmod +x heartbeat/eDir88])
0c4b27
 AC_CONFIG_FILES([heartbeat/fio], [chmod +x heartbeat/fio])
0c4b27
+AC_CONFIG_FILES([heartbeat/galera], [chmod +x heartbeat/galera])
0c4b27
 AC_CONFIG_FILES([heartbeat/gcp-pd-move], [chmod +x heartbeat/gcp-pd-move])
0c4b27
 AC_CONFIG_FILES([heartbeat/gcp-vpc-move-ip], [chmod +x heartbeat/gcp-vpc-move-ip])
0c4b27
 AC_CONFIG_FILES([heartbeat/gcp-vpc-move-vip], [chmod +x heartbeat/gcp-vpc-move-vip])
0c4b27
@@ -993,6 +994,7 @@ AC_CONFIG_FILES([heartbeat/machine-info], [chmod +x heartbeat/machine-info])
0c4b27
 AC_CONFIG_FILES([heartbeat/mariadb], [chmod +x heartbeat/mariadb])
0c4b27
 AC_CONFIG_FILES([heartbeat/mpathpersist], [chmod +x heartbeat/mpathpersist])
0c4b27
 AC_CONFIG_FILES([heartbeat/nfsnotify], [chmod +x heartbeat/nfsnotify])
0c4b27
+AC_CONFIG_FILES([heartbeat/rabbitmq-cluster], [chmod +x heartbeat/rabbitmq-cluster])
0c4b27
 AC_CONFIG_FILES([heartbeat/redis], [chmod +x heartbeat/redis])
0c4b27
 AC_CONFIG_FILES([heartbeat/rsyslog], [chmod +x heartbeat/rsyslog])
0c4b27
 AC_CONFIG_FILES([heartbeat/sg_persist], [chmod +x heartbeat/sg_persist])
0c4b27
diff --git a/heartbeat/galera b/heartbeat/galera.in
0c4b27
similarity index 98%
0c4b27
rename from heartbeat/galera
0c4b27
rename to heartbeat/galera.in
0c4b27
index c2f636f0d..7f5f2f1eb 100755
0c4b27
--- a/heartbeat/galera
0c4b27
+++ b/heartbeat/galera.in
0c4b27
@@ -1,4 +1,4 @@
0c4b27
-#!/bin/sh
0c4b27
+#!@BASH_SHELL@
0c4b27
 #
0c4b27
 # Copyright (c) 2014 David Vossel <davidvossel@gmail.com>
0c4b27
 #                    All Rights Reserved.
0c4b27
@@ -447,7 +447,7 @@ is_two_node_mode_active()
0c4b27
     # crm_node or corosync-quorumtool cannot access various corosync
0c4b27
     # flags when running inside a bundle, so only count the cluster
0c4b27
     # members
0c4b27
-    ocf_is_true "$OCF_RESKEY_two_node_mode" && ${HA_SBIN_DIR}/crm_mon -1X | xmllint --xpath "count(//nodes/node[@type='member'])" - | grep -q -w 2
0c4b27
+    ocf_is_true "$OCF_RESKEY_two_node_mode" && crm_mon_no_validation -1X | xmllint --xpath "count(//nodes/node[@type='member'])" - | grep -q -w 2
0c4b27
 }
0c4b27
 
0c4b27
 is_last_node_in_quorate_partition()
0c4b27
@@ -458,7 +458,7 @@ is_last_node_in_quorate_partition()
0c4b27
     # is clean), we shouldn't consider ourself quorate.
0c4b27
     local partition_members=$(${HA_SBIN_DIR}/crm_node -p | wc -w)
0c4b27
     local quorate=$(${HA_SBIN_DIR}/crm_node -q)
0c4b27
-    local clean_members=$(${HA_SBIN_DIR}/crm_mon -1X | xmllint --xpath 'count(//nodes/node[@type="member" and @unclean="false"])' -)
0c4b27
+    local clean_members=$(crm_mon_no_validation -1X | xmllint --xpath 'count(//nodes/node[@type="member" and @unclean="false"])' -)
0c4b27
 
0c4b27
     [ "$partition_members" = 1 ] && [ "$quorate" = 1 ] && [ "$clean_members" = 2 ]
0c4b27
 }
0c4b27
@@ -480,7 +480,7 @@ master_exists()
0c4b27
         XMLOPT="--output-as=xml"
0c4b27
         ocf_version_cmp "$OCF_RESKEY_crm_feature_set" "3.2.0"
0c4b27
         if [ $? -eq 1 ]; then
0c4b27
-            crm_mon -1 $XMLOPT >/dev/null 2>&1
0c4b27
+            crm_mon_no_validation -1 $XMLOPT >/dev/null 2>&1
0c4b27
             if [ $? -ne 0 ]; then
0c4b27
                 XMLOPT="--as-xml"
0c4b27
             fi
0c4b27
@@ -461,7 +461,7 @@
0c4b27
     else
0c4b27
         XMLOPT="--as-xml"
0c4b27
     fi
0c4b27
-    crm_mon -1 $XMLOPT | grep -q -i -E "resource.*id=\"${INSTANCE_ATTR_NAME}\".*role=\"(Promoted|Master)\".*active=\"true\".*orphaned=\"false\".*failed=\"false\""
0c4b27
+    crm_mon_no_validation -1 $XMLOPT | grep -q -i -E "resource.*id=\"${INSTANCE_ATTR_NAME}\".*role=\"(Promoted|Master)\".*active=\"true\".*orphaned=\"false\".*failed=\"false\""
0c4b27
     return $?
0c4b27
 }
0c4b27
 
0c4b27
diff --git a/heartbeat/ocf-shellfuncs.in b/heartbeat/ocf-shellfuncs.in
0c4b27
index ac75dfc87..760790cbd 100644
0c4b27
--- a/heartbeat/ocf-shellfuncs.in
0c4b27
+++ b/heartbeat/ocf-shellfuncs.in
0c4b27
@@ -41,6 +41,8 @@
0c4b27
 unset LC_ALL; export LC_ALL
0c4b27
 unset LANGUAGE; export LANGUAGE
0c4b27
 
0c4b27
+: ${HA_SBIN_DIR:=@sbindir@}
0c4b27
+
0c4b27
 __SCRIPT_NAME=`basename $0`
0c4b27
 
0c4b27
 if [ -z "$OCF_ROOT" ]; then
0c4b27
@@ -670,6 +672,20 @@ EOF
0c4b27
 	systemctl daemon-reload
0c4b27
 }
0c4b27
 
0c4b27
+# usage: crm_mon_no_validation args...
0c4b27
+# run crm_mon without any cib schema validation
0c4b27
+# This is useful when an agent runs in a bundle to avoid potential
0c4b27
+# schema validation errors when host and bundle are not perfectly aligned
0c4b27
+# To be used, your shell must support on process substitution (e.g. bash)
0c4b27
+# returns:
0c4b27
+#    <crm_mon error codes>
0c4b27
+crm_mon_no_validation()
0c4b27
+{
0c4b27
+	# The subshell prevents parsing error with incompatible shells
0c4b27
+	"$SHELL" -c "CIB_file=<(${HA_SBIN_DIR}/cibadmin -Q | sed 's/validate-with=\"[^\"]*\"/validate-with=\"none\"/') \
0c4b27
+	${HA_SBIN_DIR}/crm_mon \$*" -- $*
0c4b27
+}
0c4b27
+
0c4b27
 #
0c4b27
 # pseudo_resource status tracking function...
0c4b27
 #
0c4b27
diff --git a/heartbeat/rabbitmq-cluster b/heartbeat/rabbitmq-cluster.in
0c4b27
similarity index 98%
0c4b27
rename from heartbeat/rabbitmq-cluster
0c4b27
rename to heartbeat/rabbitmq-cluster.in
0c4b27
index f7d48120c..abd0662f2 100755
0c4b27
--- a/heartbeat/rabbitmq-cluster
0c4b27
+++ b/heartbeat/rabbitmq-cluster.in
0c4b27
@@ -1,4 +1,4 @@
0c4b27
-#!/bin/sh
0c4b27
+#!@BASH_SHELL@
0c4b27
 #
0c4b27
 # Copyright (c) 2014 David Vossel <davidvossel@gmail.com>
0c4b27
 #                    All Rights Reserved.
0c4b27
@@ -195,7 +195,7 @@ rmq_join_list()
0c4b27
 		# ...
0c4b27
 		local remote_join_list=$(cibadmin -Q --xpath "//node_state//nvpair[@name='$RMQ_CRM_ATTR_COOKIE']" | grep "$RMQ_CRM_ATTR_COOKIE" | sed -n -e "s/^.*value=.\(.*\)\".*$/\1/p")
0c4b27
 		# The following expression prepares a filter like '-e overcloud-rabbit-0 -e overcloud-rabbit-1 -e ...'
0c4b27
-		local filter=$(crm_mon -r --as-xml | xmllint --format --xpath "//nodes//node[@online='true' and @standby='false']/@name" - | xargs -n1 echo | awk -F= '{print "-e "$2}')
0c4b27
+		local filter=$(crm_mon_no_validation -r --as-xml | xmllint --format --xpath "//nodes//node[@online='true' and @standby='false']/@name" - | xargs -n1 echo | awk -F= '{print "-e "$2}')
0c4b27
 		# export the intersection which gives us only the nodes that
0c4b27
 		# a) wrote their namein the cib attrd
0c4b27
 		# b) run on nodes where pacemaker_remote is enabled
0c4b27
diff --git a/heartbeat/redis.in b/heartbeat/redis.in
0c4b27
index 8afdf08a9..f53d46964 100755
0c4b27
--- a/heartbeat/redis.in
0c4b27
+++ b/heartbeat/redis.in
0c4b27
@@ -278,7 +278,7 @@ master_is_active()
0c4b27
 			XMLOPT="--output-as=xml"
0c4b27
 			ocf_version_cmp "$OCF_RESKEY_crm_feature_set" "3.2.0"
0c4b27
 			if [ $? -eq 1 ]; then
0c4b27
-				crm_mon -1 $XMLOPT >/dev/null 2>&1
0c4b27
+				crm_mon_no_validation -1 $XMLOPT >/dev/null 2>&1
0c4b27
 				if [ $? -ne 0 ]; then
0c4b27
 					XMLOPT="--as-xml"
0c4b27
 				fi
0c4b27
@@ -286,7 +286,7 @@ master_is_active()
0c4b27
 		else
0c4b27
 			XMLOPT="--as-xml"
0c4b27
 		fi
0c4b27
-		crm_mon -1 $XMLOPT | grep -q -i -E "resource.*id=\"${OCF_RESOURCE_INSTANCE}\".* role=\"(Promoted|Master)\".* active=\"true\".* orphaned=\"false\".* failed=\"false\""
0c4b27
+		crm_mon_no_validation -1 $XMLOPT | grep -q -i -E "resource.*id=\"${OCF_RESOURCE_INSTANCE}\".* role=\"(Promoted|Master)\".* active=\"true\".* orphaned=\"false\".* failed=\"false\""
0c4b27
 		MASTER_ACTIVE=$?
0c4b27
 		MASTER_ACTIVE_CACHED="true"
0c4b27
 	fi