9cfbb1f1d62618d78c7663930a703b15a125ceef
[cascardo/ovs.git] / tests / vlog.at
1 AT_BANNER([vlog])
2
3 AT_SETUP([vlog - Python])
4 AT_SKIP_IF([test $HAVE_PYTHON = no])
5 AT_CAPTURE_FILE([log_file])
6 AT_CAPTURE_FILE([stderr_log])
7 AT_CHECK([$PYTHON $srcdir/test-vlog.py --log-file log_file \
8 -v dbg module_1:info module_2:warn syslog:off 2>stderr_log])
9
10 AT_CHECK([sed -e 's/.*-.*-.*T..:..:..Z |//' \
11 -e 's/File ".*", line [[0-9]][[0-9]]*,/File <name>, line <number>,/' \
12 stderr_log], [0], [dnl
13   0  | module_0 | EMER | emergency
14   1  | module_0 | ERR | error
15   2  | module_0 | WARN | warning
16   3  | module_0 | INFO | information
17   4  | module_0 | DBG | debug
18   5  | module_0 | EMER | emergency exception
19 Traceback (most recent call last):
20   File <name>, line <number>, in main
21     assert fail
22 AssertionError
23   6  | module_0 | ERR | error exception
24 Traceback (most recent call last):
25   File <name>, line <number>, in main
26     assert fail
27 AssertionError
28   7  | module_0 | WARN | warn exception
29 Traceback (most recent call last):
30   File <name>, line <number>, in main
31     assert fail
32 AssertionError
33   8  | module_0 | INFO | information exception
34 Traceback (most recent call last):
35   File <name>, line <number>, in main
36     assert fail
37 AssertionError
38   9  | module_0 | DBG | debug exception
39 Traceback (most recent call last):
40   File <name>, line <number>, in main
41     assert fail
42 AssertionError
43   10 | module_0 | ERR | exception
44 Traceback (most recent call last):
45   File <name>, line <number>, in main
46     assert fail
47 AssertionError
48   11 | module_1 | EMER | emergency
49   12 | module_1 | ERR | error
50   13 | module_1 | WARN | warning
51   14 | module_1 | INFO | information
52   16 | module_1 | EMER | emergency exception
53 Traceback (most recent call last):
54   File <name>, line <number>, in main
55     assert fail
56 AssertionError
57   17 | module_1 | ERR | error exception
58 Traceback (most recent call last):
59   File <name>, line <number>, in main
60     assert fail
61 AssertionError
62   18 | module_1 | WARN | warn exception
63 Traceback (most recent call last):
64   File <name>, line <number>, in main
65     assert fail
66 AssertionError
67   19 | module_1 | INFO | information exception
68 Traceback (most recent call last):
69   File <name>, line <number>, in main
70     assert fail
71 AssertionError
72   21 | module_1 | ERR | exception
73 Traceback (most recent call last):
74   File <name>, line <number>, in main
75     assert fail
76 AssertionError
77   22 | module_2 | EMER | emergency
78   23 | module_2 | ERR | error
79   24 | module_2 | WARN | warning
80   27 | module_2 | EMER | emergency exception
81 Traceback (most recent call last):
82   File <name>, line <number>, in main
83     assert fail
84 AssertionError
85   28 | module_2 | ERR | error exception
86 Traceback (most recent call last):
87   File <name>, line <number>, in main
88     assert fail
89 AssertionError
90   29 | module_2 | WARN | warn exception
91 Traceback (most recent call last):
92   File <name>, line <number>, in main
93     assert fail
94 AssertionError
95   32 | module_2 | ERR | exception
96 Traceback (most recent call last):
97   File <name>, line <number>, in main
98     assert fail
99 AssertionError
100 ])
101
102 AT_CLEANUP
103
104 m4_divert_push([PREPARE_TESTS])
105 vlog_filt () {
106     sed 's/.*\(opened log file\).*/\1/
107 s/.*|//' "$@"
108 }
109 m4_divert_pop([PREPARE_TESTS])
110
111 AT_SETUP([vlog - vlog/reopen - C])
112 # This test won't work as-is on Windows because Windows doesn't allow
113 # files that are open to be renamed.
114 AT_SKIP_IF([test "$IS_WIN32" = "yes"])
115 on_exit 'kill `cat test-unixctl.pid`'
116
117 AT_CAPTURE_FILE([log])
118 AT_CAPTURE_FILE([log.old])
119 AT_CHECK([ovstest test-unixctl --log-file=`pwd`/log --pidfile --detach],
120   [0], [], [stderr])
121 AT_CHECK([vlog_filt stderr], [0],
122   [opened log file
123 ])
124
125 AT_CHECK([APPCTL -t test-unixctl log message])
126 mv log log.old
127 AT_CHECK([APPCTL -t test-unixctl log message2])
128 AT_CHECK([APPCTL -t test-unixctl vlog/reopen])
129 AT_CHECK([APPCTL -t test-unixctl log message3])
130 AT_CHECK([APPCTL -t test-unixctl exit])
131
132 AT_CHECK([vlog_filt log.old], [0], [dnl
133 opened log file
134 Entering run loop.
135 message
136 message2
137 closing log file
138 ])
139 AT_CHECK([vlog_filt log], [0], [dnl
140 opened log file
141 message3
142 ])
143 AT_CLEANUP
144
145 AT_SETUP([vlog - vlog/reopen - Python])
146 AT_SKIP_IF([test $HAVE_PYTHON = no])
147 on_exit 'kill `cat test-unixctl.py.pid`'
148
149 AT_CAPTURE_FILE([log])
150 AT_CAPTURE_FILE([log.old])
151 AT_CHECK([$PYTHON $srcdir/test-unixctl.py --log-file=`pwd`/log --pidfile --detach])
152
153 AT_CHECK([APPCTL -t test-unixctl.py log message])
154 mv log log.old
155 AT_CHECK([APPCTL -t test-unixctl.py log message2])
156 AT_CHECK([APPCTL -t test-unixctl.py vlog/reopen])
157 AT_CHECK([APPCTL -t test-unixctl.py log message3])
158 AT_CHECK([APPCTL -t test-unixctl.py exit])
159
160 AT_CHECK([sed 's/.*|//' log.old], [0], [dnl
161  Entering run loop.
162  message
163  message2
164 ])
165 AT_CHECK([sed 's/.*|//' log], [0], [dnl
166  message3
167 ])
168 AT_CLEANUP
169
170 AT_SETUP([vlog - vlog/reopen without log file - C])
171 on_exit 'kill `cat test-unixctl.pid`'
172
173 AT_CHECK([ovstest test-unixctl --pidfile --detach])
174
175 AT_CHECK([APPCTL -t test-unixctl vlog/reopen], [2], [],
176   [Logging to file not configured
177 ovs-appctl: test-unixctl: server returned an error
178 ])
179 AT_CLEANUP
180
181 AT_SETUP([vlog - vlog/reopen without log file - Python])
182 AT_SKIP_IF([test $HAVE_PYTHON = no])
183 on_exit 'kill `cat test-unixctl.py.pid`'
184
185 AT_CHECK([$PYTHON $srcdir/test-unixctl.py --pidfile --detach])
186
187 AT_CHECK([APPCTL -t test-unixctl.py vlog/reopen], [0],
188   [Logging to file not configured
189 ])
190 AT_CLEANUP
191
192 dnl This checks that if vlog/reopen can't reopen the log file,
193 dnl nothing particularly bad (e.g. a crash) happens.
194 AT_SETUP([vlog - vlog/reopen can't reopen log file - C])
195 # Verify that /dev/full is a character device that fails writes.
196 AT_SKIP_IF([test ! -c /dev/full])
197 AT_SKIP_IF([echo > /dev/full])
198
199 on_exit 'kill `cat test-unixctl.pid`'
200
201 AT_CHECK([ovstest test-unixctl --log-file=`pwd`/log --pidfile --detach],
202   [0], [], [stderr])
203 AT_CHECK([vlog_filt stderr], [0], [opened log file
204 ])
205
206 AT_CHECK([APPCTL -t test-unixctl log message])
207 mv log log.old
208 ln -s /dev/full log
209 AT_CHECK([APPCTL -t test-unixctl vlog/reopen])
210 AT_CHECK([APPCTL -t test-unixctl log message2])
211 rm log
212 AT_CHECK([APPCTL -t test-unixctl vlog/reopen])
213 AT_CHECK([APPCTL -t test-unixctl log message3])
214 AT_CHECK([APPCTL -t test-unixctl exit])
215 AT_CHECK([vlog_filt log.old], [0], [dnl
216 opened log file
217 Entering run loop.
218 message
219 closing log file
220 ])
221 AT_CHECK([vlog_filt log], [0], [dnl
222 opened log file
223 message3
224 ])
225 AT_CLEANUP
226
227 dnl This checks that if vlog/reopen can't reopen the log file,
228 dnl nothing particularly bad (e.g. Python throws an exception and
229 dnl aborts the program) happens.
230 AT_SETUP([vlog - vlog/reopen can't reopen log file - Python])
231 AT_SKIP_IF([test $HAVE_PYTHON = no])
232
233 # Verify that /dev/full is a character device that fails writes.
234 AT_SKIP_IF([test ! -c /dev/full])
235 AT_SKIP_IF([echo > /dev/full])
236
237 on_exit 'kill `cat test-unixctl.py.pid`'
238
239 AT_CHECK([$PYTHON $srcdir/test-unixctl.py --log-file=`pwd`/log --pidfile --detach])
240 AT_CHECK([APPCTL -t test-unixctl.py log message])
241 mv log log.old
242 ln -s /dev/full log
243 AT_CHECK([APPCTL -t test-unixctl.py vlog/reopen])
244 AT_CHECK([APPCTL -t test-unixctl.py log message2])
245 rm log
246 AT_CHECK([APPCTL -t test-unixctl.py vlog/reopen])
247 AT_CHECK([APPCTL -t test-unixctl.py log message3])
248 AT_CHECK([APPCTL -t test-unixctl.py exit])
249 AT_CHECK([sed 's/.*|//' log.old], [0], [dnl
250  Entering run loop.
251  message
252 ])
253 AT_CHECK([sed 's/.*|//' log], [0], [dnl
254  message3
255 ])
256 AT_CLEANUP
257
258 AT_SETUP([vlog - vlog/close - C])
259 on_exit 'kill `cat test-unixctl.pid`'
260
261 AT_CAPTURE_FILE([log])
262 AT_CAPTURE_FILE([log.old])
263 AT_CHECK([ovstest test-unixctl --log-file=`pwd`/log --pidfile --detach],
264   [0], [], [stderr])
265 AT_CHECK([vlog_filt stderr], [0], [opened log file
266 ])
267
268 AT_CHECK([APPCTL -t test-unixctl log message])
269 AT_CHECK([APPCTL -t test-unixctl log message2])
270
271 # After closing the log file, message3 won't appear anywhere.
272 AT_CHECK([APPCTL -t test-unixctl vlog/close])
273 mv log log.old
274 AT_CHECK([APPCTL -t test-unixctl log message3])
275
276 # Closing the log file again is harmless.
277 AT_CHECK([APPCTL -t test-unixctl vlog/close])
278 AT_CHECK([APPCTL -t test-unixctl log message4])
279
280 # After reopening the log file, further messages start appearing again.
281 AT_CHECK([APPCTL -t test-unixctl vlog/reopen])
282 AT_CHECK([APPCTL -t test-unixctl log message5])
283 AT_CHECK([APPCTL -t test-unixctl exit])
284
285 AT_CHECK([vlog_filt log.old], [0], [dnl
286 opened log file
287 Entering run loop.
288 message
289 message2
290 ])
291 AT_CHECK([vlog_filt log], [0], [dnl
292 opened log file
293 message5
294 ])
295 AT_CLEANUP
296
297 AT_SETUP([vlog - vlog/close - Python])
298 AT_SKIP_IF([test $HAVE_PYTHON = no])
299 on_exit 'kill `cat test-unixctl.py.pid`'
300
301 AT_CAPTURE_FILE([log])
302 AT_CAPTURE_FILE([log.old])
303 AT_CHECK([$PYTHON $srcdir/test-unixctl.py --log-file=`pwd`/log --pidfile --detach])
304
305 AT_CHECK([APPCTL -t test-unixctl.py log message])
306 AT_CHECK([APPCTL -t test-unixctl.py log message2])
307
308 # After closing the log file, message3 won't appear anywhere.
309 AT_CHECK([APPCTL -t test-unixctl.py vlog/close])
310 mv log log.old
311 AT_CHECK([APPCTL -t test-unixctl.py log message3])
312
313 # Closing the log file again is harmless.
314 AT_CHECK([APPCTL -t test-unixctl.py vlog/close])
315 AT_CHECK([APPCTL -t test-unixctl.py log message4])
316
317 # After reopening the log file, further messages start appearing again.
318 AT_CHECK([APPCTL -t test-unixctl.py vlog/reopen])
319 AT_CHECK([APPCTL -t test-unixctl.py log message5])
320 AT_CHECK([APPCTL -t test-unixctl.py exit])
321
322 AT_CHECK([sed 's/.*|//' log.old], [0], [dnl
323  Entering run loop.
324  message
325  message2
326 ])
327 AT_CHECK([sed 's/.*|//' log], [0], [dnl
328  message5
329 ])
330 AT_CLEANUP
331
332 AT_SETUP([vlog - vlog/set and vlog/list - C])
333 on_exit 'kill `cat test-unixctl.pid`'
334
335 AT_CAPTURE_FILE([log])
336 AT_CHECK([ovstest test-unixctl --log-file=`pwd`/log --pidfile --detach],
337   [0], [], [stderr])
338 AT_CHECK([vlog_filt stderr], [0], [opened log file
339 ])
340
341 AT_CHECK([APPCTL -t test-unixctl vlog/list | sed -n '1,2p
342 /\(test_unixctl\|daemon\) /p'], [0], [dnl
343                  console    syslog    file
344                  -------    ------    ------
345 daemon             OFF       INFO       INFO
346 test_unixctl       OFF       INFO       INFO
347 ])
348
349 AT_CHECK([APPCTL -t test-unixctl vlog/set daemon:syslog:err])
350 AT_CHECK([APPCTL -t test-unixctl vlog/set file:dbg])
351 AT_CHECK([APPCTL -t test-unixctl vlog/set nonexistent], [2], [],
352   [no destination, level, or module "nonexistent"
353 ovs-appctl: test-unixctl: server returned an error
354 ])
355 AT_CHECK([APPCTL -t test-unixctl vlog/list | sed -n '1,2p
356 /\(test_unixctl\|daemon\) /p'], [0], [dnl
357                  console    syslog    file
358                  -------    ------    ------
359 daemon             OFF        ERR        DBG
360 test_unixctl       OFF       INFO        DBG
361 ])
362
363 AT_CHECK([APPCTL -t test-unixctl vlog/set pattern], [2], [],
364   [missing destination
365 ovs-appctl: test-unixctl: server returned an error
366 ])
367 AT_CHECK([APPCTL -t test-unixctl vlog/set pattern:nonexistent], [2], [],
368   [unknown destination "nonexistent"
369 ovs-appctl: test-unixctl: server returned an error
370 ])
371 AT_CHECK([APPCTL -t test-unixctl vlog/set pattern:file:'I<3OVS|%m'])
372 AT_CHECK([APPCTL -t test-unixctl log patterntest])
373 AT_CHECK([grep -q 'I<3OVS' log])
374 AT_CLEANUP
375
376 AT_SETUP([vlog - vlog/set and vlog/list - Python])
377 AT_SKIP_IF([test $HAVE_PYTHON = no])
378 on_exit 'kill `cat test-unixctl.py.pid`'
379
380 AT_CAPTURE_FILE([log])
381 AT_CHECK([$PYTHON $srcdir/test-unixctl.py --log-file=`pwd`/log --pidfile --detach])
382
383 AT_CHECK([APPCTL -t test-unixctl.py vlog/list], [0], [dnl
384                  console    syslog    file
385                  -------    ------    ------
386 daemon            info       info       info
387 fatal-signal      info       info       info
388 jsonrpc           info       info       info
389 poller            info       info       info
390 reconnect         info       info       info
391 socket_util       info       info       info
392 stream            info       info       info
393 test-unixctl      info       info       info
394 unixctl_server    info       info       info
395 ])
396
397 AT_CHECK([APPCTL -t test-unixctl.py vlog/set daemon:syslog:err])
398 AT_CHECK([APPCTL -t test-unixctl.py vlog/set file:dbg])
399 AT_CHECK([APPCTL -t test-unixctl.py vlog/set nonexistent], [0],
400   [no destination, level, or module "nonexistent"
401 ])
402 AT_CHECK([APPCTL -t test-unixctl.py vlog/list], [0], [dnl
403                  console    syslog    file
404                  -------    ------    ------
405 daemon            info        err        dbg
406 fatal-signal      info       info        dbg
407 jsonrpc           info       info        dbg
408 poller            info       info        dbg
409 reconnect         info       info        dbg
410 socket_util       info       info        dbg
411 stream            info       info        dbg
412 test-unixctl      info       info        dbg
413 unixctl_server    info       info        dbg
414 ])
415
416 AT_CHECK([APPCTL -t test-unixctl.py vlog/set pattern], [0],
417   [Please supply a valid pattern and destination
418 ])
419 AT_CHECK([APPCTL -t test-unixctl.py vlog/set pattern:nonexistent], [0],
420   [Destination nonexistent does not exist
421 ])
422 AT_CHECK([APPCTL -t test-unixctl.py vlog/set pattern:file:'I<3OVS|%m'])
423 AT_CHECK([APPCTL -t test-unixctl.py log patterntest])
424 AT_CHECK([grep -q 'I<3OVS' log])
425 AT_CLEANUP
426
427 AT_SETUP([vlog - RFC5424 facility])
428 on_exit 'kill `cat ovsdb-server.pid`'
429
430 dnl Create database.
431 touch .conf.db.~lock~
432 AT_CHECK([ovsdb-tool create conf.db $abs_top_srcdir/vswitchd/vswitch.ovsschema])
433
434 AT_CHECK([ovsdb-server --detach --no-chdir --pidfile \
435           --remote=punix:$OVS_RUNDIR/db.sock -vPATTERN:file:"<%B>1 %A %m" \
436           --log-file], [0], [], [stderr])
437 AT_CHECK([ovs-appctl -t ovsdb-server exit])
438
439 # A default facility of LOG_LOCAL0 while writing to file.
440 AT_CHECK([head -1 ovsdb-server.log | awk '{print $1}'], [0], [<133>1
441 ])
442 rm ovsdb-server.log
443
444 AT_CHECK([ovsdb-server --detach --no-chdir --pidfile \
445           --remote=punix:$OVS_RUNDIR/db.sock -vPATTERN:file:"<%B>1 %A %m" \
446           -vFACILITY:daemon --log-file], [0], [], [stderr])
447
448 AT_CHECK([head -1 ovsdb-server.log | awk '{print $1}'], [0], [<29>1
449 ])
450
451 AT_CHECK([ovs-appctl -t ovsdb-server vlog/set FACILITY:invalid], [2], [],
452 [invalid facility
453 ovs-appctl: ovsdb-server: server returned an error
454 ])
455
456 AT_CHECK([ovs-appctl -t ovsdb-server vlog/set FACILITY:local7])
457 AT_CHECK([ovs-appctl -t ovsdb-server vlog/set ANY:file:DBG])
458 AT_CHECK([ovs-appctl -t ovsdb-server exit])
459
460 AT_CHECK([tail -1 ovsdb-server.log | awk '{print $1}'], [0], [<191>1
461 ])
462 AT_CLEANUP
463
464 AT_SETUP([vlog - RFC5424 facility - Python])
465 AT_SKIP_IF([test $HAVE_PYTHON = no])
466 on_exit 'kill `cat test-unixctl.py.pid`'
467
468 AT_CHECK([$PYTHON $srcdir/test-unixctl.py --log-file=`pwd`/log --pidfile \
469 -vFACILITY:invalid --detach], [1], [], [test-unixctl.py: processing "FACILITY:invalid": Facility invalid is invalid
470 ])
471
472 AT_CHECK([$PYTHON $srcdir/test-unixctl.py --log-file=`pwd`/log --pidfile \
473 -vFACILITY:daemon --detach])
474
475 AT_CHECK([ovs-appctl -t test-unixctl.py vlog/set FACILITY:invalid], [0],
476 [Facility invalid is invalid
477 ])
478
479 AT_CHECK([ovs-appctl -t test-unixctl.py vlog/set FACILITY:local0])
480 AT_CLEANUP