mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-11-10 11:29:51 +00:00
* Remove I/O in event loop for add-on backup and restore Remove I/O in event loop for add-on backup and restore operations. On backup, this moves the add-on shutdown before metadata is stored in the backup, which slightly lenghens the time the add-on is actually stopped. However, the biggest contributor here is likely adding the image itself if it is a local backup. However, since that is the minority of cases, I've opted for simplicity over optimizing for this case. * Use partial to explicitly bind arguments
64 lines
2.2 KiB
Python
64 lines
2.2 KiB
Python
"""Test host apparmor control."""
|
|
|
|
import errno
|
|
from pathlib import Path
|
|
from unittest.mock import patch
|
|
|
|
from pytest import raises
|
|
|
|
from supervisor.coresys import CoreSys
|
|
from supervisor.exceptions import HostAppArmorError
|
|
|
|
|
|
async def test_load_profile_error(coresys: CoreSys):
|
|
"""Test error loading apparmor profile."""
|
|
test_path = Path("test")
|
|
with (
|
|
patch("supervisor.host.apparmor.validate_profile"),
|
|
patch(
|
|
"supervisor.host.apparmor.shutil.copyfile", side_effect=(err := OSError())
|
|
),
|
|
):
|
|
err.errno = errno.EBUSY
|
|
with raises(HostAppArmorError):
|
|
await coresys.host.apparmor.load_profile("test", test_path)
|
|
assert coresys.core.healthy is True
|
|
|
|
err.errno = errno.EBADMSG
|
|
with raises(HostAppArmorError):
|
|
await coresys.host.apparmor.load_profile("test", test_path)
|
|
assert coresys.core.healthy is False
|
|
|
|
|
|
async def test_remove_profile_error(coresys: CoreSys, path_extern):
|
|
"""Test error removing apparmor profile."""
|
|
coresys.host.apparmor._profiles.add("test") # pylint: disable=protected-access
|
|
with patch("supervisor.host.apparmor.Path.unlink", side_effect=(err := OSError())):
|
|
err.errno = errno.EBUSY
|
|
with raises(HostAppArmorError):
|
|
await coresys.host.apparmor.remove_profile("test")
|
|
assert coresys.core.healthy is True
|
|
|
|
err.errno = errno.EBADMSG
|
|
with raises(HostAppArmorError):
|
|
await coresys.host.apparmor.remove_profile("test")
|
|
assert coresys.core.healthy is False
|
|
|
|
|
|
def test_backup_profile_error(coresys: CoreSys, path_extern):
|
|
"""Test error while backing up apparmor profile."""
|
|
test_path = Path("test")
|
|
coresys.host.apparmor._profiles.add("test") # pylint: disable=protected-access
|
|
with patch(
|
|
"supervisor.host.apparmor.shutil.copyfile", side_effect=(err := OSError())
|
|
):
|
|
err.errno = errno.EBUSY
|
|
with raises(HostAppArmorError):
|
|
coresys.host.apparmor.backup_profile("test", test_path)
|
|
assert coresys.core.healthy is True
|
|
|
|
err.errno = errno.EBADMSG
|
|
with raises(HostAppArmorError):
|
|
coresys.host.apparmor.backup_profile("test", test_path)
|
|
assert coresys.core.healthy is False
|