]> git.proxmox.com Git - ovs.git/blame - tests/test-daemon.py
python: Upgrade daemon module to argparse.
[ovs.git] / tests / test-daemon.py
CommitLineData
00c08589 1# Copyright (c) 2010, 2011 Nicira Networks.
9c64f238 2#
99155935
BP
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:
9c64f238 6#
99155935 7# http://www.apache.org/licenses/LICENSE-2.0
9c64f238 8#
99155935
BP
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
b153e667 15import argparse
aacea8ba 16import logging
6793129d 17import signal
99155935
BP
18import sys
19import time
20
21import ovs.daemon
22import ovs.util
23
50e97486
EJ
24
25def handler(signum, _):
6793129d
EJ
26 raise Exception("Signal handler called with %d" % signum)
27
50e97486 28
b153e667 29def main():
aacea8ba 30 logging.basicConfig(level=logging.DEBUG)
6793129d
EJ
31
32 signal.signal(signal.SIGHUP, handler)
33
b153e667
EJ
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().")
99155935 38
b153e667
EJ
39 ovs.daemon.add_args(parser)
40 args = parser.parse_args()
41 ovs.daemon.handle_args(args)
99155935 42
99155935 43 ovs.daemon.daemonize_start()
b153e667 44 if args.bail:
99155935
BP
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
50e97486 53
99155935 54if __name__ == '__main__':
6793129d 55 try:
b153e667 56 main()
6793129d
EJ
57 except SystemExit:
58 # Let system.exit() calls complete normally
59 raise
60 except:
61 sys.exit(ovs.daemon.RESTART_EXIT_CODE)