From f4b43739da0c9ed33f184f2031c0ea5cf5fe5a77 Mon Sep 17 00:00:00 2001 From: Mike Degatano Date: Fri, 1 Sep 2023 05:18:22 -0400 Subject: [PATCH] Skip plugin update on startup if supervisor out of date (#4515) --- supervisor/core.py | 4 ++-- supervisor/plugins/manager.py | 5 ++++- tests/plugins/test_plugin_manager.py | 33 +++++++++++++++++++++++++++- 3 files changed, 38 insertions(+), 4 deletions(-) diff --git a/supervisor/core.py b/supervisor/core.py index 7841147d7..ac93ae8f2 100644 --- a/supervisor/core.py +++ b/supervisor/core.py @@ -135,10 +135,10 @@ class Core(CoreSysAttributes): self.sys_mounts.load(), # Load Docker manager self.sys_docker.load(), - # Load Plugins container - self.sys_plugins.load(), # load last available data self.sys_updater.load(), + # Load Plugins container + self.sys_plugins.load(), # Load Home Assistant self.sys_homeassistant.load(), # Load CPU/Arch diff --git a/supervisor/plugins/manager.py b/supervisor/plugins/manager.py index bfbd462e8..494cd4997 100644 --- a/supervisor/plugins/manager.py +++ b/supervisor/plugins/manager.py @@ -75,8 +75,11 @@ class PluginManager(CoreSysAttributes): ) capture_exception(err) + # Exit if supervisor out of date. Plugins can't update until then + if self.sys_supervisor.need_update: + return + # Check requirements - await self.sys_updater.reload() for plugin in self.all_plugins: # Check if need an update if not plugin.need_update: diff --git a/tests/plugins/test_plugin_manager.py b/tests/plugins/test_plugin_manager.py index 46c3d75a0..9143787ab 100644 --- a/tests/plugins/test_plugin_manager.py +++ b/tests/plugins/test_plugin_manager.py @@ -1,9 +1,13 @@ """Test plugin manager.""" -from unittest.mock import patch +from unittest.mock import PropertyMock, patch + +from awesomeversion import AwesomeVersion from supervisor.coresys import CoreSys from supervisor.docker.interface import DockerInterface +from supervisor.plugins.base import PluginBase +from supervisor.supervisor import Supervisor def mock_awaitable_bool(value: bool): @@ -29,3 +33,30 @@ async def test_repair(coresys: CoreSys): await coresys.plugins.repair() assert install.call_count == len(coresys.plugins.all_plugins) + + +async def test_load(coresys: CoreSys): + """Test plugin manager load.""" + coresys.hardware.disk.get_disk_free_space = lambda x: 5000 + await coresys.updater.load() + + need_update = PropertyMock(return_value=True) + with patch.object(DockerInterface, "attach") as attach, patch.object( + DockerInterface, "update" + ) as update, patch.object(Supervisor, "need_update", new=need_update), patch.object( + PluginBase, "need_update", new=PropertyMock(return_value=True) + ), patch.object( + PluginBase, + "version", + new=PropertyMock(return_value=AwesomeVersion("1970-01-01")), + ): + await coresys.plugins.load() + + assert attach.call_count == 5 + update.assert_not_called() + + need_update.return_value = False + await coresys.plugins.load() + + assert attach.call_count == 10 + assert update.call_count == 5