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