2023-03-13 08:44:20 +00:00
|
|
|
"""Test issues from supervisor issues."""
|
2022-10-31 13:57:54 +00:00
|
|
|
from __future__ import annotations
|
|
|
|
|
2023-04-19 06:07:38 +00:00
|
|
|
from asyncio import TimeoutError
|
2022-10-31 13:57:54 +00:00
|
|
|
import os
|
|
|
|
from typing import Any
|
|
|
|
from unittest.mock import ANY, patch
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
from homeassistant.components.repairs import DOMAIN as REPAIRS_DOMAIN
|
|
|
|
from homeassistant.core import HomeAssistant
|
|
|
|
from homeassistant.setup import async_setup_component
|
|
|
|
|
|
|
|
from .test_init import MOCK_ENVIRON
|
|
|
|
|
|
|
|
from tests.test_util.aiohttp import AiohttpClientMocker
|
2023-02-13 10:13:48 +00:00
|
|
|
from tests.typing import WebSocketGenerator
|
2022-10-31 13:57:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
|
|
async def setup_repairs(hass):
|
|
|
|
"""Set up the repairs integration."""
|
|
|
|
assert await async_setup_component(hass, REPAIRS_DOMAIN, {REPAIRS_DOMAIN: {}})
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
2023-04-19 06:07:38 +00:00
|
|
|
async def mock_all(all_setup_requests):
|
2022-10-31 13:57:54 +00:00
|
|
|
"""Mock all setup requests."""
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
|
|
async def fixture_supervisor_environ():
|
|
|
|
"""Mock os environ for supervisor."""
|
|
|
|
with patch.dict(os.environ, MOCK_ENVIRON):
|
|
|
|
yield
|
|
|
|
|
|
|
|
|
|
|
|
def mock_resolution_info(
|
|
|
|
aioclient_mock: AiohttpClientMocker,
|
|
|
|
unsupported: list[str] | None = None,
|
|
|
|
unhealthy: list[str] | None = None,
|
2023-04-19 06:07:38 +00:00
|
|
|
issues: list[dict[str, str]] | None = None,
|
2022-10-31 13:57:54 +00:00
|
|
|
):
|
2023-04-19 06:07:38 +00:00
|
|
|
"""Mock resolution/info endpoint with unsupported/unhealthy reasons and/or issues."""
|
2022-10-31 13:57:54 +00:00
|
|
|
aioclient_mock.get(
|
|
|
|
"http://127.0.0.1/resolution/info",
|
|
|
|
json={
|
|
|
|
"result": "ok",
|
|
|
|
"data": {
|
|
|
|
"unsupported": unsupported or [],
|
|
|
|
"unhealthy": unhealthy or [],
|
|
|
|
"suggestions": [],
|
2023-04-19 06:07:38 +00:00
|
|
|
"issues": [
|
|
|
|
{k: v for k, v in issue.items() if k != "suggestions"}
|
|
|
|
for issue in issues
|
|
|
|
]
|
|
|
|
if issues
|
|
|
|
else [],
|
2022-10-31 13:57:54 +00:00
|
|
|
"checks": [
|
|
|
|
{"enabled": True, "slug": "supervisor_trust"},
|
|
|
|
{"enabled": True, "slug": "free_space"},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
)
|
|
|
|
|
2023-04-19 06:07:38 +00:00
|
|
|
if issues:
|
|
|
|
suggestions_by_issue = {
|
|
|
|
issue["uuid"]: issue.get("suggestions", []) for issue in issues
|
|
|
|
}
|
|
|
|
for issue_uuid, suggestions in suggestions_by_issue.items():
|
|
|
|
aioclient_mock.get(
|
|
|
|
f"http://127.0.0.1/resolution/issue/{issue_uuid}/suggestions",
|
|
|
|
json={"result": "ok", "data": {"suggestions": suggestions}},
|
|
|
|
)
|
|
|
|
for suggestion in suggestions:
|
|
|
|
aioclient_mock.post(
|
|
|
|
f"http://127.0.0.1/resolution/suggestion/{suggestion['uuid']}",
|
|
|
|
json={"result": "ok"},
|
|
|
|
)
|
|
|
|
|
2022-10-31 13:57:54 +00:00
|
|
|
|
|
|
|
def assert_repair_in_list(issues: list[dict[str, Any]], unhealthy: bool, reason: str):
|
|
|
|
"""Assert repair for unhealthy/unsupported in list."""
|
|
|
|
repair_type = "unhealthy" if unhealthy else "unsupported"
|
|
|
|
assert {
|
|
|
|
"breaks_in_ha_version": None,
|
|
|
|
"created": ANY,
|
|
|
|
"dismissed_version": None,
|
|
|
|
"domain": "hassio",
|
|
|
|
"ignored": False,
|
|
|
|
"is_fixable": False,
|
|
|
|
"issue_id": f"{repair_type}_system_{reason}",
|
|
|
|
"issue_domain": None,
|
|
|
|
"learn_more_url": f"https://www.home-assistant.io/more-info/{repair_type}/{reason}",
|
|
|
|
"severity": "critical" if unhealthy else "warning",
|
2022-11-02 01:29:11 +00:00
|
|
|
"translation_key": f"{repair_type}_{reason}",
|
|
|
|
"translation_placeholders": None,
|
2022-10-31 13:57:54 +00:00
|
|
|
} in issues
|
|
|
|
|
|
|
|
|
2023-04-19 06:07:38 +00:00
|
|
|
def assert_issue_repair_in_list(
|
|
|
|
issues: list[dict[str, Any]],
|
|
|
|
uuid: str,
|
|
|
|
context: str,
|
|
|
|
type_: str,
|
|
|
|
fixable: bool,
|
|
|
|
reference: str | None,
|
|
|
|
):
|
|
|
|
"""Assert repair for unhealthy/unsupported in list."""
|
|
|
|
assert {
|
|
|
|
"breaks_in_ha_version": None,
|
|
|
|
"created": ANY,
|
|
|
|
"dismissed_version": None,
|
|
|
|
"domain": "hassio",
|
|
|
|
"ignored": False,
|
|
|
|
"is_fixable": fixable,
|
|
|
|
"issue_id": uuid,
|
|
|
|
"issue_domain": None,
|
|
|
|
"learn_more_url": None,
|
|
|
|
"severity": "warning",
|
|
|
|
"translation_key": f"issue_{context}_{type_}",
|
|
|
|
"translation_placeholders": {"reference": reference} if reference else None,
|
|
|
|
} in issues
|
|
|
|
|
|
|
|
|
2023-03-13 08:44:20 +00:00
|
|
|
async def test_unhealthy_issues(
|
2022-10-31 13:57:54 +00:00
|
|
|
hass: HomeAssistant,
|
|
|
|
aioclient_mock: AiohttpClientMocker,
|
2023-02-13 10:13:48 +00:00
|
|
|
hass_ws_client: WebSocketGenerator,
|
|
|
|
) -> None:
|
2023-03-13 08:44:20 +00:00
|
|
|
"""Test issues added for unhealthy systems."""
|
2022-10-31 13:57:54 +00:00
|
|
|
mock_resolution_info(aioclient_mock, unhealthy=["docker", "setup"])
|
|
|
|
|
|
|
|
result = await async_setup_component(hass, "hassio", {})
|
|
|
|
assert result
|
|
|
|
|
|
|
|
client = await hass_ws_client(hass)
|
|
|
|
|
|
|
|
await client.send_json({"id": 1, "type": "repairs/list_issues"})
|
|
|
|
msg = await client.receive_json()
|
|
|
|
assert msg["success"]
|
|
|
|
assert len(msg["result"]["issues"]) == 2
|
|
|
|
assert_repair_in_list(msg["result"]["issues"], unhealthy=True, reason="docker")
|
|
|
|
assert_repair_in_list(msg["result"]["issues"], unhealthy=True, reason="setup")
|
|
|
|
|
|
|
|
|
2023-03-13 08:44:20 +00:00
|
|
|
async def test_unsupported_issues(
|
2022-10-31 13:57:54 +00:00
|
|
|
hass: HomeAssistant,
|
|
|
|
aioclient_mock: AiohttpClientMocker,
|
2023-02-13 10:13:48 +00:00
|
|
|
hass_ws_client: WebSocketGenerator,
|
|
|
|
) -> None:
|
2023-03-13 08:44:20 +00:00
|
|
|
"""Test issues added for unsupported systems."""
|
2022-10-31 13:57:54 +00:00
|
|
|
mock_resolution_info(aioclient_mock, unsupported=["content_trust", "os"])
|
|
|
|
|
|
|
|
result = await async_setup_component(hass, "hassio", {})
|
|
|
|
assert result
|
|
|
|
|
|
|
|
client = await hass_ws_client(hass)
|
|
|
|
|
|
|
|
await client.send_json({"id": 1, "type": "repairs/list_issues"})
|
|
|
|
msg = await client.receive_json()
|
|
|
|
assert msg["success"]
|
|
|
|
assert len(msg["result"]["issues"]) == 2
|
|
|
|
assert_repair_in_list(
|
|
|
|
msg["result"]["issues"], unhealthy=False, reason="content_trust"
|
|
|
|
)
|
|
|
|
assert_repair_in_list(msg["result"]["issues"], unhealthy=False, reason="os")
|
|
|
|
|
|
|
|
|
2023-03-13 08:44:20 +00:00
|
|
|
async def test_unhealthy_issues_add_remove(
|
2022-10-31 13:57:54 +00:00
|
|
|
hass: HomeAssistant,
|
|
|
|
aioclient_mock: AiohttpClientMocker,
|
2023-02-13 10:13:48 +00:00
|
|
|
hass_ws_client: WebSocketGenerator,
|
|
|
|
) -> None:
|
2023-03-13 08:44:20 +00:00
|
|
|
"""Test unhealthy issues added and removed from dispatches."""
|
2022-10-31 13:57:54 +00:00
|
|
|
mock_resolution_info(aioclient_mock)
|
|
|
|
|
|
|
|
result = await async_setup_component(hass, "hassio", {})
|
|
|
|
assert result
|
|
|
|
|
|
|
|
client = await hass_ws_client(hass)
|
|
|
|
|
|
|
|
await client.send_json(
|
|
|
|
{
|
|
|
|
"id": 1,
|
|
|
|
"type": "supervisor/event",
|
|
|
|
"data": {
|
|
|
|
"event": "health_changed",
|
|
|
|
"data": {
|
|
|
|
"healthy": False,
|
|
|
|
"unhealthy_reasons": ["docker"],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
)
|
|
|
|
msg = await client.receive_json()
|
|
|
|
assert msg["success"]
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
|
|
|
|
await client.send_json({"id": 2, "type": "repairs/list_issues"})
|
|
|
|
msg = await client.receive_json()
|
|
|
|
assert msg["success"]
|
|
|
|
assert len(msg["result"]["issues"]) == 1
|
|
|
|
assert_repair_in_list(msg["result"]["issues"], unhealthy=True, reason="docker")
|
|
|
|
|
|
|
|
await client.send_json(
|
|
|
|
{
|
|
|
|
"id": 3,
|
|
|
|
"type": "supervisor/event",
|
|
|
|
"data": {
|
|
|
|
"event": "health_changed",
|
|
|
|
"data": {"healthy": True},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
)
|
|
|
|
msg = await client.receive_json()
|
|
|
|
assert msg["success"]
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
|
|
|
|
await client.send_json({"id": 4, "type": "repairs/list_issues"})
|
|
|
|
msg = await client.receive_json()
|
|
|
|
assert msg["success"]
|
|
|
|
assert msg["result"] == {"issues": []}
|
|
|
|
|
|
|
|
|
2023-03-13 08:44:20 +00:00
|
|
|
async def test_unsupported_issues_add_remove(
|
2022-10-31 13:57:54 +00:00
|
|
|
hass: HomeAssistant,
|
|
|
|
aioclient_mock: AiohttpClientMocker,
|
2023-02-13 10:13:48 +00:00
|
|
|
hass_ws_client: WebSocketGenerator,
|
|
|
|
) -> None:
|
2023-03-13 08:44:20 +00:00
|
|
|
"""Test unsupported issues added and removed from dispatches."""
|
2022-10-31 13:57:54 +00:00
|
|
|
mock_resolution_info(aioclient_mock)
|
|
|
|
|
|
|
|
result = await async_setup_component(hass, "hassio", {})
|
|
|
|
assert result
|
|
|
|
|
|
|
|
client = await hass_ws_client(hass)
|
|
|
|
|
|
|
|
await client.send_json(
|
|
|
|
{
|
|
|
|
"id": 1,
|
|
|
|
"type": "supervisor/event",
|
|
|
|
"data": {
|
|
|
|
"event": "supported_changed",
|
|
|
|
"data": {
|
|
|
|
"supported": False,
|
|
|
|
"unsupported_reasons": ["os"],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
)
|
|
|
|
msg = await client.receive_json()
|
|
|
|
assert msg["success"]
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
|
|
|
|
await client.send_json({"id": 2, "type": "repairs/list_issues"})
|
|
|
|
msg = await client.receive_json()
|
|
|
|
assert msg["success"]
|
|
|
|
assert len(msg["result"]["issues"]) == 1
|
|
|
|
assert_repair_in_list(msg["result"]["issues"], unhealthy=False, reason="os")
|
|
|
|
|
|
|
|
await client.send_json(
|
|
|
|
{
|
|
|
|
"id": 3,
|
|
|
|
"type": "supervisor/event",
|
|
|
|
"data": {
|
|
|
|
"event": "supported_changed",
|
|
|
|
"data": {"supported": True},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
)
|
|
|
|
msg = await client.receive_json()
|
|
|
|
assert msg["success"]
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
|
|
|
|
await client.send_json({"id": 4, "type": "repairs/list_issues"})
|
|
|
|
msg = await client.receive_json()
|
|
|
|
assert msg["success"]
|
|
|
|
assert msg["result"] == {"issues": []}
|
|
|
|
|
|
|
|
|
2023-03-13 08:44:20 +00:00
|
|
|
async def test_reset_issues_supervisor_restart(
|
2022-10-31 13:57:54 +00:00
|
|
|
hass: HomeAssistant,
|
|
|
|
aioclient_mock: AiohttpClientMocker,
|
2023-02-13 10:13:48 +00:00
|
|
|
hass_ws_client: WebSocketGenerator,
|
|
|
|
) -> None:
|
2023-04-19 06:07:38 +00:00
|
|
|
"""All issues reset on supervisor restart."""
|
|
|
|
mock_resolution_info(
|
|
|
|
aioclient_mock,
|
|
|
|
unsupported=["os"],
|
|
|
|
unhealthy=["docker"],
|
|
|
|
issues=[
|
|
|
|
{
|
|
|
|
"uuid": "1234",
|
|
|
|
"type": "reboot_required",
|
|
|
|
"context": "system",
|
|
|
|
"reference": None,
|
|
|
|
}
|
|
|
|
],
|
|
|
|
)
|
2022-10-31 13:57:54 +00:00
|
|
|
|
|
|
|
result = await async_setup_component(hass, "hassio", {})
|
|
|
|
assert result
|
|
|
|
|
|
|
|
client = await hass_ws_client(hass)
|
|
|
|
|
|
|
|
await client.send_json({"id": 1, "type": "repairs/list_issues"})
|
|
|
|
msg = await client.receive_json()
|
|
|
|
assert msg["success"]
|
2023-04-19 06:07:38 +00:00
|
|
|
assert len(msg["result"]["issues"]) == 3
|
2022-10-31 13:57:54 +00:00
|
|
|
assert_repair_in_list(msg["result"]["issues"], unhealthy=True, reason="docker")
|
|
|
|
assert_repair_in_list(msg["result"]["issues"], unhealthy=False, reason="os")
|
2023-04-19 06:07:38 +00:00
|
|
|
assert_issue_repair_in_list(
|
|
|
|
msg["result"]["issues"],
|
|
|
|
uuid="1234",
|
|
|
|
context="system",
|
|
|
|
type_="reboot_required",
|
|
|
|
fixable=False,
|
|
|
|
reference=None,
|
|
|
|
)
|
2022-10-31 13:57:54 +00:00
|
|
|
|
|
|
|
aioclient_mock.clear_requests()
|
|
|
|
mock_resolution_info(aioclient_mock)
|
|
|
|
await client.send_json(
|
|
|
|
{
|
|
|
|
"id": 2,
|
|
|
|
"type": "supervisor/event",
|
|
|
|
"data": {
|
|
|
|
"event": "supervisor_update",
|
|
|
|
"update_key": "supervisor",
|
|
|
|
"data": {},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
)
|
|
|
|
msg = await client.receive_json()
|
|
|
|
assert msg["success"]
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
|
|
|
|
await client.send_json({"id": 3, "type": "repairs/list_issues"})
|
|
|
|
msg = await client.receive_json()
|
|
|
|
assert msg["success"]
|
|
|
|
assert msg["result"] == {"issues": []}
|
|
|
|
|
|
|
|
|
|
|
|
async def test_reasons_added_and_removed(
|
|
|
|
hass: HomeAssistant,
|
|
|
|
aioclient_mock: AiohttpClientMocker,
|
2023-02-13 10:13:48 +00:00
|
|
|
hass_ws_client: WebSocketGenerator,
|
|
|
|
) -> None:
|
2022-10-31 13:57:54 +00:00
|
|
|
"""Test an unsupported/unhealthy reasons being added and removed at same time."""
|
|
|
|
mock_resolution_info(aioclient_mock, unsupported=["os"], unhealthy=["docker"])
|
|
|
|
|
|
|
|
result = await async_setup_component(hass, "hassio", {})
|
|
|
|
assert result
|
|
|
|
|
|
|
|
client = await hass_ws_client(hass)
|
|
|
|
|
|
|
|
await client.send_json({"id": 1, "type": "repairs/list_issues"})
|
|
|
|
msg = await client.receive_json()
|
|
|
|
assert msg["success"]
|
|
|
|
assert len(msg["result"]["issues"]) == 2
|
|
|
|
assert_repair_in_list(msg["result"]["issues"], unhealthy=True, reason="docker")
|
|
|
|
assert_repair_in_list(msg["result"]["issues"], unhealthy=False, reason="os")
|
|
|
|
|
|
|
|
aioclient_mock.clear_requests()
|
|
|
|
mock_resolution_info(
|
|
|
|
aioclient_mock, unsupported=["content_trust"], unhealthy=["setup"]
|
|
|
|
)
|
|
|
|
await client.send_json(
|
|
|
|
{
|
|
|
|
"id": 2,
|
|
|
|
"type": "supervisor/event",
|
|
|
|
"data": {
|
|
|
|
"event": "supervisor_update",
|
|
|
|
"update_key": "supervisor",
|
|
|
|
"data": {},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
)
|
|
|
|
msg = await client.receive_json()
|
|
|
|
assert msg["success"]
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
|
|
|
|
await client.send_json({"id": 3, "type": "repairs/list_issues"})
|
|
|
|
msg = await client.receive_json()
|
|
|
|
assert msg["success"]
|
|
|
|
assert len(msg["result"]["issues"]) == 2
|
|
|
|
assert_repair_in_list(msg["result"]["issues"], unhealthy=True, reason="setup")
|
|
|
|
assert_repair_in_list(
|
|
|
|
msg["result"]["issues"], unhealthy=False, reason="content_trust"
|
|
|
|
)
|
2022-11-02 01:29:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
async def test_ignored_unsupported_skipped(
|
|
|
|
hass: HomeAssistant,
|
|
|
|
aioclient_mock: AiohttpClientMocker,
|
2023-02-13 10:13:48 +00:00
|
|
|
hass_ws_client: WebSocketGenerator,
|
|
|
|
) -> None:
|
2022-11-02 01:29:11 +00:00
|
|
|
"""Unsupported reasons which have an identical unhealthy reason are ignored."""
|
|
|
|
mock_resolution_info(
|
|
|
|
aioclient_mock, unsupported=["privileged"], unhealthy=["privileged"]
|
|
|
|
)
|
|
|
|
|
|
|
|
result = await async_setup_component(hass, "hassio", {})
|
|
|
|
assert result
|
|
|
|
|
|
|
|
client = await hass_ws_client(hass)
|
|
|
|
|
|
|
|
await client.send_json({"id": 1, "type": "repairs/list_issues"})
|
|
|
|
msg = await client.receive_json()
|
|
|
|
assert msg["success"]
|
|
|
|
assert len(msg["result"]["issues"]) == 1
|
|
|
|
assert_repair_in_list(msg["result"]["issues"], unhealthy=True, reason="privileged")
|
|
|
|
|
|
|
|
|
|
|
|
async def test_new_unsupported_unhealthy_reason(
|
|
|
|
hass: HomeAssistant,
|
|
|
|
aioclient_mock: AiohttpClientMocker,
|
2023-02-13 10:13:48 +00:00
|
|
|
hass_ws_client: WebSocketGenerator,
|
|
|
|
) -> None:
|
2022-11-02 01:29:11 +00:00
|
|
|
"""New unsupported/unhealthy reasons result in a generic repair until next core update."""
|
|
|
|
mock_resolution_info(
|
|
|
|
aioclient_mock, unsupported=["fake_unsupported"], unhealthy=["fake_unhealthy"]
|
|
|
|
)
|
|
|
|
|
|
|
|
result = await async_setup_component(hass, "hassio", {})
|
|
|
|
assert result
|
|
|
|
|
|
|
|
client = await hass_ws_client(hass)
|
|
|
|
|
|
|
|
await client.send_json({"id": 1, "type": "repairs/list_issues"})
|
|
|
|
msg = await client.receive_json()
|
|
|
|
assert msg["success"]
|
|
|
|
assert len(msg["result"]["issues"]) == 2
|
|
|
|
assert {
|
|
|
|
"breaks_in_ha_version": None,
|
|
|
|
"created": ANY,
|
|
|
|
"dismissed_version": None,
|
|
|
|
"domain": "hassio",
|
|
|
|
"ignored": False,
|
|
|
|
"is_fixable": False,
|
|
|
|
"issue_id": "unhealthy_system_fake_unhealthy",
|
|
|
|
"issue_domain": None,
|
|
|
|
"learn_more_url": "https://www.home-assistant.io/more-info/unhealthy/fake_unhealthy",
|
|
|
|
"severity": "critical",
|
|
|
|
"translation_key": "unhealthy",
|
|
|
|
"translation_placeholders": {"reason": "fake_unhealthy"},
|
|
|
|
} in msg["result"]["issues"]
|
|
|
|
assert {
|
|
|
|
"breaks_in_ha_version": None,
|
|
|
|
"created": ANY,
|
|
|
|
"dismissed_version": None,
|
|
|
|
"domain": "hassio",
|
|
|
|
"ignored": False,
|
|
|
|
"is_fixable": False,
|
|
|
|
"issue_id": "unsupported_system_fake_unsupported",
|
|
|
|
"issue_domain": None,
|
|
|
|
"learn_more_url": "https://www.home-assistant.io/more-info/unsupported/fake_unsupported",
|
|
|
|
"severity": "warning",
|
|
|
|
"translation_key": "unsupported",
|
|
|
|
"translation_placeholders": {"reason": "fake_unsupported"},
|
|
|
|
} in msg["result"]["issues"]
|
2023-04-19 06:07:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
async def test_supervisor_issues(
|
|
|
|
hass: HomeAssistant,
|
|
|
|
aioclient_mock: AiohttpClientMocker,
|
|
|
|
hass_ws_client: WebSocketGenerator,
|
|
|
|
) -> None:
|
|
|
|
"""Test repairs added for supervisor issue."""
|
|
|
|
mock_resolution_info(
|
|
|
|
aioclient_mock,
|
|
|
|
issues=[
|
|
|
|
{
|
|
|
|
"uuid": "1234",
|
|
|
|
"type": "reboot_required",
|
|
|
|
"context": "system",
|
|
|
|
"reference": None,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"uuid": "1235",
|
|
|
|
"type": "multiple_data_disks",
|
|
|
|
"context": "system",
|
|
|
|
"reference": "/dev/sda1",
|
|
|
|
"suggestions": [
|
|
|
|
{
|
|
|
|
"uuid": "1236",
|
|
|
|
"type": "rename_data_disk",
|
|
|
|
"context": "system",
|
|
|
|
"reference": "/dev/sda1",
|
|
|
|
}
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"uuid": "1237",
|
|
|
|
"type": "should_not_be_repair",
|
|
|
|
"context": "fake",
|
|
|
|
"reference": None,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
)
|
|
|
|
|
|
|
|
result = await async_setup_component(hass, "hassio", {})
|
|
|
|
assert result
|
|
|
|
|
|
|
|
client = await hass_ws_client(hass)
|
|
|
|
|
|
|
|
await client.send_json({"id": 1, "type": "repairs/list_issues"})
|
|
|
|
msg = await client.receive_json()
|
|
|
|
assert msg["success"]
|
|
|
|
assert len(msg["result"]["issues"]) == 2
|
|
|
|
assert_issue_repair_in_list(
|
|
|
|
msg["result"]["issues"],
|
|
|
|
uuid="1234",
|
|
|
|
context="system",
|
|
|
|
type_="reboot_required",
|
|
|
|
fixable=False,
|
|
|
|
reference=None,
|
|
|
|
)
|
|
|
|
assert_issue_repair_in_list(
|
|
|
|
msg["result"]["issues"],
|
|
|
|
uuid="1235",
|
|
|
|
context="system",
|
|
|
|
type_="multiple_data_disks",
|
|
|
|
fixable=True,
|
|
|
|
reference="/dev/sda1",
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
async def test_supervisor_issues_add_remove(
|
|
|
|
hass: HomeAssistant,
|
|
|
|
aioclient_mock: AiohttpClientMocker,
|
|
|
|
hass_ws_client: WebSocketGenerator,
|
|
|
|
) -> None:
|
|
|
|
"""Test supervisor issues added and removed from dispatches."""
|
|
|
|
mock_resolution_info(aioclient_mock)
|
|
|
|
|
|
|
|
result = await async_setup_component(hass, "hassio", {})
|
|
|
|
assert result
|
|
|
|
|
|
|
|
client = await hass_ws_client(hass)
|
|
|
|
|
|
|
|
await client.send_json(
|
|
|
|
{
|
|
|
|
"id": 1,
|
|
|
|
"type": "supervisor/event",
|
|
|
|
"data": {
|
|
|
|
"event": "issue_changed",
|
|
|
|
"data": {
|
|
|
|
"uuid": "1234",
|
|
|
|
"type": "reboot_required",
|
|
|
|
"context": "system",
|
|
|
|
"reference": None,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
)
|
|
|
|
msg = await client.receive_json()
|
|
|
|
assert msg["success"]
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
|
|
|
|
await client.send_json({"id": 2, "type": "repairs/list_issues"})
|
|
|
|
msg = await client.receive_json()
|
|
|
|
assert msg["success"]
|
|
|
|
assert len(msg["result"]["issues"]) == 1
|
|
|
|
assert_issue_repair_in_list(
|
|
|
|
msg["result"]["issues"],
|
|
|
|
uuid="1234",
|
|
|
|
context="system",
|
|
|
|
type_="reboot_required",
|
|
|
|
fixable=False,
|
|
|
|
reference=None,
|
|
|
|
)
|
|
|
|
|
|
|
|
await client.send_json(
|
|
|
|
{
|
|
|
|
"id": 3,
|
|
|
|
"type": "supervisor/event",
|
|
|
|
"data": {
|
|
|
|
"event": "issue_changed",
|
|
|
|
"data": {
|
|
|
|
"uuid": "1234",
|
|
|
|
"type": "reboot_required",
|
|
|
|
"context": "system",
|
|
|
|
"reference": None,
|
|
|
|
"suggestions": [
|
|
|
|
{
|
|
|
|
"uuid": "1235",
|
|
|
|
"type": "execute_reboot",
|
|
|
|
"context": "system",
|
|
|
|
"reference": None,
|
|
|
|
}
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
)
|
|
|
|
msg = await client.receive_json()
|
|
|
|
assert msg["success"]
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
|
|
|
|
await client.send_json({"id": 4, "type": "repairs/list_issues"})
|
|
|
|
msg = await client.receive_json()
|
|
|
|
assert msg["success"]
|
|
|
|
assert len(msg["result"]["issues"]) == 1
|
|
|
|
assert_issue_repair_in_list(
|
|
|
|
msg["result"]["issues"],
|
|
|
|
uuid="1234",
|
|
|
|
context="system",
|
|
|
|
type_="reboot_required",
|
|
|
|
fixable=True,
|
|
|
|
reference=None,
|
|
|
|
)
|
|
|
|
|
|
|
|
await client.send_json(
|
|
|
|
{
|
|
|
|
"id": 5,
|
|
|
|
"type": "supervisor/event",
|
|
|
|
"data": {
|
|
|
|
"event": "issue_removed",
|
|
|
|
"data": {
|
|
|
|
"uuid": "1234",
|
|
|
|
"type": "reboot_required",
|
|
|
|
"context": "system",
|
|
|
|
"reference": None,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
)
|
|
|
|
msg = await client.receive_json()
|
|
|
|
assert msg["success"]
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
|
|
|
|
await client.send_json({"id": 6, "type": "repairs/list_issues"})
|
|
|
|
msg = await client.receive_json()
|
|
|
|
assert msg["success"]
|
|
|
|
assert msg["result"] == {"issues": []}
|
|
|
|
|
|
|
|
|
|
|
|
async def test_supervisor_issues_suggestions_fail(
|
|
|
|
hass: HomeAssistant,
|
|
|
|
aioclient_mock: AiohttpClientMocker,
|
|
|
|
hass_ws_client: WebSocketGenerator,
|
|
|
|
) -> None:
|
|
|
|
"""Test failing to get suggestions for issue skips it."""
|
|
|
|
aioclient_mock.get(
|
|
|
|
"http://127.0.0.1/resolution/info",
|
|
|
|
json={
|
|
|
|
"result": "ok",
|
|
|
|
"data": {
|
|
|
|
"unsupported": [],
|
|
|
|
"unhealthy": [],
|
|
|
|
"suggestions": [],
|
|
|
|
"issues": [
|
|
|
|
{
|
|
|
|
"uuid": "1234",
|
|
|
|
"type": "reboot_required",
|
|
|
|
"context": "system",
|
|
|
|
"reference": None,
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"checks": [
|
|
|
|
{"enabled": True, "slug": "supervisor_trust"},
|
|
|
|
{"enabled": True, "slug": "free_space"},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
)
|
|
|
|
aioclient_mock.get(
|
|
|
|
"http://127.0.0.1/resolution/issue/1234/suggestions",
|
|
|
|
exc=TimeoutError(),
|
|
|
|
)
|
|
|
|
|
|
|
|
result = await async_setup_component(hass, "hassio", {})
|
|
|
|
assert result
|
|
|
|
|
|
|
|
client = await hass_ws_client(hass)
|
|
|
|
|
|
|
|
await client.send_json({"id": 1, "type": "repairs/list_issues"})
|
|
|
|
msg = await client.receive_json()
|
|
|
|
assert msg["success"]
|
|
|
|
assert len(msg["result"]["issues"]) == 0
|
|
|
|
|
|
|
|
|
|
|
|
async def test_supervisor_remove_missing_issue_without_error(
|
|
|
|
hass: HomeAssistant,
|
|
|
|
aioclient_mock: AiohttpClientMocker,
|
|
|
|
hass_ws_client: WebSocketGenerator,
|
|
|
|
) -> None:
|
|
|
|
"""Test HA skips message to remove issue that it didn't know about (sync issue)."""
|
|
|
|
mock_resolution_info(aioclient_mock)
|
|
|
|
|
|
|
|
result = await async_setup_component(hass, "hassio", {})
|
|
|
|
assert result
|
|
|
|
|
|
|
|
client = await hass_ws_client(hass)
|
|
|
|
|
|
|
|
await client.send_json(
|
|
|
|
{
|
|
|
|
"id": 5,
|
|
|
|
"type": "supervisor/event",
|
|
|
|
"data": {
|
|
|
|
"event": "issue_removed",
|
|
|
|
"data": {
|
|
|
|
"uuid": "1234",
|
|
|
|
"type": "reboot_required",
|
|
|
|
"context": "system",
|
|
|
|
"reference": None,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
)
|
|
|
|
msg = await client.receive_json()
|
|
|
|
assert msg["success"]
|
|
|
|
await hass.async_block_till_done()
|