cluster: STABLE3 - fencing: Fencing fails if telnet/ssh is not available

Marek Grác marx@fedoraproject.org
Mon Jul 20 14:56:00 GMT 2009


Gitweb:        http://git.fedorahosted.org/git/cluster.git?p=cluster.git;a=commitdiff;h=11996d184948d4becf3de29568ea1520e24b2cc3
Commit:        11996d184948d4becf3de29568ea1520e24b2cc3
Parent:        abfc1f6194474c3d218e340c7c3bf1a8d246fcdb
Author:        Marek 'marx' Grac <mgrac@redhat.com>
AuthorDate:    Mon Jul 20 16:51:23 2009 +0200
Committer:     Marek 'marx' Grac <mgrac@redhat.com>
CommitterDate: Mon Jul 20 16:51:23 2009 +0200

fencing: Fencing fails if telnet/ssh is not available

bz#512343
---
 fence/agents/lib/fencing.py.py |   39 ++++++++++++++++++++++++++++++++-------
 fence/agents/wti/fence_wti.py  |    9 ++++++++-
 2 files changed, 40 insertions(+), 8 deletions(-)

diff --git a/fence/agents/lib/fencing.py.py b/fence/agents/lib/fencing.py.py
index bd4c114..6a2e8b3 100644
--- a/fence/agents/lib/fencing.py.py
+++ b/fence/agents/lib/fencing.py.py
@@ -19,6 +19,7 @@ LOGIN_TIMEOUT = 5
 LOG_MODE_VERBOSE = 100
 LOG_MODE_QUIET = 0
 
+EC_GENERIC_ERROR   = 1
 EC_BAD_ARGS        = 2
 EC_LOGIN_DENIED    = 3
 EC_CONNECTION_LOST = 4
@@ -706,13 +707,24 @@ def fence_login(options):
 
 		if options.has_key("-z"):
 			command = '%s %s %s %s' % (SSL_PATH, force_ipvx, options["-a"], options["-u"])
-			conn = fspawn(command)
+			try:
+				conn = fspawn(command)
+			except pexpect.ExceptionPexpect, ex:
+			 	## SSL telnet is part of the fencing package
+			 	sys.stderr.write(str(ex) + "\n")
+			 	sys.exit(EC_GENERIC_ERROR)
 		elif options.has_key("-x") and 0 == options.has_key("-k"):
 			command = '%s %s %s@%s -p %s' % (SSH_PATH, force_ipvx, options["-l"], options["-a"], options["-u"])
 			if options.has_key("ssh_options"):
 				command += ' ' + options["ssh_options"]
-			conn = fspawn(command)
-
+			try:
+				conn = fspawn(command)
+			except pexpect.ExceptionPexpect, ex:
+				sys.stderr.write(str(ex) + "\n")
+				sys.stderr.write("Due to limitations, binary dependencies on fence agents "
+				"are not in the spec file and must be installed separately." + "\n")
+				sys.exit(EC_GENERIC_ERROR)
+				
 			if options.has_key("telnet_over_ssh"):
 				#This is for stupid ssh servers (like ALOM) which behave more like telnet (ignore name and display login prompt)
 				result = conn.log_expect(options, [ re_login, "Are you sure you want to continue connecting (yes/no)?" ], LOGIN_TIMEOUT)
@@ -734,7 +746,13 @@ def fence_login(options):
 			command = '%s %s %s@%s -i %s -p %s' % (SSH_PATH, force_ipvx, options["-l"], options["-a"], options["-k"], options["-u"])
 			if options.has_key("ssh_options"):
 				command += ' ' + options["ssh_options"]
-			conn = fspawn(command)
+			try:
+				conn = fspawn(command)
+			except pexpect.ExceptionPexpect, ex:
+				sys.stderr.write(str(ex) + "\n")
+				sys.stderr.write("Due to limitations, binary dependencies on fence agents "
+				"are not in the spec file and must be installed separately." + "\n")
+				sys.exit(EC_GENERIC_ERROR)
 
 			result = conn.log_expect(options, [ options["-c"], "Are you sure you want to continue connecting (yes/no)?", "Enter passphrase for key '"+options["-k"]+"':" ], LOGIN_TIMEOUT)
 			if result == 1:
@@ -747,9 +765,16 @@ def fence_login(options):
 				else:
 					fail_usage("Failed: You have to enter passphrase (-p) for identity file")
 		else:
-			conn = fspawn(TELNET_PATH)
-			conn.send("set binary\n")
-			conn.send("open %s -%s\n"%(options["-a"], options["-u"]))
+			try:
+				conn = fspawn(TELNET_PATH)
+				conn.send("set binary\n")
+				conn.send("open %s -%s\n"%(options["-a"], options["-u"]))
+			except pexpect.ExceptionPexpect, ex:
+				sys.stderr.write(str(ex) + "\n")
+				sys.stderr.write("Due to limitations, binary dependencies on fence agents "
+				"are not in the spec file and must be installed separately." + "\n")
+				sys.exit(EC_GENERIC_ERROR)
+
 			conn.log_expect(options, re_login, LOGIN_TIMEOUT)
 			conn.send(options["-l"]+"\r\n")
 			conn.log_expect(options, re_pass, SHELL_TIMEOUT)
diff --git a/fence/agents/wti/fence_wti.py b/fence/agents/wti/fence_wti.py
index 13c6b52..5326e6d 100644
--- a/fence/agents/wti/fence_wti.py
+++ b/fence/agents/wti/fence_wti.py
@@ -97,7 +97,14 @@ def main():
 	#####	
 	if 0 == options.has_key("-x"):
 		try:
-			conn = fspawn ('telnet ' + options["-a"])
+			try:
+				conn = fspawn('%s %s' % (TELNET_PATH, options["-a"]))
+			except pexpect.ExceptionPexpect, ex:
+				sys.stderr.write(str(ex) + "\n")
+				sys.stderr.write("Due to limitations, binary dependencies on fence agents "
+				"are not in the spec file and must be installed separately." + "\n")
+				sys.exit(EC_GENERIC_ERROR)
+			
 			re_login = re.compile("(login: )|(Login Name:  )|(username: )|(User Name :)", re.IGNORECASE)
 			re_prompt = re.compile("|".join(map (lambda x: "(" + x + ")", options["-c"])), re.IGNORECASE)
 



More information about the Cluster-cvs mailing list