Blob Blame History Raw
From e5fc48f45a60228a82980dcd6d68ca01cf447eac Mon Sep 17 00:00:00 2001
From: Ondrej Mular <omular@redhat.com>
Date: Tue, 7 Dec 2021 11:58:09 +0100
Subject: [PATCH 2/3] fix rsc update cmd when unable to get agent metadata

`resource update` command failed with a traceback when updating a
resource with a non-existing resource agent
---
 pcs/resource.py                        | 14 ++++++++------
 pcs_test/tier1/legacy/test_resource.py | 21 +++++++++++++++++++++
 2 files changed, 29 insertions(+), 6 deletions(-)

diff --git a/pcs/resource.py b/pcs/resource.py
index c0e8b0d9..4514338d 100644
--- a/pcs/resource.py
+++ b/pcs/resource.py
@@ -1049,13 +1049,15 @@ def resource_update(lib, args, modifiers, deal_with_guest_change=True):
         if report_list:
             process_library_reports(report_list)
     except lib_ra.ResourceAgentError as e:
-        severity = (
-            reports.ReportItemSeverity.WARNING
-            if modifiers.get("--force")
-            else reports.ReportItemSeverity.ERROR
-        )
         process_library_reports(
-            [lib_ra.resource_agent_error_to_report_item(e, severity)]
+            [
+                lib_ra.resource_agent_error_to_report_item(
+                    e,
+                    reports.get_severity(
+                        reports.codes.FORCE, modifiers.get("--force")
+                    ),
+                )
+            ]
         )
     except LibraryError as e:
         process_library_reports(e.args)
diff --git a/pcs_test/tier1/legacy/test_resource.py b/pcs_test/tier1/legacy/test_resource.py
index 3f0e08b9..bae0587a 100644
--- a/pcs_test/tier1/legacy/test_resource.py
+++ b/pcs_test/tier1/legacy/test_resource.py
@@ -4879,6 +4879,27 @@ class UpdateInstanceAttrs(
             ),
         )
 
+    def test_nonexisting_agent(self):
+        agent = "ocf:pacemaker:nonexistent"
+        message = (
+            f"Agent '{agent}' is not installed or does "
+            "not provide valid metadata: Metadata query for "
+            f"{agent} failed: Input/output error"
+        )
+        self.assert_pcs_success(
+            f"resource create --force D0 {agent}".split(),
+            f"Warning: {message}\n",
+        )
+
+        self.assert_pcs_fail(
+            "resource update D0 test=testA".split(),
+            f"Error: {message}, use --force to override\n",
+        )
+        self.assert_pcs_success(
+            "resource update --force D0 test=testA".split(),
+            f"Warning: {message}\n",
+        )
+
     def test_update_existing(self):
         xml = """
             <resources>
-- 
2.31.1