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

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