Skip to content

Commit

Permalink
Fix addon in wrong state after restore (#5111)
Browse files Browse the repository at this point in the history
* Fix addon in wrong state after restore

* Do not stop docker monitor for a shutdown
  • Loading branch information
mdegat01 committed Jun 4, 2024
1 parent e57de4a commit c4452a8
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 4 deletions.
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()

0 comments on commit c4452a8

Please sign in to comment.