commit 78e7ffd2488b53e627482e78d9f7a23d0b4ba514 Author: Jan Friesse <jfriesse@redhat.com> Date: Tue Mar 16 13:43:06 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 RHBZ#573834 diff --git a/fence/agents/lib/fencing_snmp.py.py b/fence/agents/lib/fencing_snmp.py.py index 1519457..1146222 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))