From c4452a85b4cabaabdeb35f548cd4cf3b7c850f66 Mon Sep 17 00:00:00 2001 From: Mike Degatano Date: Tue, 4 Jun 2024 10:17:43 -0400 Subject: [PATCH] Fix addon in wrong state after restore (#5111) * Fix addon in wrong state after restore * Do not stop docker monitor for a shutdown --- supervisor/addons/addon.py | 2 +- supervisor/core.py | 3 --- tests/backups/test_manager.py | 37 +++++++++++++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 4 deletions(-) diff --git a/supervisor/addons/addon.py b/supervisor/addons/addon.py index fac2536b433..3cf66fd6396 100644 --- a/supervisor/addons/addon.py +++ b/supervisor/addons/addon.py @@ -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() diff --git a/supervisor/core.py b/supervisor/core.py index 2b5b0fa5aeb..9f3b9bb61ae 100644 --- a/supervisor/core.py +++ b/supervisor/core.py @@ -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) diff --git a/tests/backups/test_manager.py b/tests/backups/test_manager.py index ff9b6e7d2f2..4caee39f769 100644 --- a/tests/backups/test_manager.py +++ b/tests/backups/test_manager.py @@ -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()