From 86ed03f8adee56c050c73018537371c230a664a6 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 08:50:17 +0200 Subject: Adding upstream version 4.12.1. Signed-off-by: Daniel Baumann --- lib/check_used_options.py | 68 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 lib/check_used_options.py (limited to 'lib/check_used_options.py') diff --git a/lib/check_used_options.py b/lib/check_used_options.py new file mode 100644 index 0000000..ad4a387 --- /dev/null +++ b/lib/check_used_options.py @@ -0,0 +1,68 @@ +## Check if fence agent uses only options["--??"] which are defined in fencing library or +## fence agent itself +## +## Usage: ./check_used_options.py fence-agent (e.g. lpar/fence_lpar.py) +## + +import sys, re +sys.path.append("@FENCEAGENTSLIBDIR@") +from fencing import all_opt + +def main(): + agent = sys.argv[1] + + available = {} + + ## all_opt from fencing library are imported + for k in list(all_opt.keys()): + if "longopt" in all_opt[k]: + available["--" + all_opt[k]["longopt"]] = True + + ## add UUID which is derived automatically from --plug if possible + available["--uuid"] = True + + ## all_opt defined in fence agent are found + agent_file = open(agent) + opt_re = re.compile(r"\s*all_opt\[\"([^\"]*)\"\] = {") + opt_longopt_re = re.compile(r"\"longopt\"\s*:\s*\"([^\"]*)\"") + + in_opt = False + for line in agent_file: + if opt_re.search(line) != None: + in_opt = True + if in_opt and opt_longopt_re.search(line) != None: + available["--" + opt_longopt_re.search(line).group(1)] = True + in_opt = False + + ## check if all options are defined + agent_file = open(agent) + option_use_re = re.compile(r"options\[\"(-[^\"]*)\"\]") + option_in_re = re.compile(r"\"(-[^\"]*)\" in options") + option_has_re = re.compile(r"options.has_key\(\"(-[^\"]*)\"\)") + + counter = 0 + without_errors = True + for line in agent_file: + counter += 1 + + for option in option_use_re.findall(line): + if option not in available: + print("ERROR on line %d in %s: option %s is not defined" % (counter, agent, option_use_re.search(line).group(1))) + without_errors = False + + for option in option_in_re.findall(line): + if option not in available: + print("ERROR on line %d in %s: option %s is not defined" % (counter, agent, option_has_re.search(line).group(1))) + without_errors = False + + for option in option_has_re.findall(line): + print("ERROR on line %d in %s: option %s: has_key() not supported in Python 3" % (counter, agent, option_has_re.search(line).group(1))) + without_errors = False + + if without_errors: + sys.exit(0) + else: + sys.exit(1) + +if __name__ == "__main__": + main() -- cgit v1.2.3