5 AT_SKIP_IF([test $2 = no])
6 AT_CAPTURE_FILE([log_file])
7 AT_CAPTURE_FILE([stderr_log])
8 AT_CHECK([$3 $srcdir/test-vlog.py --log-file log_file \
9 -v dbg module_1:info module_2:warn syslog:off 2>stderr_log])
11 AT_CHECK([sed -e 's/.*-.*-.*T..:..:..Z |//' \
12 -e 's/File ".*", line [[0-9]][[0-9]]*,/File <name>, line <number>,/' \
13 stderr_log], [0], [dnl
14 0 | module_0 | EMER | emergency
15 1 | module_0 | ERR | error
16 2 | module_0 | WARN | warning
17 3 | module_0 | INFO | information
18 4 | module_0 | DBG | debug
19 5 | module_0 | EMER | emergency exception
20 Traceback (most recent call last):
21 File <name>, line <number>, in main
24 6 | module_0 | ERR | error exception
25 Traceback (most recent call last):
26 File <name>, line <number>, in main
29 7 | module_0 | WARN | warn exception
30 Traceback (most recent call last):
31 File <name>, line <number>, in main
34 8 | module_0 | INFO | information exception
35 Traceback (most recent call last):
36 File <name>, line <number>, in main
39 9 | module_0 | DBG | debug exception
40 Traceback (most recent call last):
41 File <name>, line <number>, in main
44 10 | module_0 | ERR | exception
45 Traceback (most recent call last):
46 File <name>, line <number>, in main
49 11 | module_1 | EMER | emergency
50 12 | module_1 | ERR | error
51 13 | module_1 | WARN | warning
52 14 | module_1 | INFO | information
53 16 | module_1 | EMER | emergency exception
54 Traceback (most recent call last):
55 File <name>, line <number>, in main
58 17 | module_1 | ERR | error exception
59 Traceback (most recent call last):
60 File <name>, line <number>, in main
63 18 | module_1 | WARN | warn exception
64 Traceback (most recent call last):
65 File <name>, line <number>, in main
68 19 | module_1 | INFO | information exception
69 Traceback (most recent call last):
70 File <name>, line <number>, in main
73 21 | module_1 | ERR | exception
74 Traceback (most recent call last):
75 File <name>, line <number>, in main
78 22 | module_2 | EMER | emergency
79 23 | module_2 | ERR | error
80 24 | module_2 | WARN | warning
81 27 | module_2 | EMER | emergency exception
82 Traceback (most recent call last):
83 File <name>, line <number>, in main
86 28 | module_2 | ERR | error exception
87 Traceback (most recent call last):
88 File <name>, line <number>, in main
91 29 | module_2 | WARN | warn exception
92 Traceback (most recent call last):
93 File <name>, line <number>, in main
96 32 | module_2 | ERR | exception
97 Traceback (most recent call last):
98 File <name>, line <number>, in main
105 VLOG_PYN([Python2], [$HAVE_PYTHON], [$PYTHON])
106 VLOG_PYN([Python3], [$HAVE_PYTHON3], [$PYTHON3])
108 m4_divert_push([PREPARE_TESTS])
110 sed 's/.*\(opened log file\).*/\1/
113 m4_divert_pop([PREPARE_TESTS])
115 AT_SETUP([vlog - vlog/reopen - C])
116 # This test won't work as-is on Windows because Windows doesn't allow
117 # files that are open to be renamed.
118 AT_SKIP_IF([test "$IS_WIN32" = "yes"])
119 on_exit 'kill `cat test-unixctl.pid`'
121 AT_CAPTURE_FILE([log])
122 AT_CAPTURE_FILE([log.old])
123 AT_CHECK([ovstest test-unixctl --log-file=`pwd`/log --pidfile --detach],
125 AT_CHECK([vlog_filt stderr], [0],
129 AT_CHECK([APPCTL -t test-unixctl log message])
131 AT_CHECK([APPCTL -t test-unixctl log message2])
132 AT_CHECK([APPCTL -t test-unixctl vlog/reopen])
133 AT_CHECK([APPCTL -t test-unixctl log message3])
134 AT_CHECK([APPCTL -t test-unixctl exit])
136 AT_CHECK([vlog_filt log.old], [0], [dnl
143 AT_CHECK([vlog_filt log], [0], [dnl
149 m4_define([VLOG_REOPEN_PYN],
150 [AT_SETUP([vlog - vlog/reopen - $1])
151 AT_SKIP_IF([test $2 = no])
152 on_exit 'kill `cat test-unixctl.py.pid`'
154 AT_CAPTURE_FILE([log])
155 AT_CAPTURE_FILE([log.old])
156 AT_CHECK([$3 $srcdir/test-unixctl.py --log-file=`pwd`/log --pidfile --detach])
158 AT_CHECK([APPCTL -t test-unixctl.py log message])
160 AT_CHECK([APPCTL -t test-unixctl.py log message2])
161 AT_CHECK([APPCTL -t test-unixctl.py vlog/reopen])
162 AT_CHECK([APPCTL -t test-unixctl.py log message3])
163 AT_CHECK([APPCTL -t test-unixctl.py exit])
165 AT_CHECK([sed 's/.*|//' log.old], [0], [dnl
170 AT_CHECK([sed 's/.*|//' log], [0], [dnl
175 VLOG_REOPEN_PYN([Python2], [$HAVE_PYTHON], [$PYTHON])
176 VLOG_REOPEN_PYN([Python3], [$HAVE_PYTHON3], [$PYTHON3])
178 AT_SETUP([vlog - vlog/reopen without log file - C])
179 on_exit 'kill `cat test-unixctl.pid`'
181 AT_CHECK([ovstest test-unixctl --pidfile --detach])
183 AT_CHECK([APPCTL -t test-unixctl vlog/reopen], [2], [],
184 [Logging to file not configured
185 ovs-appctl: test-unixctl: server returned an error
187 OVS_APP_EXIT_AND_WAIT([test-unixctl])
190 m4_define([VLOG_REOPEN_WITHOUT_FILE_PYN],
191 [AT_SETUP([vlog - vlog/reopen without log file - $1])
192 AT_SKIP_IF([test $2 = no])
193 on_exit 'kill `cat test-unixctl.py.pid`'
195 AT_CHECK([$3 $srcdir/test-unixctl.py --pidfile --detach])
197 AT_CHECK([APPCTL -t test-unixctl.py vlog/reopen], [0],
198 [Logging to file not configured
202 VLOG_REOPEN_WITHOUT_FILE_PYN([Python2], [$HAVE_PYTHON], [$PYTHON])
203 VLOG_REOPEN_WITHOUT_FILE_PYN([Python3], [$HAVE_PYTHON3], [$PYTHON3])
205 dnl This checks that if vlog/reopen can't reopen the log file,
206 dnl nothing particularly bad (e.g. a crash) happens.
207 AT_SETUP([vlog - vlog/reopen can't reopen log file - C])
208 # Verify that /dev/full is a character device that fails writes.
209 AT_SKIP_IF([test ! -c /dev/full])
210 AT_SKIP_IF([echo > /dev/full])
212 on_exit 'kill `cat test-unixctl.pid`'
214 AT_CHECK([ovstest test-unixctl --log-file=`pwd`/log --pidfile --detach],
216 AT_CHECK([vlog_filt stderr], [0], [opened log file
219 AT_CHECK([APPCTL -t test-unixctl log message])
222 AT_CHECK([APPCTL -t test-unixctl vlog/reopen])
223 AT_CHECK([APPCTL -t test-unixctl log message2])
225 AT_CHECK([APPCTL -t test-unixctl vlog/reopen])
226 AT_CHECK([APPCTL -t test-unixctl log message3])
227 AT_CHECK([APPCTL -t test-unixctl exit])
228 AT_CHECK([vlog_filt log.old], [0], [dnl
234 AT_CHECK([vlog_filt log], [0], [dnl
240 dnl This checks that if vlog/reopen can't reopen the log file,
241 dnl nothing particularly bad (e.g. Python throws an exception and
242 dnl aborts the program) happens.
243 m4_define([VLOG_CANT_REOPEN_PYN],
244 [AT_SETUP([vlog - vlog/reopen can't reopen log file - $1])
245 AT_SKIP_IF([test $2 = no])
247 # Verify that /dev/full is a character device that fails writes.
248 AT_SKIP_IF([test ! -c /dev/full])
249 AT_SKIP_IF([echo > /dev/full])
251 on_exit 'kill `cat test-unixctl.py.pid`'
253 AT_CHECK([$3 $srcdir/test-unixctl.py --log-file=`pwd`/log --pidfile --detach])
254 AT_CHECK([APPCTL -t test-unixctl.py log message])
257 AT_CHECK([APPCTL -t test-unixctl.py vlog/reopen])
258 AT_CHECK([APPCTL -t test-unixctl.py log message2])
260 AT_CHECK([APPCTL -t test-unixctl.py vlog/reopen])
261 AT_CHECK([APPCTL -t test-unixctl.py log message3])
262 AT_CHECK([APPCTL -t test-unixctl.py exit])
263 AT_CHECK([sed 's/.*|//' log.old], [0], [dnl
267 AT_CHECK([sed 's/.*|//' log], [0], [dnl
272 VLOG_CANT_REOPEN_PYN([Python2], [$HAVE_PYTHON], [$PYTHON])
273 VLOG_CANT_REOPEN_PYN([Python3], [$HAVE_PYTHON3], [$PYTHON3])
275 AT_SETUP([vlog - vlog/close - C])
276 on_exit 'kill `cat test-unixctl.pid`'
278 AT_CAPTURE_FILE([log])
279 AT_CAPTURE_FILE([log.old])
280 AT_CHECK([ovstest test-unixctl --log-file=`pwd`/log --pidfile --detach],
282 AT_CHECK([vlog_filt log], [0], [opened log file
286 AT_CHECK([APPCTL -t test-unixctl log message])
287 AT_CHECK([APPCTL -t test-unixctl log message2])
289 # After closing the log file, message3 won't appear anywhere.
290 AT_CHECK([APPCTL -t test-unixctl vlog/close])
292 AT_CHECK([APPCTL -t test-unixctl log message3])
294 # Closing the log file again is harmless.
295 AT_CHECK([APPCTL -t test-unixctl vlog/close])
296 AT_CHECK([APPCTL -t test-unixctl log message4])
298 # After reopening the log file, further messages start appearing again.
299 AT_CHECK([APPCTL -t test-unixctl vlog/reopen])
300 AT_CHECK([APPCTL -t test-unixctl log message5])
301 AT_CHECK([APPCTL -t test-unixctl exit])
303 AT_CHECK([vlog_filt log.old], [0], [dnl
309 AT_CHECK([vlog_filt log], [0], [dnl
315 m4_define([VLOG_CLOSE_PYN],
316 [AT_SETUP([vlog - vlog/close - $1])
317 AT_SKIP_IF([test $2 = no])
318 on_exit 'kill `cat test-unixctl.py.pid`'
320 AT_CAPTURE_FILE([log])
321 AT_CAPTURE_FILE([log.old])
322 AT_CHECK([$3 $srcdir/test-unixctl.py --log-file=`pwd`/log --pidfile --detach])
324 AT_CHECK([APPCTL -t test-unixctl.py log message])
325 AT_CHECK([APPCTL -t test-unixctl.py log message2])
327 # After closing the log file, message3 won't appear anywhere.
328 AT_CHECK([APPCTL -t test-unixctl.py vlog/close])
330 AT_CHECK([APPCTL -t test-unixctl.py log message3])
332 # Closing the log file again is harmless.
333 AT_CHECK([APPCTL -t test-unixctl.py vlog/close])
334 AT_CHECK([APPCTL -t test-unixctl.py log message4])
336 # After reopening the log file, further messages start appearing again.
337 AT_CHECK([APPCTL -t test-unixctl.py vlog/reopen])
338 AT_CHECK([APPCTL -t test-unixctl.py log message5])
339 AT_CHECK([APPCTL -t test-unixctl.py exit])
341 AT_CHECK([sed 's/.*|//' log.old], [0], [dnl
346 AT_CHECK([sed 's/.*|//' log], [0], [dnl
351 VLOG_CLOSE_PYN([Python2], [$HAVE_PYTHON], [$PYTHON])
352 VLOG_CLOSE_PYN([Python3], [$HAVE_PYTHON3], [$PYTHON3])
354 AT_SETUP([vlog - vlog/set and vlog/list - C])
355 on_exit 'kill `cat test-unixctl.pid`'
357 AT_CAPTURE_FILE([log])
358 AT_CHECK([ovstest test-unixctl --log-file=`pwd`/log --pidfile --detach],
360 AT_CHECK([vlog_filt log], [0], [opened log file
364 AT_CHECK([APPCTL -t test-unixctl vlog/list | sed -n '1,2p
365 /test_unixctl /p; /daemon /p'], [0], [dnl
367 ------- ------ ------
369 test_unixctl OFF INFO INFO
372 AT_CHECK([APPCTL -t test-unixctl vlog/set daemon:syslog:err])
373 AT_CHECK([APPCTL -t test-unixctl vlog/set file:dbg])
374 AT_CHECK([APPCTL -t test-unixctl vlog/set nonexistent], [2], [],
375 [no destination, level, or module "nonexistent"
376 ovs-appctl: test-unixctl: server returned an error
378 AT_CHECK([APPCTL -t test-unixctl vlog/list | sed -n '1,2p
379 /test_unixctl /p; /daemon /p'], [0], [dnl
381 ------- ------ ------
383 test_unixctl OFF INFO DBG
386 AT_CHECK([APPCTL -t test-unixctl vlog/set pattern], [2], [],
388 ovs-appctl: test-unixctl: server returned an error
390 AT_CHECK([APPCTL -t test-unixctl vlog/set pattern:nonexistent], [2], [],
391 [unknown destination "nonexistent"
392 ovs-appctl: test-unixctl: server returned an error
394 AT_CHECK([APPCTL -t test-unixctl vlog/set pattern:file:'I<3OVS|%m'])
395 AT_CHECK([APPCTL -t test-unixctl log patterntest])
396 AT_CHECK([grep -q 'I<3OVS' log])
397 OVS_APP_EXIT_AND_WAIT([test-unixctl])
400 m4_define([VLOG_SET_AND_LIST_PYN],
401 [AT_SETUP([vlog - vlog/set and vlog/list - $1])
402 AT_SKIP_IF([test $2 = no])
403 on_exit 'kill `cat test-unixctl.py.pid`'
405 AT_CAPTURE_FILE([log])
406 AT_CHECK([$3 $srcdir/test-unixctl.py --log-file=`pwd`/log --pidfile --detach])
408 AT_CHECK([APPCTL -t test-unixctl.py vlog/list], [0], [dnl
410 ------- ------ ------
411 daemon info info info
412 fatal-signal info info info
413 jsonrpc info info info
414 poller info info info
415 reconnect info info info
416 socket_util info info info
417 stream info info info
418 test-unixctl info info info
419 unixctl_server info info info
422 AT_CHECK([APPCTL -t test-unixctl.py vlog/set daemon:syslog:err])
423 AT_CHECK([APPCTL -t test-unixctl.py vlog/set file:dbg])
424 AT_CHECK([APPCTL -t test-unixctl.py vlog/set nonexistent], [0],
425 [no destination, level, or module "nonexistent"
427 AT_CHECK([APPCTL -t test-unixctl.py vlog/list], [0], [dnl
429 ------- ------ ------
431 fatal-signal info info dbg
432 jsonrpc info info dbg
434 reconnect info info dbg
435 socket_util info info dbg
437 test-unixctl info info dbg
438 unixctl_server info info dbg
441 AT_CHECK([APPCTL -t test-unixctl.py vlog/set pattern], [0],
442 [Please supply a valid pattern and destination
444 AT_CHECK([APPCTL -t test-unixctl.py vlog/set pattern:nonexistent], [0],
445 [Destination nonexistent does not exist
447 AT_CHECK([APPCTL -t test-unixctl.py vlog/set pattern:file:'I<3OVS|%m'])
448 AT_CHECK([APPCTL -t test-unixctl.py log patterntest])
449 AT_CHECK([grep -q 'I<3OVS' log])
452 VLOG_SET_AND_LIST_PYN([Python2], [$HAVE_PYTHON], [$PYTHON])
453 VLOG_SET_AND_LIST_PYN([Python3], [$HAVE_PYTHON3], [$PYTHON3])
455 AT_SETUP([vlog - RFC5424 facility])
456 on_exit 'kill `cat ovsdb-server.pid`'
459 touch .conf.db.~lock~
460 AT_CHECK([ovsdb-tool create conf.db $abs_top_srcdir/vswitchd/vswitch.ovsschema])
462 AT_CHECK([ovsdb-server --detach --no-chdir --pidfile \
463 --remote=punix:$OVS_RUNDIR/db.sock -vPATTERN:file:"<%B>1 %A %m" \
464 --log-file], [0], [], [stderr])
465 OVS_APP_EXIT_AND_WAIT([ovsdb-server])
467 # A default facility of LOG_LOCAL0 while writing to file.
468 AT_CHECK([head -1 ovsdb-server.log | awk '{print $1}'], [0], [<133>1
472 AT_CHECK([ovsdb-server --detach --no-chdir --pidfile \
473 --remote=punix:$OVS_RUNDIR/db.sock -vPATTERN:file:"<%B>1 %A %m" \
474 -vFACILITY:daemon --log-file], [0], [], [stderr])
476 AT_CHECK([head -1 ovsdb-server.log | awk '{print $1}'], [0], [<29>1
479 AT_CHECK([ovs-appctl -t ovsdb-server vlog/set FACILITY:invalid], [2], [],
481 ovs-appctl: ovsdb-server: server returned an error
484 AT_CHECK([ovs-appctl -t ovsdb-server vlog/set FACILITY:local7])
485 AT_CHECK([ovs-appctl -t ovsdb-server vlog/set ANY:file:DBG])
486 OVS_APP_EXIT_AND_WAIT([ovsdb-server])
488 AT_CHECK([tail -1 ovsdb-server.log | awk '{print $1}'], [0], [<191>1
492 m4_define([VLOG_RFC5424_PYN],
493 [AT_SETUP([vlog - RFC5424 facility - $1])
494 AT_SKIP_IF([test $2 = no])
495 on_exit 'kill `cat test-unixctl.py.pid`'
497 AT_CHECK([$3 $srcdir/test-unixctl.py --log-file=`pwd`/log --pidfile \
498 -vFACILITY:invalid --detach], [1], [], [test-unixctl.py: processing "FACILITY:invalid": Facility invalid is invalid
501 AT_CHECK([$3 $srcdir/test-unixctl.py --log-file=`pwd`/log --pidfile \
502 -vFACILITY:daemon --detach])
504 AT_CHECK([ovs-appctl -t test-unixctl.py vlog/set FACILITY:invalid], [0],
505 [Facility invalid is invalid
508 AT_CHECK([ovs-appctl -t test-unixctl.py vlog/set FACILITY:local0])
511 VLOG_RFC5424_PYN([Python2], [$HAVE_PYTHON], [$PYTHON])
512 VLOG_RFC5424_PYN([Python3], [$HAVE_PYTHON3], [$PYTHON3])