2019-02-07 13:20:03 +00:00
|
|
|
#!/usr/bin/env python
|
2018-06-07 16:22:49 +00:00
|
|
|
#
|
|
|
|
# this script generate supervisord configs for running a test network on loopback
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
|
|
from argparse import ArgumentParser as AP
|
|
|
|
from configparser import ConfigParser as CP
|
|
|
|
|
|
|
|
import os
|
|
|
|
|
2018-06-19 17:11:24 +00:00
|
|
|
|
|
|
|
def svcNodeName(id): return 'svc-node-%03d' % id
|
|
|
|
|
|
|
|
|
|
|
|
def clientNodeName(id): return 'client-node-%03d' % id
|
|
|
|
|
2018-06-07 16:22:49 +00:00
|
|
|
|
|
|
|
def main():
|
|
|
|
ap = AP()
|
2018-09-06 13:16:24 +00:00
|
|
|
ap.add_argument('--valgrind', type=bool, default=False)
|
2018-06-07 16:22:49 +00:00
|
|
|
ap.add_argument('--dir', type=str, default='testnet_tmp')
|
2018-06-19 17:11:24 +00:00
|
|
|
ap.add_argument('--svc', type=int, default=20,
|
|
|
|
help='number of service nodes')
|
2018-06-07 16:22:49 +00:00
|
|
|
ap.add_argument('--baseport', type=int, default=19000)
|
2018-06-19 17:11:24 +00:00
|
|
|
ap.add_argument('--clients', type=int, default=200,
|
|
|
|
help='number of client nodes')
|
2018-06-07 16:22:49 +00:00
|
|
|
ap.add_argument('--bin', type=str, required=True)
|
|
|
|
ap.add_argument('--out', type=str, required=True)
|
2018-06-19 17:11:24 +00:00
|
|
|
ap.add_argument('--connect', type=int, default=10)
|
2019-02-07 13:20:03 +00:00
|
|
|
ap.add_argument('--ip', type=str, default=None)
|
2018-07-11 16:11:19 +00:00
|
|
|
ap.add_argument('--ifname', type=str, default='lo')
|
2019-02-07 13:20:03 +00:00
|
|
|
ap.add_argument('--netid', type=str, default=None)
|
2021-04-12 11:38:12 +00:00
|
|
|
ap.add_argument('--loglevel', type=str, default='info')
|
2018-06-07 16:22:49 +00:00
|
|
|
args = ap.parse_args()
|
|
|
|
|
2018-09-06 13:16:24 +00:00
|
|
|
if args.valgrind:
|
|
|
|
exe = 'valgrind {}'.format(args.bin)
|
|
|
|
else:
|
2020-02-02 16:31:01 +00:00
|
|
|
exe = '{} -v'.format(args.bin)
|
2018-06-07 16:22:49 +00:00
|
|
|
basedir = os.path.abspath(args.dir)
|
2018-06-19 17:11:24 +00:00
|
|
|
|
2018-06-07 16:22:49 +00:00
|
|
|
for nodeid in range(args.svc):
|
|
|
|
config = CP()
|
2018-07-02 19:24:22 +00:00
|
|
|
config['router'] = {
|
2021-04-12 11:38:12 +00:00
|
|
|
'data-dir': '.',
|
2018-07-02 19:24:22 +00:00
|
|
|
'net-threads': '1',
|
2018-08-02 00:51:08 +00:00
|
|
|
'worker-threads': '4',
|
2019-05-09 20:28:56 +00:00
|
|
|
'nickname': svcNodeName(nodeid),
|
|
|
|
'min-connections': "{}".format(args.connect)
|
2018-07-02 19:24:22 +00:00
|
|
|
}
|
2019-02-07 13:20:03 +00:00
|
|
|
if args.netid:
|
|
|
|
config['router']['netid'] = args.netid
|
2021-04-12 11:38:27 +00:00
|
|
|
|
2019-02-07 13:20:03 +00:00
|
|
|
if args.ip:
|
|
|
|
config['router']['public-ip'] = args.ip
|
|
|
|
config['router']['public-port'] = str(args.baseport + nodeid)
|
2021-04-12 11:38:27 +00:00
|
|
|
|
2018-06-07 16:22:49 +00:00
|
|
|
config['bind'] = {
|
2018-07-11 16:11:19 +00:00
|
|
|
args.ifname: str(args.baseport + nodeid)
|
2018-06-07 16:22:49 +00:00
|
|
|
}
|
|
|
|
config['netdb'] = {
|
2018-06-19 17:11:24 +00:00
|
|
|
'dir': 'netdb'
|
2018-06-07 16:22:49 +00:00
|
|
|
}
|
2018-12-17 22:43:16 +00:00
|
|
|
config['network'] = {
|
|
|
|
'type' : 'null'
|
|
|
|
}
|
2019-04-12 15:29:48 +00:00
|
|
|
config['api'] = {
|
|
|
|
'enabled': 'false'
|
|
|
|
}
|
2020-02-02 16:31:01 +00:00
|
|
|
config['lokid'] = {
|
2021-04-12 11:38:12 +00:00
|
|
|
'enabled': 'false',
|
2020-02-02 16:31:01 +00:00
|
|
|
}
|
2018-06-07 16:22:49 +00:00
|
|
|
d = os.path.join(args.dir, svcNodeName(nodeid))
|
|
|
|
if not os.path.exists(d):
|
|
|
|
os.mkdir(d)
|
|
|
|
fp = os.path.join(d, 'daemon.ini')
|
|
|
|
with open(fp, 'w') as f:
|
|
|
|
config.write(f)
|
2019-07-19 17:56:17 +00:00
|
|
|
for n in [0]:
|
2021-04-12 11:38:12 +00:00
|
|
|
if nodeid is not 0:
|
|
|
|
f.write("[bootstrap]\nadd-node={}\n".format(os.path.join(basedir,svcNodeName(n), 'self.signed')))
|
|
|
|
else:
|
|
|
|
f.write("[bootstrap]\nseed-node=true\n")
|
2018-06-07 16:22:49 +00:00
|
|
|
|
|
|
|
for nodeid in range(args.clients):
|
|
|
|
config = CP()
|
2018-07-11 16:11:19 +00:00
|
|
|
|
2018-07-02 19:24:22 +00:00
|
|
|
config['router'] = {
|
2021-04-12 11:38:12 +00:00
|
|
|
'data-dir': '.',
|
2018-07-02 19:24:22 +00:00
|
|
|
'net-threads': '1',
|
2018-08-02 00:51:08 +00:00
|
|
|
'worker-threads': '2',
|
|
|
|
'nickname': clientNodeName(nodeid)
|
2018-07-02 19:24:22 +00:00
|
|
|
}
|
2019-02-08 14:04:18 +00:00
|
|
|
if args.netid:
|
|
|
|
config['router']['netid'] = args.netid
|
|
|
|
|
2021-04-12 11:38:12 +00:00
|
|
|
config["logging"] = {
|
|
|
|
"level": args.loglevel
|
|
|
|
}
|
|
|
|
|
2018-06-07 16:22:49 +00:00
|
|
|
config['netdb'] = {
|
2018-06-19 17:11:24 +00:00
|
|
|
'dir': 'netdb'
|
2018-06-07 16:22:49 +00:00
|
|
|
}
|
2019-04-12 15:29:48 +00:00
|
|
|
config['api'] = {
|
|
|
|
'enabled': 'false'
|
|
|
|
}
|
2018-12-17 22:43:16 +00:00
|
|
|
config['network'] = {
|
|
|
|
'type' : 'null'
|
|
|
|
}
|
2018-06-07 16:22:49 +00:00
|
|
|
d = os.path.join(args.dir, clientNodeName(nodeid))
|
|
|
|
if not os.path.exists(d):
|
|
|
|
os.mkdir(d)
|
2019-05-09 20:28:56 +00:00
|
|
|
fp = os.path.join(d, 'client.ini')
|
2018-06-07 16:22:49 +00:00
|
|
|
with open(fp, 'w') as f:
|
|
|
|
config.write(f)
|
2020-01-14 20:12:47 +00:00
|
|
|
for n in [0]:
|
2019-05-09 20:28:56 +00:00
|
|
|
otherID = (n + nodeid) % args.svc
|
2021-04-12 11:38:12 +00:00
|
|
|
f.write("[bootstrap]\nadd-node={}\n".format(os.path.join(basedir,svcNodeName(otherID), 'self.signed')))
|
2018-06-19 17:11:24 +00:00
|
|
|
|
2018-06-07 16:22:49 +00:00
|
|
|
with open(args.out, 'w') as f:
|
2021-04-12 11:38:12 +00:00
|
|
|
basedir = os.path.join(args.dir, 'svc-node-%(process_num)03d')
|
2018-06-07 16:22:49 +00:00
|
|
|
f.write('''[program:svc-node]
|
|
|
|
directory = {}
|
2021-04-12 11:38:12 +00:00
|
|
|
command = {} -r {}/daemon.ini
|
2018-08-04 02:59:32 +00:00
|
|
|
autorestart=true
|
2018-06-07 16:22:49 +00:00
|
|
|
redirect_stderr=true
|
2018-08-02 21:26:14 +00:00
|
|
|
#stdout_logfile=/dev/fd/1
|
|
|
|
stdout_logfile={}/svc-node-%(process_num)03d-log.txt
|
2018-06-07 16:22:49 +00:00
|
|
|
stdout_logfile_maxbytes=0
|
|
|
|
process_name = svc-node-%(process_num)03d
|
|
|
|
numprocs = {}
|
2021-04-12 11:38:12 +00:00
|
|
|
'''.format(basedir, exe, basedir, args.dir, args.svc))
|
|
|
|
basedir = os.path.join(args.dir, 'client-node-%(process_num)03d')
|
2019-05-09 20:28:56 +00:00
|
|
|
f.write('''[program:Client-node]
|
2018-06-07 16:22:49 +00:00
|
|
|
directory = {}
|
2021-04-12 11:38:12 +00:00
|
|
|
command = bash -c "sleep 5 && {} {}/client.ini"
|
2018-08-04 02:59:32 +00:00
|
|
|
autorestart=true
|
2018-06-07 16:22:49 +00:00
|
|
|
redirect_stderr=true
|
2018-08-02 21:26:14 +00:00
|
|
|
#stdout_logfile=/dev/fd/1
|
|
|
|
stdout_logfile={}/client-node-%(process_num)03d-log.txt
|
2018-06-07 16:22:49 +00:00
|
|
|
stdout_logfile_maxbytes=0
|
|
|
|
process_name = client-node-%(process_num)03d
|
|
|
|
numprocs = {}
|
2021-04-12 11:38:12 +00:00
|
|
|
'''.format(basedir, exe, basedir, args.dir, args.clients))
|
2018-06-07 16:22:49 +00:00
|
|
|
f.write('[supervisord]\ndirectory=.\n')
|
2018-06-19 17:11:24 +00:00
|
|
|
|
|
|
|
|
2018-06-07 16:22:49 +00:00
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|