Commit graph

268 commits

Author SHA1 Message Date
Zbigniew Jędrzejewski-Szmek
308ae4440c Prepare v234 v234 2017-03-25 21:33:59 -04: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
Zbigniew Jędrzejewski-Szmek
fe9756d3ab Makefile: add convenience "shell" target to start python shell 2017-03-19 13:17:13 -04:00
Zbigniew Jędrzejewski-Szmek
3f9386a435 Makefile: add "doc" target for convenience 2017-03-19 13:17:13 -04:00
Zbigniew Jędrzejewski-Szmek
ae08cbfe11 Makefile: remove unneeded -I/usr/include from flags
gcc warns about an include directive that shadows the system include
directory at high verbosity levels. Let's filter it out (pkgconfig
implements that) to reduce noise and also to make the command line
shorter.
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
e121ae49ab Merge pull request #34 from keszybz/test-skipping
Improve test skipping on old systems.
2017-03-13 16:03:49 -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
Johannes Weberhofer
3645c3597e Added section for installation on openSUSE & SLE (#35) 2016-12-16 21:08:42 -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
Zbigniew Jędrzejewski-Szmek
930bf89796 setup.py: allow LIBSYSTEMD_VERSION to be overridden
This is useful when testing against old or unreleases versions of
the library:
  make PYTHON=python3 INCLUDE_DIR=/home/zbyszek/src/systemd-master/src LIBSYSTEMD_VERSION=233
2016-12-14 22:52:47 -05:00
Zbigniew Jędrzejewski-Szmek
b4cfd41a06 Makefile: use $(INCLUDE_DIR) also for compilation
This way we can compile against unreleased systemd:
make PYTHON=python3 INCLUDE_DIR=/home/zbyszek/src/systemd/src
(cd build/lib.linux-x86_64-3.5; systemd-socket-activate -E LD_LIBRARY_PATH=/home/zbyszek/src/systemd-master/.libs -l2000 -l127.0.0.1:2001 python3)
2016-12-13 20:27:47 -05:00
Zbigniew Jędrzejewski-Szmek
e4ff9e6f7c build-sys: add sign and upload targets 2016-12-13 20:27:47 -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
0cae964314 Prepare v233 v233 2016-10-17 04:16:43 -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
Robert James Hernandez
aabbf9b40d Updating docs for missing dependency (#28)
I was trying to build python-systemd from source but ran into the same issue here: #17

I Figure the docs should be updated to reflect this dependency.
2016-10-10 20:11:10 -04:00
Zbigniew Jędrzejewski-Szmek
84fcfc05e5 setup.py: make build fail if undeclared symbols are used
This will detect cases where the autoconfig based on version is wrong.

Debian bug #839224.
2016-10-01 17:45:09 +02:00
Zbigniew Jędrzejewski-Szmek
911591a118 build-sys: import "pytest" instead of "py.test"
Fixes the following error in rawhide:
/usr/bin/python3: loader for pytest cannot handle py.test
2016-09-22 20:57:12 -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
c3c412f90e build-sys: add doc-sync target 2016-09-22 09:59:04 -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
34ce13054b Prepare v232 v232 2016-09-21 20:57:58 -04:00
Zbigniew Jędrzejewski-Szmek
3758d884d4 setup.py: change name to systemd-python
This name is unused on pypi. Let's grab it.
2016-09-21 20:57:58 -04:00
Zbigniew Jędrzejewski-Szmek
416efbf411 docs: autoregenerate id128.rst 2016-09-21 20:56:17 -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