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

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