blob: ad4a3878358cbbc2b740bc7b2a390bfa464daf5f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
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()
|