apport_python_hook: support dbus-broker - #645
Open
bdrung wants to merge 4 commits into
Open
Conversation
In case `dbus_service_unknown_analysis` fails to parse the D-Bus name, the function should print an error message and return. If `sys.stderr` is not available, no error message is printed but the function is continued. Return in that case as well, because the D-Bus name is required for the following code.
The variable `service` is used for the content of the D-Bus service files. mypy would complain when reusing this variable for `str` later on.
Let `dbus_service_unknown_analysis` return a `dict` to avoid needing to pass around the problem report. This allows adding type hints to this function without needing to make `apport.report.Report` available.
The tests `test_dbus_service_unknown_wrongbus_notrunning` and `test_dbus_service_unknown_wrongbus_running` started to fail once Ubuntu switched to dbus-broker (see https://launchpad.net/bugs/2015538). These tests create Python code similar to: ```python #!/usr/bin/python3 import dbus obj = dbus.SessionBus().get_object("org.gtk.vfs.Metadata", "/org/gtk/vfs/metadata") assert obj obj = dbus.SystemBus().get_object("org.gtk.vfs.Metadata", "/org/gtk/vfs/metadata") ``` On Ubuntu 26.04 this code fails with: ``` Traceback (most recent call last): File "/usr/lib/python3/dist-packages/dbus/bus.py", line 173, in activate_name_owner return self.get_name_owner(bus_name) ~~~~~~~~~~~~~~~~~~~^^^^^^^^^^ File "/usr/lib/python3/dist-packages/dbus/bus.py", line 348, in get_name_owner return self.call_blocking(BUS_DAEMON_NAME, BUS_DAEMON_PATH, ~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ BUS_DAEMON_IFACE, 'GetNameOwner', ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 's', (bus_name,)) ^^^^^^^^^^^^^^^^^ File "/usr/lib/python3/dist-packages/dbus/connection.py", line 696, in call_blocking reply_message = self.send_message_with_reply_and_block( message, timeout) dbus.exceptions.DBusException: org.freedesktop.DBus.Error.NameHasNoOwner: Could not get owner of name 'org.gtk.vfs.Metadata': no such name During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/usr/bin/test.py", line 4, in <module> obj = dbus.SessionBus().get_object("org.gtk.vfs.Metadata", "/org/gtk/vfs/metadata") File "/usr/lib/python3/dist-packages/dbus/bus.py", line 237, in get_object return self.ProxyObjectClass(self, bus_name, object_path, ~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ introspect=introspect, ^^^^^^^^^^^^^^^^^^^^^^ follow_name_owner_changes=follow_name_owner_changes) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3/dist-packages/dbus/proxies.py", line 250, in __init__ self._named_service = conn.activate_name_owner(bus_name) ~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^ File "/usr/lib/python3/dist-packages/dbus/bus.py", line 178, in activate_name_owner self.start_service_by_name(bus_name) ~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^ File "/usr/lib/python3/dist-packages/dbus/bus.py", line 273, in start_service_by_name return (True, self.call_blocking(BUS_DAEMON_NAME, BUS_DAEMON_PATH, ~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ BUS_DAEMON_IFACE, ^^^^^^^^^^^^^^^^^ 'StartServiceByName', ^^^^^^^^^^^^^^^^^^^^^ 'su', (bus_name, flags))) ^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3/dist-packages/dbus/connection.py", line 696, in call_blocking reply_message = self.send_message_with_reply_and_block( message, timeout) dbus.exceptions.DBusException: org.freedesktop.DBus.Error.ServiceUnknown: The name org.gtk.vfs.Metadata was not provided by any .service files ``` On Ubuntu 26.10 with dbus-broker it fails with less information in the exception: ``` Traceback (most recent call last): File "/usr/lib/python3/dist-packages/dbus/bus.py", line 173, in activate_name_owner return self.get_name_owner(bus_name) ~~~~~~~~~~~~~~~~~~~^^^^^^^^^^ File "/usr/lib/python3/dist-packages/dbus/bus.py", line 348, in get_name_owner return self.call_blocking(BUS_DAEMON_NAME, BUS_DAEMON_PATH, ~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ BUS_DAEMON_IFACE, 'GetNameOwner', ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 's', (bus_name,)) ^^^^^^^^^^^^^^^^^ File "/usr/lib/python3/dist-packages/dbus/connection.py", line 696, in call_blocking reply_message = self.send_message_with_reply_and_block( message, timeout) dbus.exceptions.DBusException: org.freedesktop.DBus.Error.NameHasNoOwner: The name does not have an owner During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/usr/bin/test.py", line 6, in <module> obj = dbus.SystemBus().get_object("org.gtk.vfs.Metadata", "/org/gtk/vfs/metadata") File "/usr/lib/python3/dist-packages/dbus/bus.py", line 237, in get_object return self.ProxyObjectClass(self, bus_name, object_path, ~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ introspect=introspect, ^^^^^^^^^^^^^^^^^^^^^^ follow_name_owner_changes=follow_name_owner_changes) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3/dist-packages/dbus/proxies.py", line 250, in __init__ self._named_service = conn.activate_name_owner(bus_name) ~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^ File "/usr/lib/python3/dist-packages/dbus/bus.py", line 178, in activate_name_owner self.start_service_by_name(bus_name) ~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^ File "/usr/lib/python3/dist-packages/dbus/bus.py", line 273, in start_service_by_name return (True, self.call_blocking(BUS_DAEMON_NAME, BUS_DAEMON_PATH, ~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ BUS_DAEMON_IFACE, ^^^^^^^^^^^^^^^^^ 'StartServiceByName', ^^^^^^^^^^^^^^^^^^^^^ 'su', (bus_name, flags))) ^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3/dist-packages/dbus/connection.py", line 696, in call_blocking reply_message = self.send_message_with_reply_and_block( message, timeout) dbus.exceptions.DBusException: org.freedesktop.DBus.Error.ServiceUnknown: The name is not activatable ``` The dbus-python code uses `bus_name` as variable before calling D-Bus in most cases. So walk down the traceback to extract the bus name from there. Bug: https://launchpad.net/bugs/2163744
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #645 +/- ##
==========================================
- Coverage 84.48% 84.48% -0.01%
==========================================
Files 106 106
Lines 21044 21055 +11
Branches 3192 3194 +2
==========================================
+ Hits 17780 17788 +8
- Misses 2790 2792 +2
- Partials 474 475 +1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The tests
test_dbus_service_unknown_wrongbus_notrunningandtest_dbus_service_unknown_wrongbus_runningstarted to fail once Ubuntu switched to dbus-broker (see https://launchpad.net/bugs/2015538).These tests create Python code similar to:
On Ubuntu 26.04 this code fails with:
On Ubuntu 26.10 with dbus-broker it fails with less information in the exception:
The dbus-python code uses
bus_nameas variable before calling D-Bus in most cases. So walk down the traceback to extract the bus name from there.Bug: https://launchpad.net/bugs/2163744