public inbox for cluster-cvs@sourceware.org
help / color / mirror / Atom feed
* cluster: RHEL55 - fence_wti: #508262 - Fence agent ends with traceback when option is missing
@ 2009-08-31 16:02 Marek Grác
  0 siblings, 0 replies; only message in thread
From: Marek Grác @ 2009-08-31 16:02 UTC (permalink / raw)
  To: cluster-cvs-relay

Gitweb:        http://git.fedorahosted.org/git/cluster.git?p=cluster.git;a=commitdiff;h=0b53674b0634755fe041e6e8fbd00780ca5c8791
Commit:        0b53674b0634755fe041e6e8fbd00780ca5c8791
Parent:        48dea103eae0f4e963d295e21c242cb104d35d65
Author:        Marek 'marx' Grac <mgrac@redhat.com>
AuthorDate:    Mon Aug 31 17:09:57 2009 +0200
Committer:     Marek 'marx' Grac <mgrac@redhat.com>
CommitterDate: Mon Aug 31 17:09:57 2009 +0200

fence_wti: #508262 - Fence agent ends with traceback when option is missing

Login name/password are NOT required for WTI, so they have to be checked after
login/password is encountered. Similar problem exists for APC.
---
 fence/agents/apc/fence_apc.py |   16 ++++++++--------
 fence/agents/wti/fence_wti.py |   14 ++++++++++----
 2 files changed, 18 insertions(+), 12 deletions(-)

diff --git a/fence/agents/apc/fence_apc.py b/fence/agents/apc/fence_apc.py
index 447d589..ac272fa 100755
--- a/fence/agents/apc/fence_apc.py
+++ b/fence/agents/apc/fence_apc.py
@@ -26,7 +26,7 @@ BUILD_DATE=""
 #END_VERSION_GENERATION
 
 def get_power_status(conn, options):
-	result = ""
+	exp_result = 0
 	outlets = {}
 	try:
 		conn.send("1\r\n")
@@ -68,8 +68,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:
@@ -77,7 +77,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)
@@ -90,12 +91,11 @@ def get_power_status(conn, options):
 		return outlets
 	else:
 		try:
-			status = re.compile("\s*"+options["-n"]+"-.*(ON|OFF)", re.IGNORECASE).search(result).group(1)
-		except AttributeError:
+			(_, status) = outlets[options["-n"]]
+			return status.lower().strip()
+		except KeyError:
 			fail(EC_STATUS)
 
-		return status.lower().strip()
-
 def set_power_status(conn, options):
 	action = {
 		'on' : "1",
diff --git a/fence/agents/wti/fence_wti.py b/fence/agents/wti/fence_wti.py
index 062e1a5..79024ae 100755
--- a/fence/agents/wti/fence_wti.py
+++ b/fence/agents/wti/fence_wti.py
@@ -102,12 +102,18 @@ def main():
 
 			result = conn.log_expect(options, [ re_login, "Password: ", re_prompt ], SHELL_TIMEOUT)
 			if result == 0:
-				conn.send(options["-l"]+"\r\n")
-				result = conn.log_expect(options, [ re_login, "Password: ", re_prompt ], SHELL_TIMEOUT)
+				if options.has_key("-l"):
+					conn.send(options["-l"]+"\r\n")
+					result = conn.log_expect(options, [ re_login, "Password: ", re_prompt ], SHELL_TIMEOUT)
+				else:
+					fail_usage("Failed: You have to set login name")
 		
 			if result == 1:
-				conn.send(options["-p"]+"\r\n")
-				conn.log_expect(options, options["-c"], SHELL_TIMEOUT)	
+				if options.has_key("-p"):
+					conn.send(options["-p"]+"\r\n")
+					conn.log_expect(options, options["-c"], SHELL_TIMEOUT)	
+				else:
+					fail_usage("Failed: You have to enter password or password script")
 		except pexpect.EOF:
 			fail(EC_LOGIN_DENIED) 
 		except pexpect.TIMEOUT:


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2009-08-31 16:02 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-08-31 16:02 cluster: RHEL55 - fence_wti: #508262 - Fence agent ends with traceback when option is missing 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).