]> git.proxmox.com Git - ovs.git/blame - tests/daemon-py.at
Require Python 3 and remove support for Python 2.
[ovs.git] / tests / daemon-py.at
CommitLineData
1ca0323e
BP
1AT_BANNER([daemon unit tests - Python3])
2
3AT_SETUP([daemon - Python3])
4# Skip this test for Windows, echo $! gives shell pid instead of parent process
5AT_SKIP_IF([test "$IS_WIN32" = "yes"])
6AT_KEYWORDS([python daemon])
7
8on_exit 'kill $(cat *.pid)'
9pidfile=test-daemon.py.pid
10
11# Start the daemon and wait for the pidfile to get created
12# and that its contents are the correct pid.
13AT_CHECK([$PYTHON3 $srcdir/test-daemon.py --pidfile & echo $!], [0], [stdout])
14pid=$(cat stdout)
15
16OVS_WAIT_UNTIL([test -s $pidfile], [kill $pid])
17AT_CHECK([test $pid = $(cat $pidfile)])
18AT_CHECK([kill -0 $pid])
19
20# Kill the daemon and make sure that the pidfile gets deleted.
21kill $pid
22OVS_WAIT_WHILE([kill -0 $pid])
23AT_CHECK([test ! -e $pidfile])
24AT_CLEANUP
25
26AT_SETUP([daemon --monitor - Python3])
27# Skip this test for Windows, echo $! gives shell pid instead of parent process
28AT_SKIP_IF([test "$IS_WIN32" = "yes"])
29
30on_exit 'kill $(cat *.pid)'
31pidfile=test-daemon.py.pid
32
33# Start the daemon and wait for the pidfile to get created.
34AT_CHECK([$PYTHON3 $srcdir/test-daemon.py --pidfile --monitor & echo $!], [0], [stdout])
35monitor=$(cat stdout)
36OVS_WAIT_UNTIL([test -s $pidfile])
37child=$(cat $pidfile)
38
39# Check that the pidfile names a running process,
40# and that the parent process of that process is our child process.
41check_ancestors $child $monitor
42
43# Kill the daemon process, making it look like a segfault,
44# and wait for a new child process to get spawned.
45AT_CHECK([kill -SEGV $child])
46OVS_WAIT_WHILE([kill -0 $child])
47OVS_WAIT_UNTIL([test -s $pidfile && test $(cat $pidfile) != $child])
48child2=$(cat $pidfile)
49
50# Check that the pidfile names a running process,
51# and that the parent process of that process is our child process.
52check_ancestors $child2 $monitor
53
54# Kill the daemon process with SIGTERM, and wait for the daemon
55# and the monitor processes to go away and the pidfile to get deleted.
56AT_CHECK([kill $child2])
57OVS_WAIT_WHILE([kill -0 $monitor || kill -0 $child2 || test -e $pidfile])
58AT_CLEANUP
59
60AT_SETUP([daemon --monitor restart exit code - Python3])
61# Skip this test for Windows, echo $! gives shell pid instead of parent process
62AT_SKIP_IF([test "$IS_WIN32" = "yes"])
63
64on_exit 'kill $(cat *.pid)'
65pidfile=test-daemon.py.pid
66
67# Start the daemon and wait for the pidfile to get created.
68AT_CHECK([$PYTHON3 $srcdir/test-daemon.py --pidfile --monitor & echo $!], [0], [stdout])
69monitor=$(cat stdout)
70OVS_WAIT_UNTIL([test -s $pidfile])
71child=$(cat $pidfile)
72
73# Check that the pidfile names a running process,
74# and that the parent process of that process is our child process.
75check_ancestors $child $monitor
76
77# HUP the daemon process causing it to throw an exception,
78# and wait for a new child process to get spawned.
79AT_CHECK([kill -HUP $child])
80OVS_WAIT_WHILE([kill -0 $child])
81OVS_WAIT_UNTIL([test -s $pidfile && test $child != $(cat $pidfile)])
82child2=$(cat $pidfile)
83
84# Check that the pidfile names a running process,
85# and that the parent process of that process is our child process.
86check_ancestors $child2 $monitor
87
88# Kill the daemon process with SIGTERM, and wait for the daemon
89# and the monitor processes to go away and the pidfile to get deleted.
90AT_CHECK([kill $child2])
91OVS_WAIT_WHILE([kill -0 $monitor || kill -0 $child2 || test -e $pidfile])
92AT_CLEANUP
93
94AT_SETUP([daemon --detach - Python3])
95
96# Skip this test for Windows, the pid file not removed if the daemon is killed
97AT_SKIP_IF([test "$IS_WIN32" = "yes"])
98
99on_exit 'kill $(cat *.pid)'
100pidfile=test-daemon.py.pid
101
102# Start the daemon and make sure that the pidfile exists immediately.
103# We don't wait for the pidfile to get created because the daemon is
104# supposed to do so before the parent exits.
105AT_CHECK([$PYTHON3 $srcdir/test-daemon.py --pidfile --detach --no-chdir], [0])
106AT_CHECK([test -s $pidfile])
107pid=$(cat $pidfile)
108check_ancestors $pid 1
109
110# Kill the daemon and make sure that the pidfile gets deleted.
111AT_CHECK([kill $pid])
112OVS_WAIT_WHILE([kill -0 $pid])
113AT_CHECK([test ! -e $pidfile])
114AT_CLEANUP
115
116AT_SETUP([daemon --detach --monitor - Python3])
117
118# Skip this test for Windows, uses Linux specific kill signal
119AT_SKIP_IF([test "$IS_WIN32" = "yes"])
120
121on_exit 'kill $(cat *.pid)'
122pidfile=test-daemon.py.pid
123
124# Start the daemon and make sure that the pidfile exists immediately.
125# We don't wait for the pidfile to get created because the daemon is
126# supposed to do so before the parent exits.
127AT_CHECK([$PYTHON3 $srcdir/test-daemon.py --pidfile --detach --no-chdir --monitor], [0])
128AT_CHECK([test -s $pidfile])
129child=$(cat $pidfile)
130AT_CHECK([parent_pid $child], [0], [stdout])
131monitor=$(cat stdout)
132
133# Check that the pidfile names a running process,
134# and that the parent process of that process is a running process,
135# and that the parent process of that process is init.
136check_ancestors $child $monitor 1
137
138# Kill the daemon process, making it look like a segfault,
139# and wait for a new daemon process to get spawned.
140AT_CHECK([kill -SEGV $child])
141OVS_WAIT_WHILE([kill -0 $child])
142OVS_WAIT_UNTIL([test -s $pidfile && test $(cat $pidfile) != $child])
143child2=$(cat $pidfile)
144
145# Check that the pidfile names a running process,
146# and that the parent process of that process is our child process.
147check_ancestors $child2 $monitor 1
148
149# Kill the daemon process with SIGTERM, and wait for the daemon
150# and the monitor processes to go away and the pidfile to get deleted.
151AT_CHECK([kill $child2])
152OVS_WAIT_WHILE([kill -0 $child2 || kill -0 $monitor || test -e $pidfile])
153AT_CLEANUP
154
155AT_SETUP([daemon --detach startup errors - Python3])
156AT_CHECK([$PYTHON3 $srcdir/test-daemon.py --pidfile --detach --no-chdir --bail], [1], [], [stderr])
157AT_CHECK([grep 'test-daemon.py: exiting after daemonize_start() as requested' stderr],
158 [0], [ignore])
159AT_CHECK([test ! -s test-daemon.py.pid])
160AT_CLEANUP
161
162AT_SETUP([daemon --detach --monitor startup errors - Python3])
163AT_CAPTURE_FILE([pid])
164AT_CHECK([$PYTHON3 $srcdir/test-daemon.py --pidfile --detach --no-chdir --monitor --bail], [1], [], [stderr])
165AT_CHECK([grep 'test-daemon.py: exiting after daemonize_start() as requested' stderr],
166 [0], [ignore])
167AT_CHECK([test ! -s test-daemon.py.pid])
168AT_CLEANUP
169
170AT_SETUP([daemon --detach closes standard fds - Python3])
171# Skip this test for Windows, uses Linux specific kill signal
172AT_SKIP_IF([test "$IS_WIN32" = "yes"])
173
174AT_CHECK([(yes 2>stderr; echo $? > status) | $PYTHON3 $srcdir/test-daemon.py --pidfile --detach --no-chdir])
175AT_CHECK([kill $(cat test-daemon.py.pid)])
176AT_CHECK([test -s status])
177if grep '[[bB]]roken pipe' stderr >/dev/null 2>&1; then
178 # Something in the environment caused SIGPIPE to be ignored, but
179 # 'yes' at least told us that it got EPIPE. Good enough; we know
180 # that stdout was closed.
181 :
182else
183 # Otherwise make sure that 'yes' died from SIGPIPE.
184 AT_CHECK([kill -l `cat status`], [0], [PIPE
99155935 185])
1ca0323e
BP
186fi
187AT_CLEANUP
188
189AT_SETUP([daemon --detach --monitor closes standard fds - Python3])
190# Skip this test for Windows, uses Linux specific kill signal
191AT_SKIP_IF([test "$IS_WIN32" = "yes"])
192AT_CHECK([(yes 2>stderr; echo $? > status) | $PYTHON3 $srcdir/test-daemon.py --pidfile --detach --no-chdir], [0], [], [])
193AT_CHECK([kill $(cat test-daemon.py.pid)])
194AT_CHECK([test -s status])
195if grep '[[bB]]roken pipe' stderr >/dev/null 2>&1; then
196 # Something in the environment caused SIGPIPE to be ignored, but
197 # 'yes' at least told us that it got EPIPE. Good enough; we know
198 # that stdout was closed.
199 :
200else
201 # Otherwise make sure that 'yes' died from SIGPIPE.
202 AT_CHECK([kill -l `cat status`], [0], [PIPE
99155935 203])
1ca0323e
BP
204fi
205AT_CLEANUP