This is the mail archive of the cluster-cvs@sourceware.org mailing list for the cluster.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

cluster: RHEL4 - fence_agents: #489670 - Exceptions in fencing agents


Gitweb:        http://git.fedorahosted.org/git/cluster.git?p=cluster.git;a=commitdiff;h=45e6691b0096275e138568ce1e4b934b4ba0573c
Commit:        45e6691b0096275e138568ce1e4b934b4ba0573c
Parent:        1e89c485ec2de1f91727569ba3230b36b26034d3
Author:        Marek 'marx' Grac <mgrac@redhat.com>
AuthorDate:    Fri Mar 13 15:57:17 2009 +0100
Committer:     Marek 'marx' Grac <mgrac@redhat.com>
CommitterDate: Fri Mar 13 16:07:35 2009 +0100

fence_agents: #489670 - Exceptions in fencing agents

Several of new fencing agent does not work when bad options are entered (bad
password, non-existent outlet number, ...). This is not a problem.
Unfortunately python exceptions are thrown and we don't care about catching
them. Such output is very usefull for debugging (as people tends to send it)
but it will be better if the user will see that the error is in the input data

There should be no changes to code itself, only exception handling was added.
---
 fence/agents/apc/fence_apc.py                 |    6 +++++-
 fence/agents/bladecenter/fence_bladecenter.py |    5 ++++-
 fence/agents/ilo/fence_ilo.py                 |    2 ++
 fence/agents/lib/fencing.py.py                |    6 +++++-
 fence/agents/lpar/fence_lpar.py               |   12 +++++++++---
 5 files changed, 25 insertions(+), 6 deletions(-)

diff --git a/fence/agents/apc/fence_apc.py b/fence/agents/apc/fence_apc.py
index 4ac8be9..e069a97 100755
--- a/fence/agents/apc/fence_apc.py
+++ b/fence/agents/apc/fence_apc.py
@@ -79,7 +79,11 @@ def get_power_status(conn, options):
 	except pexpect.TIMEOUT:
 		fail(EC_TIMED_OUT)
 
-	status = re.compile("\s*"+options["-n"]+"-.*(ON|OFF)", re.IGNORECASE).search(result).group(1)
+	try:
+		status = re.compile("\s*"+options["-n"]+"-.*(ON|OFF)", re.IGNORECASE).search(result).group(1)
+	except AttributeError:
+		fail(EC_STATUS)
+
 	return status.lower().strip()
 
 def set_power_status(conn, options):
diff --git a/fence/agents/bladecenter/fence_bladecenter.py b/fence/agents/bladecenter/fence_bladecenter.py
index ff7ad67..9fdfe97 100755
--- a/fence/agents/bladecenter/fence_bladecenter.py
+++ b/fence/agents/bladecenter/fence_bladecenter.py
@@ -28,7 +28,10 @@ def get_power_status(conn, options):
 		node_cmd = "system:blade\[" + options["-n"] + "\]>"
 
 		conn.send("env -T system:blade[" + options["-n"] + "]\r\n")
-		conn.log_expect(options, node_cmd, SHELL_TIMEOUT)
+		i = conn.log_expect(options, [ node_cmd, "system>" ] , SHELL_TIMEOUT)
+		if i == 1:
+			## Given blade number does not exist
+			fail(EC_STATUS)
 		conn.send("power -state\r\n")
 		conn.log_expect(options, node_cmd, SHELL_TIMEOUT)
 		status = conn.before.splitlines()[-1]
diff --git a/fence/agents/ilo/fence_ilo.py b/fence/agents/ilo/fence_ilo.py
index 3cada5e..6513e2a 100755
--- a/fence/agents/ilo/fence_ilo.py
+++ b/fence/agents/ilo/fence_ilo.py
@@ -92,6 +92,8 @@ def main():
 		conn.send("</LOGIN>\r\n")
 	except pexpect.TIMEOUT:
 		fail(EC_LOGIN_DENIED)
+	except pexpect.EOF:
+		fail(EC_LOGIN_DENIED)
 
 	##
 	## Fence operations
diff --git a/fence/agents/lib/fencing.py.py b/fence/agents/lib/fencing.py.py
index c187b4a..461edb2 100644
--- a/fence/agents/lib/fencing.py.py
+++ b/fence/agents/lib/fencing.py.py
@@ -28,6 +28,8 @@ EC_CONNECTION_LOST = 4
 EC_TIMED_OUT       = 5
 EC_WAITING_ON      = 6
 EC_WAITING_OFF     = 7
+EC_STATUS          = 8
+EC_STATUS_HMC      = 9
 
 TELNET_PATH = "/usr/bin/telnet"
 SSH_PATH    = "/usr/bin/ssh"
@@ -166,7 +168,9 @@ def fail(error_code):
 		EC_CONNECTION_LOST : "Connection lost",
 		EC_TIMED_OUT : "Connection timed out",
 		EC_WAITING_ON : "Failed: Timed out waiting to power ON",
-		EC_WAITING_OFF : "Failed: Timed out waiting to power OFF"
+		EC_WAITING_OFF : "Failed: Timed out waiting to power OFF",
+ 		EC_STATUS : "Failed: Unable to obtain correct plug status or plug is not available",
+ 		EC_STATUS_HMC : "Failed: Either unable to obtaion correct plug status, partition is not available or incorrect HMC version used"	
 	}[error_code] + "\n"
 	sys.stderr.write(message)
 	sys.exit(error_code)
diff --git a/fence/agents/lpar/fence_lpar.py b/fence/agents/lpar/fence_lpar.py
index d0664eb..450b507 100755
--- a/fence/agents/lpar/fence_lpar.py
+++ b/fence/agents/lpar/fence_lpar.py
@@ -31,7 +31,10 @@ def get_power_status(conn, options):
 		except pexpect.TIMEOUT:
 			fail(EC_TIMED_OUT)
 
-		status = re.compile("^" + options["-n"] + ",(.*?),.*$", re.IGNORECASE | re.MULTILINE).search(conn.before).group(1)
+		try:
+			status = re.compile("^" + options["-n"] + ",(.*?),.*$", re.IGNORECASE | re.MULTILINE).search(conn.before).group(1)
+		except AttributeError:
+			fail(EC_STATUS_HMC)
 	elif options["-H"] == "4":
 		try:
 			conn.send("lssyscfg -r lpar -m "+ options["-s"] +" --filter 'lpar_names=" + options["-n"] + "'\n")
@@ -40,8 +43,11 @@ def get_power_status(conn, options):
 			fail(EC_CONNECTION_LOST)
 		except pexpect.TIMEOUT:
 			fail(EC_TIMED_OUT)
-				
-		status = re.compile(",state=(.*?),", re.IGNORECASE).search(conn.before).group(1)
+
+		try:				
+			status = re.compile(",state=(.*?),", re.IGNORECASE).search(conn.before).group(1)
+		except AttributeError:
+			fail(EC_STATUS_HMC)
 
 	##
 	## Transformation to standard ON/OFF status if possible


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]