From 48e666e1fc53ae13b325b7575abec67e901fb5eb Mon Sep 17 00:00:00 2001 From: Mike Degatano Date: Mon, 26 Sep 2022 12:27:08 -0400 Subject: [PATCH] Bad introspection causes DBus error not KeyError (#3898) * Bad introspection causes DBus error not KeyError * Fix none error on disconnect race --- supervisor/dbus/interface.py | 2 +- supervisor/utils/dbus.py | 4 ++-- .../fixtures/test_no_properties_interface.xml | 21 +++++++++++++++++++ tests/utils/test_dbus.py | 16 ++++++++++++++ 4 files changed, 40 insertions(+), 3 deletions(-) create mode 100644 tests/fixtures/test_no_properties_interface.xml create mode 100644 tests/utils/test_dbus.py diff --git a/supervisor/dbus/interface.py b/supervisor/dbus/interface.py index 10981690f..678134ce0 100644 --- a/supervisor/dbus/interface.py +++ b/supervisor/dbus/interface.py @@ -58,7 +58,7 @@ class DBusInterfaceProxy(DBusInterface): await super().connect(bus) await self.update() - if self.sync_properties: + if self.sync_properties and self.is_connected: self.dbus.sync_property_changes(self.properties_interface, self.update) @dbus_connected diff --git a/supervisor/utils/dbus.py b/supervisor/utils/dbus.py index a0e63512c..4a10ad1b1 100644 --- a/supervisor/utils/dbus.py +++ b/supervisor/utils/dbus.py @@ -147,8 +147,8 @@ class DBus: async def get_properties(self, interface: str) -> dict[str, Any]: """Read all properties from interface.""" - return await DBus.call_dbus( - self._proxies[DBUS_INTERFACE_PROPERTIES], "call_get_all", interface + return await DBusCallWrapper(self, DBUS_INTERFACE_PROPERTIES).call_get_all( + interface ) def sync_property_changes( diff --git a/tests/fixtures/test_no_properties_interface.xml b/tests/fixtures/test_no_properties_interface.xml new file mode 100644 index 000000000..54fbc3f59 --- /dev/null +++ b/tests/fixtures/test_no_properties_interface.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tests/utils/test_dbus.py b/tests/utils/test_dbus.py new file mode 100644 index 000000000..648b68dcc --- /dev/null +++ b/tests/utils/test_dbus.py @@ -0,0 +1,16 @@ +"""Test dbus utility.""" +from dbus_fast.aio.message_bus import MessageBus +import pytest + +from supervisor.dbus.const import DBUS_OBJECT_BASE +from supervisor.exceptions import DBusInterfaceMethodError +from supervisor.utils.dbus import DBus + + +async def test_missing_properties_interface(dbus_bus: MessageBus, dbus: list[str]): + """Test introspection missing properties interface.""" + service = await DBus.connect( + dbus_bus, "test.no.properties.interface", DBUS_OBJECT_BASE + ) + with pytest.raises(DBusInterfaceMethodError): + await service.get_properties("test.no.properties.interface")