From 69bfb22dbd68023069f6dae11e418f6ad455474f Mon Sep 17 00:00:00 2001 From: Ondrej Mular Date: Tue, 7 Dec 2021 11:14:37 +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 b2a5e355..928477b2 100644 --- a/pcs/resource.py +++ b/pcs/resource.py @@ -1075,13 +1075,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 417ca131..0f8415b4 100644 --- a/pcs_test/tier1/legacy/test_resource.py +++ b/pcs_test/tier1/legacy/test_resource.py @@ -4882,6 +4882,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 = """ -- 2.31.1