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

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