Blame SOURCES/bz1470827-all-agents-log-exceptions-fail.patch

021bc5
From bf32059e26f6a7d019df0f7949ce66adf997bc21 Mon Sep 17 00:00:00 2001
021bc5
From: Oyvind Albrigtsen <oalbrigt@redhat.com>
021bc5
Date: Fri, 8 Feb 2019 14:16:31 +0100
021bc5
Subject: [PATCH] log exceptions to be more detailed when failing
021bc5
021bc5
---
021bc5
 agents/apc/fence_apc.py                   |  6 ++++--
021bc5
 agents/cisco_ucs/fence_cisco_ucs.py       |  3 ++-
021bc5
 agents/eps/fence_eps.py                   |  3 ++-
021bc5
 agents/ilo_moonshot/fence_ilo_moonshot.py |  3 ++-
021bc5
 agents/lpar/fence_lpar.py                 |  6 ++++--
021bc5
 agents/ovh/fence_ovh.py                   |  3 ++-
021bc5
 agents/sanbox2/fence_sanbox2.py           | 12 ++++++++----
021bc5
 agents/vmware_soap/fence_vmware_soap.py   |  9 ++++++---
021bc5
 8 files changed, 30 insertions(+), 15 deletions(-)
021bc5
021bc5
diff --git a/agents/apc/fence_apc.py b/agents/apc/fence_apc.py
021bc5
index 24a5a4232..dd0287f83 100644
021bc5
--- a/agents/apc/fence_apc.py
021bc5
+++ b/agents/apc/fence_apc.py
021bc5
@@ -90,7 +90,8 @@ def get_power_status(conn, options):
021bc5
 		try:
021bc5
 			(_, status) = outlets[options["--plug"]]
021bc5
 			return status.lower().strip()
021bc5
-		except KeyError:
021bc5
+		except KeyError as e:
021bc5
+			logging.error("Failed: {}".format(str(e)))
021bc5
 			fail(EC_STATUS)
021bc5
 
021bc5
 def set_power_status(conn, options):
021bc5
@@ -199,7 +200,8 @@ def get_power_status5(conn, options):
021bc5
 		try:
021bc5
 			(_, status) = outlets[options["--plug"]]
021bc5
 			return status.lower().strip()
021bc5
-		except KeyError:
021bc5
+		except KeyError as e:
021bc5
+			logging.error("Failed: {}".format(str(e)))
021bc5
 			fail(EC_STATUS)
021bc5
 
021bc5
 def set_power_status5(conn, options):
021bc5
diff --git a/agents/cisco_ucs/fence_cisco_ucs.py b/agents/cisco_ucs/fence_cisco_ucs.py
021bc5
index ec3117548..2280dbbc7 100644
021bc5
--- a/agents/cisco_ucs/fence_cisco_ucs.py
021bc5
+++ b/agents/cisco_ucs/fence_cisco_ucs.py
021bc5
@@ -174,7 +174,8 @@ def main():
021bc5
 		if result == None:
021bc5
 			## Cookie is absenting in response
021bc5
 			fail(EC_LOGIN_DENIED)
021bc5
-	except Exception:
021bc5
+	except Exception as e:
021bc5
+		logging.error("Failed: {}".format(str(e)))
021bc5
 		fail(EC_LOGIN_DENIED)
021bc5
 
021bc5
 	options_global["cookie"] = result.group(1)
021bc5
diff --git a/agents/eps/fence_eps.py b/agents/eps/fence_eps.py
021bc5
index 74c89b95b..f0df86231 100644
021bc5
--- a/agents/eps/fence_eps.py
021bc5
+++ b/agents/eps/fence_eps.py
021bc5
@@ -56,7 +56,8 @@ def eps_run_command(options, params):
021bc5
 		conn.close()
021bc5
 	except socket.timeout:
021bc5
 		fail(EC_TIMED_OUT)
