Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix addon in wrong state after restore #5111

Merged
merged 2 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion supervisor/addons/addon.py
Original file line number Diff line number Diff line change
Expand Up @@ -1343,11 +1343,11 @@ def _restore_data():
)
raise AddonsError() from err

finally:
# Is add-on loaded
if not self.loaded:
await self.load()

finally:
# Run add-on
if data[ATTR_STATE] == AddonState.STARTED:
wait_for_start = await self.start()
Expand Down
3 changes: 0 additions & 3 deletions supervisor/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,9 +345,6 @@ async def shutdown(self):
if self.state == CoreState.RUNNING:
self.state = CoreState.SHUTDOWN

# Stop docker monitoring
await self.sys_docker.unload()

# Shutdown Application Add-ons, using Home Assistant API
await self.sys_addons.shutdown(AddonStartup.APPLICATION)

Expand Down
37 changes: 37 additions & 0 deletions tests/backups/test_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -1750,3 +1750,40 @@ def mock_is_dir(path: Path) -> bool:

assert "Could not list backups" in caplog.text
assert coresys.core.healthy is healthy_expected


async def test_monitoring_after_full_restore(
coresys: CoreSys, full_backup_mock, install_addon_ssh, container
):
"""Test monitoring of addon state still works after full restore."""
coresys.core.state = CoreState.RUNNING
coresys.hardware.disk.get_disk_free_space = lambda x: 5000
coresys.homeassistant.core.start = AsyncMock(return_value=None)
coresys.homeassistant.core.stop = AsyncMock(return_value=None)
coresys.homeassistant.core.update = AsyncMock(return_value=None)

manager = BackupManager(coresys)

backup_instance = full_backup_mock.return_value
assert await manager.do_restore_full(backup_instance)

backup_instance.restore_addons.assert_called_once_with([TEST_ADDON_SLUG])
assert coresys.core.state == CoreState.RUNNING
coresys.docker.unload.assert_not_called()


async def test_monitoring_after_partial_restore(
coresys: CoreSys, partial_backup_mock, install_addon_ssh, container
):
"""Test monitoring of addon state still works after full restore."""
coresys.core.state = CoreState.RUNNING
coresys.hardware.disk.get_disk_free_space = lambda x: 5000

manager = BackupManager(coresys)

backup_instance = partial_backup_mock.return_value
assert await manager.do_restore_partial(backup_instance, addons=[TEST_ADDON_SLUG])

backup_instance.restore_addons.assert_called_once_with([TEST_ADDON_SLUG])
assert coresys.core.state == CoreState.RUNNING
coresys.docker.unload.assert_not_called()
Loading