Blame SOURCES/bz1827559-fence_vmware_rest-improve-exception-handling.patch

bf99d3
From 020f48a309bcad659dc493960d2b39e8e1243085 Mon Sep 17 00:00:00 2001
bf99d3
From: Thomas Abraham <tabraham@suse.com>
bf99d3
Date: Mon, 20 Apr 2020 20:28:43 -0400
bf99d3
Subject: [PATCH] fence_vmware_rest: improve exception handling in
bf99d3
 send_command()
bf99d3
bf99d3
If an exception occurs, simply raise it. pycurl's perform() method can
bf99d3
generate a pycurl.error object, which does not support indexing and
bf99d3
attempting to do so will generate an exception that hides the original
bf99d3
exception.
bf99d3
bf99d3
Also, don't assume that the remote will return a JSON formatted response.
bf99d3
If it doesn't, a exception will occur accessing result which will not
bf99d3
raise the intended exception.
bf99d3
---
bf99d3
 agents/vmware_rest/fence_vmware_rest.py | 8 ++++++--
bf99d3
 1 file changed, 6 insertions(+), 2 deletions(-)
bf99d3
bf99d3
diff --git a/agents/vmware_rest/fence_vmware_rest.py b/agents/vmware_rest/fence_vmware_rest.py
bf99d3
index d07bc10d..1505ffe6 100644
bf99d3
--- a/agents/vmware_rest/fence_vmware_rest.py
bf99d3
+++ b/agents/vmware_rest/fence_vmware_rest.py
bf99d3
@@ -124,7 +124,7 @@ def send_command(conn, command, method="GET"):
bf99d3
 	try:
bf99d3
 		conn.perform()
bf99d3
 	except Exception as e:
bf99d3
-		raise Exception(e[1])
bf99d3
+		raise(e)
bf99d3
 
bf99d3
 	rc = conn.getinfo(pycurl.HTTP_CODE)
bf99d3
 	result = web_buffer.getvalue().decode("UTF-8")
bf99d3
@@ -135,7 +135,11 @@ def send_command(conn, command, method="GET"):
bf99d3
 		result = json.loads(result)
bf99d3
 
bf99d3
 	if rc != 200:
bf99d3
-		raise Exception("{}: {}".format(rc, result["value"]["messages"][0]["default_message"]))
bf99d3
+		if len(result) > 0:
bf99d3
+			raise Exception("{}: {}".format(rc, 
bf99d3
+					result["value"]["messages"][0]["default_message"]))
bf99d3
+		else:
bf99d3
+			raise Exception("Remote returned {} for request to {}".format(rc, url))
bf99d3
 
bf99d3
 	logging.debug("url: {}".format(url))
bf99d3
 	logging.debug("method: {}".format(method))