]>
Commit | Line | Data |
---|---|---|
99155935 BP |
1 | AT_BANNER([daemon unit tests - Python]) |
2 | ||
cede00f2 RB |
3 | m4_define([DAEMON_PYN], |
4 | [AT_SETUP([daemon - $1]) | |
5 | AT_SKIP_IF([test $2 = no]) | |
fef32d76 PB |
6 | # Skip this test for Windows, echo $! gives shell pid instead of parent process |
7 | AT_SKIP_IF([test "$IS_WIN32" = "yes"]) | |
cede00f2 RB |
8 | AT_KEYWORDS([python daemon]) |
9 | AT_CAPTURE_FILE([pid]) | |
10 | AT_CAPTURE_FILE([expected]) | |
11 | # Start the daemon and wait for the pidfile to get created | |
12 | # and that its contents are the correct pid. | |
56120500 | 13 | AT_CHECK([$3 $srcdir/test-daemon.py --pidfile=pid& echo $! > expected], [0]) |
cede00f2 RB |
14 | OVS_WAIT_UNTIL([test -s pid], [kill `cat expected`]) |
15 | AT_CHECK( | |
16 | [pid=`cat pid` && expected=`cat expected` && test "$pid" = "$expected"], | |
17 | [0], [], [], [kill `cat expected`]) | |
18 | AT_CHECK([kill -0 `cat pid`], [0], [], [], [kill `cat expected`]) | |
19 | # Kill the daemon and make sure that the pidfile gets deleted. | |
20 | kill `cat expected` | |
21 | OVS_WAIT_WHILE([kill -0 `cat expected`]) | |
22 | AT_CHECK([test ! -e pid]) | |
23 | AT_CLEANUP]) | |
24 | ||
25 | DAEMON_PYN([Python2], [$HAVE_PYTHON], [$PYTHON]) | |
26 | DAEMON_PYN([Python3], [$HAVE_PYTHON3], [$PYTHON3]) | |
27 | ||
28 | m4_define([DAEMON_MONITOR_PYN], | |
29 | [AT_SETUP([daemon --monitor - $1]) | |
30 | AT_SKIP_IF([test $2 = no]) | |
fef32d76 PB |
31 | # Skip this test for Windows, echo $! gives shell pid instead of parent process |
32 | AT_SKIP_IF([test "$IS_WIN32" = "yes"]) | |
cede00f2 RB |
33 | AT_CAPTURE_FILE([pid]) |
34 | AT_CAPTURE_FILE([parent]) | |
35 | AT_CAPTURE_FILE([parentpid]) | |
36 | AT_CAPTURE_FILE([newpid]) | |
37 | # Start the daemon and wait for the pidfile to get created. | |
56120500 BP |
38 | AT_CHECK([$3 $srcdir/test-daemon.py --pidfile=pid --monitor& echo $! > parent], [0]) |
39 | on_exit 'kill `cat parent`' | |
40 | OVS_WAIT_UNTIL([test -s pid]) | |
cede00f2 RB |
41 | # Check that the pidfile names a running process, |
42 | # and that the parent process of that process is our child process. | |
56120500 BP |
43 | AT_CHECK([kill -0 `cat pid`]) |
44 | AT_CHECK([parent_pid `cat pid` > parentpid]) | |
cede00f2 RB |
45 | AT_CHECK( |
46 | [parentpid=`cat parentpid` && | |
47 | parent=`cat parent` && | |
56120500 | 48 | test $parentpid = $parent]) |
cede00f2 RB |
49 | # Kill the daemon process, making it look like a segfault, |
50 | # and wait for a new child process to get spawned. | |
56120500 BP |
51 | AT_CHECK([cp pid oldpid]) |
52 | AT_CHECK([kill -SEGV `cat pid`], [0], [], [ignore]) | |
53 | OVS_WAIT_WHILE([kill -0 `cat oldpid`]) | |
54 | OVS_WAIT_UNTIL([test -s pid && test `cat pid` != `cat oldpid`]) | |
55 | AT_CHECK([cp pid newpid]) | |
cede00f2 RB |
56 | # Check that the pidfile names a running process, |
57 | # and that the parent process of that process is our child process. | |
56120500 | 58 | AT_CHECK([parent_pid `cat pid` > parentpid]) |
cede00f2 RB |
59 | AT_CHECK( |
60 | [parentpid=`cat parentpid` && | |
61 | parent=`cat parent` && | |
56120500 | 62 | test $parentpid = $parent]) |
cede00f2 RB |
63 | # Kill the daemon process with SIGTERM, and wait for the daemon |
64 | # and the monitor processes to go away and the pidfile to get deleted. | |
56120500 BP |
65 | AT_CHECK([kill `cat pid`]) |
66 | OVS_WAIT_WHILE([kill -0 `cat parent` || kill -0 `cat newpid` || test -e pid]) | |
cede00f2 RB |
67 | AT_CLEANUP]) |
68 | ||
69 | DAEMON_MONITOR_PYN([Python2], [$HAVE_PYTHON], [$PYTHON]) | |
70 | DAEMON_MONITOR_PYN([Python3], [$HAVE_PYTHON3], [$PYTHON3]) | |
71 | ||
72 | m4_define([DAEMON_MONITOR_RESTART_PYN], | |
73 | [AT_SETUP([daemon --monitor restart exit code - $1]) | |
74 | AT_SKIP_IF([test $2 = no]) | |
fef32d76 PB |
75 | # Skip this test for Windows, echo $! gives shell pid instead of parent process |
76 | AT_SKIP_IF([test "$IS_WIN32" = "yes"]) | |
cede00f2 RB |
77 | AT_CAPTURE_FILE([pid]) |
78 | AT_CAPTURE_FILE([parent]) | |
79 | AT_CAPTURE_FILE([parentpid]) | |
80 | AT_CAPTURE_FILE([newpid]) | |
81 | # Start the daemon and wait for the pidfile to get created. | |
56120500 BP |
82 | AT_CHECK([$3 $srcdir/test-daemon.py --pidfile=pid --monitor& echo $! > parent], [0]) |
83 | on_exit 'kill `cat parent`' | |
84 | OVS_WAIT_UNTIL([test -s pid]) | |
cede00f2 RB |
85 | # Check that the pidfile names a running process, |
86 | # and that the parent process of that process is our child process. | |
56120500 BP |
87 | AT_CHECK([kill -0 `cat pid`]) |
88 | AT_CHECK([parent_pid `cat pid` > parentpid]) | |
cede00f2 RB |
89 | AT_CHECK( |
90 | [parentpid=`cat parentpid` && | |
91 | parent=`cat parent` && | |
56120500 | 92 | test $parentpid = $parent]) |
cede00f2 RB |
93 | # HUP the daemon process causing it to throw an exception, |
94 | # and wait for a new child process to get spawned. | |
56120500 BP |
95 | AT_CHECK([cp pid oldpid]) |
96 | AT_CHECK([kill -HUP `cat pid`]) | |
97 | OVS_WAIT_WHILE([kill -0 `cat oldpid`]) | |
98 | OVS_WAIT_UNTIL([test -s pid && test `cat pid` != `cat oldpid`]) | |
99 | AT_CHECK([cp pid newpid]) | |
cede00f2 RB |
100 | # Check that the pidfile names a running process, |
101 | # and that the parent process of that process is our child process. | |
56120500 | 102 | AT_CHECK([parent_pid `cat pid` > parentpid]) |
cede00f2 RB |
103 | AT_CHECK( |
104 | [parentpid=`cat parentpid` && | |
105 | parent=`cat parent` && | |
56120500 | 106 | test $parentpid = $parent]) |
cede00f2 RB |
107 | # Kill the daemon process with SIGTERM, and wait for the daemon |
108 | # and the monitor processes to go away and the pidfile to get deleted. | |
56120500 BP |
109 | AT_CHECK([kill `cat pid`], [0], [], [ignore]) |
110 | OVS_WAIT_WHILE([kill -0 `cat parent` || kill -0 `cat newpid` || test -e pid]) | |
cede00f2 RB |
111 | AT_CLEANUP]) |
112 | ||
113 | DAEMON_MONITOR_RESTART_PYN([Python2], [$HAVE_PYTHON], [$PYTHON]) | |
114 | DAEMON_MONITOR_RESTART_PYN([Python3], [$HAVE_PYTHON3], [$PYTHON3]) | |
115 | ||
116 | m4_define([DAEMON_DETACH_PYN], | |
117 | [AT_SETUP([daemon --detach - $1]) | |
118 | AT_SKIP_IF([test $2 = no]) | |
7c20fb26 PB |
119 | # Skip this test for Windows, the pid file not removed if the daemon is killed |
120 | AT_SKIP_IF([test "$IS_WIN32" = "yes"]) | |
cede00f2 RB |
121 | AT_CAPTURE_FILE([pid]) |
122 | # Start the daemon and make sure that the pidfile exists immediately. | |
123 | # We don't wait for the pidfile to get created because the daemon is | |
124 | # supposed to do so before the parent exits. | |
56120500 | 125 | AT_CHECK([$3 $srcdir/test-daemon.py --pidfile=pid --detach], [0]) |
cede00f2 RB |
126 | AT_CHECK([test -s pid]) |
127 | AT_CHECK([kill -0 `cat pid`]) | |
128 | # Kill the daemon and make sure that the pidfile gets deleted. | |
129 | cp pid saved-pid | |
130 | kill `cat pid` | |
131 | OVS_WAIT_WHILE([kill -0 `cat saved-pid`]) | |
132 | AT_CHECK([test ! -e pid]) | |
133 | AT_CLEANUP]) | |
134 | ||
135 | DAEMON_DETACH_PYN([Python2], [$HAVE_PYTHON], [$PYTHON]) | |
136 | DAEMON_DETACH_PYN([Python3], [$HAVE_PYTHON3], [$PYTHON3]) | |
137 | ||
cede00f2 RB |
138 | m4_define([DAEMON_DETACH_MONITOR_PYN], |
139 | [AT_SETUP([daemon --detach --monitor - $1]) | |
140 | AT_SKIP_IF([test $2 = no]) | |
fef32d76 PB |
141 | # Skip this test for Windows, uses Linux specific kill signal |
142 | AT_SKIP_IF([test "$IS_WIN32" = "yes"]) | |
cede00f2 RB |
143 | AT_CAPTURE_FILE([daemon]) |
144 | AT_CAPTURE_FILE([olddaemon]) | |
145 | AT_CAPTURE_FILE([newdaemon]) | |
146 | AT_CAPTURE_FILE([monitor]) | |
147 | AT_CAPTURE_FILE([newmonitor]) | |
148 | AT_CAPTURE_FILE([init]) | |
149 | # Start the daemon and make sure that the pidfile exists immediately. | |
150 | # We don't wait for the pidfile to get created because the daemon is | |
151 | # supposed to do so before the parent exits. | |
56120500 BP |
152 | AT_CHECK([$3 $srcdir/test-daemon.py --pidfile=daemon --detach --monitor], [0]) |
153 | on_exit 'kill `cat daemon olddaemon newdaemon monitor`' | |
cede00f2 RB |
154 | AT_CHECK([test -s daemon]) |
155 | # Check that the pidfile names a running process, | |
156 | # and that the parent process of that process is a running process, | |
157 | # and that the parent process of that process is init. | |
56120500 BP |
158 | AT_CHECK([kill -0 `cat daemon`]) |
159 | AT_CHECK([parent_pid `cat daemon` > monitor]) | |
160 | AT_CHECK([kill -0 `cat monitor`]) | |
161 | AT_CHECK([parent_pid `cat monitor` > init]) | |
162 | AT_CHECK([test `cat init` != $$]) | |
cede00f2 RB |
163 | # Kill the daemon process, making it look like a segfault, |
164 | # and wait for a new daemon process to get spawned. | |
56120500 BP |
165 | AT_CHECK([cp daemon olddaemon]) |
166 | AT_CHECK([kill -SEGV `cat daemon`], [0], [ignore], [ignore]) | |
167 | OVS_WAIT_WHILE([kill -0 `cat olddaemon`]) | |
168 | OVS_WAIT_UNTIL([test -s daemon && test `cat daemon` != `cat olddaemon`]) | |
169 | AT_CHECK([cp daemon newdaemon]) | |
cede00f2 RB |
170 | # Check that the pidfile names a running process, |
171 | # and that the parent process of that process is our child process. | |
56120500 BP |
172 | AT_CHECK([kill -0 `cat daemon`]) |
173 | AT_CHECK([diff olddaemon newdaemon], [1], [ignore]) | |
174 | AT_CHECK([parent_pid `cat daemon` > newmonitor]) | |
175 | AT_CHECK([diff monitor newmonitor]) | |
176 | AT_CHECK([kill -0 `cat newmonitor`]) | |
177 | AT_CHECK([parent_pid `cat newmonitor` > init]) | |
178 | AT_CHECK([test `cat init` != $$]) | |
cede00f2 RB |
179 | # Kill the daemon process with SIGTERM, and wait for the daemon |
180 | # and the monitor processes to go away and the pidfile to get deleted. | |
56120500 | 181 | AT_CHECK([kill `cat daemon`], [0], [], [ignore]) |
cede00f2 | 182 | OVS_WAIT_WHILE( |
56120500 | 183 | [kill -0 `cat monitor` || kill -0 `cat newdaemon` || test -e daemon]) |
cede00f2 RB |
184 | AT_CLEANUP]) |
185 | ||
186 | DAEMON_DETACH_MONITOR_PYN([Python2], [$HAVE_PYTHON], [$PYTHON]) | |
187 | DAEMON_DETACH_MONITOR_PYN([Python3], [$HAVE_PYTHON3], [$PYTHON3]) | |
cede00f2 RB |
188 | |
189 | m4_define([DAEMON_DETACH_ERRORS_PYN], | |
190 | [AT_SETUP([daemon --detach startup errors - $1]) | |
191 | AT_SKIP_IF([test $2 = no]) | |
192 | AT_CAPTURE_FILE([pid]) | |
56120500 | 193 | AT_CHECK([$3 $srcdir/test-daemon.py --pidfile=pid --detach --bail], [1], [], [stderr]) |
cede00f2 RB |
194 | AT_CHECK([grep 'test-daemon.py: exiting after daemonize_start() as requested' stderr], |
195 | [0], [ignore], []) | |
196 | AT_CHECK([test ! -s pid]) | |
197 | AT_CLEANUP]) | |
198 | ||
199 | DAEMON_DETACH_ERRORS_PYN([Python2], [$HAVE_PYTHON], [$PYTHON]) | |
200 | DAEMON_DETACH_ERRORS_PYN([Python3], [$HAVE_PYTHON3], [$PYTHON3]) | |
201 | ||
202 | m4_define([DAEMON_DETACH_MONITOR_ERRORS_PYN], | |
203 | [AT_SETUP([daemon --detach --monitor startup errors - $1]) | |
204 | AT_SKIP_IF([test $2 = no]) | |
205 | AT_CAPTURE_FILE([pid]) | |
56120500 | 206 | AT_CHECK([$3 $srcdir/test-daemon.py --pidfile=pid --detach --monitor --bail], [1], [], [stderr]) |
cede00f2 RB |
207 | AT_CHECK([grep 'test-daemon.py: exiting after daemonize_start() as requested' stderr], |
208 | [0], [ignore], []) | |
209 | AT_CHECK([test ! -s pid]) | |
210 | AT_CLEANUP]) | |
211 | ||
212 | DAEMON_DETACH_MONITOR_ERRORS_PYN([Python2], [$HAVE_PYTHON], [$PYTHON]) | |
213 | DAEMON_DETACH_MONITOR_ERRORS_PYN([Python3], [$HAVE_PYTHON3], [$PYTHON3]) | |
214 | ||
215 | m4_define([DAEMON_DETACH_CLOSES_FDS_PYN], | |
216 | [AT_SETUP([daemon --detach closes standard fds - $1]) | |
217 | AT_SKIP_IF([test $2 = no]) | |
fef32d76 PB |
218 | # Skip this test for Windows, uses Linux specific kill signal |
219 | AT_SKIP_IF([test "$IS_WIN32" = "yes"]) | |
cede00f2 RB |
220 | AT_CAPTURE_FILE([pid]) |
221 | AT_CAPTURE_FILE([status]) | |
222 | AT_CAPTURE_FILE([stderr]) | |
56120500 | 223 | AT_CHECK([(yes 2>stderr; echo $? > status) | $3 $srcdir/test-daemon.py --pidfile=pid --detach]) |
cede00f2 RB |
224 | AT_CHECK([kill `cat pid`]) |
225 | AT_CHECK([test -s status]) | |
226 | if grep '[[bB]]roken pipe' stderr >/dev/null 2>&1; then | |
227 | # Something in the environment caused SIGPIPE to be ignored, but | |
228 | # 'yes' at least told us that it got EPIPE. Good enough; we know | |
229 | # that stdout was closed. | |
230 | : | |
231 | else | |
232 | # Otherwise make sure that 'yes' died from SIGPIPE. | |
233 | AT_CHECK([kill -l `cat status`], [0], [PIPE | |
99155935 | 234 | ]) |
cede00f2 RB |
235 | fi |
236 | AT_CLEANUP]) | |
237 | ||
238 | DAEMON_DETACH_CLOSES_FDS_PYN([Python2], [$HAVE_PYTHON], [$PYTHON]) | |
239 | DAEMON_DETACH_CLOSES_FDS_PYN([Python3], [$HAVE_PYTHON3], [$PYTHON3]) | |
240 | ||
241 | m4_define([DAEMON_DETACH_MONITOR_CLOSES_FDS_PYN], | |
242 | [AT_SETUP([daemon --detach --monitor closes standard fds - $1]) | |
243 | AT_SKIP_IF([test $2 = no]) | |
fef32d76 PB |
244 | # Skip this test for Windows, uses Linux specific kill signal |
245 | AT_SKIP_IF([test "$IS_WIN32" = "yes"]) | |
cede00f2 RB |
246 | AT_CAPTURE_FILE([pid]) |
247 | AT_CAPTURE_FILE([status]) | |
248 | AT_CAPTURE_FILE([stderr]) | |
249 | OVSDB_INIT([db]) | |
56120500 | 250 | AT_CHECK([(yes 2>stderr; echo $? > status) | $3 $srcdir/test-daemon.py --pidfile=pid --detach], [0], [], []) |
cede00f2 RB |
251 | AT_CHECK([kill `cat pid`]) |
252 | AT_CHECK([test -s status]) | |
253 | if grep '[[bB]]roken pipe' stderr >/dev/null 2>&1; then | |
254 | # Something in the environment caused SIGPIPE to be ignored, but | |
255 | # 'yes' at least told us that it got EPIPE. Good enough; we know | |
256 | # that stdout was closed. | |
257 | : | |
258 | else | |
259 | # Otherwise make sure that 'yes' died from SIGPIPE. | |
260 | AT_CHECK([kill -l `cat status`], [0], [PIPE | |
99155935 | 261 | ]) |
cede00f2 RB |
262 | fi |
263 | AT_CLEANUP]) | |
264 | ||
265 | DAEMON_DETACH_MONITOR_CLOSES_FDS_PYN([Python2], [$HAVE_PYTHON], [$PYTHON]) | |
266 | DAEMON_DETACH_MONITOR_CLOSES_FDS_PYN([Python3], [$HAVE_PYTHON3], [$PYTHON3]) |