From 42f885595e827bdf8624d543f471f2790e97587e Mon Sep 17 00:00:00 2001 From: Stefan Agner Date: Thu, 29 May 2025 11:49:19 +0200 Subject: [PATCH] Avoid early DNS plug-in start (#5922) * Avoid early DNS plug-in start A connectivity check can potentially be triggered before the DNS plug-in is loaded. Avoid calling restart on the DNS plug-in before it got initially loaded. This prevents starting before attaching. The attaching makes sure that the DNS plug-in container is recreated before the DNS plug-in is initially started, which is e.g. needed by a potentially hassio network configuration change (e.g. the migration required to enable/disable IPv6 on the hassio network, see #5879). * Mock DNS plug-in running --- supervisor/host/network.py | 1 + supervisor/plugins/dns.py | 2 +- tests/host/test_connectivity.py | 9 +++++++-- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/supervisor/host/network.py b/supervisor/host/network.py index b77c96434..cd37a7d36 100644 --- a/supervisor/host/network.py +++ b/supervisor/host/network.py @@ -158,6 +158,7 @@ class NetworkManager(CoreSysAttributes): DBUS_ATTR_PRIMARY_CONNECTION in changed and changed[DBUS_ATTR_PRIMARY_CONNECTION] and changed[DBUS_ATTR_PRIMARY_CONNECTION] != DBUS_OBJECT_BASE + and await self.sys_plugins.dns.is_running() ): await self.sys_plugins.dns.restart() diff --git a/supervisor/plugins/dns.py b/supervisor/plugins/dns.py index cbff26b10..5da4254a6 100644 --- a/supervisor/plugins/dns.py +++ b/supervisor/plugins/dns.py @@ -211,7 +211,7 @@ class PluginDns(PluginBase): try: await self.instance.restart() except DockerError as err: - raise CoreDNSError("Can't start CoreDNS plugin", _LOGGER.error) from err + raise CoreDNSError("Can't restart CoreDNS plugin", _LOGGER.error) from err async def start(self) -> None: """Run CoreDNS.""" diff --git a/tests/host/test_connectivity.py b/tests/host/test_connectivity.py index 77e3c7483..a68a5ab5c 100644 --- a/tests/host/test_connectivity.py +++ b/tests/host/test_connectivity.py @@ -2,7 +2,7 @@ # pylint: disable=protected-access import asyncio -from unittest.mock import PropertyMock, patch +from unittest.mock import AsyncMock, PropertyMock, patch import pytest @@ -92,7 +92,12 @@ async def test_dns_restart_on_connection_change( ): """Test dns plugin is restarted when primary connection changes.""" await coresys.host.network.load() - with patch.object(PluginDns, "restart") as restart: + with ( + patch.object(PluginDns, "restart") as restart, + patch.object( + PluginDns, "is_running", new_callable=AsyncMock, return_value=True + ), + ): network_manager_service.emit_properties_changed({"PrimaryConnection": "/"}) await network_manager_service.ping() restart.assert_not_called()