mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-07-09 18:26:30 +00:00
Supervisor updated before addon repositories (#3795)
This commit is contained in:
parent
e6dfe83d62
commit
5fc9484f73
@ -59,7 +59,7 @@ class Tasks(CoreSysAttributes):
|
|||||||
self.sys_scheduler.register_task(self._update_observer, RUN_UPDATE_OBSERVER)
|
self.sys_scheduler.register_task(self._update_observer, RUN_UPDATE_OBSERVER)
|
||||||
|
|
||||||
# Reload
|
# Reload
|
||||||
self.sys_scheduler.register_task(self.sys_store.reload, RUN_RELOAD_ADDONS)
|
self.sys_scheduler.register_task(self._reload_store, RUN_RELOAD_ADDONS)
|
||||||
self.sys_scheduler.register_task(self.sys_updater.reload, RUN_RELOAD_UPDATER)
|
self.sys_scheduler.register_task(self.sys_updater.reload, RUN_RELOAD_UPDATER)
|
||||||
self.sys_scheduler.register_task(self.sys_backups.reload, RUN_RELOAD_BACKUPS)
|
self.sys_scheduler.register_task(self.sys_backups.reload, RUN_RELOAD_BACKUPS)
|
||||||
self.sys_scheduler.register_task(self.sys_host.reload, RUN_RELOAD_HOST)
|
self.sys_scheduler.register_task(self.sys_host.reload, RUN_RELOAD_HOST)
|
||||||
@ -316,3 +316,8 @@ class Tasks(CoreSysAttributes):
|
|||||||
await self.sys_host.network.check_connectivity()
|
await self.sys_host.network.check_connectivity()
|
||||||
finally:
|
finally:
|
||||||
self._cache["connectivity"] = 0
|
self._cache["connectivity"] = 0
|
||||||
|
|
||||||
|
@Job(conditions=[JobCondition.SUPERVISOR_UPDATED])
|
||||||
|
async def _reload_store(self) -> None:
|
||||||
|
"""Reload store and check for addon updates."""
|
||||||
|
await self.sys_store.reload()
|
||||||
|
@ -80,6 +80,7 @@ class StoreManager(CoreSysAttributes, FileConfiguration):
|
|||||||
self._data[ATTR_REPOSITORIES], add_with_errors=True
|
self._data[ATTR_REPOSITORIES], add_with_errors=True
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@Job(conditions=[JobCondition.SUPERVISOR_UPDATED], on_condition=StoreJobError)
|
||||||
async def reload(self) -> None:
|
async def reload(self) -> None:
|
||||||
"""Update add-ons from repository and reload list."""
|
"""Update add-ons from repository and reload list."""
|
||||||
tasks = [repository.update() for repository in self.all]
|
tasks = [repository.update() for repository in self.all]
|
||||||
@ -90,7 +91,10 @@ class StoreManager(CoreSysAttributes, FileConfiguration):
|
|||||||
await self.load()
|
await self.load()
|
||||||
self._read_addons()
|
self._read_addons()
|
||||||
|
|
||||||
@Job(conditions=[JobCondition.INTERNET_SYSTEM])
|
@Job(
|
||||||
|
conditions=[JobCondition.INTERNET_SYSTEM, JobCondition.SUPERVISOR_UPDATED],
|
||||||
|
on_condition=StoreJobError,
|
||||||
|
)
|
||||||
async def add_repository(
|
async def add_repository(
|
||||||
self, url: str, *, persist: bool = True, add_with_errors: bool = False
|
self, url: str, *, persist: bool = True, add_with_errors: bool = False
|
||||||
):
|
):
|
||||||
@ -194,7 +198,6 @@ class StoreManager(CoreSysAttributes, FileConfiguration):
|
|||||||
await self.data.update()
|
await self.data.update()
|
||||||
self._read_addons()
|
self._read_addons()
|
||||||
|
|
||||||
@Job(conditions=[JobCondition.INTERNET_SYSTEM])
|
|
||||||
async def update_repositories(
|
async def update_repositories(
|
||||||
self,
|
self,
|
||||||
list_repositories: list[str],
|
list_repositories: list[str],
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
"""Test add custom repository."""
|
"""Test add custom repository."""
|
||||||
import json
|
import json
|
||||||
from unittest.mock import patch
|
from unittest.mock import PropertyMock, patch
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
@ -10,6 +10,7 @@ from supervisor.exceptions import (
|
|||||||
StoreError,
|
StoreError,
|
||||||
StoreGitCloneError,
|
StoreGitCloneError,
|
||||||
StoreGitError,
|
StoreGitError,
|
||||||
|
StoreJobError,
|
||||||
StoreNotFound,
|
StoreNotFound,
|
||||||
)
|
)
|
||||||
from supervisor.resolution.const import SuggestionType
|
from supervisor.resolution.const import SuggestionType
|
||||||
@ -287,3 +288,22 @@ async def test_add_with_update_repositories(
|
|||||||
|
|
||||||
assert repository.source in coresys.store.repository_urls
|
assert repository.source in coresys.store.repository_urls
|
||||||
assert "http://example.com" in coresys.store.repository_urls
|
assert "http://example.com" in coresys.store.repository_urls
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("use_update", [True, False])
|
||||||
|
async def test_add_repository_fails_if_out_of_date(
|
||||||
|
coresys: CoreSys, store_manager: StoreManager, use_update: bool
|
||||||
|
):
|
||||||
|
"""Test adding a repository fails when supervisor not updated."""
|
||||||
|
with patch.object(
|
||||||
|
type(coresys.supervisor), "need_update", new=PropertyMock(return_value=True)
|
||||||
|
), pytest.raises(StoreJobError):
|
||||||
|
if use_update:
|
||||||
|
await store_manager.update_repositories(
|
||||||
|
coresys.store.repository_urls + ["http://example.com"],
|
||||||
|
add_with_errors=True,
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
await store_manager.add_repository(
|
||||||
|
"http://example.com", add_with_errors=True
|
||||||
|
)
|
||||||
|
@ -1,9 +1,12 @@
|
|||||||
"""Test store manager."""
|
"""Test store manager."""
|
||||||
from unittest.mock import patch
|
from unittest.mock import PropertyMock, patch
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
from supervisor.bootstrap import migrate_system_env
|
from supervisor.bootstrap import migrate_system_env
|
||||||
from supervisor.const import ATTR_ADDONS_CUSTOM_LIST
|
from supervisor.const import ATTR_ADDONS_CUSTOM_LIST
|
||||||
from supervisor.coresys import CoreSys
|
from supervisor.coresys import CoreSys
|
||||||
|
from supervisor.exceptions import StoreJobError
|
||||||
from supervisor.store import StoreManager
|
from supervisor.store import StoreManager
|
||||||
from supervisor.store.repository import Repository
|
from supervisor.store.repository import Repository
|
||||||
|
|
||||||
@ -100,3 +103,11 @@ async def test_load_from_core_config(coresys: CoreSys):
|
|||||||
|
|
||||||
coresys.config.save_data.assert_called_once()
|
coresys.config.save_data.assert_called_once()
|
||||||
coresys.store.save_data.assert_called_once()
|
coresys.store.save_data.assert_called_once()
|
||||||
|
|
||||||
|
|
||||||
|
async def test_reload_fails_if_out_of_date(coresys: CoreSys):
|
||||||
|
"""Test reload fails when supervisor not updated."""
|
||||||
|
with patch.object(
|
||||||
|
type(coresys.supervisor), "need_update", new=PropertyMock(return_value=True)
|
||||||
|
), pytest.raises(StoreJobError):
|
||||||
|
await coresys.store.reload()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user