mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-07-09 18:26:30 +00:00
Move addon repo migration to bootstrap (#3672)
* Move addon repo migration to bootstrap * Save data after migrating it
This commit is contained in:
parent
977fd8abe2
commit
7a74d77d43
@ -22,6 +22,8 @@ from .auth import Auth
|
||||
from .backups.manager import BackupManager
|
||||
from .bus import Bus
|
||||
from .const import (
|
||||
ATTR_ADDONS_CUSTOM_LIST,
|
||||
ATTR_REPOSITORIES,
|
||||
ENV_HOMEASSISTANT_REPOSITORY,
|
||||
ENV_SUPERVISOR_MACHINE,
|
||||
ENV_SUPERVISOR_NAME,
|
||||
@ -49,6 +51,7 @@ from .resolution.module import ResolutionManager
|
||||
from .security.module import Security
|
||||
from .services import ServiceManager
|
||||
from .store import StoreManager
|
||||
from .store.validate import ensure_builtin_repositories
|
||||
from .supervisor import Supervisor
|
||||
from .updater import Updater
|
||||
|
||||
@ -216,6 +219,16 @@ def migrate_system_env(coresys: CoreSys) -> None:
|
||||
except OSError:
|
||||
_LOGGER.error("Can't cleanup old Add-on build directory at '%s'", old_build)
|
||||
|
||||
# Supervisor 2022.5 -> 2022.6. Can be removed after 2022.9
|
||||
# pylint: disable=protected-access
|
||||
if len(coresys.config.addons_repositories) > 0:
|
||||
coresys.store._data[ATTR_REPOSITORIES] = ensure_builtin_repositories(
|
||||
coresys.config.addons_repositories
|
||||
)
|
||||
coresys.config._data[ATTR_ADDONS_CUSTOM_LIST] = []
|
||||
coresys.store.save_data()
|
||||
coresys.config.save_data()
|
||||
|
||||
|
||||
def initialize_logging() -> None:
|
||||
"""Initialize the logging."""
|
||||
|
@ -327,7 +327,3 @@ class CoreConfig(FileConfiguration):
|
||||
return
|
||||
|
||||
self._data[ATTR_ADDONS_CUSTOM_LIST].remove(repo)
|
||||
|
||||
def clear_addons_repositories(self) -> None:
|
||||
"""Clear custom repositories list from core config."""
|
||||
self._data[ATTR_ADDONS_CUSTOM_LIST] = []
|
||||
|
@ -73,13 +73,6 @@ class StoreManager(CoreSysAttributes, FileConfiguration):
|
||||
"""Start up add-on management."""
|
||||
await self.data.update()
|
||||
|
||||
# Backwards compatibility - Remove after 2022.9
|
||||
if len(self.sys_config.addons_repositories) > 0:
|
||||
self._data[ATTR_REPOSITORIES] = ensure_builtin_repositories(
|
||||
self.sys_config.addons_repositories
|
||||
)
|
||||
self.sys_config.clear_addons_repositories()
|
||||
|
||||
# Init custom repositories and load add-ons
|
||||
await self.update_repositories(
|
||||
self._data[ATTR_REPOSITORIES], add_with_errors=True
|
||||
|
@ -16,7 +16,7 @@ from supervisor import config as su_config
|
||||
from supervisor.addons.addon import Addon
|
||||
from supervisor.api import RestAPI
|
||||
from supervisor.bootstrap import initialize_coresys
|
||||
from supervisor.const import ATTR_REPOSITORIES, REQUEST_FROM
|
||||
from supervisor.const import ATTR_ADDONS_CUSTOM_LIST, ATTR_REPOSITORIES, REQUEST_FROM
|
||||
from supervisor.coresys import CoreSys
|
||||
from supervisor.dbus.agent import OSAgent
|
||||
from supervisor.dbus.const import DBUS_SIGNAL_NM_CONNECTION_ACTIVE_CHANGED
|
||||
@ -322,7 +322,7 @@ async def repository(coresys: CoreSys):
|
||||
coresys.store._data[ATTR_REPOSITORIES].remove(
|
||||
"https://github.com/esphome/home-assistant-addon"
|
||||
)
|
||||
coresys.config.clear_addons_repositories()
|
||||
coresys.config._data[ATTR_ADDONS_CUSTOM_LIST] = []
|
||||
|
||||
with patch(
|
||||
"supervisor.store.validate.BUILTIN_REPOSITORIES", {"local", "core"}
|
||||
|
@ -1,6 +1,7 @@
|
||||
"""Test store manager."""
|
||||
from unittest.mock import patch
|
||||
|
||||
from supervisor.bootstrap import migrate_system_env
|
||||
from supervisor.const import ATTR_ADDONS_CUSTOM_LIST
|
||||
from supervisor.coresys import CoreSys
|
||||
from supervisor.store import StoreManager
|
||||
@ -70,29 +71,32 @@ async def test_load_with_custom_repository(coresys: CoreSys):
|
||||
|
||||
async def test_load_from_core_config(coresys: CoreSys):
|
||||
"""Test custom repositories loaded from core config when present."""
|
||||
store_manager = StoreManager(coresys)
|
||||
|
||||
# pylint: disable=protected-access
|
||||
coresys.config._data[ATTR_ADDONS_CUSTOM_LIST] = ["http://example.com"]
|
||||
assert coresys.config.addons_repositories == ["http://example.com"]
|
||||
|
||||
migrate_system_env(coresys)
|
||||
|
||||
with patch("supervisor.store.repository.Repository.load", return_value=None), patch(
|
||||
"supervisor.store.repository.Repository.validate", return_value=True
|
||||
), patch("pathlib.Path.exists", return_value=True):
|
||||
await store_manager.load()
|
||||
await coresys.store.load()
|
||||
|
||||
assert len(store_manager.all) == 5
|
||||
assert isinstance(store_manager.get("core"), Repository)
|
||||
assert isinstance(store_manager.get("local"), Repository)
|
||||
assert len(coresys.store.all) == 5
|
||||
assert isinstance(coresys.store.get("core"), Repository)
|
||||
assert isinstance(coresys.store.get("local"), Repository)
|
||||
|
||||
assert len(store_manager.repository_urls) == 3
|
||||
assert len(coresys.store.repository_urls) == 3
|
||||
assert (
|
||||
"https://github.com/hassio-addons/repository" in store_manager.repository_urls
|
||||
"https://github.com/hassio-addons/repository" in coresys.store.repository_urls
|
||||
)
|
||||
assert (
|
||||
"https://github.com/esphome/home-assistant-addon"
|
||||
in store_manager.repository_urls
|
||||
in coresys.store.repository_urls
|
||||
)
|
||||
assert "http://example.com" in store_manager.repository_urls
|
||||
assert "http://example.com" in coresys.store.repository_urls
|
||||
|
||||
assert coresys.config.addons_repositories == []
|
||||
|
||||
coresys.config.save_data.assert_called_once()
|
||||
coresys.store.save_data.assert_called_once()
|
||||
|
Loading…
x
Reference in New Issue
Block a user