File fence_vmware_rest-improve-exception-handling-in-send_command.patch of Package fence-agents.14952

From 021a8d04ee1580e4f3a2e8ce8c32832b8cc7e795 Mon Sep 17 00:00:00 2001
From: Thomas Abraham <tabraham@suse.com>
Date: Mon, 20 Apr 2020 20:28:43 -0400
Subject: [PATCH] fence_vmware_rest: improve exception handling in
 send_command()

If an exception occurs, simply raise it. pycurl's perform() method can
generate a pycurl.error object, which does not support indexing and
attempting to do so will generate an exception that hides the original
exception.

Also, don't assume that the remote will return a JSON formatted response.
If it doesn't, a exception will occur accessing result which will not
raise the intended exception.
---
 agents/vmware_rest/fence_vmware_rest.py | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/agents/vmware_rest/fence_vmware_rest.py b/agents/vmware_rest/fence_vmware_rest.py
index b544d385..755d3e52 100644
--- a/agents/vmware_rest/fence_vmware_rest.py
+++ b/agents/vmware_rest/fence_vmware_rest.py
@@ -109,7 +109,7 @@ def send_command(conn, command, method="GET"):
 	try:
 		conn.perform()
 	except Exception as e:
-		raise Exception(e[1])
+		raise(e)
 
 	rc = conn.getinfo(pycurl.HTTP_CODE)
 	result = web_buffer.getvalue().decode()
@@ -120,7 +120,11 @@ def send_command(conn, command, method="GET"):
 		result = json.loads(result)
 
 	if rc != 200:
-		raise Exception("{}: {}".format(rc, result["value"]["messages"][0]["default_message"]))
+		if len(result) > 0:
+			raise Exception("{}: {}".format(rc, 
+					result["value"]["messages"][0]["default_message"]))
+		else:
+			raise Exception("Remote returned {} for request to {}".format(rc, url))
 
 	logging.debug("url: {}".format(url))
 	logging.debug("method: {}".format(method))
-- 
2.25.0

openSUSE Build Service is sponsored by