Skip plugin update on startup if supervisor out of date (#4515)

This commit is contained in:
Mike Degatano 2023-09-01 05:18:22 -04:00 committed by GitHub
parent 4838b280ad
commit f4b43739da
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 38 additions and 4 deletions

View File

@ -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

View File

@ -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:

View File

@ -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