Blame SOURCES/bz1920947-fence_redfish-2-add-diag-action-logic.patch

6e6885
From b50523850e7fe1ba73d4ff0ede193c9860eff2bc Mon Sep 17 00:00:00 2001
6e6885
From: Oyvind Albrigtsen <oalbrigt@redhat.com>
6e6885
Date: Fri, 7 May 2021 10:35:00 +0200
6e6885
Subject: [PATCH] fence_redfish: add missing diag logic
6e6885
6e6885
---
6e6885
 agents/redfish/fence_redfish.py | 15 +++++++++++++--
6e6885
 1 file changed, 13 insertions(+), 2 deletions(-)
6e6885
6e6885
diff --git a/agents/redfish/fence_redfish.py b/agents/redfish/fence_redfish.py
6e6885
index 9a7d604d3..0f5af523c 100644
6e6885
--- a/agents/redfish/fence_redfish.py
6e6885
+++ b/agents/redfish/fence_redfish.py
6e6885
@@ -42,7 +42,7 @@ def set_power_status(conn, options):
6e6885
         'off': "ForceOff",
6e6885
         'reboot': "ForceRestart",
6e6885
         'diag': "Nmi"
6e6885
-    }[options["--action"]]
6e6885
+    }[options.get("original-action") or options["--action"]]
6e6885
 
6e6885
     payload = {'ResetType': action}
6e6885
 
6e6885
@@ -56,6 +56,8 @@ def set_power_status(conn, options):
6e6885
     response = send_post_request(options, action_uri, payload)
6e6885
     if response['ret'] is False:
6e6885
         fail_usage("Error sending power command")
6e6885
+    if options.get("original-action") == "diag":
6e6885
+        return True
6e6885
     return
6e6885
 
6e6885
 def send_get_request(options, uri):
6e6885
@@ -159,7 +161,16 @@ def main():
6e6885
         else:
6e6885
             options["--systems-uri"] = sysresult["uri"]
6e6885
 
6e6885
-    result = fence_action(None, options, set_power_status, get_power_status, None)
6e6885
+    reboot_fn = None
6e6885
+    if options["--action"] == "diag":
6e6885
+        # Diag is a special action that can't be verified so we will reuse reboot functionality
6e6885
+        # to minimize impact on generic library
6e6885
+        options["original-action"] = options["--action"]
6e6885
+        options["--action"] = "reboot"
6e6885
+        options["--method"] = "cycle"
6e6885
+        reboot_fn = set_power_status
6e6885
+
6e6885
+    result = fence_action(None, options, set_power_status, get_power_status, None, reboot_fn)
6e6885
     sys.exit(result)
6e6885
 
6e6885
 if __name__ == "__main__":