File bsc#1171372-0001-Refactor-libstonithd-functionize-fudging-metadata-of.patch of Package pacemaker.26926

From 5390c9147e6afdfc3d3a4e5aedf705284e426b13 Mon Sep 17 00:00:00 2001
From: "Gao,Yan" <ygao@suse.com>
Date: Wed, 15 Apr 2020 17:19:32 +0200
Subject: [PATCH 1/2] Refactor: libstonithd: functionize fudging metadata of
 RHCS-style agent to make specific parameter non-required

The parameter `port` of RHCS-style fence-agents is fudged to be shown as
`required="0"` in the metadata output by `stonith_admin --metadata` or
`crm_resource --show-metadata`. So that users know they don't have to
configure it. Pacemaker handles and passes the parameter to the agent
when executing it.
---
 lib/fencing/st_rhcs.c | 30 +++++++++++++++++++++++-------
 1 file changed, 23 insertions(+), 7 deletions(-)

diff --git a/lib/fencing/st_rhcs.c b/lib/fencing/st_rhcs.c
index 99f00a83d..16aa0f0c6 100644
--- a/lib/fencing/st_rhcs.c
+++ b/lib/fencing/st_rhcs.c
@@ -85,6 +85,28 @@ stonith__list_rhcs_agents(stonith_key_value_t **devices)
     return count;
 }
 
+static void
+stonith_rhcs_parameter_not_required(xmlNode *metadata, const char *parameter)
+{
+    char *xpath = NULL;
+    xmlXPathObject *xpathObj = NULL;
+
+    CRM_CHECK(metadata != NULL, return);
+    CRM_CHECK(parameter != NULL, return);
+
+    xpath = crm_strdup_printf("//parameter[@name='%s']", parameter);
+    /* Fudge metadata so that the parameter isn't required in config
+     * Pacemaker handles and adds it */
+    xpathObj = xpath_search(metadata, xpath);
+    if (numXpathResults(xpathObj) > 0) {
+        xmlNode *tmp = getXpathResult(xpathObj, 0);
+
+        crm_xml_add(tmp, "required", "0");
+    }
+    freeXpathObject(xpathObj);
+    free(xpath);
+}
+
 /*!
  * \brief Execute RHCS-compatible agent's meta-data action
  *
@@ -156,13 +178,7 @@ stonith__rhcs_metadata(const char *agent, int timeout, char **output)
     freeXpathObject(xpathObj);
 
     // Fudge metadata so port isn't required in config (pacemaker adds it)
-    xpathObj = xpath_search(xml, "//parameter[@name='port']");
-    if (numXpathResults(xpathObj) > 0) {
-        xmlNode *tmp = getXpathResult(xpathObj, 0);
-
-        crm_xml_add(tmp, "required", "0");
-    }
-    freeXpathObject(xpathObj);
+    stonith_rhcs_parameter_not_required(xml, "port");
 
     buffer = dump_xml_formatted_with_text(xml);
     free_xml(xml);
-- 
2.26.1

openSUSE Build Service is sponsored by