36923b
From 9853f4d05a376062d60f2e4c90938e587992237b Mon Sep 17 00:00:00 2001
36923b
From: Chris Lumens <clumens@redhat.com>
36923b
Date: Mon, 27 Jun 2022 12:06:24 -0400
36923b
Subject: [PATCH 1/2] Fix: tools: Don't output "(null)" in crm_attribute's
36923b
 quiet mode.
36923b
36923b
If the attribute queried for has no value, simply do not output
36923b
anything.
36923b
36923b
Regression in 2.1.3 introduced by 8c03553bbf
36923b
36923b
Fixes T502
36923b
See: rhbz#2099331
36923b
---
36923b
 tools/crm_attribute.c | 4 +++-
36923b
 1 file changed, 3 insertions(+), 1 deletion(-)
36923b
36923b
diff --git a/tools/crm_attribute.c b/tools/crm_attribute.c
36923b
index 0bd9dee81..b1463f906 100644
36923b
--- a/tools/crm_attribute.c
36923b
+++ b/tools/crm_attribute.c
36923b
@@ -56,7 +56,9 @@ attribute_text(pcmk__output_t *out, va_list args)
36923b
     char *host G_GNUC_UNUSED = va_arg(args, char *);
36923b
 
36923b
     if (out->quiet) {
36923b
-        pcmk__formatted_printf(out, "%s\n", value);
36923b
+        if (value != NULL) {
36923b
+            pcmk__formatted_printf(out, "%s\n", value);
36923b
+        }
36923b
     } else {
36923b
         out->info(out, "%s%s %s%s %s%s value=%s",
36923b
                   scope ? "scope=" : "", scope ? scope : "",
36923b
-- 
36923b
2.31.1
36923b
36923b
36923b
From 16d00a9b3ef27afd09f5c046ea1be50fc664ed84 Mon Sep 17 00:00:00 2001
36923b
From: Chris Lumens <clumens@redhat.com>
36923b
Date: Mon, 27 Jun 2022 12:18:06 -0400
36923b
Subject: [PATCH 2/2] Test: cts: Add a test for querying an attribute that does
36923b
 not exist.
36923b
36923b
---
36923b
 cts/cli/regression.tools.exp | 4 ++++
36923b
 cts/cts-cli.in               | 5 +++++
36923b
 2 files changed, 9 insertions(+)
36923b
36923b
diff --git a/cts/cli/regression.tools.exp b/cts/cli/regression.tools.exp
36923b
index 0d1cfa2ab..464472d42 100644
36923b
--- a/cts/cli/regression.tools.exp
36923b
+++ b/cts/cli/regression.tools.exp
36923b
@@ -24,6 +24,10 @@ A new shadow instance was created.  To begin using it paste the following into y
36923b
 </cib>
36923b
 =#=#=#= End test: Validate CIB - OK (0) =#=#=#=
36923b
 * Passed: cibadmin       - Validate CIB
36923b
+=#=#=#= Begin test: Query the value of an attribute that does not exist =#=#=#=
36923b
+crm_attribute: Error performing operation: No such device or address
36923b
+=#=#=#= End test: Query the value of an attribute that does not exist - No such object (105) =#=#=#=
36923b
+* Passed: crm_attribute  - Query the value of an attribute that does not exist
36923b
 =#=#=#= Begin test: Configure something before erasing =#=#=#=
36923b
 =#=#=#= Current cib after: Configure something before erasing =#=#=#=
36923b
 <cib epoch="2" num_updates="0" admin_epoch="0">
36923b
diff --git a/cts/cts-cli.in b/cts/cts-cli.in
36923b
index 8565c485a..b895d36ec 100755
36923b
--- a/cts/cts-cli.in
36923b
+++ b/cts/cts-cli.in
36923b
@@ -511,6 +511,10 @@ function test_tools() {
36923b
     cmd="cibadmin -Q"
36923b
     test_assert $CRM_EX_OK
36923b
 
36923b
+    desc="Query the value of an attribute that does not exist"
36923b
+    cmd="crm_attribute -n ABCD --query --quiet"
36923b
+    test_assert $CRM_EX_NOSUCH 0
36923b
+
36923b
     desc="Configure something before erasing"
36923b
     cmd="crm_attribute -n cluster-delay -v 60s"
36923b
     test_assert $CRM_EX_OK
36923b
@@ -1980,6 +1984,7 @@ for t in $tests; do
36923b
         -e 's/ end=\"[0-9][-+: 0-9]*Z*\"/ end=\"\"/' \
36923b
         -e 's/ start=\"[0-9][-+: 0-9]*Z*\"/ start=\"\"/' \
36923b
         -e 's/^Error checking rule: Device not configured/Error checking rule: No such device or address/' \
36923b
+        -e 's/Error performing operation: Device not configured/Error performing operation: No such device or address/' \
36923b
         -e 's/\(Injecting attribute last-failure-ping#monitor_10000=\)[0-9]*/\1/' \
36923b
         -e 's/^lt-//' \
36923b
         -e 's/ocf::/ocf:/' \
36923b
-- 
36923b
2.31.1
36923b