Blame SOURCES/bz1666914-2-fence_redfish-fail-invalid-cert.patch

674a4f
From 7aa3c50d1d02dd26bdeac99c49ada72f842d88e8 Mon Sep 17 00:00:00 2001
674a4f
From: Oyvind Albrigtsen <oalbrigt@redhat.com>
674a4f
Date: Thu, 17 Jan 2019 16:52:52 +0100
674a4f
Subject: [PATCH] fence_redfish: fail when using invalid cert without
674a4f
 --ssl-insecure
674a4f
674a4f
---
674a4f
 agents/redfish/fence_redfish.py | 16 ++++++++++------
674a4f
 1 file changed, 10 insertions(+), 6 deletions(-)
674a4f
674a4f
diff --git a/agents/redfish/fence_redfish.py b/agents/redfish/fence_redfish.py
674a4f
index 67ef67ab..5b719d4b 100644
674a4f
--- a/agents/redfish/fence_redfish.py
674a4f
+++ b/agents/redfish/fence_redfish.py
674a4f
@@ -6,6 +6,7 @@
674a4f
 
674a4f
 import sys
674a4f
 import re
674a4f
+import logging
674a4f
 import json
674a4f
 import requests
674a4f
 import atexit
674a4f
@@ -20,6 +21,9 @@ def get_power_status(conn, options):
674a4f
     if response['ret'] is False:
674a4f
         fail_usage("Couldn't get power information")
674a4f
     data = response['data']
674a4f
+
674a4f
+    logging.debug("PowerState is: " + data[u'PowerState'])
674a4f
+
674a4f
     if data[u'PowerState'].strip() == "Off":
674a4f
         return "off"
674a4f
     else:
674a4f
@@ -50,21 +54,21 @@ def set_power_status(conn, options):
674a4f
 def send_get_request(options, uri):
674a4f
     full_uri = "https://" + options["--ip"] + uri
674a4f
     try:
674a4f
-        resp = requests.get(full_uri, verify=False,
674a4f
+        resp = requests.get(full_uri, verify=not "--ssl-insecure" in options,
674a4f
                             auth=(options["--username"], options["--password"]))
674a4f
         data = resp.json()
674a4f
-    except:
674a4f
-        return {'ret': False}
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
     full_uri = "https://" + options["--ip"] + uri
674a4f
     try:
674a4f
         requests.post(full_uri, data=json.dumps(payload),
674a4f
-                      headers=headers, verify=False,
674a4f
+                      headers=headers, verify=not "--ssl-insecure" in options,
674a4f
                       auth=(options["--username"], options["--password"]))
674a4f
-    except:
674a4f
-        return {'ret': False}
674a4f
+    except Exception as e:
674a4f
+        fail_usage("Failed: send_post_request: " + str(e))
674a4f
     return {'ret': True}
674a4f
 
674a4f
 def find_systems_resource(options):