Commit graph

188 commits

Author SHA1 Message Date
Zbigniew Jędrzejewski-Szmek
a54a7a2f51 Update to constants from systemd-233
In systemd-233 the format of the constants file changed to use
SD_ID128_MAKE_STR macro and long lines are broken with '\'.
Doing this in sed is too anyoing — add a simple python script to
do the processing.
2017-03-25 21:33:05 -04:00
Zbigniew Jędrzejewski-Szmek
a5dc4ab856 journal: fix repr of JournalHandler to match python3.6
We get <systemd.journal.JournalHandler object at ...> in older versions,
and <JournalHandler (NOTSET)> in since Python 3.6.
c075201147
2017-03-25 12:31:45 -04:00
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
Wesley Bowman
08857486e6 Remove mid from JournalHandler
Removed mid variable from JournalHandler since the MESSAGE_ID is already
in the extras variable. MESSAGE_ID was being set to None, but this won't
appear in the logs.
2017-03-19 13:33:32 -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
c7e393b3ca journal: improve docstring formatting a bit 2017-03-12 12:46:16 -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
Jimmy Cao
8921c79fb9 Prevent non-str values from being concatenated with + (#40)
Make _make_line concatenate only strings directly.
2017-03-12 12:16:45 -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
Ville Skyttä
ea8e705939 Python 3.6 invalid escape sequence deprecation fixes (#43)
https://docs.python.org/3/whatsnew/3.6.html#deprecated-python-behavior
2017-03-11 13:47:37 -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
5ffc226890 _daemon: allow specifying flowinfo
Not particularly useful, but let's have it for completeness.
2016-12-15 21:00:08 -05:00
Zbigniew Jędrzejewski-Szmek
17a1dad795 util: add compatibility for old glibc
Oh, Ubuntu!
2016-12-15 21:00:08 -05:00
Zbigniew Jędrzejewski-Szmek
63cc41a456 daemon: add basic support for sd_is_socket_sockaddr
Later on a proper wrapper in daemon.py should be added.
2016-12-15 21:00:08 -05:00
Zbigniew Jędrzejewski-Szmek
5d3be8ccba _daemon,_reader: return ENOSYS instead of NotImplemented
In _reader we were raising OSError(errno=ENOSYS), but in _dameon
we were raising NotImplementedError. Let's always use ENOSYS.

Also, make the messages in _reader more specific.

Fixes #33.
2016-12-15 20:57:44 -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
Oleksii Shevchuk
0af056c35f Include all fields from record (#30)
This approach allows to use LoggerAdapter+extra or .info(.., extra={})
to transparently add extra fields to journal.
2016-10-27 14:02:14 -04:00
Zbigniew Jędrzejewski-Szmek
276f137b57 id128: add SD_MESSAGE_TRUNCATED_CORE from upcoming systemd-232 2016-10-17 04:16:43 -04:00
Zbigniew Jędrzejewski-Szmek
5a5063bac0 journal: allow stream() to be used without any arguments
It's fairly easy to provide a reasonable default for the first argument.
Let's do that.

Also, the documentation was misleading, suggesting that the function itself
can be passed as file parameter to print(). Use a different name for the
temporary variable to clarify that.
2016-10-17 04:10:06 -04:00
Zbigniew Jędrzejewski-Szmek
52d9f51b9b journal: bump default log level for stream() to INFO
By default debug messages are ignored, and INFO should be used for
"normal" messages.
2016-10-17 04:02:50 -04:00
Zbigniew Jędrzejewski-Szmek
8024fc6171 _reader: use proper ifdef guard for sd_j_open_files_fd 2016-09-22 20:57:12 -04: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
b9767792b9 docs: fix sphinx format warning
build/lib.linux-x86_64-3.5/systemd/journal.py:docstring of systemd.journal.stream:15: WARNING: Literal block expected; none found.
2016-09-22 09:52:58 -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
d713eacb7e Store id128-constants.h in the repository
Instead of generating the list of message ids anew during every build,
the file is generated manually and committed into the
repository. Also, the list of defines is stored in id128-defines.h,
also kept in the repository. Both files should only grow.

This should make build easier. But it also fixes a problem with
systemd, which occasionally drops message definitions. We will keep
them forever, so it should be safe to rely on the presence of message
definitions which systemd does not use anymore.

Fixes #23.
2016-09-21 20:16:37 -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
89badf50b7 journal: add support for sd_journal_open_files_fd 2016-09-21 15:32:58 -04:00
Zbigniew Jędrzejewski-Szmek
ee9ab0bd65 journal: make sd_journal_enumerate return text strings
Those are field names and they should always be ASCII, and converting
them to str automatically makes the answer more useful.
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
42f627b302 Reformat documentation to be more PEP257-compliant
Wrapping the sources to ~80 columns means that the formatted output is
annoying to read. Rewrap to ~74 columns in the output.

Also remove some obsolete descritions of journal permissions and refer
to journalctl(1) instead.

Add some missing docstrings.
2016-09-20 09:38:36 -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
Zbigniew Jędrzejewski-Szmek
36a384a683 journal: add wrappers for sd_has_*_files 2016-09-20 09:38:14 -04:00
Zbigniew Jędrzejewski-Szmek
819ea77d1b journal: add wrapper for sd_journal_enumerate 2016-09-20 09:38:10 -04:00
Zbigniew Jędrzejewski-Szmek
ffba3a2ff8 journal: check errors properly in query_unique 2016-09-20 09:38:03 -04:00
Michael Biebl
4c6072f61b Fix typo (#26) 2016-07-16 11:20:52 -04:00
Ville Skyttä
4c5e850b49 Use log.warning instead of deprecated log.warn in example code 2016-05-21 08:50:13 +03: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
Michael Herold
3d046016c4 Fixes Reader.seek_monotonic(datetime.timedelta) 2015-12-10 00:18:01 +01:00
Zbigniew Jędrzejewski-Szmek
c8749e7fbc reader: avoid gcc warning
gcc warns that r might be uninitialized, because it doesn't
know that r will be initialized in the 'if' statement.

Initialize the variable to avoid the warning.
2015-12-02 20:44:15 -05:00
Zbigniew Jędrzejewski-Szmek
8ccd64789a tests: mirror is-systemd-running test from systemd 2015-10-28 10:02:53 -04:00