File pacemaker#3292-0001-Log-scheduler-improve-logs-for-invalid-id-ref-s.patch of Package pacemaker.34782

From a183dff646d40103f8a852a226abc7d32bcfd946 Mon Sep 17 00:00:00 2001
From: Ken Gaillot <kgaillot@redhat.com>
Date: Tue, 23 May 2023 11:00:27 -0500
Subject: [PATCH] Log: scheduler: improve logs for invalid id-ref's

Always treat as configuration error
---
 lib/common/xml.c                    |  9 +++++----
 lib/pacemaker/pcmk_sched_constraints.c |  3 +--
 lib/pengine/rules.c                 | 11 +++++++++--
 3 files changed, 15 insertions(+), 8 deletions(-)

Index: pacemaker-2.0.5+20201202.ba59be712/lib/common/xml.c
===================================================================
--- pacemaker-2.0.5+20201202.ba59be712.orig/lib/common/xml.c
+++ pacemaker-2.0.5+20201202.ba59be712/lib/common/xml.c
@@ -2866,12 +2866,13 @@ expand_idref(xmlNode * input, xmlNode *
     if (ref != NULL) {
         char *xpath_string = crm_strdup_printf("//%s[@id='%s']", tag, ref);
 
-        result = get_xpath_object(xpath_string, top, LOG_ERR);
-        if (result == NULL) {
+        result = get_xpath_object(xpath_string, top, LOG_DEBUG);
+        if (result == NULL) { // Not possible with schema validation enabled
             char *nodePath = (char *)xmlGetNodePath(top);
 
-            crm_err("No match for %s found in %s: Invalid configuration", xpath_string,
-                    crm_str(nodePath));
+            pcmk__config_err("Ignoring invalid %s configuration: "
+                             XML_ATTR_IDREF " '%s' does not reference "
+                             "a valid object", result->name, ref);
             free(nodePath);
         }
         free(xpath_string);
Index: pacemaker-2.0.5+20201202.ba59be712/lib/pengine/rules.c
===================================================================
--- pacemaker-2.0.5+20201202.ba59be712.orig/lib/pengine/rules.c
+++ pacemaker-2.0.5+20201202.ba59be712/lib/pengine/rules.c
@@ -457,6 +457,10 @@ populate_hash(xmlNode * nvpair_list, GHa
         if (pcmk__str_eq((const char *)an_attr->name, XML_CIB_TAG_NVPAIR, pcmk__str_none)) {
             xmlNode *ref_nvpair = expand_idref(an_attr, top);
 
+            if (ref_nvpair == NULL) {
+                continue; // Not possible with schema validation enabled
+            }
+
             name = crm_element_value(an_attr, XML_NVPAIR_ATTR_NAME);
             if (name == NULL) {
                 name = crm_element_value(ref_nvpair, XML_NVPAIR_ATTR_NAME);
@@ -633,7 +637,7 @@ make_pairs(xmlNode *top, xmlNode *xml_ob
             pair = NULL;
             attr_set = expand_idref(attr_set, top);
             if (attr_set == NULL) {
-                continue;
+                continue; // Not possible with schema validation enabled
             }
 
             pair = calloc(1, sizeof(sorted_set_t));
@@ -856,6 +860,10 @@ pe_eval_expr(xmlNode *rule, pe_rule_eval
     const char *value = NULL;
 
     rule = expand_idref(rule, NULL);
+    if (rule == NULL) {
+        return FALSE; // Not possible with schema validation enabled
+    }
+
     value = crm_element_value(rule, XML_RULE_ATTR_BOOLEAN_OP);
     if (pcmk__str_eq(value, "or", pcmk__str_casei)) {
         do_and = FALSE;
openSUSE Build Service is sponsored by