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

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