cluster-devel.redhat.com archive mirror
 help / color / mirror / Atom feed
* [Cluster-devel] [PATCH] Autodetect EOL in fence agents
@ 2012-05-09  8:37 Marek 'marx' Grac
  0 siblings, 0 replies; only message in thread
From: Marek 'marx' Grac @ 2012-05-09  8:37 UTC (permalink / raw)
  To: cluster-devel.redhat.com

Fence agents diffes in EOL they accept. EOL \r\n is quite universal but in some cases
it is translated to \n\n what makes login process impossible to complete as it ends like
(capitals are fence agent response)

Login: USER\n
Password: \n

Login: PASSWORD\n

Until now there was a device option that handles that login_eol_lf but we found out that there are few
APC devices which does not work correctly with \r\n and needs \n. So we have to autodetect it, this feature was
added to standard library. As it can also helps with common problem when you have to write exactly
conn.send("message" + "\r\n"). Method conn.sendline("") uses EOL according to platform, so we have decided to create
new method conn.sendxline (need a better name) which uses correct EOL. We need conn.sendline in communication with other local
application so we should not reuse it for this purpose.
---
 fence/agents/lib/fencing.py.py |   37 +++++++++++++++++++++++--------------
 1 files changed, 23 insertions(+), 14 deletions(-)

diff --git a/fence/agents/lib/fencing.py.py b/fence/agents/lib/fencing.py.py
index 5748391..a61c45f 100644
--- a/fence/agents/lib/fencing.py.py
+++ b/fence/agents/lib/fencing.py.py
@@ -175,11 +175,6 @@ all_opt = {
 		"required" : "0",
 		"shortdesc" : "Force ribcl version to use",
 		"order" : 1 },
-	"login_eol_lf" : {
-		"getopt" : "",
-		"help" : "",
-		"order" : 1
-		},
 	"cmd_prompt" : {
 		"getopt" : "c:",
 		"longopt" : "command-prompt",
@@ -407,12 +402,20 @@ all_opt = {
 common_opt = [ "retry_on", "delay" ]
 
 class fspawn(pexpect.spawn):
+	def __init__(self, options, command):
+		pexpect.spawn.__init__(self, command)
+		self.opt = options
+		
 	def log_expect(self, options, pattern, timeout):
 		result = self.expect(pattern, timeout)
 		if options["log"] >= LOG_MODE_VERBOSE:
 			options["debug_fh"].write(self.before + self.after)
 		return result
 
+	# send EOL according to what was detected in login process (telnet)
+	def sendxline(self, message):
+		self.send(message + self.opt["eol"])
+
 def atexit_handler():
 	try:
 		sys.stdout.close()
@@ -864,10 +867,7 @@ def fence_login(options):
 	if (options.has_key("-4")):
 		force_ipvx="-4 "
 
-	if (options["device_opt"].count("login_eol_lf")):
-		login_eol = "\n"
-	else:
-		login_eol = "\r\n"
+	options["eol"] = "\r\n"
 
 	## Do the delay of the fence device before logging in
 	## Delay is important for two-node clusters fencing but we do not need to delay 'status' operations
@@ -939,7 +939,7 @@ def fence_login(options):
 					fail_usage("Failed: You have to enter passphrase (-p) for identity file")
 		else:
 			try:
-				conn = fspawn(TELNET_PATH)
+				conn = fspawn(options, TELNET_PATH)
 				conn.send("set binary\n")
 				conn.send("open %s -%s\n"%(options["-a"], options["-u"]))
 			except pexpect.ExceptionPexpect, ex:
@@ -948,11 +948,20 @@ def fence_login(options):
 				"are not in the spec file and must be installed separately." + "\n")
 				sys.exit(EC_GENERIC_ERROR)
 
-			conn.log_expect(options, re_login, int(options["-y"]))
-			conn.send(options["-l"] + login_eol)
-			conn.log_expect(options, re_pass, int(options["-Y"]))
+			result = conn.log_expect(options, re_login, int(options["-y"]))
+			conn.sendxline(options["-l"])
+
+			## automatically change end of line separator
+			screen = conn.read_nonblocking(size=100, timeout=int(options["-Y"]))
+			if (re_login.search(screen) != None):
+				options["eol"] = "\n"
+				conn.sendxline(options["-l"])
+				result = conn.log_expect(options, re_pass, int(options["-y"]))
+			elif (re_pass.search(screen) == None):
+				conn.log_expect(options, re_pass, int(options["-Y"]))
+
 			try:
-				conn.send(options["-p"] + login_eol)
+				conn.sendxline(options["-p"])
 				conn.log_expect(options, options["-c"], int(options["-Y"]))
 			except KeyError:
 				fail(EC_PASSWORD_MISSING)
-- 
1.7.7.6



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

only message in thread, other threads:[~2012-05-09  8:37 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-05-09  8:37 [Cluster-devel] [PATCH] Autodetect EOL in fence agents Marek 'marx' Grac

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 NNTP newsgroup(s).