fence-agents: master - fencing: Short options can be misinterpreted

Marek GrĂ¡c marx at fedoraproject.org
Wed Jan 7 13:41:06 UTC 2015


Gitweb:        http://git.fedorahosted.org/git/?p=fence-agents.git;a=commitdiff;h=60333a24b22438ba33184aa803eb2386fca0e0ad
Commit:        60333a24b22438ba33184aa803eb2386fca0e0ad
Parent:        f5401fc8dad9a39da0a279b7d55149dc0ebcba26
Author:        Marek 'marx' Grac <mgrac at redhat.com>
AuthorDate:    Wed Jan 7 14:11:13 2015 +0100
Committer:     Marek 'marx' Grac <mgrac at redhat.com>
CommitterDate: Wed Jan 7 14:11:13 2015 +0100

fencing: Short options can be misinterpreted

If there are several entries in all_opt that have same short getopt. It
is possible that they are handled incorrectly and they are stored under same
key in 'options' variable.

This update fixes this problem for cases when the other of all_opt entries should
not be present at all. E.g. -d is used for vmware_type and snmp_version, and they are
not allowed at same time.
---
 fence/agents/lib/fencing.py.py |    8 ++++++--
 1 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/fence/agents/lib/fencing.py.py b/fence/agents/lib/fencing.py.py
index 83bbfcd..9172782 100644
--- a/fence/agents/lib/fencing.py.py
+++ b/fence/agents/lib/fencing.py.py
@@ -1195,6 +1195,7 @@ def _parse_input_stdin(avail_opt):
 	return opt
 
 def _parse_input_cmdline(avail_opt):
+	filtered_opts = {}
 	(getopt_string, longopt_list) = _prepare_getopt_args(avail_opt)
 
 	try:
@@ -1202,12 +1203,15 @@ def _parse_input_cmdline(avail_opt):
 	except getopt.GetoptError, error:
 		fail_usage("Parse error: " + error.msg)
 
+	for opt in avail_opt:
+		filtered_opts.update({opt : all_opt[opt]})
+
 	# Short and long getopt names are changed to consistent "--" + long name (e.g. --username)
 	long_opts = {}
 	for arg_name in dict(entered_opt).keys():
-		all_key = [key for (key, value) in all_opt.items() \
+		all_key = [key for (key, value) in filtered_opts.items() \
 			if "--" + value.get("longopt", "") == arg_name or "-" + value.get("getopt", "").rstrip(":") == arg_name][0]
-		long_opts["--" + all_opt[all_key]["longopt"]] = dict(entered_opt)[arg_name]
+		long_opts["--" + filtered_opts[all_key]["longopt"]] = dict(entered_opt)[arg_name]
 
 	return long_opts
 


More information about the cluster-commits mailing list