fence-agents: master - fencing: SNMP fence agents don't fail

Jan Friesse honzaf at fedoraproject.org
Tue Mar 16 10:14:06 UTC 2010


Gitweb:        http://git.fedorahosted.org/git/fence-agents.git?p=fence-agents.git;a=commitdiff;h=fa9d0561d813b2d2002623e0aad665a5949fcc59
Commit:        fa9d0561d813b2d2002623e0aad665a5949fcc59
Parent:        928565680d90fea362c00a2883abc4d8578a4787
Author:        Jan Friesse <jfriesse at redhat.com>
AuthorDate:    Tue Mar 16 11:12:30 2010 +0100
Committer:     Jan Friesse <jfriesse at redhat.com>
CommitterDate: Tue Mar 16 11:12:30 2010 +0100

fencing: SNMP fence agents don't fail

Net-SNMP command-line utilities have interesting "feature"
causing too short pass-phrase (shorter then 8 characters)
write error but sadly, not return error code. In such case,
fencing can be considered successful even if it is not.

Patch fixes this by:
- Pass v3 options only for v3 mode
- Search for Error string in snmpcmd output
---
 fence/agents/lib/fencing_snmp.py.py |   13 +++++++++++--
 1 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/fence/agents/lib/fencing_snmp.py.py b/fence/agents/lib/fencing_snmp.py.py
index 94f5af5..4f55795 100644
--- a/fence/agents/lib/fencing_snmp.py.py
+++ b/fence/agents/lib/fencing_snmp.py.py
@@ -58,12 +58,20 @@ class FencingSnmp:
 		self.complete_missed_params()
 
 		#mapping from our option to snmpcmd option
-		mapping=(('d','v'), ('c','c'),('b','a'),('E','l'),('B','x'),('P','X'),('p','A'),('l','u'))
+		mapping=(('d','v'),('c','c'))
 
 		for item in mapping:
 			if (self.options.has_key("-"+item[0])):
 				cmd+=" -%s '%s'"%(item[1],self.quote_for_run(self.options["-"+item[0]]))
 
+		# Some options make sense only for v3 (and for v1/2c can cause "problems")
+		if (self.options.has_key("-d")) and (self.options["-d"] == "3"):
+			# Mapping from our options to snmpcmd options for v3
+			mapping_v3=(('b','a'),('E','l'),('B','x'),('P','X'),('p','A'),('l','u'))
+			for item in mapping_v3:
+				if (self.options.has_key("-"+item[0])):
+					cmd+=" -%s '%s'"%(item[1],self.quote_for_run(self.options["-"+item[0]]))
+
 		force_ipvx=""
 
 		if (self.options.has_key("-6")):
@@ -86,7 +94,8 @@ class FencingSnmp:
 				fail(EC_TIMED_OUT)
 
 			self.log_command(res_output)
-			if (res_code!=0):
+
+			if (res_code!=0) or (re.search("^Error ", res_output, re.MULTILINE) != None):
 				fail_usage("Returned %d: %s"%(res_code,res_output))
 		except pexpect.ExceptionPexpect:
 			fail_usage("Cannot run command %s"%(command))


More information about the cluster-commits mailing list