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

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