Blame SOURCES/bz1384485-01-fix-rsc-update-cmd-when-unable-to-get-agent-metadata.patch

bcd546
From e5fc48f45a60228a82980dcd6d68ca01cf447eac Mon Sep 17 00:00:00 2001
bcd546
From: Ondrej Mular <omular@redhat.com>
bcd546
Date: Tue, 7 Dec 2021 11:58:09 +0100
bcd546
Subject: [PATCH 2/3] fix rsc update cmd when unable to get agent metadata
bcd546
bcd546
`resource update` command failed with a traceback when updating a
bcd546
resource with a non-existing resource agent
bcd546
---
bcd546
 pcs/resource.py                        | 14 ++++++++------
bcd546
 pcs_test/tier1/legacy/test_resource.py | 21 +++++++++++++++++++++
bcd546
 2 files changed, 29 insertions(+), 6 deletions(-)
bcd546
bcd546
diff --git a/pcs/resource.py b/pcs/resource.py
bcd546
index c0e8b0d9..4514338d 100644
bcd546
--- a/pcs/resource.py
bcd546
+++ b/pcs/resource.py
bcd546
@@ -1049,13 +1049,15 @@ def resource_update(lib, args, modifiers, deal_with_guest_change=True):
bcd546
         if report_list:
bcd546
             process_library_reports(report_list)
bcd546
     except lib_ra.ResourceAgentError as e:
bcd546
-        severity = (
bcd546
-            reports.ReportItemSeverity.WARNING
bcd546
-            if modifiers.get("--force")
bcd546
-            else reports.ReportItemSeverity.ERROR
bcd546
-        )
bcd546
         process_library_reports(
bcd546
-            [lib_ra.resource_agent_error_to_report_item(e, severity)]
bcd546
+            [
bcd546
+                lib_ra.resource_agent_error_to_report_item(
bcd546
+                    e,
bcd546
+                    reports.get_severity(
bcd546
+                        reports.codes.FORCE, modifiers.get("--force")
bcd546
+                    ),
bcd546
+                )
bcd546
+            ]
bcd546
         )
bcd546
     except LibraryError as e:
bcd546
         process_library_reports(e.args)
bcd546
diff --git a/pcs_test/tier1/legacy/test_resource.py b/pcs_test/tier1/legacy/test_resource.py
bcd546
index 3f0e08b9..bae0587a 100644
bcd546
--- a/pcs_test/tier1/legacy/test_resource.py
bcd546
+++ b/pcs_test/tier1/legacy/test_resource.py
bcd546
@@ -4879,6 +4879,27 @@ class UpdateInstanceAttrs(
bcd546
             ),
bcd546
         )
bcd546
 
bcd546
+    def test_nonexisting_agent(self):
bcd546
+        agent = "ocf:pacemaker:nonexistent"
bcd546
+        message = (
bcd546
+            f"Agent '{agent}' is not installed or does "
bcd546
+            "not provide valid metadata: Metadata query for "
bcd546
+            f"{agent} failed: Input/output error"
bcd546
+        )
bcd546
+        self.assert_pcs_success(
bcd546
+            f"resource create --force D0 {agent}".split(),
bcd546
+            f"Warning: {message}\n",
bcd546
+        )
bcd546
+
bcd546
+        self.assert_pcs_fail(
bcd546
+            "resource update D0 test=testA".split(),
bcd546
+            f"Error: {message}, use --force to override\n",
bcd546
+        )
bcd546
+        self.assert_pcs_success(
bcd546
+            "resource update --force D0 test=testA".split(),
bcd546
+            f"Warning: {message}\n",
bcd546
+        )
bcd546
+
bcd546
     def test_update_existing(self):
bcd546
         xml = """
bcd546
             <resources>
bcd546
-- 
bcd546
2.31.1
bcd546