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

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