1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
==========================
Logging and OOPS reporting
==========================
The Mailman XMLRPCRunner logs errors and reports OOPSes.
Error logging
=============
The log_exception() function is used by XMLRPCRunner to report known
exceptions. It reports the OOPS.
>>> from lp.services.mailman.monkeypatches.xmlrpcrunner import (
... log_exception)
>>> def test_log_exception():
... """Raise an error to test log_exception."""
... try:
... raise AssertionError("There is an OOPS in progress.")
... except AssertionError, error:
... log_exception('Generated Error: %s', error)
>>> from lp.testing.fixture import CaptureOops
>>> capture = CaptureOops()
>>> capture.setUp()
>>> test_log_exception()
>>> oops = capture.oopses[0]
>>> capture.cleanUp()
>>> print oops['reporter']
T-mailman
>>> print oops['id']
OOPS-...
>>> print oops['type']
AssertionError
>>> print oops['value']
There is an OOPS in progress.
>>> print oops['tb_text']
Traceback (most recent call last):
...
AssertionError: There is an OOPS in progress.
The message was written to the XMLRPCRunner's xmlrpc log.
>>> xmlrpc_watcher.wait('Generated')
>>> print 'log:', xmlrpc_watcher.last_lines_read[-1]
log: ... Generated Error: There is an OOPS in progress.
And the message and traceback was written to the error log.
>>> error_watcher.wait('Generated')
>>> print 'log:', error_watcher.last_lines_read[-1]
log: ... Generated Error: There is an OOPS in progress.
>>> error_watcher.wait('AssertionError: There')
>>> print error_watcher.last_lines_read[-1]
AssertionError: There is an OOPS in progress.
XMLRPCRunner's _oneloop() method will log an 'Unexpected XMLRPCRunner
exception' if any uncaught exception occurs in the loop. The logging was
tested by sabotaging the code by adding an undefined name ('defect') to
the _create() method. The create-lists-txt test was run to generate a
"NameError: global name 'defect' is not defined". The error was written
to the xmlrpc log, and an OOPS was reported.
|