]> git.proxmox.com Git - ovs.git/blob - tests/test-daemon.py
Fix ovs-dpctl-top by removing 3 wrong hunks in py3-compat.patch.
[ovs.git] / tests / test-daemon.py
1 # Copyright (c) 2010, 2011 Nicira, Inc.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at:
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 import argparse
16 import signal
17 import sys
18 import time
19
20 import ovs.daemon
21 import ovs.util
22
23
24 def handler(signum, _):
25 raise Exception("Signal handler called with %d" % signum)
26
27
28 def main():
29
30 if sys.platform != 'win32':
31 # signal.SIGHUP does not exist on Windows
32 signal.signal(signal.SIGHUP, handler)
33
34 parser = argparse.ArgumentParser(
35 description="Open vSwitch daemonization test program for Python.")
36 parser.add_argument("-b", "--bail", action="store_true",
37 help="Exit with an error after daemonize_start().")
38
39 ovs.daemon.add_args(parser)
40 args = parser.parse_args()
41 ovs.daemon.handle_args(args)
42
43 ovs.daemon.daemonize_start()
44 if args.bail:
45 sys.stderr.write("%s: exiting after daemonize_start() as requested\n"
46 % ovs.util.PROGRAM_NAME)
47 sys.exit(1)
48 ovs.daemon.daemonize_complete()
49
50 while True:
51 time.sleep(1)
52
53
54 if __name__ == '__main__':
55 try:
56 main()
57 except SystemExit:
58 # Let system.exit() calls complete normally
59 raise
60 except:
61 sys.exit(ovs.daemon.RESTART_EXIT_CODE)