mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-11-09 10:59:43 +00:00
Use longer timeouts for API checks before trigger a rollback (#4658)
* Don't check if Core is running to trigger rollback Currently we check for Core API access and that the state is running. If this is not fulfilled within 5 minutes, we rollback to the previous version. It can take quite a while until Home Assistant Core is in state running. In fact, after going through bootstrap, it can theoretically take indefinitely (as in there is no timeout from Core side). So to trigger rollback, rather than check the state to be running, just check if the API is accessible in this case. This prevents spurious rollbacks. * Check Core status with and timeout after a longer time Instead of checking the Core API just for response, do check the state. Use a timeout which is long enough to cover all stages and other timeouts during Core startup. * Introduce get_api_state and better status messages * Update supervisor/homeassistant/api.py Co-authored-by: J. Nick Koston <nick@koston.org> * Add successful start test --------- Co-authored-by: J. Nick Koston <nick@koston.org>
This commit is contained in:
@@ -275,7 +275,7 @@ async def test_api_check_timeout(
|
||||
"""Test attempts to contact the API timeout."""
|
||||
container.status = "stopped"
|
||||
coresys.homeassistant.version = AwesomeVersion("2023.9.0")
|
||||
coresys.homeassistant.api.check_api_state.return_value = False
|
||||
coresys.homeassistant.api.get_api_state.return_value = None
|
||||
|
||||
async def mock_instance_start(*_):
|
||||
container.status = "running"
|
||||
@@ -294,8 +294,33 @@ async def test_api_check_timeout(
|
||||
), pytest.raises(HomeAssistantCrashError):
|
||||
await coresys.homeassistant.core.start()
|
||||
|
||||
assert coresys.homeassistant.api.check_api_state.call_count == 5
|
||||
assert coresys.homeassistant.api.get_api_state.call_count == 3
|
||||
assert (
|
||||
"No API response in 5 minutes, assuming core has had a fatal startup error"
|
||||
in caplog.text
|
||||
"No Home Assistant Core response, assuming a fatal startup error" in caplog.text
|
||||
)
|
||||
|
||||
|
||||
async def test_api_check_success(
|
||||
coresys: CoreSys, container: MagicMock, caplog: pytest.LogCaptureFixture
|
||||
):
|
||||
"""Test attempts to contact the API timeout."""
|
||||
container.status = "stopped"
|
||||
coresys.homeassistant.version = AwesomeVersion("2023.9.0")
|
||||
|
||||
async def mock_instance_start(*_):
|
||||
container.status = "running"
|
||||
|
||||
with patch.object(
|
||||
DockerHomeAssistant, "start", new=mock_instance_start
|
||||
), patch.object(DockerAPI, "container_is_initialized", return_value=True), travel(
|
||||
datetime(2023, 10, 2, 0, 0, 0), tick=False
|
||||
) as traveller:
|
||||
|
||||
async def mock_sleep(*args):
|
||||
traveller.shift(timedelta(minutes=1))
|
||||
|
||||
with patch("supervisor.homeassistant.core.asyncio.sleep", new=mock_sleep):
|
||||
await coresys.homeassistant.core.start()
|
||||
|
||||
assert coresys.homeassistant.api.get_api_state.call_count == 1
|
||||
assert "Detect a running Home Assistant instance" in caplog.text
|
||||
|
||||
Reference in New Issue
Block a user