Process NetworkManager PrimaryConnection changes (#5903)

Process NetworkManager interface updates in case PrimaryConnection
changes. This makes sure that the /network/interface/default/info
endpoint can be used to get the IP address of the primary interface.
This commit is contained in:
Stefan Agner 2025-05-21 13:50:46 +02:00 committed by GitHub
parent 1faf529b42
commit 8251b6c61c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 30 additions and 4 deletions

View File

@ -185,10 +185,14 @@ class NetworkManager(DBusInterfaceProxy):
if not changed and self.dns.is_connected: if not changed and self.dns.is_connected:
await self.dns.update() await self.dns.update()
if changed and ( if (
changed
and DBUS_ATTR_PRIMARY_CONNECTION not in changed
and (
DBUS_ATTR_DEVICES not in changed DBUS_ATTR_DEVICES not in changed
or {intr.object_path for intr in self.interfaces if intr.managed}.issubset( or {
set(changed[DBUS_ATTR_DEVICES]) intr.object_path for intr in self.interfaces if intr.managed
}.issubset(set(changed[DBUS_ATTR_DEVICES]))
) )
): ):
# If none of our managed devices were removed then most likely this is just veths changing. # If none of our managed devices were removed then most likely this is just veths changing.

View File

@ -249,3 +249,25 @@ async def test_network_manager_stopped(
capture_exception.assert_called_once() capture_exception.assert_called_once()
assert isinstance(capture_exception.call_args.args[0], DBusServiceUnkownError) assert isinstance(capture_exception.call_args.args[0], DBusServiceUnkownError)
assert "NetworkManager not responding" in caplog.text assert "NetworkManager not responding" in caplog.text
async def test_primary_connection_update(
network_manager_service: NetworkManagerService,
network_manager: NetworkManager,
):
"""Test handling of primary connection change."""
interface = next(
(
intr
for intr in network_manager.interfaces
if intr.object_path == "/org/freedesktop/NetworkManager/Devices/1"
),
None,
)
await network_manager.update({"PrimaryConnection": "/"})
assert interface.primary is False
await network_manager.update(
{"PrimaryConnection": "/org/freedesktop/NetworkManager/ActiveConnection/1"}
)
assert interface.primary is True