Better handle runtime recovery mode in bootstrap (#138624)

* Better handle runtime recovery mode in bootstrap

* Add test
This commit is contained in:
Artur Pragacz 2025-02-24 13:23:39 +01:00 committed by GitHub
parent fc8affd243
commit d9eb248e91
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 41 additions and 32 deletions

View File

@ -328,10 +328,10 @@ async def async_setup_hass(
block_async_io.enable() block_async_io.enable()
if not (recovery_mode := runtime_config.recovery_mode):
config_dict = None config_dict = None
basic_setup_success = False basic_setup_success = False
if not (recovery_mode := runtime_config.recovery_mode):
await hass.async_add_executor_job(conf_util.process_ha_config_upgrade, hass) await hass.async_add_executor_job(conf_util.process_ha_config_upgrade, hass)
try: try:
@ -355,12 +355,16 @@ async def async_setup_hass(
hass = await create_hass() hass = await create_hass()
elif not basic_setup_success: elif not basic_setup_success:
_LOGGER.warning("Unable to set up core integrations. Activating recovery mode") _LOGGER.warning(
"Unable to set up core integrations. Activating recovery mode"
)
recovery_mode = True recovery_mode = True
await stop_hass(hass) await stop_hass(hass)
hass = await create_hass() hass = await create_hass()
elif any(domain not in hass.config.components for domain in CRITICAL_INTEGRATIONS): elif any(
domain not in hass.config.components for domain in CRITICAL_INTEGRATIONS
):
_LOGGER.warning( _LOGGER.warning(
"Detected that %s did not load. Activating recovery mode", "Detected that %s did not load. Activating recovery mode",
",".join(CRITICAL_INTEGRATIONS), ",".join(CRITICAL_INTEGRATIONS),

View File

@ -12,7 +12,7 @@ from unittest.mock import AsyncMock, Mock, patch
import pytest import pytest
from homeassistant import bootstrap, config as config_util, loader, runner from homeassistant import bootstrap, config as config_util, core, loader, runner
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ( from homeassistant.const import (
BASE_PLATFORMS, BASE_PLATFORMS,
@ -787,6 +787,9 @@ async def test_setup_hass_recovery_mode(
) -> None: ) -> None:
"""Test it works.""" """Test it works."""
with ( with (
patch(
"homeassistant.core.HomeAssistant", wraps=core.HomeAssistant
) as mock_hass,
patch("homeassistant.components.browser.setup") as browser_setup, patch("homeassistant.components.browser.setup") as browser_setup,
patch( patch(
"homeassistant.config_entries.ConfigEntries.async_domains", "homeassistant.config_entries.ConfigEntries.async_domains",
@ -805,6 +808,8 @@ async def test_setup_hass_recovery_mode(
), ),
) )
mock_hass.assert_called_once()
assert "recovery_mode" in hass.config.components assert "recovery_mode" in hass.config.components
assert len(mock_mount_local_lib_path.mock_calls) == 0 assert len(mock_mount_local_lib_path.mock_calls) == 0