forked from LNST-project/lnst
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlnst-slave
executable file
·102 lines (88 loc) · 2.83 KB
/
lnst-slave
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#! /usr/bin/env python2
"""
Net test slave
Copyright 2011 Red Hat, Inc.
Licensed under the GNU General Public License, version 2 as
published by the Free Software Foundation; see COPYING for details.
"""
__author__ = """
[email protected] (Jiri Pirko)
"""
import getopt
import sys
import os
import logging
from lnst.Common.Daemon import Daemon
from lnst.Common.Logs import LoggingCtl
from lnst.Common.Config import lnst_config
from lnst.Common.Colours import load_presets_from_config
from lnst.Slave.NetTestSlave import NetTestSlave
def usage():
"""
Print usage of this app
"""
print "Usage: %s [OPTION...]" % sys.argv[0]
print ""
print " -d, --debug emit debugging messages"
print " -h, --help print this message"
print " -e, --daemonize go to background after init"
print " -i, --pidfile file to write daemonized process pid"
print " -m, --no-colours disable coloured terminal output"
print " -p, --port xmlrpc port to listen on"
sys.exit()
def main():
"""
Main function
"""
try:
opts = getopt.getopt(
sys.argv[1:],
"dhei:p:m",
["debug", "help", "daemonize", "pidfile=", "port=", "no-colours"]
)[0]
except getopt.GetoptError as err:
print str(err)
usage()
sys.exit()
lnst_config.slave_init()
dirname = os.path.dirname(sys.argv[0])
gitcfg = os.path.join(dirname, "lnst-slave.conf")
if os.path.isfile(gitcfg):
lnst_config.load_config(gitcfg)
else:
lnst_config.load_config('/etc/lnst-slave.conf')
usr_cfg = os.path.expanduser('~/.lnst/lnst-slave.conf')
if os.path.isfile(usr_cfg):
lnst_config.load_config(usr_cfg)
debug = False
daemon = False
pidfile = "/var/run/lnst-slave.pid"
port = None
coloured_output = not lnst_config.get_option("colours", "disable_colours")
for opt, arg in opts:
if opt in ("-d", "--debug"):
debug = True
elif opt in ("-h", "--help"):
usage()
elif opt in ("-e", "--daemonize"):
daemon = True
elif opt in ("-i", "--pidfile"):
pidfile = arg
elif opt in ("-p", "--port"):
port = int(arg)
elif opt in ("-m", "--no-colours"):
coloured_output = False
load_presets_from_config(lnst_config)
log_ctl = LoggingCtl(debug,
log_dir=lnst_config.get_option('environment', 'log_dir'),
colours=coloured_output)
logging.info("Started")
if port != None:
lnst_config.set_option("environment", "rpcport", port)
nettestslave = NetTestSlave(log_ctl)
if daemon:
daemon = Daemon(pidfile)
daemon.daemonize()
nettestslave.run()
if __name__ == "__main__":
main()