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