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,12 +1,15 @@
"""Test hardware utils."""
# pylint: disable=protected-access
import errno
from pathlib import Path
from unittest.mock import MagicMock
from unittest.mock import MagicMock, patch
from pytest import LogCaptureFixture
from supervisor.coresys import CoreSys
from supervisor.hardware.data import Device
def test_have_audio(coresys):
def test_have_audio(coresys: CoreSys):
"""Test usb device filter."""
assert not coresys.hardware.helper.support_audio
@@ -26,7 +29,7 @@ def test_have_audio(coresys):
assert coresys.hardware.helper.support_audio
def test_have_usb(coresys):
def test_have_usb(coresys: CoreSys):
"""Test usb device filter."""
assert not coresys.hardware.helper.support_usb
@@ -46,7 +49,7 @@ def test_have_usb(coresys):
assert coresys.hardware.helper.support_usb
def test_have_gpio(coresys):
def test_have_gpio(coresys: CoreSys):
"""Test usb device filter."""
assert not coresys.hardware.helper.support_gpio
@@ -66,7 +69,7 @@ def test_have_gpio(coresys):
assert coresys.hardware.helper.support_gpio
def test_hide_virtual_device(coresys):
def test_hide_virtual_device(coresys: CoreSys):
"""Test hidding virtual devices."""
udev_device = MagicMock()
@@ -81,3 +84,15 @@ def test_hide_virtual_device(coresys):
udev_device.sys_path = "/sys/devices/virtual/vc/vcs1"
assert coresys.hardware.helper.hide_virtual_device(udev_device)
def test_last_boot_error(coresys: CoreSys, caplog: LogCaptureFixture):
"""Test error reading last boot."""
with patch(
"supervisor.hardware.helper.Path.read_text", side_effect=(err := OSError())
):
err.errno = errno.EBADMSG
assert coresys.hardware.helper.last_boot is None
assert coresys.core.healthy is True
assert "Can't read stat data" in caplog.text