mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-12-24 12:29:08 +00:00
Create addon boot failed issue for repair (#5397)
* Create addon boot failed issue for repair * MDont make new objects for contains checks
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
"""Test addon manager."""
|
||||
|
||||
import asyncio
|
||||
from collections.abc import AsyncGenerator, Generator
|
||||
from copy import deepcopy
|
||||
from pathlib import Path
|
||||
from unittest.mock import AsyncMock, MagicMock, Mock, PropertyMock, patch
|
||||
@@ -25,6 +26,8 @@ from supervisor.exceptions import (
|
||||
DockerNotFound,
|
||||
)
|
||||
from supervisor.plugins.dns import PluginDns
|
||||
from supervisor.resolution.const import ContextType, IssueType, SuggestionType
|
||||
from supervisor.resolution.data import Issue, Suggestion
|
||||
from supervisor.store.addon import AddonStore
|
||||
from supervisor.store.repository import Repository
|
||||
from supervisor.utils import check_exception_chain
|
||||
@@ -33,9 +36,21 @@ from supervisor.utils.common import write_json_file
|
||||
from tests.common import load_json_fixture
|
||||
from tests.const import TEST_ADDON_SLUG
|
||||
|
||||
BOOT_FAIL_ISSUE = Issue(
|
||||
IssueType.BOOT_FAIL, ContextType.ADDON, reference=TEST_ADDON_SLUG
|
||||
)
|
||||
BOOT_FAIL_SUGGESTIONS = [
|
||||
Suggestion(
|
||||
SuggestionType.EXECUTE_START, ContextType.ADDON, reference=TEST_ADDON_SLUG
|
||||
),
|
||||
Suggestion(
|
||||
SuggestionType.DISABLE_BOOT, ContextType.ADDON, reference=TEST_ADDON_SLUG
|
||||
),
|
||||
]
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
async def fixture_mock_arch_disk() -> None:
|
||||
async def fixture_mock_arch_disk() -> AsyncGenerator[None]:
|
||||
"""Mock supported arch and disk space."""
|
||||
with (
|
||||
patch("shutil.disk_usage", return_value=(42, 42, 2 * (1024.0**3))),
|
||||
@@ -45,13 +60,15 @@ async def fixture_mock_arch_disk() -> None:
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
async def fixture_remove_wait_boot(coresys: CoreSys) -> None:
|
||||
async def fixture_remove_wait_boot(coresys: CoreSys) -> AsyncGenerator[None]:
|
||||
"""Remove default wait boot time for tests."""
|
||||
coresys.config.wait_boot = 0
|
||||
|
||||
|
||||
@pytest.fixture(name="install_addon_example_image")
|
||||
def fixture_install_addon_example_image(coresys: CoreSys, repository) -> Addon:
|
||||
def fixture_install_addon_example_image(
|
||||
coresys: CoreSys, repository
|
||||
) -> Generator[Addon]:
|
||||
"""Install local_example add-on with image."""
|
||||
store = coresys.addons.store["local_example_image"]
|
||||
coresys.addons.data.install(store)
|
||||
@@ -114,14 +131,17 @@ async def test_addon_boot_system_error(
|
||||
):
|
||||
"""Test system errors during addon boot."""
|
||||
install_addon_ssh.boot = AddonBoot.AUTO
|
||||
assert coresys.resolution.issues == []
|
||||
assert coresys.resolution.suggestions == []
|
||||
with (
|
||||
patch.object(Addon, "write_options"),
|
||||
patch.object(DockerAddon, "run", side_effect=err),
|
||||
):
|
||||
await coresys.addons.boot(AddonStartup.APPLICATION)
|
||||
|
||||
assert install_addon_ssh.boot == AddonBoot.MANUAL
|
||||
capture_exception.assert_not_called()
|
||||
assert coresys.resolution.issues == [BOOT_FAIL_ISSUE]
|
||||
assert coresys.resolution.suggestions == BOOT_FAIL_SUGGESTIONS
|
||||
|
||||
|
||||
async def test_addon_boot_user_error(
|
||||
@@ -132,8 +152,9 @@ async def test_addon_boot_user_error(
|
||||
with patch.object(Addon, "write_options", side_effect=AddonConfigurationError):
|
||||
await coresys.addons.boot(AddonStartup.APPLICATION)
|
||||
|
||||
assert install_addon_ssh.boot == AddonBoot.MANUAL
|
||||
capture_exception.assert_not_called()
|
||||
assert coresys.resolution.issues == [BOOT_FAIL_ISSUE]
|
||||
assert coresys.resolution.suggestions == BOOT_FAIL_SUGGESTIONS
|
||||
|
||||
|
||||
async def test_addon_boot_other_error(
|
||||
@@ -148,8 +169,9 @@ async def test_addon_boot_other_error(
|
||||
):
|
||||
await coresys.addons.boot(AddonStartup.APPLICATION)
|
||||
|
||||
assert install_addon_ssh.boot == AddonBoot.AUTO
|
||||
capture_exception.assert_called_once_with(err)
|
||||
assert coresys.resolution.issues == [BOOT_FAIL_ISSUE]
|
||||
assert coresys.resolution.suggestions == BOOT_FAIL_SUGGESTIONS
|
||||
|
||||
|
||||
async def test_addon_shutdown_error(
|
||||
|
||||
Reference in New Issue
Block a user