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

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