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

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