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

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