osmo-gsm-tester/selftest
Neels Hofmeyr 1a7a3f0e43 fix and refactor logging: drop 'with', simplify
With the recent fix of the junit report related issues, another issue arose:
the 'with log.Origin' was changed to disallow __enter__ing an object twice to
fix problems, now still code would fail because it tries to do 'with' on the
same object twice. The only reason is to ensure that logging is associated with
a given object. Instead of complicating even more, implement differently.

Refactor logging to simplify use: drop the 'with Origin' style completely, and
instead use the python stack to determine which objects are created by which,
and which object to associate a log statement with.

The new way: we rely on the convention that each class instance has a local
'self' referencing the object instance. If we need to find an origin as a new
object's parent, or to associate a log message with, we traverse each stack
frame, fetching the first local 'self' object that is a log.Origin class
instance.

How to use:

Simply call log.log() anywhere, and it finds an Origin object to log for, from
the stack. Alternatively call self.log() for any Origin() object to skip the
lookup.

Create classes as child class of log.Origin and make sure to call
super().__init__(category, name). This constructor will magically find a parent
Origin on the stack.

When an exception happens, we first escalate the exception up through call
scopes to where ever it is handled by log.log_exn(). This then finds an Origin
object in the traceback's stack frames, no need to nest in 'with' scopes.

Hence the 'with log.Origin' now "happens implicitly", we can write pure natural
python code, no more hassles with scope ordering.

Furthermore, any frame can place additional logging information in a frame by
calling log.ctx(). This is automatically inserted in the ancestry associated
with a log statement / exception.

Change-Id: I5f9b53150f2bb6fa9d63ce27f0806f0ca6a45e90
2017-06-13 13:32:01 +02:00
..
conf rename resource nitb_iface to ip_address 2017-05-29 00:18:43 +02:00
config_test core implementation 2017-04-08 15:43:19 +02:00
dbus_test core implementation 2017-04-08 15:43:19 +02:00
process_test core implementation 2017-04-08 15:43:19 +02:00
py_import_test core implementation 2017-04-08 15:43:19 +02:00
suite_test refactor: fix error handling; fix log.Origin; only one trial 2017-06-09 00:35:20 +02:00
template_test core implementation 2017-04-08 15:43:19 +02:00
trial_test core implementation 2017-04-08 15:43:19 +02:00
Makefile core implementation 2017-04-08 15:43:19 +02:00
_prep.py log.py: tweak LogTarget list, require explicit LogTarget 2017-05-08 10:12:25 +00:00
all_tests.py core implementation 2017-04-08 15:43:19 +02:00
config_test.err core implementation 2017-04-08 15:43:19 +02:00
config_test.ok fix and refactor logging: drop 'with', simplify 2017-06-13 13:32:01 +02:00
config_test.py fix 'make check' 2017-04-27 20:24:50 +02:00
lock_test.err core implementation 2017-04-08 15:43:19 +02:00
lock_test.ok cosmetic: lock test: add quotes 2017-05-11 12:33:00 +02:00
lock_test.sh cosmetic: lock test: add quotes 2017-05-11 12:33:00 +02:00
lock_test_help.py lock test: make more robust against timing 2017-05-11 10:31:46 +00:00
log_test.err core implementation 2017-04-08 15:43:19 +02:00
log_test.ok fix and refactor logging: drop 'with', simplify 2017-06-13 13:32:01 +02:00
log_test.py fix and refactor logging: drop 'with', simplify 2017-06-13 13:32:01 +02:00
misc.py core implementation 2017-04-08 15:43:19 +02:00
process_test.err core implementation 2017-04-08 15:43:19 +02:00
process_test.ok fix problem in origin ancestry: don't add self twice 2017-06-07 19:53:24 +02:00
process_test.ok.ign core implementation 2017-04-08 15:43:19 +02:00
process_test.py Add remote user for RemoteProcress 2017-05-04 13:16:21 +00:00
resource_test.err core implementation 2017-04-08 15:43:19 +02:00
resource_test.ok fix and refactor logging: drop 'with', simplify 2017-06-13 13:32:01 +02:00
resource_test.ok.ign config: resolve real paths from symlinks, add paths debug logging 2017-05-04 20:56:48 +00:00
resource_test.py fix and refactor logging: drop 'with', simplify 2017-06-13 13:32:01 +02:00
sms_test.err sms_test: add output checks 2017-05-31 20:40:18 +02:00
sms_test.ok sms_test: add output checks 2017-05-31 20:40:18 +02:00
sms_test.py fix: Sms.__eq__ bug due to typo 2017-05-31 20:39:42 +02:00
suite_test.err core implementation 2017-04-08 15:43:19 +02:00
suite_test.ok fix and refactor logging: drop 'with', simplify 2017-06-13 13:32:01 +02:00
suite_test.ok.ign refactor: fix error handling; fix log.Origin; only one trial 2017-06-09 00:35:20 +02:00
suite_test.py fix and refactor logging: drop 'with', simplify 2017-06-13 13:32:01 +02:00
template_test.err core implementation 2017-04-08 15:43:19 +02:00
template_test.ok fix and refactor logging: drop 'with', simplify 2017-06-13 13:32:01 +02:00
template_test.py config: nitb template: move ip_address to nitb.ip_address 2017-05-29 00:18:43 +02:00
trial_test.err core implementation 2017-04-08 15:43:19 +02:00
trial_test.ok trial.py: Remove accidental double creation of file 2017-05-24 12:02:43 +00:00
trial_test.ok.ign trial: always use abspath 2017-05-15 14:25:24 +02:00
trial_test.py core implementation 2017-04-08 15:43:19 +02:00
util_test.err core implementation 2017-04-08 15:43:19 +02:00
util_test.ok core implementation 2017-04-08 15:43:19 +02:00
util_test.py core implementation 2017-04-08 15:43:19 +02:00