Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update DNS plug-in on network change #5331

Merged
merged 2 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions supervisor/host/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
from ..dbus.const import (
DBUS_ATTR_CONNECTION_ENABLED,
DBUS_ATTR_CONNECTIVITY,
DBUS_ATTR_PRIMARY_CONNECTION,
DBUS_IFACE_NM,
DBUS_OBJECT_BASE,
DBUS_SIGNAL_NM_CONNECTION_ACTIVE_CHANGED,
ConnectionStateType,
ConnectivityState,
Expand Down Expand Up @@ -148,6 +150,15 @@ async def _check_connectivity_changed(
connectivity_check: bool | None = changed.get(DBUS_ATTR_CONNECTION_ENABLED)
connectivity: bool | None = changed.get(DBUS_ATTR_CONNECTIVITY)

# This potentially updated the DNS configuration. Make sure the DNS plug-in
# picks up the latest settings.
if (
DBUS_ATTR_PRIMARY_CONNECTION in changed
and changed[DBUS_ATTR_PRIMARY_CONNECTION]
and changed[DBUS_ATTR_PRIMARY_CONNECTION] != DBUS_OBJECT_BASE
):
await self.sys_plugins.dns.restart()

if (
connectivity_check is True
or DBUS_ATTR_CONNECTION_ENABLED in invalidated
Expand Down
18 changes: 18 additions & 0 deletions tests/host/test_connectivity.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import pytest

from supervisor.coresys import CoreSys
from supervisor.plugins.dns import PluginDns

from tests.dbus_service_mocks.network_manager import (
NetworkManager as NetworkManagerService,
Expand Down Expand Up @@ -84,3 +85,20 @@ async def test_connectivity_events(coresys: CoreSys, force: bool):
},
}
)


async def test_dns_restart_on_connection_change(
coresys: CoreSys, network_manager_service: NetworkManagerService
):
"""Test dns plugin is restarted when primary connection changes."""
await coresys.host.network.load()
with patch.object(PluginDns, "restart") as restart:
network_manager_service.emit_properties_changed({"PrimaryConnection": "/"})
await network_manager_service.ping()
restart.assert_not_called()

network_manager_service.emit_properties_changed(
{"PrimaryConnection": "/org/freedesktop/NetworkManager/ActiveConnection/2"}
)
await network_manager_service.ping()
restart.assert_called_once()
Loading