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()