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
This commit is contained in:
Stefan Agner 2025-05-29 11:49:19 +02:00 committed by GitHub
parent 2a88cb9339
commit 42f885595e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 9 additions and 3 deletions

View File

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

View File

@ -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."""

View File

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