From d21a2283105b4ec821c80efe1460059d3b40fbbf Mon Sep 17 00:00:00 2001 From: liupei Date: Sat, 21 Dec 2024 22:59:41 +0800 Subject: [PATCH] API: libcrmcommon: add pcmk_cib_node_shutdown() --- ...crmcommon-add-pcmk_cib_node_shutdown.patch | 173 ++++++++++++++++++ ...-Detect-newly-created-alerts-section.patch | 43 +++++ pacemaker.spec | 8 +- 3 files changed, 223 insertions(+), 1 deletion(-) create mode 100644 backport-API-libcrmcommon-add-pcmk_cib_node_shutdown.patch create mode 100644 backport-Fix-libcrmcommon-Detect-newly-created-alerts-section.patch diff --git a/backport-API-libcrmcommon-add-pcmk_cib_node_shutdown.patch b/backport-API-libcrmcommon-add-pcmk_cib_node_shutdown.patch new file mode 100644 index 0000000..ebdece9 --- /dev/null +++ b/backport-API-libcrmcommon-add-pcmk_cib_node_shutdown.patch @@ -0,0 +1,173 @@ +From c714a2460cee17d296f9246f98b3465bc95a6dba Mon Sep 17 00:00:00 2001 +From: Ken Gaillot +Date: Tue, 13 Aug 2024 11:56:44 -0500 +Subject: [PATCH] API: libcrmcommon: add pcmk_cib_node_shutdown() + +This is intended for sbd's use, to replace its own shutdown_attr_in_cib() +--- + include/crm/common/nodes.h | 4 ++ + lib/common/nodes.c | 30 ++++++++ + lib/common/tests/nodes/Makefile.am | 5 +- + .../tests/nodes/pcmk_cib_node_shutdown_test.c | 70 +++++++++++++++++++ + 4 files changed, 107 insertions(+), 2 deletions(-) + create mode 100644 lib/common/tests/nodes/pcmk_cib_node_shutdown_test.c + +diff --git a/include/crm/common/nodes.h b/include/crm/common/nodes.h +index 5f6f25ff0c..64c574ad3c 100644 +--- a/include/crm/common/nodes.h ++++ b/include/crm/common/nodes.h +@@ -12,6 +12,7 @@ + + #include // bool + #include // gboolean, GList, GHashTable ++#include // xmlNode + + #include // pcmk_resource_t, pcmk_scheduler_t + +@@ -180,6 +181,9 @@ bool pcmk_node_is_in_maintenance(const pcmk_node_t *node); + bool pcmk_foreach_active_resource(pcmk_node_t *node, + bool (*fn)(pcmk_resource_t *, void *), + void *user_data); ++ ++const char *pcmk_cib_node_shutdown(xmlNode *cib, const char *node); ++ + /*! + * \internal + * \brief Return a string suitable for logging as a node name +diff --git a/lib/common/nodes.c b/lib/common/nodes.c +index 4edeafbc42..5228ea2618 100644 +--- a/lib/common/nodes.c ++++ b/lib/common/nodes.c +@@ -161,3 +161,33 @@ pcmk__find_node_in_list(const GList *nodes, const char *node_name) + } + return NULL; + } ++ ++#define XP_SHUTDOWN "//" PCMK__XE_NODE_STATE "[@" PCMK_XA_UNAME "='%s']/" \ ++ PCMK__XE_TRANSIENT_ATTRIBUTES "/" PCMK_XE_INSTANCE_ATTRIBUTES "/" \ ++ PCMK_XE_NVPAIR "[@" PCMK_XA_NAME "='" PCMK__NODE_ATTR_SHUTDOWN "']" ++ ++/*! ++ * \brief Get value of a node's shutdown attribute from CIB, if present ++ * ++ * \param[in] cib CIB to check ++ * \param[in] node Name of node to check ++ * ++ * \return Value of shutdown attribute for \p node in \p cib if any, ++ * otherwise NULL ++ * \note The return value is a pointer into \p cib and so is valid only for the ++ * lifetime of that object. ++ */ ++const char * ++pcmk_cib_node_shutdown(xmlNode *cib, const char *node) ++{ ++ if ((cib != NULL) && (node != NULL)) { ++ char *xpath = crm_strdup_printf(XP_SHUTDOWN, node); ++ xmlNode *match = get_xpath_object(xpath, cib, LOG_TRACE); ++ ++ free(xpath); ++ if (match != NULL) { ++ return crm_element_value(match, PCMK_XA_VALUE); ++ } ++ } ++ return NULL; ++} +diff --git a/lib/common/tests/nodes/Makefile.am b/lib/common/tests/nodes/Makefile.am +index f52c615e4d..6c4964e1d0 100644 +--- a/lib/common/tests/nodes/Makefile.am ++++ b/lib/common/tests/nodes/Makefile.am +@@ -12,12 +12,13 @@ include $(top_srcdir)/mk/unittest.mk + + # Add "_test" to the end of all test program names to simplify .gitignore. + check_PROGRAMS = pcmk__find_node_in_list_test \ ++ pcmk__xe_add_node_test \ ++ pcmk_cib_node_shutdown_test \ + pcmk_foreach_active_resource_test \ + pcmk_node_is_clean_test \ + pcmk_node_is_in_maintenance_test \ + pcmk_node_is_online_test \ + pcmk_node_is_pending_test \ +- pcmk_node_is_shutting_down_test \ +- pcmk__xe_add_node_test ++ pcmk_node_is_shutting_down_test + + TESTS = $(check_PROGRAMS) +diff --git a/lib/common/tests/nodes/pcmk_cib_node_shutdown_test.c b/lib/common/tests/nodes/pcmk_cib_node_shutdown_test.c +new file mode 100644 +index 0000000000..a64a7283e8 +--- /dev/null ++++ b/lib/common/tests/nodes/pcmk_cib_node_shutdown_test.c +@@ -0,0 +1,70 @@ ++/* ++ * Copyright 2024 the Pacemaker project contributors ++ * ++ * The version control history for this file may have further details. ++ * ++ * This source code is licensed under the GNU General Public License version 2 ++ * or later (GPLv2+) WITHOUT ANY WARRANTY. ++ */ ++ ++#include ++ ++#include // NULL ++#include // xmlNode ++ ++#include ++#include ++ ++// Minimum CIB structure needed for function's XPath search ++#define CIB_XML \ ++ "<" PCMK_XE_CIB ">" \ ++ "<" PCMK_XE_STATUS ">" \ ++ "<" PCMK__XE_NODE_STATE " " PCMK_XA_UNAME "='node1'>" \ ++ "<" PCMK__XE_TRANSIENT_ATTRIBUTES ">" \ ++ "<" PCMK_XE_INSTANCE_ATTRIBUTES ">" \ ++ "<" PCMK_XE_NVPAIR " " \ ++ PCMK_XA_NAME "='" PCMK__NODE_ATTR_SHUTDOWN "' " \ ++ PCMK_XA_VALUE "='999'/>" \ ++ "" \ ++ "" \ ++ "" \ ++ "" \ ++ "" ++ ++static void ++null_args(void **state) ++{ ++ xmlNode *xml = pcmk__xml_parse(CIB_XML); ++ ++ assert_non_null(xml); ++ assert_null(pcmk_cib_node_shutdown(NULL, NULL)); ++ assert_null(pcmk_cib_node_shutdown(xml, NULL)); ++ assert_null(pcmk_cib_node_shutdown(NULL, "node1")); ++ free_xml(xml); ++} ++ ++static void ++shutdown_absent(void **state) ++{ ++ xmlNode *xml = pcmk__xml_parse(CIB_XML); ++ ++ assert_non_null(xml); ++ assert_null(pcmk_cib_node_shutdown(xml, "node")); ++ assert_null(pcmk_cib_node_shutdown(xml, "node10")); ++ free_xml(xml); ++} ++ ++static void ++shutdown_present(void **state) ++{ ++ xmlNode *xml = pcmk__xml_parse(CIB_XML); ++ ++ assert_non_null(xml); ++ assert_string_equal(pcmk_cib_node_shutdown(xml, "node1"), "999"); ++ free_xml(xml); ++} ++ ++PCMK__UNIT_TEST(NULL, NULL, ++ cmocka_unit_test(null_args), ++ cmocka_unit_test(shutdown_absent), ++ cmocka_unit_test(shutdown_present)) +-- +2.33.1.windows.1 + diff --git a/backport-Fix-libcrmcommon-Detect-newly-created-alerts-section.patch b/backport-Fix-libcrmcommon-Detect-newly-created-alerts-section.patch new file mode 100644 index 0000000..c37a8dc --- /dev/null +++ b/backport-Fix-libcrmcommon-Detect-newly-created-alerts-section.patch @@ -0,0 +1,43 @@ +From 562745575a4d8dc00c239e674714856c51cac6ef Mon Sep 17 00:00:00 2001 +From: Reid Wahl +Date: Wed, 28 Aug 2024 19:12:20 -0700 +Subject: [PATCH] Fix: libcrmcommon: Detect newly created alerts section + +This fixes a regression introduced by 20ad1a9. + +If the CIB does not already contain an alerts element, creating a new +alert requires creating the alerts element. This is included in the +patchset as a create operation. (Adding a new alert to an existing +alerts element is a modify operation.) + +Prior to this commit, we were checking whether cib_op="create". We +should be checking whether operation="create". + +As a result, if a new alert was created in a CIB that did not previously +contain an alerts element, the controller would not detect the change +and would not process the new alert. + +Fixes T865 +Fixes RHEL-55458 + +Signed-off-by: Reid Wahl +--- + lib/cib/cib_utils.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/lib/cib/cib_utils.c b/lib/cib/cib_utils.c +index f868f11397..d4b8120fbc 100644 +--- a/lib/cib/cib_utils.c ++++ b/lib/cib/cib_utils.c +@@ -160,7 +160,7 @@ element_in_patchset_v2(const xmlNode *patchset, const char *element) + NULL, NULL); + change != NULL; change = pcmk__xe_next_same(change)) { + +- const char *op = crm_element_value(change, PCMK__XA_CIB_OP); ++ const char *op = crm_element_value(change, PCMK_XA_OPERATION); + const char *diff_xpath = crm_element_value(change, PCMK_XA_PATH); + + if (pcmk__str_eq(diff_xpath, element_regex, pcmk__str_regex)) { +-- +2.33.1.windows.1 + diff --git a/pacemaker.spec b/pacemaker.spec index e7d6854..1eef850 100644 --- a/pacemaker.spec +++ b/pacemaker.spec @@ -17,7 +17,7 @@ ## can be incremented to build packages reliably considered "newer" ## than previously built packages with the same pcmkversion) %global pcmkversion 2.1.8 -%global specversion 7 +%global specversion 8 ## Upstream commit (full commit ID, abbreviated commit ID, or tag) to build %global commit 3980678f0372f2c7c294c01f61d63f0b2cafaad1 @@ -166,6 +166,8 @@ Patch10: backport-Low-tools-handle-orphans-when-outputting-node-histor.pat Patch11: backport-Refactor-lrmd-Move-TLS-connection-success-failure-in.patch Patch12: backport-Low-lrmd-Report-connection-failures-in-tls_handshake.patch Patch13: backport-Feature-lrmd-Perform-the-TLS-handshake-asynchronousl.patch +Patch14: backport-API-libcrmcommon-add-pcmk_cib_node_shutdown.patch +Patch15: backport-Fix-libcrmcommon-Detect-newly-created-alerts-section.patch Requires: resource-agents Requires: %{pkgname_pcmk_libs} = %{version}-%{release} @@ -773,6 +775,10 @@ exit 0 %license %{nagios_name}-%{nagios_hash}/COPYING %changelog +* Mon Dec 23 2024 liupei - 2.1.8-8 +- API: libcrmcommon: add pcmk_cib_node_shutdown() +- Fix: libcrmcommon: Detect newly created alerts section + * Thu Dec 19 2024 liupei - 2.1.8-7 - Feature: lrmd: Perform the TLS handshake asynchronously. - Low: lrmd: Report connection failures in tls_handshake_failed. -- Gitee