1 AT_BANNER([daemon unit tests - Python])
3 AT_SETUP([daemon - Python])
4 AT_SKIP_IF([test $HAVE_PYTHON = no])
6 AT_CAPTURE_FILE([expected])
7 # Start the daemon and wait for the pidfile to get created
8 # and that its contents are the correct pid.
9 AT_CHECK([$PYTHON $srcdir/test-daemon.py --pidfile-name=$PWD/pid& echo $! > expected], [0])
10 OVS_WAIT_UNTIL([test -s pid], [kill `cat expected`])
12 [pid=`cat pid` && expected=`cat expected` && test "$pid" = "$expected"],
13 [0], [], [], [kill `cat expected`])
14 AT_CHECK([kill -0 `cat pid`], [0], [], [], [kill `cat expected`])
15 # Kill the daemon and make sure that the pidfile gets deleted.
17 OVS_WAIT_WHILE([kill -0 `cat expected`])
18 AT_CHECK([test ! -e pid])
21 AT_SETUP([daemon --monitor - Python])
22 AT_SKIP_IF([test $HAVE_PYTHON = no])
23 AT_CAPTURE_FILE([pid])
24 AT_CAPTURE_FILE([parent])
25 AT_CAPTURE_FILE([parentpid])
26 AT_CAPTURE_FILE([newpid])
27 # Start the daemon and wait for the pidfile to get created.
28 AT_CHECK([$PYTHON $srcdir/test-daemon.py --pidfile-name=$PWD/pid --monitor& echo $! > parent], [0])
29 OVS_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.
32 AT_CHECK([kill -0 `cat pid`], [0], [], [], [kill `cat parent`])
33 AT_CHECK([ps -o ppid= -p `cat pid` > parentpid],
34 [0], [], [], [kill `cat parent`])
36 [parentpid=`cat parentpid` &&
37 parent=`cat parent` &&
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.
42 AT_CHECK([cp pid oldpid], [0], [], [], [kill `cat parent`])
43 AT_CHECK([kill -SEGV `cat pid`], [0], [], [ignore], [kill `cat parent`])
44 OVS_WAIT_WHILE([kill -0 `cat oldpid`], [kill `cat parent`])
45 OVS_WAIT_UNTIL([test -s pid && test `cat pid` != `cat oldpid`],
47 AT_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.
50 AT_CHECK([ps -o ppid= -p `cat pid` > parentpid],
51 [0], [], [], [kill `cat parent`])
53 [parentpid=`cat parentpid` &&
54 parent=`cat parent` &&
55 test $parentpid = $parent],
56 [0], [], [], [kill `cat parent`])
57 # Kill the daemon process with SIGTERM, and wait for the daemon
58 # and the monitor processes to go away and the pidfile to get deleted.
59 AT_CHECK([kill `cat pid`], [0], [], [ignore], [kill `cat parent`])
60 OVS_WAIT_WHILE([kill -0 `cat parent` || kill -0 `cat newpid` || test -e pid],
64 AT_SETUP([daemon --monitor restart exit code - Python])
65 AT_SKIP_IF([test $HAVE_PYTHON = no])
66 AT_CAPTURE_FILE([pid])
67 AT_CAPTURE_FILE([parent])
68 AT_CAPTURE_FILE([parentpid])
69 AT_CAPTURE_FILE([newpid])
70 # Start the daemon and wait for the pidfile to get created.
71 AT_CHECK([$PYTHON $srcdir/test-daemon.py --pidfile-name=$PWD/pid --monitor& echo $! > parent], [0])
72 OVS_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.
75 AT_CHECK([kill -0 `cat pid`], [0], [], [], [kill `cat parent`])
76 AT_CHECK([ps -o ppid= -p `cat pid` > parentpid],
77 [0], [], [], [kill `cat parent`])
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.
85 AT_CHECK([cp pid oldpid], [0], [], [], [kill `cat parent`])
86 AT_CHECK([kill -HUP `cat pid`], [0], [], [ignore], [kill `cat parent`])
87 OVS_WAIT_WHILE([kill -0 `cat oldpid`], [kill `cat parent`])
88 OVS_WAIT_UNTIL([test -s pid && test `cat pid` != `cat oldpid`],
90 AT_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.
93 AT_CHECK([ps -o ppid= -p `cat pid` > parentpid],
94 [0], [], [], [kill `cat parent`])
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
101 # and the monitor processes to go away and the pidfile to get deleted.
102 AT_CHECK([kill `cat pid`], [0], [], [ignore], [kill `cat parent`])
103 OVS_WAIT_WHILE([kill -0 `cat parent` || kill -0 `cat newpid` || test -e pid],
107 AT_SETUP([daemon --detach - Python])
108 AT_SKIP_IF([test $HAVE_PYTHON = no])
109 AT_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.
113 AT_CHECK([$PYTHON $srcdir/test-daemon.py --pidfile-name=$PWD/pid --detach], [0])
114 AT_CHECK([test -s pid])
115 AT_CHECK([kill -0 `cat pid`])
116 # Kill the daemon and make sure that the pidfile gets deleted.
119 OVS_WAIT_WHILE([kill -0 `cat saved-pid`])
120 AT_CHECK([test ! -e pid])
123 AT_SETUP([daemon --detach --monitor - Python])
124 AT_SKIP_IF([test $HAVE_PYTHON = no])
126 [AT_CHECK([$1], [$2], [$3], [$4], [kill `cat daemon monitor`])])
127 AT_CAPTURE_FILE([daemon])
128 AT_CAPTURE_FILE([olddaemon])
129 AT_CAPTURE_FILE([newdaemon])
130 AT_CAPTURE_FILE([monitor])
131 AT_CAPTURE_FILE([newmonitor])
132 AT_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.
136 AT_CHECK([$PYTHON $srcdir/test-daemon.py --pidfile-name=$PWD/daemon --detach --monitor], [0])
137 AT_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.
141 CHECK([kill -0 `cat daemon`])
142 CHECK([ps -o ppid= -p `cat daemon` > monitor])
143 CHECK([kill -0 `cat monitor`])
144 CHECK([ps -o ppid= -p `cat monitor` > init])
145 CHECK([test `cat init` = 1])
146 # Kill the daemon process, making it look like a segfault,
147 # and wait for a new daemon process to get spawned.
148 CHECK([cp daemon olddaemon])
149 CHECK([kill -SEGV `cat daemon`], [0], [ignore], [ignore])
150 OVS_WAIT_WHILE([kill -0 `cat olddaemon`], [kill `cat olddaemon daemon`])
151 OVS_WAIT_UNTIL([test -s daemon && test `cat daemon` != `cat olddaemon`],
152 [kill `cat olddaemon daemon`])
153 CHECK([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.
156 CHECK([kill -0 `cat daemon`])
157 CHECK([diff olddaemon newdaemon], [1], [ignore])
158 CHECK([ps -o ppid= -p `cat daemon` > newmonitor])
159 CHECK([diff monitor newmonitor])
160 CHECK([kill -0 `cat newmonitor`])
161 CHECK([ps -o ppid= -p `cat newmonitor` > init])
162 CHECK([test `cat init` = 1])
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.
165 CHECK([kill `cat daemon`], [0], [], [ignore])
167 [kill -0 `cat monitor` || kill -0 `cat newdaemon` || test -e daemon],
168 [kill `cat monitor newdaemon`])
172 AT_SETUP([daemon --detach startup errors - Python])
173 AT_SKIP_IF([test $HAVE_PYTHON = no])
174 AT_CAPTURE_FILE([pid])
175 AT_CHECK([$PYTHON $srcdir/test-daemon.py --pidfile-name=$PWD/pid --detach --bail], [1], [], [stderr])
176 AT_CHECK([grep 'test-daemon.py: exiting after daemonize_start() as requested' stderr],
178 AT_CHECK([test ! -s pid])
181 AT_SETUP([daemon --detach --monitor startup errors - Python])
182 AT_SKIP_IF([test $HAVE_PYTHON = no])
183 AT_CAPTURE_FILE([pid])
184 AT_CHECK([$PYTHON $srcdir/test-daemon.py --pidfile-name=$PWD/pid --detach --monitor --bail], [1], [], [stderr])
185 AT_CHECK([grep 'test-daemon.py: exiting after daemonize_start() as requested' stderr],
187 AT_CHECK([test ! -s pid])
190 AT_SETUP([daemon --detach closes standard fds - Python])
191 AT_SKIP_IF([test $HAVE_PYTHON = no])
192 AT_CAPTURE_FILE([pid])
193 AT_CAPTURE_FILE([status])
194 AT_CAPTURE_FILE([stderr])
195 AT_CHECK([(yes 2>stderr; echo $? > status) | $PYTHON $srcdir/test-daemon.py --pidfile-name=$PWD/pid --detach], [0], [], [])
196 AT_CHECK([kill `cat pid`])
197 AT_CHECK([test -s status])
198 if 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.
204 # Otherwise make sure that 'yes' died from SIGPIPE.
205 AT_CHECK([kill -l `cat status`], [0], [PIPE
210 AT_SETUP([daemon --detach --monitor closes standard fds])
211 AT_CAPTURE_FILE([pid])
212 AT_CAPTURE_FILE([status])
213 AT_CAPTURE_FILE([stderr])
215 AT_CHECK([(yes 2>stderr; echo $? > status) | $PYTHON $srcdir/test-daemon.py --pidfile-name=$PWD/pid --detach], [0], [], [])
216 AT_CHECK([kill `cat pid`])
217 AT_CHECK([test -s status])
218 if 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.
224 # Otherwise make sure that 'yes' died from SIGPIPE.
225 AT_CHECK([kill -l `cat status`], [0], [PIPE