public inbox for cluster-cvs@sourceware.org
help / color / mirror / Atom feed
* fence-agents: master - fence_agents: #487501 - Exceptions in fencing agents
@ 2009-03-16  9:47 Marek Grác
  0 siblings, 0 replies; 2+ messages in thread
From: Marek Grác @ 2009-03-16  9:47 UTC (permalink / raw)
  To: cluster-cvs-relay

Gitweb:        http://git.fedorahosted.org/git/fence-agents.git?p=fence-agents.git;a=commitdiff;h=15f6d084bb714086348d21f4ea84eebc6250c5a8
Commit:        15f6d084bb714086348d21f4ea84eebc6250c5a8
Parent:        39b9aad2b1f0a03738f72dc1c100dc88e5c66d71
Author:        Marek 'marx' Grac <mgrac@redhat.com>
AuthorDate:    Mon Mar 16 10:44:34 2009 +0100
Committer:     Marek 'marx' Grac <mgrac@redhat.com>
CommitterDate: Mon Mar 16 10:44:34 2009 +0100

fence_agents: #487501 - Exceptions in fencing agents

Fixing previous patch
---
 fence/agents/apc/fence_apc.py |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/fence/agents/apc/fence_apc.py b/fence/agents/apc/fence_apc.py
index 6707787..46e992f 100755
--- a/fence/agents/apc/fence_apc.py
+++ b/fence/agents/apc/fence_apc.py
@@ -68,7 +68,7 @@ def get_power_status(conn, options):
 			conn.send(options["-s"]+"\r\n")
 			
 		while True:
-			exp_result == conn.log_expect(options, [ options["-c"],  "Press <ENTER>" ], SHELL_TIMEOUT)
+			exp_result = conn.log_expect(options, [ options["-c"],  "Press <ENTER>" ], SHELL_TIMEOUT)
 			lines = conn.before.split("\n");
 			show_re = re.compile('^\s*(\d+)- (.*?)\s+(ON|OFF)\s*$')
 			for x in lines:


^ permalink raw reply	[flat|nested] 2+ messages in thread

* fence-agents: master - fence_agents: #487501 - Exceptions in fencing agents
@ 2009-03-13 14:42 Marek Grác
  0 siblings, 0 replies; 2+ messages in thread
From: Marek Grác @ 2009-03-13 14:42 UTC (permalink / raw)
  To: cluster-cvs-relay

Gitweb:        http://git.fedorahosted.org/git/fence-agents.git?p=fence-agents.git;a=commitdiff;h=871b325a3de336380b60f4570635f91f98c87c01
Commit:        871b325a3de336380b60f4570635f91f98c87c01
Parent:        5527e1cdacf43e47a7f84cb1f55be6b5a2a769e5
Author:        Marek 'marx' Grac <mgrac@redhat.com>
AuthorDate:    Fri Mar 13 15:36:56 2009 +0100
Committer:     Marek 'marx' Grac <mgrac@redhat.com>
CommitterDate: Fri Mar 13 15:39:56 2009 +0100

fence_agents: #487501 - 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.

Only bigger change is in APC. In other cases only catching exception was added.
---
 fence/agents/apc/fence_apc.py                 |   16 ++++++++++------
 fence/agents/bladecenter/fence_bladecenter.py |    5 ++++-
 fence/agents/ilo/fence_ilo.py                 |    2 ++
 fence/agents/lib/fencing.py.py                |    4 +++-
 fence/agents/lpar/fence_lpar.py               |   12 +++++++++---
 5 files changed, 28 insertions(+), 11 deletions(-)

diff --git a/fence/agents/apc/fence_apc.py b/fence/agents/apc/fence_apc.py
index ca5d2ac..6707787 100755
--- a/fence/agents/apc/fence_apc.py
+++ b/fence/agents/apc/fence_apc.py
@@ -25,7 +25,7 @@ BUILD_DATE="March, 2008"
 #END_VERSION_GENERATION
 
 def get_power_status(conn, options):
-	result = ""
+	exp_result = 0
 	outlets = {}
 	try:
 		conn.send("1\r\n")
@@ -67,8 +67,8 @@ def get_power_status(conn, options):
 		else:
 			conn.send(options["-s"]+"\r\n")
 			
-		while 1 == conn.log_expect(options, [ options["-c"],  "Press <ENTER>" ], SHELL_TIMEOUT):
-			result += conn.before
+		while True:
+			exp_result == conn.log_expect(options, [ options["-c"],  "Press <ENTER>" ], SHELL_TIMEOUT)
 			lines = conn.before.split("\n");
 			show_re = re.compile('^\s*(\d+)- (.*?)\s+(ON|OFF)\s*$')
 			for x in lines:
@@ -76,7 +76,8 @@ def get_power_status(conn, options):
 				if (res != None):
 					outlets[res.group(1)] = (res.group(2), res.group(3))
 			conn.send("\r\n")
-		result += conn.before
+			if exp_result == 0:
+				break
 		conn.send(chr(03))		
 		conn.log_expect(options, "- Logout", SHELL_TIMEOUT)
 		conn.log_expect(options, options["-c"], SHELL_TIMEOUT)
@@ -88,8 +89,11 @@ def get_power_status(conn, options):
 	if ["list", "monitor"].count(options["-o"]) == 1:
 		return outlets
 	else:
-		status = re.compile("\s*"+options["-n"]+"-.*(ON|OFF)", re.IGNORECASE).search(result).group(1)
-		return status.lower().strip()
+		try:
+			(_, status) = outlets[options["-n"]]
+			return status.lower().strip()
+		except KeyError:
+			fail(EC_STATUS)
 
 def set_power_status(conn, options):
 	action = {
diff --git a/fence/agents/bladecenter/fence_bladecenter.py b/fence/agents/bladecenter/fence_bladecenter.py
index a5da620..3e277e1 100644
--- a/fence/agents/bladecenter/fence_bladecenter.py
+++ b/fence/agents/bladecenter/fence_bladecenter.py
@@ -27,7 +27,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 13263d3..fafade1 100755
--- a/fence/agents/ilo/fence_ilo.py
+++ b/fence/agents/ilo/fence_ilo.py
@@ -93,6 +93,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 c6a5a33..e5473e1 100644
--- a/fence/agents/lib/fencing.py.py
+++ b/fence/agents/lib/fencing.py.py
@@ -26,6 +26,7 @@ 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"
@@ -304,7 +305,8 @@ def fail(error_code):
 		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_STATUS : "Failed: Unable to obtain correct plug status"
+		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 27fc4ad..2d03b14 100644
--- a/fence/agents/lpar/fence_lpar.py
+++ b/fence/agents/lpar/fence_lpar.py
@@ -30,7 +30,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")
@@ -39,8 +42,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


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2009-03-16  9:47 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-03-16  9:47 fence-agents: master - fence_agents: #487501 - Exceptions in fencing agents Marek Grác
  -- strict thread matches above, loose matches on Subject: below --
2009-03-13 14:42 Marek Grác

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).