1
0
mirror of https://github.com/home-assistant/supervisor.git synced 2025-12-24 12:29:08 +00:00

Mark system as unhealthy on OSError Bad message errors (#4750)

* Bad message error marks system as unhealthy

* Finish adding test cases for changes

* Rename test file for uniqueness

* bad_message to oserror_bad_message

* Omit some checks and check for network mounts
This commit is contained in:
Mike Degatano
2023-12-21 12:05:29 -05:00
committed by GitHub
parent b7ddfba71d
commit 3cc6bd19ad
24 changed files with 481 additions and 28 deletions

View File

@@ -1,8 +1,11 @@
"""Testing handling with CoreState."""
# pylint: disable=W0212
import datetime
import errno
from unittest.mock import AsyncMock, PropertyMock, patch
from pytest import LogCaptureFixture
from supervisor.const import CoreState
from supervisor.coresys import CoreSys
from supervisor.exceptions import WhoamiSSLError
@@ -14,7 +17,6 @@ from supervisor.utils.whoami import WhoamiData
def test_write_state(run_dir, coresys: CoreSys):
"""Test write corestate to /run/supervisor."""
coresys.core.state = CoreState.RUNNING
assert run_dir.read_text() == CoreState.RUNNING
@@ -77,3 +79,16 @@ async def test_adjust_system_datetime_if_time_behind(coresys: CoreSys):
mock_retrieve_whoami.assert_called_once()
mock_set_datetime.assert_called_once()
mock_check_connectivity.assert_called_once()
def test_write_state_failure(run_dir, coresys: CoreSys, caplog: LogCaptureFixture):
"""Test failure to write corestate to /run/supervisor."""
with patch(
"supervisor.core.RUN_SUPERVISOR_STATE.write_text",
side_effect=(err := OSError()),
):
err.errno = errno.EBADMSG
coresys.core.state = CoreState.RUNNING
assert "Can't update the Supervisor state" in caplog.text
assert coresys.core.healthy is True