Watchdog does not start core before supervisor (#4955)

This commit is contained in:
Mike Degatano 2024-03-13 04:08:27 -04:00 committed by GitHub
parent 02c6011818
commit 9ca927dbe7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 34 additions and 3 deletions

View File

@ -86,7 +86,9 @@ class HomeAssistantCore(JobGroup):
await self.instance.get_latest_version() await self.instance.get_latest_version()
) )
await self.instance.attach(version=self.sys_homeassistant.version) await self.instance.attach(
version=self.sys_homeassistant.version, skip_state_event_if_down=True
)
except DockerError: except DockerError:
_LOGGER.info( _LOGGER.info(
"No Home Assistant Docker image %s found.", self.sys_homeassistant.image "No Home Assistant Docker image %s found.", self.sys_homeassistant.image
@ -115,7 +117,9 @@ class HomeAssistantCore(JobGroup):
"""Install a landing page.""" """Install a landing page."""
# Try to use a preinstalled landingpage # Try to use a preinstalled landingpage
try: try:
await self.instance.attach(version=LANDINGPAGE) await self.instance.attach(
version=LANDINGPAGE, skip_state_event_if_down=True
)
except DockerError: except DockerError:
pass pass
else: else:

View File

@ -1,6 +1,6 @@
"""Test Home Assistant watchdog.""" """Test Home Assistant watchdog."""
import asyncio import asyncio
from unittest.mock import PropertyMock, patch from unittest.mock import AsyncMock, MagicMock, PropertyMock, patch
from awesomeversion import AwesomeVersion from awesomeversion import AwesomeVersion
@ -135,3 +135,30 @@ async def test_home_assistant_watchdog_rebuild_on_failure(coresys: CoreSys) -> N
await asyncio.sleep(0) await asyncio.sleep(0)
start.assert_called_once() start.assert_called_once()
rebuild.assert_called_once() rebuild.assert_called_once()
async def test_home_assistant_watchdog_skip_on_load(
coresys: CoreSys, container: MagicMock
) -> None:
"""Test home assistant watchdog skips a crash event on load."""
container.status = "stopped"
container.attrs["State"]["ExitCode"] = 1
coresys.homeassistant.core.watchdog = True
events = AsyncMock()
coresys.bus.register_event(BusEvent.DOCKER_CONTAINER_STATE_CHANGE, events)
coresys.homeassistant.version = AwesomeVersion("2022.7.3")
with patch(
"supervisor.docker.interface.DockerInterface.version",
new=PropertyMock(return_value=AwesomeVersion("2022.7.3")),
), patch.object(
type(coresys.homeassistant.core), "restart"
) as restart, patch.object(type(coresys.homeassistant.core), "start") as start:
await coresys.homeassistant.core.load()
# No events should be raised on attach
await asyncio.sleep(0)
events.assert_not_called()
restart.assert_not_called()
start.assert_not_called()