Bad introspection causes DBus error not KeyError (#3898)

* Bad introspection causes DBus error not KeyError

* Fix none error on disconnect race
This commit is contained in:
Mike Degatano 2022-09-26 12:27:08 -04:00 committed by GitHub
parent ff462ae976
commit 48e666e1fc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 40 additions and 3 deletions

View File

@ -58,7 +58,7 @@ class DBusInterfaceProxy(DBusInterface):
await super().connect(bus) await super().connect(bus)
await self.update() 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) self.dbus.sync_property_changes(self.properties_interface, self.update)
@dbus_connected @dbus_connected

View File

@ -147,8 +147,8 @@ class DBus:
async def get_properties(self, interface: str) -> dict[str, Any]: async def get_properties(self, interface: str) -> dict[str, Any]:
"""Read all properties from interface.""" """Read all properties from interface."""
return await DBus.call_dbus( return await DBusCallWrapper(self, DBUS_INTERFACE_PROPERTIES).call_get_all(
self._proxies[DBUS_INTERFACE_PROPERTIES], "call_get_all", interface interface
) )
def sync_property_changes( def sync_property_changes(

View File

@ -0,0 +1,21 @@
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<node>
<interface name="org.freedesktop.DBus.Introspectable">
<method name="Introspect">
<arg type="s" name="xml_data" direction="out"/>
</method>
</interface>
<interface name="org.freedesktop.DBus.Peer">
<method name="Ping"/>
<method name="GetMachineId">
<arg type="s" name="machine_uuid" direction="out"/>
</method>
</interface>
<interface name="test.no.properties.interface">
<method name="Hello">
<arg type="s" name="hello" direction="out"/>
</method>
<property type="s" name="World" access="read"/>
</interface>
</node>

16
tests/utils/test_dbus.py Normal file
View File

@ -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")