diff options
author | Linus Nordberg <linus@nordu.net> | 2017-03-09 15:17:58 +0100 |
---|---|---|
committer | Linus Nordberg <linus@nordu.net> | 2017-03-09 15:17:58 +0100 |
commit | 863ef44a16759501c7ce939e93bf2891a552b2e3 (patch) | |
tree | 0fc28971759e60a044425d6d3f45ccfb596ed2e0 /tools/compileconfig.py | |
parent | 221c6771035d7a3c1e0441a46248a44ca2e99077 (diff) | |
parent | a08cb72fa60bdb11873a2409c3b5aa8ff2b4667d (diff) |
Merge remote-tracking branch 'refs/remotes/map/refactor-tests'
Diffstat (limited to 'tools/compileconfig.py')
-rwxr-xr-x | tools/compileconfig.py | 66 |
1 files changed, 42 insertions, 24 deletions
diff --git a/tools/compileconfig.py b/tools/compileconfig.py index 6ecfcad..d5a22df 100755 --- a/tools/compileconfig.py +++ b/tools/compileconfig.py @@ -434,7 +434,27 @@ def gen_config(nodename, config, localconfig): plopconfigfile.close() -def gen_testmakefile(config, testmakefile, machines, shellvars=False): +def print_nodevar(configfile, delimiter, nodetype, bootname, names, testaddresses, gennodes=True, gentesturl=True): + if gennodes: + print >>configfile, nodetype + "NODES=" + delimiter + " ".join(['%s:%s' % (name, bootname) for name in names]) + delimiter + for name in names: + print >>configfile, name.upper().replace("-", "_") + "ONLY" + "NODES=" + delimiter + '%s:%s' % (name, bootname) + delimiter + if gentesturl: + print >>configfile, name.upper().replace("-", "_") + "ONLY" + "TESTURLS=" + delimiter + " ".join(testaddresses[name]) + delimiter + else: + print >>configfile, nodetype + "NODES=" + delimiter + delimiter + if gentesturl: + print >>configfile, nodetype + "TESTURLS=" + delimiter + " ".join([address for name in names for address in testaddresses[name]]) + delimiter + else: + print >>configfile, nodetype + "TESTURLS=" + delimiter + delimiter + +def multivaldict(dictlist): + d = {} + for (key, value) in dictlist: + d.setdefault(key, []).append(value) + return d + +def gen_testmakefile(config, testmakefile, shellvars=False): configfile = open(testmakefile, "w") print >>configfile, "#", testmakefile, "generated by", sys.argv[0], datetime.now() @@ -444,27 +464,26 @@ def gen_testmakefile(config, testmakefile, machines, shellvars=False): mergenodenames = set([node["name"] for node in config["mergenodes"]]) mergesecondarynodenames = set([node["name"] for node in config["mergenodes"] if node["name"] != config["primarymergenode"]]) - frontendnodeaddresses = [node["publicaddress"] for node in config["frontendnodes"]] - storagenodeaddresses = [node["address"] for node in config["storagenodes"]] - signingnodeaddresses = [node["address"] for node in config["signingnodes"]] - mergesecondarynodeaddresses = [node["address"] for node in config["mergenodes"] if node["name"] != config["primarymergenode"]] + frontendnodenames_except_last = sorted(frontendnodenames)[:-1] + frontendnodenames_except_first = sorted(frontendnodenames)[1:] + + allnodes = config["frontendnodes"] + config["storagenodes"] + config["signingnodes"] + config["mergenodes"] + testaddresses = multivaldict([(node["name"], node["address"]) for node in allnodes]) + delimiter = '"' if shellvars else '' + + print_nodevar(configfile, delimiter, "FRONTEND", "catlfish", frontendnodenames, testaddresses) + print_nodevar(configfile, delimiter, "FRONTENDEXCEPTLAST", "catlfish", frontendnodenames_except_last, testaddresses) + print_nodevar(configfile, delimiter, "FRONTENDEXCEPTFIRST", "catlfish", frontendnodenames_except_first, testaddresses) + print_nodevar(configfile, delimiter, "STORAGE", "catlfish", storagenodenames, testaddresses, gennodes=False) + print_nodevar(configfile, delimiter, "SIGNING", "catlfish", signingnodenames, testaddresses) + print_nodevar(configfile, delimiter, "MERGESECONDARY", "catlfish", mergesecondarynodenames, testaddresses) + print_nodevar(configfile, delimiter, "MERGEPRIMARY", "merge", [config["primarymergenode"]], testaddresses, gentesturl=False) - print >>configfile, "NODES=" + delimiter + " ".join(frontendnodenames|storagenodenames|signingnodenames|mergenodenames) + delimiter - - print >>configfile, "FRONTENDNODES=" + delimiter + " ".join(['%s:%s' % (name, 'catlfish') for name in frontendnodenames]) + delimiter - print >>configfile, "STORAGENODES=" + delimiter + " ".join(['%s:%s' % (name, 'catlfish') for name in storagenodenames if name not in frontendnodenames]) + delimiter - print >>configfile, "SIGNINGNODES=" + delimiter + " ".join(['%s:%s' % (name, 'catlfish') for name in signingnodenames]) + delimiter - print >>configfile, "MERGESECONDARYNODES=" + delimiter + " ".join(['%s:%s' % (name, 'catlfish') for name in mergesecondarynodenames]) + delimiter - print >>configfile, "MERGEPRIMARYNODES=" + delimiter + '%s:%s' % (config["primarymergenode"], 'merge') + delimiter - - print >>configfile, "MACHINES=" + delimiter + " ".join([str(e) for e in range(1, machines+1)]) + delimiter - print >>configfile, "FRONTENDTESTURLS=" + delimiter + " ".join(frontendnodeaddresses) + delimiter - print >>configfile, "STORAGETESTURLS=" + delimiter + " ".join(storagenodeaddresses) + delimiter - print >>configfile, "SIGNINGTESTURLS=" + delimiter + " ".join(signingnodeaddresses) + delimiter - print >>configfile, "MERGESECONDARYTESTURLS=" + delimiter + " ".join(mergesecondarynodeaddresses) + delimiter - print >>configfile, "MERGEPRIMARYTESTURLS=" + delimiter + " ".join([]) + delimiter + print >>configfile, "NODES=" + delimiter + " ".join(set([node["name"] for node in allnodes])) + delimiter + + print >>configfile, "MACHINES=" + delimiter + " ".join([str(e) for e in frontendnodenames]) + delimiter print >>configfile, "BASEURL=" + delimiter + config["baseurl"] + delimiter configfile.close() @@ -484,15 +503,14 @@ def main(): parser.add_argument("--testmakefile", metavar="file", help="Generate makefile variables for test") parser.add_argument("--testshellvars", metavar="file", help="Generate shell variable file for test") parser.add_argument("--getnodenames", action='store_true', help="Get list of node names") - parser.add_argument("--machines", type=int, metavar="n", help="Number of machines") args = parser.parse_args() - if args.testmakefile and args.machines: + if args.testmakefile: config = readconfig.read_config(args.config) - gen_testmakefile(config, args.testmakefile, args.machines) - elif args.testshellvars and args.machines: + gen_testmakefile(config, args.testmakefile) + elif args.testshellvars: config = readconfig.read_config(args.config) - gen_testmakefile(config, args.testshellvars, args.machines, shellvars=True) + gen_testmakefile(config, args.testshellvars, shellvars=True) elif args.getnodenames: config = readconfig.read_config(args.config) printnodenames(config) |