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

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