Commit graph

221 commits

Author SHA1 Message Date
Zbigniew Jędrzejewski-Szmek
cc03ed6d20 tests: simplify imports
'import foo as _foo' is useful in exported modules to avoid 'foo' being
present in the public API. No need to play that game in test code.
2022-08-16 11:03:09 +02:00
Zbigniew Jędrzejewski-Szmek
ba9d9f8910 tests: python2-compat in another place 2022-08-16 11:03:09 +02:00
Zbigniew Jędrzejewski-Szmek
872ce304a0 journal: fix compatibility with python2
This is a lazy workaround: 4c9a241949
is amended to do nothing on python2, so we have the same issue that
was present before. This allows the code to execute, and hopefully
almost nobody is using python2 code anyway.

f868a56b93 is amended in the same way.
For python2 code we have the same lack of timezone-awareness as before.

This allows the tests to pass under python 2.7.
2022-08-16 11:03:09 +02:00
Zbigniew Jędrzejewski-Szmek
6320847472
Merge pull request #92 from chrismullins/support-realtime-cutoff
Support realtime cutoff access
2022-08-16 09:55:39 +02:00
Zbigniew Jędrzejewski-Szmek
d361f0bfa5 Update constants for systemd 251 2022-08-15 16:59:02 +02:00
Samuel BF
f868a56b93 Adding timezone information to datetimes from systemd-journal 2022-08-13 19:34:51 +02:00
Andrew Stone
1abac3cfec reader: Fix use of potentially uninitialized value 2022-08-13 17:03:30 +02:00
Chris Mullins
d6b3af95f5 Pass NULL for unnecessary timestamps 2021-01-03 01:34:48 +00:00
Chris Mullins
9bb147c26b Add support for sd_journal_get_cutoff_realtime_usec wrapper 2021-01-03 01:22:22 +00:00
Glandos
2166b5759c journal: remove ChainMap
"after some quick testing, the execution time got halved (32-ish
seconds to 16-ish seconds) when going through all journal entries."

Closes #63.
2020-11-12 19:19:47 +01:00
Alexander Olekhnovich
9cbc4e93b4 journal: add namespace support
Add log namespace support which is added since systemd v245
2020-11-12 19:10:13 +01:00
Tamaki Nishino
5dd8afda3e journal: allow JournalHandler constructor to be called with args in a positional param
This change enables to add extra fields to JournalHandler in a
configuration file loaded by `logging.config.fileConfig`, which only allows positional
parameters:

class=systemd.journal.JournalHandler
args={'level': INFO, 'SYSLOG_IDENTIFIER': 'my-cool-app'}

[zj: originally the patch added a new positional parameter to
__init__(), but that is not backwards compatible. So I added a new
classmethod to allow the positional parameters to be passed.]
2020-11-12 19:05:37 +01:00
Zbigniew Jędrzejewski-Szmek
397dec7411 test: make sure $NOTIFY_SOCKET is unset in test
When running the tests in Fedora's mock, the test would
fail because NOTIFY_SOCKET is set to /run/systemd/nspawn/notify, and
we get a permission error.
2020-11-12 17:20:05 +01:00
Zbigniew Jędrzejewski-Szmek
c71bbac357 reader: make PY_SSIZE_T_CLEAN 2020-11-12 17:14:34 +01:00
Zbigniew Jędrzejewski-Szmek
9bacacace4 journal: avoid warning about deprecated constant 2020-11-12 17:14:34 +01:00
Léonard Gérard
4c9a241949 Fix seek_realtime to work with timezone aware date
`strftime("%s")` is not in the official python documentation but in my system (ubuntu 18.04 python 3.6.9) it is not aware of the object timezone and will return the wrong value if the timezone is specified and is not the system local one.

There are multiple ways to ensure a python `datetime.datetime` is in local timezone, the easiest (with python 3.3+) is to call `.astimezone()` If one wants to support earlier versions of python an extra dependency might be needed like `dateutil.tz.tzlocal()`.
2020-11-12 08:50:25 +01:00
Khem Raj
ced5a20986 include endian.h for htobe16 definition 2020-11-11 22:37:22 +01:00
Zbigniew Jędrzejewski-Szmek
a402d08da4 docs: mention .process() in docstring of .fileno()
Together with the previous commit, this makes it much easier to find
the right docs. Fixes #48.
2019-06-16 19:49:54 +02:00
Zbigniew Jędrzejewski-Szmek
42ec43022e docs: use :manpage: role to provide links to systemd man pages
See https://github.com/sphinx-doc/sphinx/pull/4235 for the :manpage:
role.
2019-06-16 19:38:13 +02:00
Zbigniew Jędrzejewski-Szmek
343f97460f Use #if instead of #ifdef for compatibility checks
This has the advantage that it is slightly less verbose, and
also any potential typos in the macro names are immediately detected.
2019-06-16 18:12:45 +02:00
Zbigniew Jędrzejewski-Szmek
36c57e52be id128: update constants for systmed-243 2019-06-16 16:27:11 +02:00
Zbigniew Jędrzejewski-Szmek
83b4939e16 tests: add tests for all id128 funcs, including get_machine_app_specific() 2019-06-16 16:27:11 +02:00
Zbigniew Jędrzejewski-Szmek
b54707abf4 id128: conditionalize get_machine_app_specific on libsystemd version 2019-06-16 16:27:11 +02:00
Zbigniew Jędrzejewski-Szmek
56d6fc58c9 id128: do not copy the id128 buffer bytes
There doesn't seem to be any particular need to do this.

Also remove unused uuid variable.
2019-06-16 16:27:11 +02:00
Tomasz Meresiński
552ad76180 Add id128.get_machine_app_specific function 2019-06-16 16:27:11 +02:00
Zbigniew Jędrzejewski-Szmek
c0e9a8b949 Modernize C syntax 2019-06-16 16:27:11 +02:00
Marcel Waldvogel
5101a6a10a _listen_fd_with_names documentation now modeled after is_socket_sockaddr 2019-06-16 16:27:11 +02:00
Marcel Waldvogel
b1608daf27 Added support for listen_fds_with_names() 2019-06-16 16:27:11 +02:00
Zbigniew Jędrzejewski-Szmek
a2471e2369 tests: add the reproducer from #51
The example relies on implementation details, but I don't see
why it wouldn't work everywhere. Let's pull it in, and if it breaks
somewhere, we can remove it.
2019-06-16 16:27:11 +02:00
Zbigniew Jędrzejewski-Szmek
7e32263d79
Merge pull request #51 from feedstock/fix_notify_fs_leak
Fix notify fs leak
2019-06-16 15:17:28 +02:00
Marcel Waldvogel
216f990565 Adapt to systemd 230 tool renaming, bump version 2019-06-16 15:11:12 +02:00
Marco Paolini
6ab8f8e3f1 Fix malloc retval check 2017-09-12 02:25:11 +01:00
Marco Paolini
d93d41fd58 Avoid ref leak in notify 2017-09-12 02:19:21 +01:00
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