check-kmod: Remove all OVS modules in this target.
[cascardo/ovs.git] / tests / vlog.at
1 AT_BANNER([vlog])
2
3 m4_define([VLOG_PYN],
4   [AT_SETUP([vlog - $1])
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])
10
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
22     assert fail
23 AssertionError
24   6  | module_0 | ERR | error exception
25 Traceback (most recent call last):
26   File <name>, line <number>, in main
27     assert fail
28 AssertionError
29   7  | module_0 | WARN | warn exception
30 Traceback (most recent call last):
31   File <name>, line <number>, in main
32     assert fail
33 AssertionError
34   8  | module_0 | INFO | information exception
35 Traceback (most recent call last):
36   File <name>, line <number>, in main
37     assert fail
38 AssertionError
39   9  | module_0 | DBG | debug exception
40 Traceback (most recent call last):
41   File <name>, line <number>, in main
42     assert fail
43 AssertionError
44   10 | module_0 | ERR | exception
45 Traceback (most recent call last):
46   File <name>, line <number>, in main
47     assert fail
48 AssertionError
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
56     assert fail
57 AssertionError
58   17 | module_1 | ERR | error exception
59 Traceback (most recent call last):
60   File <name>, line <number>, in main
61     assert fail
62 AssertionError
63   18 | module_1 | WARN | warn exception
64 Traceback (most recent call last):
65   File <name>, line <number>, in main
66     assert fail
67 AssertionError
68   19 | module_1 | INFO | information exception
69 Traceback (most recent call last):
70   File <name>, line <number>, in main
71     assert fail
72 AssertionError
73   21 | module_1 | ERR | exception
74 Traceback (most recent call last):
75   File <name>, line <number>, in main
76     assert fail
77 AssertionError
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
84     assert fail
85 AssertionError
86   28 | module_2 | ERR | error exception
87 Traceback (most recent call last):
88   File <name>, line <number>, in main
89     assert fail
90 AssertionError
91   29 | module_2 | WARN | warn exception
92 Traceback (most recent call last):
93   File <name>, line <number>, in main
94     assert fail
95 AssertionError
96   32 | module_2 | ERR | exception
97 Traceback (most recent call last):
98   File <name>, line <number>, in main
99     assert fail
100 AssertionError
101 ])
102
103    AT_CLEANUP])
104
105 VLOG_PYN([Python2], [$HAVE_PYTHON], [$PYTHON])
106 VLOG_PYN([Python3], [$HAVE_PYTHON3], [$PYTHON3])
107
108 m4_divert_push([PREPARE_TESTS])
109 vlog_filt () {
110     sed 's/.*\(opened log file\).*/\1/
111 s/.*|//' "$@"
112 }
113 m4_divert_pop([PREPARE_TESTS])
114
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`'
120
121 AT_CAPTURE_FILE([log])
122 AT_CAPTURE_FILE([log.old])
123 AT_CHECK([ovstest test-unixctl --log-file=`pwd`/log --pidfile --detach],
124   [0], [], [stderr])
125 AT_CHECK([vlog_filt stderr], [0],
126   [opened log file
127 ])
128
129 AT_CHECK([APPCTL -t test-unixctl log message])
130 mv log log.old
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])
135
136 AT_CHECK([vlog_filt log.old], [0], [dnl
137 opened log file
138 Entering run loop.
139 message
140 message2
141 closing log file
142 ])
143 AT_CHECK([vlog_filt log], [0], [dnl
144 opened log file
145 message3
146 ])
147 AT_CLEANUP
148
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`'
153
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])
157
158    AT_CHECK([APPCTL -t test-unixctl.py log message])
159    mv log log.old
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])
164
165    AT_CHECK([sed 's/.*|//' log.old], [0], [dnl
166  Entering run loop.
167  message
168  message2
169 ])
170    AT_CHECK([sed 's/.*|//' log], [0], [dnl
171  message3
172 ])
173    AT_CLEANUP])
174
175 VLOG_REOPEN_PYN([Python2], [$HAVE_PYTHON], [$PYTHON])
176 VLOG_REOPEN_PYN([Python3], [$HAVE_PYTHON3], [$PYTHON3])
177
178 AT_SETUP([vlog - vlog/reopen without log file - C])
179 on_exit 'kill `cat test-unixctl.pid`'
180
181 AT_CHECK([ovstest test-unixctl --pidfile --detach])
182
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
186 ])
187 OVS_APP_EXIT_AND_WAIT([test-unixctl])
188 AT_CLEANUP
189
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`'
194
195    AT_CHECK([$3 $srcdir/test-unixctl.py --pidfile --detach])
196
197    AT_CHECK([APPCTL -t test-unixctl.py vlog/reopen], [0],
198      [Logging to file not configured
199 ])
200    AT_CLEANUP])
201
202 VLOG_REOPEN_WITHOUT_FILE_PYN([Python2], [$HAVE_PYTHON], [$PYTHON])
203 VLOG_REOPEN_WITHOUT_FILE_PYN([Python3], [$HAVE_PYTHON3], [$PYTHON3])
204
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])
211
212 on_exit 'kill `cat test-unixctl.pid`'
213
214 AT_CHECK([ovstest test-unixctl --log-file=`pwd`/log --pidfile --detach],
215   [0], [], [stderr])
216 AT_CHECK([vlog_filt stderr], [0], [opened log file
217 ])
218
219 AT_CHECK([APPCTL -t test-unixctl log message])
220 mv log log.old
221 ln -s /dev/full log
222 AT_CHECK([APPCTL -t test-unixctl vlog/reopen])
223 AT_CHECK([APPCTL -t test-unixctl log message2])
224 rm log
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
229 opened log file
230 Entering run loop.
231 message
232 closing log file
233 ])
234 AT_CHECK([vlog_filt log], [0], [dnl
235 opened log file
236 message3
237 ])
238 AT_CLEANUP
239
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])
246
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])
250
251    on_exit 'kill `cat test-unixctl.py.pid`'
252
253    AT_CHECK([$3 $srcdir/test-unixctl.py --log-file=`pwd`/log --pidfile --detach])
254    AT_CHECK([APPCTL -t test-unixctl.py log message])
255    mv log log.old
256    ln -s /dev/full log
257    AT_CHECK([APPCTL -t test-unixctl.py vlog/reopen])
258    AT_CHECK([APPCTL -t test-unixctl.py log message2])
259    rm log
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
264  Entering run loop.
265  message
266 ])
267    AT_CHECK([sed 's/.*|//' log], [0], [dnl
268  message3
269 ])
270    AT_CLEANUP])
271
272 VLOG_CANT_REOPEN_PYN([Python2], [$HAVE_PYTHON], [$PYTHON])
273 VLOG_CANT_REOPEN_PYN([Python3], [$HAVE_PYTHON3], [$PYTHON3])
274
275 AT_SETUP([vlog - vlog/close - C])
276 on_exit 'kill `cat test-unixctl.pid`'
277
278 AT_CAPTURE_FILE([log])
279 AT_CAPTURE_FILE([log.old])
280 AT_CHECK([ovstest test-unixctl --log-file=`pwd`/log --pidfile --detach],
281   [0], [], [stderr])
282 AT_CHECK([vlog_filt stderr], [0], [opened log file
283 ])
284
285 AT_CHECK([APPCTL -t test-unixctl log message])
286 AT_CHECK([APPCTL -t test-unixctl log message2])
287
288 # After closing the log file, message3 won't appear anywhere.
289 AT_CHECK([APPCTL -t test-unixctl vlog/close])
290 mv log log.old
291 AT_CHECK([APPCTL -t test-unixctl log message3])
292
293 # Closing the log file again is harmless.
294 AT_CHECK([APPCTL -t test-unixctl vlog/close])
295 AT_CHECK([APPCTL -t test-unixctl log message4])
296
297 # After reopening the log file, further messages start appearing again.
298 AT_CHECK([APPCTL -t test-unixctl vlog/reopen])
299 AT_CHECK([APPCTL -t test-unixctl log message5])
300 AT_CHECK([APPCTL -t test-unixctl exit])
301
302 AT_CHECK([vlog_filt log.old], [0], [dnl
303 opened log file
304 Entering run loop.
305 message
306 message2
307 ])
308 AT_CHECK([vlog_filt log], [0], [dnl
309 opened log file
310 message5
311 ])
312 AT_CLEANUP
313
314 m4_define([VLOG_CLOSE_PYN],
315   [AT_SETUP([vlog - vlog/close - $1])
316    AT_SKIP_IF([test $2 = no])
317    on_exit 'kill `cat test-unixctl.py.pid`'
318
319    AT_CAPTURE_FILE([log])
320    AT_CAPTURE_FILE([log.old])
321    AT_CHECK([$3 $srcdir/test-unixctl.py --log-file=`pwd`/log --pidfile --detach])
322
323    AT_CHECK([APPCTL -t test-unixctl.py log message])
324    AT_CHECK([APPCTL -t test-unixctl.py log message2])
325
326    # After closing the log file, message3 won't appear anywhere.
327    AT_CHECK([APPCTL -t test-unixctl.py vlog/close])
328    mv log log.old
329    AT_CHECK([APPCTL -t test-unixctl.py log message3])
330
331    # Closing the log file again is harmless.
332    AT_CHECK([APPCTL -t test-unixctl.py vlog/close])
333    AT_CHECK([APPCTL -t test-unixctl.py log message4])
334
335    # After reopening the log file, further messages start appearing again.
336    AT_CHECK([APPCTL -t test-unixctl.py vlog/reopen])
337    AT_CHECK([APPCTL -t test-unixctl.py log message5])
338    AT_CHECK([APPCTL -t test-unixctl.py exit])
339
340    AT_CHECK([sed 's/.*|//' log.old], [0], [dnl
341  Entering run loop.
342  message
343  message2
344 ])
345    AT_CHECK([sed 's/.*|//' log], [0], [dnl
346  message5
347 ])
348    AT_CLEANUP])
349
350 VLOG_CLOSE_PYN([Python2], [$HAVE_PYTHON], [$PYTHON])
351 VLOG_CLOSE_PYN([Python3], [$HAVE_PYTHON3], [$PYTHON3])
352
353 AT_SETUP([vlog - vlog/set and vlog/list - C])
354 on_exit 'kill `cat test-unixctl.pid`'
355
356 AT_CAPTURE_FILE([log])
357 AT_CHECK([ovstest test-unixctl --log-file=`pwd`/log --pidfile --detach],
358   [0], [], [stderr])
359 AT_CHECK([vlog_filt stderr], [0], [opened log file
360 ])
361
362 AT_CHECK([APPCTL -t test-unixctl vlog/list | sed -n '1,2p
363 /test_unixctl /p; /daemon /p'], [0], [dnl
364                  console    syslog    file
365                  -------    ------    ------
366 daemon             OFF       INFO       INFO
367 test_unixctl       OFF       INFO       INFO
368 ])
369
370 AT_CHECK([APPCTL -t test-unixctl vlog/set daemon:syslog:err])
371 AT_CHECK([APPCTL -t test-unixctl vlog/set file:dbg])
372 AT_CHECK([APPCTL -t test-unixctl vlog/set nonexistent], [2], [],
373   [no destination, level, or module "nonexistent"
374 ovs-appctl: test-unixctl: server returned an error
375 ])
376 AT_CHECK([APPCTL -t test-unixctl vlog/list | sed -n '1,2p
377 /test_unixctl /p; /daemon /p'], [0], [dnl
378                  console    syslog    file
379                  -------    ------    ------
380 daemon             OFF        ERR        DBG
381 test_unixctl       OFF       INFO        DBG
382 ])
383
384 AT_CHECK([APPCTL -t test-unixctl vlog/set pattern], [2], [],
385   [missing destination
386 ovs-appctl: test-unixctl: server returned an error
387 ])
388 AT_CHECK([APPCTL -t test-unixctl vlog/set pattern:nonexistent], [2], [],
389   [unknown destination "nonexistent"
390 ovs-appctl: test-unixctl: server returned an error
391 ])
392 AT_CHECK([APPCTL -t test-unixctl vlog/set pattern:file:'I<3OVS|%m'])
393 AT_CHECK([APPCTL -t test-unixctl log patterntest])
394 AT_CHECK([grep -q 'I<3OVS' log])
395 OVS_APP_EXIT_AND_WAIT([test-unixctl])
396 AT_CLEANUP
397
398 m4_define([VLOG_SET_AND_LIST_PYN],
399   [AT_SETUP([vlog - vlog/set and vlog/list - $1])
400    AT_SKIP_IF([test $2 = no])
401    on_exit 'kill `cat test-unixctl.py.pid`'
402
403    AT_CAPTURE_FILE([log])
404    AT_CHECK([$3 $srcdir/test-unixctl.py --log-file=`pwd`/log --pidfile --detach])
405
406    AT_CHECK([APPCTL -t test-unixctl.py vlog/list], [0], [dnl
407                  console    syslog    file
408                  -------    ------    ------
409 daemon            info       info       info
410 fatal-signal      info       info       info
411 jsonrpc           info       info       info
412 poller            info       info       info
413 reconnect         info       info       info
414 socket_util       info       info       info
415 stream            info       info       info
416 test-unixctl      info       info       info
417 unixctl_server    info       info       info
418 ])
419
420    AT_CHECK([APPCTL -t test-unixctl.py vlog/set daemon:syslog:err])
421    AT_CHECK([APPCTL -t test-unixctl.py vlog/set file:dbg])
422    AT_CHECK([APPCTL -t test-unixctl.py vlog/set nonexistent], [0],
423   [no destination, level, or module "nonexistent"
424 ])
425    AT_CHECK([APPCTL -t test-unixctl.py vlog/list], [0], [dnl
426                  console    syslog    file
427                  -------    ------    ------
428 daemon            info        err        dbg
429 fatal-signal      info       info        dbg
430 jsonrpc           info       info        dbg
431 poller            info       info        dbg
432 reconnect         info       info        dbg
433 socket_util       info       info        dbg
434 stream            info       info        dbg
435 test-unixctl      info       info        dbg
436 unixctl_server    info       info        dbg
437 ])
438
439    AT_CHECK([APPCTL -t test-unixctl.py vlog/set pattern], [0],
440   [Please supply a valid pattern and destination
441 ])
442    AT_CHECK([APPCTL -t test-unixctl.py vlog/set pattern:nonexistent], [0],
443   [Destination nonexistent does not exist
444 ])
445    AT_CHECK([APPCTL -t test-unixctl.py vlog/set pattern:file:'I<3OVS|%m'])
446    AT_CHECK([APPCTL -t test-unixctl.py log patterntest])
447    AT_CHECK([grep -q 'I<3OVS' log])
448    AT_CLEANUP])
449
450 VLOG_SET_AND_LIST_PYN([Python2], [$HAVE_PYTHON], [$PYTHON])
451 VLOG_SET_AND_LIST_PYN([Python3], [$HAVE_PYTHON3], [$PYTHON3])
452
453 AT_SETUP([vlog - RFC5424 facility])
454 on_exit 'kill `cat ovsdb-server.pid`'
455
456 dnl Create database.
457 touch .conf.db.~lock~
458 AT_CHECK([ovsdb-tool create conf.db $abs_top_srcdir/vswitchd/vswitch.ovsschema])
459
460 AT_CHECK([ovsdb-server --detach --no-chdir --pidfile \
461           --remote=punix:$OVS_RUNDIR/db.sock -vPATTERN:file:"<%B>1 %A %m" \
462           --log-file], [0], [], [stderr])
463 OVS_APP_EXIT_AND_WAIT([ovsdb-server])
464
465 # A default facility of LOG_LOCAL0 while writing to file.
466 AT_CHECK([head -1 ovsdb-server.log | awk '{print $1}'], [0], [<133>1
467 ])
468 rm ovsdb-server.log
469
470 AT_CHECK([ovsdb-server --detach --no-chdir --pidfile \
471           --remote=punix:$OVS_RUNDIR/db.sock -vPATTERN:file:"<%B>1 %A %m" \
472           -vFACILITY:daemon --log-file], [0], [], [stderr])
473
474 AT_CHECK([head -1 ovsdb-server.log | awk '{print $1}'], [0], [<29>1
475 ])
476
477 AT_CHECK([ovs-appctl -t ovsdb-server vlog/set FACILITY:invalid], [2], [],
478 [invalid facility
479 ovs-appctl: ovsdb-server: server returned an error
480 ])
481
482 AT_CHECK([ovs-appctl -t ovsdb-server vlog/set FACILITY:local7])
483 AT_CHECK([ovs-appctl -t ovsdb-server vlog/set ANY:file:DBG])
484 OVS_APP_EXIT_AND_WAIT([ovsdb-server])
485
486 AT_CHECK([tail -1 ovsdb-server.log | awk '{print $1}'], [0], [<191>1
487 ])
488 AT_CLEANUP
489
490 m4_define([VLOG_RFC5424_PYN],
491   [AT_SETUP([vlog - RFC5424 facility - $1])
492    AT_SKIP_IF([test $2 = no])
493    on_exit 'kill `cat test-unixctl.py.pid`'
494
495    AT_CHECK([$3 $srcdir/test-unixctl.py --log-file=`pwd`/log --pidfile \
496 -vFACILITY:invalid --detach], [1], [], [test-unixctl.py: processing "FACILITY:invalid": Facility invalid is invalid
497 ])
498
499    AT_CHECK([$3 $srcdir/test-unixctl.py --log-file=`pwd`/log --pidfile \
500 -vFACILITY:daemon --detach])
501
502    AT_CHECK([ovs-appctl -t test-unixctl.py vlog/set FACILITY:invalid], [0],
503 [Facility invalid is invalid
504 ])
505
506    AT_CHECK([ovs-appctl -t test-unixctl.py vlog/set FACILITY:local0])
507    AT_CLEANUP])
508
509 VLOG_RFC5424_PYN([Python2], [$HAVE_PYTHON], [$PYTHON])
510 VLOG_RFC5424_PYN([Python3], [$HAVE_PYTHON3], [$PYTHON3])