021bc5
-	except socket.error:
021bc5
+	except socket.error as e:
021bc5
+		logging.error("Failed: {}".format(str(e)))
021bc5
 		fail(EC_LOGIN_DENIED)
021bc5
 
021bc5
 	return result
021bc5
diff --git a/agents/ilo_moonshot/fence_ilo_moonshot.py b/agents/ilo_moonshot/fence_ilo_moonshot.py
021bc5
index a066a9c91..6f5cca320 100644
021bc5
--- a/agents/ilo_moonshot/fence_ilo_moonshot.py
021bc5
+++ b/agents/ilo_moonshot/fence_ilo_moonshot.py
021bc5
@@ -21,7 +21,8 @@ def get_power_status(conn, options):
021bc5
 		try:
021bc5
 			(_, status) = nodes[options["--plug"]]
021bc5
 			return status.lower()
021bc5
-		except KeyError:
021bc5
+		except KeyError as e:
021bc5
+			logging.error("Failed: {}".format(str(e)))
021bc5
 			fail(EC_STATUS)
021bc5
 
021bc5
 def set_power_status(conn, options):
021bc5
diff --git a/agents/lpar/fence_lpar.py b/agents/lpar/fence_lpar.py
021bc5
index a16103733..66cb65e41 100644
021bc5
--- a/agents/lpar/fence_lpar.py
021bc5
+++ b/agents/lpar/fence_lpar.py
021bc5
@@ -37,7 +37,8 @@ def get_power_status(conn, options):
021bc5
 		try:
021bc5
 			status = re.compile("^" + options["--plug"] + ",(.*?),.*$",
021bc5
 					re.IGNORECASE | re.MULTILINE).search(conn.before).group(1)
021bc5
-		except AttributeError:
021bc5
+		except AttributeError as e:
021bc5
+			logging.error("Failed: {}".format(str(e)))
021bc5
 			fail(EC_STATUS_HMC)
021bc5
 	elif options["--hmc-version"] in ["4", "IVM"]:
