Zbigniew Jędrzejewski-Szmek
2169cdea8d
journal: do not convert extra args to string in JournalHandler
...
send() already does conversions in a type-specific way, and doing it
in journal handler would defeat those conversions. In particular, UUIDs
would be converted to early and have dashes.
2017-03-19 15:07:59 -04:00
Zbigniew Jędrzejewski-Szmek
aa5550a9b7
test_journal: add tests for MESSAGE_ID passing
...
MESSAGE_ID passing was broken before previous commit:
TypeError: send() got multiple values for keyword argument 'MESSAGE_ID'
With the previous commit it's broken differently:
______________________________ test_journalhandler_message_id_on_handler _______________________________
def test_journalhandler_message_id_on_handler():
record = logging.LogRecord('test-logger', logging.INFO, 'testpath', 1, 'test', None, None)
sender = MockSender()
handler = journal.JournalHandler(logging.INFO, sender_function=sender.send,
MESSAGE_ID=TEST_MID)
handler.emit(record)
assert len(sender.buf) == 1
> assert 'MESSAGE_ID=' + TEST_MID.hex in sender.buf[0]
E assert ('MESSAGE_ID=' + '8441372f8dca4ca98694a6091fd8519f') in ['MESSAGE=test', 'MESSAGE_ID=8441372f-8dca-4ca9-8694-a6091fd8519f', 'CODE_FILE=testpath', 'CODE_LINE=1', 'name=test-logger', 'exc_info=None', ...]
E + where '8441372f8dca4ca98694a6091fd8519f' = UUID('8441372f-8dca-4ca9-8694-a6091fd8519f').hex
systemd/test/test_journal.py:116: AssertionError
______________________________ test_journalhandler_message_id_on_message _______________________________
def test_journalhandler_message_id_on_message():
record = logging.LogRecord('test-logger', logging.INFO, 'testpath', 1, 'test', None, None)
record.__dict__['MESSAGE_ID'] = TEST_MID2
sender = MockSender()
handler = journal.JournalHandler(logging.INFO, sender_function=sender.send,
MESSAGE_ID=TEST_MID)
handler.emit(record)
assert len(sender.buf) == 1
> assert 'MESSAGE_ID=' + TEST_MID2.hex in sender.buf[0]
E assert ('MESSAGE_ID=' + '8441370000000000000000001fd85000') in ['MESSAGE=test', 'MESSAGE_ID=84413700-0000-0000-0000-00001fd85000', 'CODE_FILE=testpath', 'CODE_LINE=1', 'name=test-logger', 'exc_info=None', ...]
E + where '8441370000000000000000001fd85000' = UUID('84413700-0000-0000-0000-00001fd85000').hex
systemd/test/test_journal.py:135: AssertionError
============================ 2 failed, 53 passed, 6 skipped in 0.16 seconds ============================
2017-03-19 15:06:19 -04:00
Zbigniew Jędrzejewski-Szmek
84371c2cfd
journal: rename SENDER_FUNCTION to sender_function
...
Let's not try to make it look like a journal field. It should
be a normal parameter.
Followup for dce0a855c3 .
2017-03-19 13:28:15 -04:00
Zbigniew Jędrzejewski-Szmek
5498ad7513
daemon: properly skip sd_is_socket_sockaddr calls if not available
...
As with other functions, the wrapper is always present, but returns
OSError: [Errno 38] Function not implemented.
2017-03-19 13:17:13 -04:00
Wesley Bowman
73807b49c4
Fix styling to match PEP8 in most places ( #45 )
...
Backwards compatibility for mapPriority is retained.
2017-03-14 17:36:46 -04:00
Zbigniew Jędrzejewski-Szmek
14b05bfff5
Adjust import order, spacing, operators as recommended by pylint
2017-03-12 12:27:49 -04:00
Zbigniew Jędrzejewski-Szmek
5aab3fc3b4
tests: move login tests from doctest to separate file
...
This way we can skip ENOENT (which happens in containers).
While at it, let's extend the tests a bit, so that we at least
call all functions and check the type of the return value.
Also, drop '.nspawn' from the machine name, nspawn doesn't
use that suffix any more.
2017-03-12 12:26:51 -04:00
Zbigniew Jędrzejewski-Szmek
753a4ca5ff
Merge pull request #31 from keszybz/is_socket_sockaddr
...
daemon: add basic support for sd_is_socket_sockaddr
2017-03-11 14:26:27 -05:00
Jeongsoo, Park
dce0a855c3
replace dict.iteritems() with dict.items() to support py3 ( #39 )
...
py3 doesn't have dict.iteritems() anymore.
2017-03-11 13:57:44 -05:00
Mike Gilbert
35a27a4372
test_daemon: xfail test_notify_with_socket if bind() fails ( #42 )
...
This bind() call may fail if TMPDIR is too long.
Bug: https://bugs.gentoo.org/610368
2017-03-11 13:51:16 -05:00
Zbigniew Jędrzejewski-Szmek
bc691d8e29
Fix handling of addresses without port and add tests
2016-12-15 21:15:51 -05:00
Zbigniew Jędrzejewski-Szmek
4a3cee1ad3
daemon: add wrapper for sd_is_socket_sockaddr and tests
...
Specifying the address without does not work.
2016-12-15 21:15:51 -05:00
Zbigniew Jędrzejewski-Szmek
5d1e3fbcdc
tests: skip journal.stream tests on ENOENT error
...
When running in a chroot, doctests that called journal.stream would
fail with ENOENT. Move the tests to test_journal, where we can skip
tests properly (without uglyfying the documentation).
Fixes #32 .
2016-12-15 20:57:44 -05:00
Zbigniew Jędrzejewski-Szmek
35a5b281ad
tests: add workaround for pre-232 system returning EINVAL on some flags
2016-09-22 20:44:25 -04:00
Zbigniew Jędrzejewski-Szmek
177ac6d894
tests: skip fdstore tests if not implemented
...
Should fix #12 .
2016-09-22 07:49:07 -04:00
Zbigniew Jędrzejewski-Szmek
9e0d797ba7
journal: convert seek_realtime argument to microseconds
...
This somewhat breaks backwards compatibility, but not for the
previously documented arguments: floats are now interpreted
differently, but ints and datetime.datetime objects are interpreted
the same as before. But the documentation clearly stated that only
ints and datetime.datetime objects were allowed.
This makes seek_realtime match seek_monotonic and other functions
which take time and follows the principle of least surprise.
Fixes #21 .
2016-09-21 20:16:37 -04:00
Zbigniew Jędrzejewski-Szmek
5211952348
tests: use a context manager, skip new functions if missing
2016-09-21 15:32:58 -04:00
Zbigniew Jędrzejewski-Szmek
02b9432e73
reader: add SD_JOURNAL_OS_ROOT and rework flag passing
...
Let's pass any flags through to the journal functions without checking
validity. Those functions do their own checking, so there's no need to
second-guess.
The semantics for _Reader(flags=0) are a bit changed:
before, this would be transformed into sd_journal_open(SD_J_LOCAL_ONLY).
Now, this results in sd_journal_open(0). Previous behaviour should be
achieved by not specifying the flags at all.
This change is necessary, because previously it was not possible to
pass flags=0 to sd_journal_open(0), i.e. it was not possible to "merge"
journals through the Python interface.
Similarly, Reader(flags=0) now means to open all journals, and
Reader(flags=None) is the same as Reader(flags=LOCAL_ONLY).
2016-09-21 15:32:58 -04:00
Zbigniew Jędrzejewski-Szmek
dadcd3d723
journal: allow sd_journal_open_directory_fd to be used
2016-09-21 15:32:58 -04:00
Zbigniew Jędrzejewski-Szmek
814cdb9d6a
tests: check enumerate_fields, has_runtime_fiels, has_persistent_files
2016-09-20 09:38:18 -04:00
Ville Skyttä
947f782886
Spelling fixes
2016-05-21 08:47:00 +03:00
Mike Gilbert
87a9d64550
test_daemon: Define a default value for SO_PASSCRED
...
The socket module seems to be missing this in python2.7.
2016-01-20 19:08:02 -05:00
Zbigniew Jędrzejewski-Szmek
8ccd64789a
tests: mirror is-systemd-running test from systemd
2015-10-28 10:02:53 -04:00
Zbigniew Jędrzejewski-Szmek
f83f19b3bd
Python2 does not have ConnectionError
2015-10-27 00:07:18 -04:00
Zbigniew Jędrzejewski-Szmek
a947f32b31
tests: add tests for notify()
2015-10-26 23:38:58 -04:00
Zbigniew Jędrzejewski-Szmek
1d8f5f26df
tests: work around bug in sd_is_mq
...
The fix was committed in v226-362-g0260d1d542.
2015-10-25 16:50:59 -04:00
Zbigniew Jędrzejewski-Szmek
173c2a89b2
tests: add simplistic tests for Reader matches
...
It would be nice to run those tests against fake journal files
with the right content to actually test the matches. But those
tests are still useful because they test that the interface
works as expected.
2015-09-16 12:43:06 +02:00
Zbigniew Jędrzejewski-Szmek
bbbc6e8a92
tests: add tests for Reader initialization
2015-09-17 11:53:45 +02:00
Zbigniew Jędrzejewski-Szmek
5bf468dca1
tests: start adding tests for JournalHandler
2015-09-17 11:53:45 +02:00
Zbigniew Jędrzejewski-Szmek
085db21e5e
tests: add more tests for socket functions
2015-09-06 18:54:55 +02:00
Zbigniew Jędrzejewski-Szmek
0cf0cf7e42
tests: daemon.booted
2015-09-05 14:18:32 +02:00
Zbigniew Jędrzejewski-Szmek
2e115f3c4f
tests: daemon.listen_fds
2015-09-05 14:18:23 +02:00
Zbigniew Jędrzejewski-Szmek
a93828172f
tests: add first test
...
This is based on the code in https://github.com/systemd/python-systemd/pull/4
by Jacek Konieczny <j.konieczny@eggsoft.pl>.
2015-08-07 11:49:56 -04:00