mirror of
https://github.com/home-assistant/supervisor.git
synced 2026-04-17 23:33:35 +01:00
Wait until mount unit is deactivated on unmount (#4733)
* Wait until mount unit is deactivated on unmount The current code does not wait until the (bind) mount unit has been actually deactivated (state "inactive"). This is especially problematic when restoring a backup, where we deactivate all bind mounts before restoring the target folder. Before the tarball is actually restored, we delete all contents of the target folder. This lead to the situation where the "rm -rf" command got executed before the bind mount actually got unmounted. The current code polls the state using an exponentially increasing delay. Wait up to 30s for the bind mount to actually deactivate. * Fix function name * Fix missing await * Address pytest errors Change state of systemd unit according to use cases. Note that this is currently rather fragile, and ideally we should have a smarter mock service instead. * Fix pylint * Fix remaining * Check transition fo failed as well * Used alternative mocking mechanism * Remove state lists in test_manager --------- Co-authored-by: Mike Degatano <michael.degatano@gmail.com>
This commit is contained in:
@@ -31,6 +31,7 @@ from supervisor.utils.json import read_json_file, write_json_file
|
||||
from tests.const import TEST_ADDON_SLUG
|
||||
from tests.dbus_service_mocks.base import DBusServiceMock
|
||||
from tests.dbus_service_mocks.systemd import Systemd as SystemdService
|
||||
from tests.dbus_service_mocks.systemd_unit import SystemdUnit as SystemdUnitService
|
||||
|
||||
|
||||
async def test_do_backup_full(coresys: CoreSys, backup_mock, install_addon_ssh):
|
||||
@@ -386,6 +387,7 @@ async def test_backup_media_with_mounts(
|
||||
):
|
||||
"""Test backing up media folder with mounts."""
|
||||
systemd_service: SystemdService = all_dbus_services["systemd"]
|
||||
systemd_unit_service: SystemdUnitService = all_dbus_services["systemd_unit"]
|
||||
systemd_service.response_get_unit = [
|
||||
DBusError("org.freedesktop.systemd1.NoSuchUnit", "error"),
|
||||
"/org/freedesktop/systemd1/unit/tmp_2dyellow_2emount",
|
||||
@@ -422,6 +424,7 @@ async def test_backup_media_with_mounts(
|
||||
backup: Backup = await coresys.backups.do_backup_partial("test", folders=["media"])
|
||||
|
||||
# Remove the mount and wipe the media folder
|
||||
systemd_unit_service.active_state = "inactive"
|
||||
await coresys.mounts.remove_mount("media_test")
|
||||
rmtree(coresys.config.path_media)
|
||||
coresys.config.path_media.mkdir()
|
||||
@@ -445,6 +448,8 @@ async def test_backup_media_with_mounts_retains_files(
|
||||
):
|
||||
"""Test backing up media folder with mounts retains mount files."""
|
||||
systemd_service: SystemdService = all_dbus_services["systemd"]
|
||||
systemd_unit_service: SystemdUnitService = all_dbus_services["systemd_unit"]
|
||||
systemd_unit_service.active_state = ["active", "active", "active", "inactive"]
|
||||
systemd_service.response_get_unit = [
|
||||
DBusError("org.freedesktop.systemd1.NoSuchUnit", "error"),
|
||||
"/org/freedesktop/systemd1/unit/tmp_2dyellow_2emount",
|
||||
@@ -496,6 +501,15 @@ async def test_backup_share_with_mounts(
|
||||
):
|
||||
"""Test backing up share folder with mounts."""
|
||||
systemd_service: SystemdService = all_dbus_services["systemd"]
|
||||
systemd_unit_service: SystemdUnitService = all_dbus_services["systemd_unit"]
|
||||
systemd_unit_service.active_state = [
|
||||
"active",
|
||||
"active",
|
||||
"active",
|
||||
"inactive",
|
||||
"active",
|
||||
"inactive",
|
||||
]
|
||||
systemd_service.response_get_unit = [
|
||||
DBusError("org.freedesktop.systemd1.NoSuchUnit", "error"),
|
||||
"/org/freedesktop/systemd1/unit/tmp_2dyellow_2emount",
|
||||
|
||||
Reference in New Issue
Block a user