021bc5
 		conn.send("lssyscfg -r lpar -m "+ options["--managed"] +
021bc5
@@ -49,7 +50,8 @@ def get_power_status(conn, options):
021bc5
 
021bc5
 		try:
021bc5
 			status = re.compile(",state=(.*?),", re.IGNORECASE).search(conn.before).group(1)
021bc5
-		except AttributeError:
021bc5
+		except AttributeError as e:
021bc5
+			logging.error("Failed: {}".format(str(e)))
021bc5
 			fail(EC_STATUS_HMC)
021bc5
 
021bc5
 	return _normalize_status(status)
021bc5
diff --git a/agents/ovh/fence_ovh.py b/agents/ovh/fence_ovh.py
021bc5
index f5403c54d..2b7eb864f 100644
021bc5
--- a/agents/ovh/fence_ovh.py
021bc5
+++ b/agents/ovh/fence_ovh.py
021bc5
@@ -66,7 +66,8 @@ def soap_login(options):
021bc5
 	try:
021bc5
 		soap = Client(url, doctor=d)
021bc5
 		session = soap.service.login(options["--username"], options["--password"], 'en', 0)
021bc5
-	except Exception:
021bc5
+	except Exception as e:
021bc5
+		logging.error("Failed: {}".format(str(e)))
021bc5
 		fail(EC_LOGIN_DENIED)
021bc5
 
021bc5
 	options["session"] = session
021bc5
diff --git a/agents/sanbox2/fence_sanbox2.py b/agents/sanbox2/fence_sanbox2.py
021bc5
index 679d1d983..179fe0e8b 100644
021bc5
--- a/agents/sanbox2/fence_sanbox2.py
021bc5
+++ b/agents/sanbox2/fence_sanbox2.py
021bc5
@@ -28,7 +28,8 @@ def get_power_status(conn, options):
021bc5
 			conn.send_eol("admin end")
021bc5
 			conn.send_eol("exit")
021bc5
 			conn.close()
021bc5
-		except Exception:
021bc5
+		except Exception as e:
021bc5
+			logging.error("Failed: {}".format(str(e)))
021bc5
 			pass
021bc5
 		fail(EC_TIMED_OUT)
021bc5
 
021bc5
@@ -54,7 +55,8 @@ def set_power_status(conn, options):
021bc5
 			conn.send_eol("admin end")
021bc5
 			conn.send_eol("exit")
021bc5
 			conn.close()
021bc5
-		except Exception:
021bc5
+		except Exception as e:
021bc5
+			logging.error("Failed: {}".format(str(e)))
021bc5
 			pass
021bc5
 		fail(EC_TIMED_OUT)
021bc5
 
021bc5
@@ -66,7 +68,8 @@ def set_power_status(conn, options):
021bc5
 			conn.send_eol("admin end")
021bc5
 			conn.send_eol("exit")
021bc5
 			conn.close()
021bc5
-		except Exception:
021bc5
+		except Exception as e:
021bc5
+			logging.error("Failed: {}".format(str(e)))
021bc5
 			pass
021bc5
 		fail(EC_TIMED_OUT)
021bc5
 
021bc5
@@ -91,7 +94,8 @@ def get_list_devices(conn, options):
021bc5
 			conn.send_eol("admin end")
021bc5
 			conn.send_eol("exit")
021bc5
 			conn.close()
021bc5
-		except Exception:
021bc5
+		except Exception as e:
021bc5
+			logging.error("Failed: {}".format(str(e)))
021bc5
 			pass
021bc5
 		fail(EC_TIMED_OUT)
021bc5
 
021bc5
diff --git a/agents/vmware_soap/fence_vmware_soap.py b/agents/vmware_soap/fence_vmware_soap.py
021bc5
index f2ab68b02..a7f08b3d6 100644
021bc5
--- a/agents/vmware_soap/fence_vmware_soap.py
021bc5
+++ b/agents/vmware_soap/fence_vmware_soap.py
021bc5
@@ -68,7 +68,8 @@ def soap_login(options):
021bc5
 		conn.service.Login(mo_SessionManager, options["--username"], options["--password"])
021bc5
 	except requests.exceptions.SSLError as ex:
021bc5
 		fail_usage("Server side certificate verification failed: %s" % ex)
021bc5
-	except Exception:
021bc5
+	except Exception as e:
021bc5
+		logging.error("Server side certificate verification failed: {}".format(str(e)))
021bc5
 		fail(EC_LOGIN_DENIED)
021bc5
 
021bc5
 	options["ServiceContent"] = ServiceContent
021bc5
@@ -126,7 +127,8 @@ def get_power_status(conn, options):
021bc5
 
021bc5
 	try:
021bc5
 		raw_machines = conn.service.RetrievePropertiesEx(mo_PropertyCollector, propFilterSpec)
021bc5
-	except Exception:
021bc5
+	except Exception as e:
021bc5
+		logging.error("Failed: {}".format(str(e)))
021bc5
 		fail(EC_STATUS)
021bc5
 
021bc5
 	(machines, uuid, mappingToUUID) = process_results(raw_machines, {}, {}, {})
021bc5
@@ -135,7 +137,8 @@ def get_power_status(conn, options):
021bc5
 	while hasattr(raw_machines, 'token'):
021bc5
 		try:
021bc5
 			raw_machines = conn.service.ContinueRetrievePropertiesEx(mo_PropertyCollector, raw_machines.token)
021bc5
-		except Exception:
021bc5
+		except Exception as e:
021bc5
+			logging.error("Failed: {}".format(str(e)))
021bc5
 			fail(EC_STATUS)
021bc5
 		(more_machines, more_uuid, more_mappingToUUID) = process_results(raw_machines, {}, {}, {})
021bc5
 		machines.update(more_machines)