Blame SOURCES/bz1704228-fence_redfish-full-redfish-spec-compliance.patch

83de4b
From 75a74debba2205547d8eefae221221c2c71d99ce Mon Sep 17 00:00:00 2001
83de4b
From: Jose Delarosa <jose.delarosa@dell.com>
83de4b
Date: Mon, 15 Apr 2019 12:46:42 -0500
83de4b
Subject: [PATCH] fence_redfish: add headers to HTTP methods
83de4b
83de4b
* Needed for full compliance with Redfish spec.
83de4b
* May cause errors in some devices if not sent.
83de4b
---
83de4b
 agents/redfish/fence_redfish.py | 13 +++++++++----
83de4b
 1 file changed, 9 insertions(+), 4 deletions(-)
83de4b
83de4b
diff --git a/agents/redfish/fence_redfish.py b/agents/redfish/fence_redfish.py
83de4b
index f1424232..390a4827 100644
83de4b
--- a/agents/redfish/fence_redfish.py
83de4b
+++ b/agents/redfish/fence_redfish.py
83de4b
@@ -16,6 +16,11 @@
83de4b
 from fencing import *
83de4b
 from fencing import fail_usage, run_delay
83de4b
 
83de4b
+GET_HEADERS = {'accept': 'application/json', 'OData-Version': '4.0'}
83de4b
+POST_HEADERS = {'content-type': 'application/json', 'accept': 'application/json',
83de4b
+                'OData-Version': '4.0'}
83de4b
+
83de4b
+
83de4b
 def get_power_status(conn, options):
83de4b
     response = send_get_request(options, options["--systems-uri"])
83de4b
     if response['ret'] is False:
83de4b
@@ -40,7 +45,6 @@ def set_power_status(conn, options):
83de4b
     }[options["--action"]]
83de4b
 
83de4b
     payload = {'ResetType': action}
83de4b
-    headers = {'content-type': 'application/json'}
83de4b
 
83de4b
     # Search for 'Actions' key and extract URI from it
83de4b
     response = send_get_request(options, options["--systems-uri"])
83de4b
@@ -49,7 +53,7 @@ def set_power_status(conn, options):
83de4b
     data = response['data']
83de4b
     action_uri = data["Actions"]["#ComputerSystem.Reset"]["target"]
83de4b
 
83de4b
-    response = send_post_request(options, action_uri, payload, headers)
83de4b
+    response = send_post_request(options, action_uri, payload)
83de4b
     if response['ret'] is False:
83de4b
         fail_usage("Error sending power command")
83de4b
     return
83de4b
@@ -58,17 +62,18 @@ def send_get_request(options, uri):
83de4b
     full_uri = "https://" + options["--ip"] + ":" + str(options["--ipport"]) + uri
83de4b
     try:
83de4b
         resp = requests.get(full_uri, verify=not "--ssl-insecure" in options,
83de4b
+                            headers=GET_HEADERS,
83de4b
                             auth=(options["--username"], options["--password"]))
83de4b
         data = resp.json()
83de4b
     except Exception as e:
83de4b
         fail_usage("Failed: send_get_request: " + str(e))
83de4b
     return {'ret': True, 'data': data}
83de4b
 
83de4b
-def send_post_request(options, uri, payload, headers):
83de4b
+def send_post_request(options, uri, payload):
83de4b
     full_uri = "https://" + options["--ip"] + ":" + str(options["--ipport"]) + uri
83de4b
     try:
83de4b
         requests.post(full_uri, data=json.dumps(payload),
83de4b
-                      headers=headers, verify=not "--ssl-insecure" in options,
83de4b
+                      headers=POST_HEADERS, verify=not "--ssl-insecure" in options,
83de4b
                       auth=(options["--username"], options["--password"]))
83de4b
     except Exception as e:
83de4b
         fail_usage("Failed: send_post_request: " + str(e))