Skip to content

Commit 8251b6c

Browse files
authored
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.
1 parent 1faf529 commit 8251b6c

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

supervisor/dbus/network/__init__.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,10 +185,14 @@ async def update(self, changed: dict[str, Any] | None = None) -> None:
185185
if not changed and self.dns.is_connected:
186186
await self.dns.update()
187187

188-
if changed and (
189-
DBUS_ATTR_DEVICES not in changed
190-
or {intr.object_path for intr in self.interfaces if intr.managed}.issubset(
191-
set(changed[DBUS_ATTR_DEVICES])
188+
if (
189+
changed
190+
and DBUS_ATTR_PRIMARY_CONNECTION not in changed
191+
and (
192+
DBUS_ATTR_DEVICES not in changed
193+
or {
194+
intr.object_path for intr in self.interfaces if intr.managed
195+
}.issubset(set(changed[DBUS_ATTR_DEVICES]))
192196
)
193197
):
194198
# If none of our managed devices were removed then most likely this is just veths changing.

tests/dbus/network/test_network_manager.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,3 +249,25 @@ async def test_network_manager_stopped(
249249
capture_exception.assert_called_once()
250250
assert isinstance(capture_exception.call_args.args[0], DBusServiceUnkownError)
251251
assert "NetworkManager not responding" in caplog.text
252+
253+
254+
async def test_primary_connection_update(
255+
network_manager_service: NetworkManagerService,
256+
network_manager: NetworkManager,
257+
):
258+
"""Test handling of primary connection change."""
259+
interface = next(
260+
(
261+
intr
262+
for intr in network_manager.interfaces
263+
if intr.object_path == "/org/freedesktop/NetworkManager/Devices/1"
264+
),
265+
None,
266+
)
267+
await network_manager.update({"PrimaryConnection": "/"})
268+
assert interface.primary is False
269+
270+
await network_manager.update(
271+
{"PrimaryConnection": "/org/freedesktop/NetworkManager/ActiveConnection/1"}
272+
)
273+
assert interface.primary is True

0 commit comments

Comments
 (0)