1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 21:06:19 +00:00

Add docker config repair for supervisor issue (#93820)

This commit is contained in:
Mike Degatano
2023-05-30 16:08:45 -04:00
committed by GitHub
parent 05c3d8bb37
commit c25b26214b
8 changed files with 376 additions and 60 deletions

View File

@@ -19,16 +19,11 @@ from tests.typing import ClientSessionGenerator
@pytest.fixture(autouse=True)
async def setup_repairs(hass):
async def setup_repairs(hass: HomeAssistant):
"""Set up the repairs integration."""
assert await async_setup_component(hass, REPAIRS_DOMAIN, {REPAIRS_DOMAIN: {}})
@pytest.fixture(autouse=True)
async def mock_all(all_setup_requests):
"""Mock all setup requests."""
@pytest.fixture(autouse=True)
async def fixture_supervisor_environ():
"""Mock os environ for supervisor."""
@@ -40,9 +35,10 @@ async def test_supervisor_issue_repair_flow(
hass: HomeAssistant,
aioclient_mock: AiohttpClientMocker,
hass_client: ClientSessionGenerator,
issue_registry: ir.IssueRegistry,
all_setup_requests,
) -> None:
"""Test fix flow for supervisor issue."""
issue_registry: ir.IssueRegistry = ir.async_get(hass)
mock_resolution_info(
aioclient_mock,
issues=[
@@ -63,8 +59,7 @@ async def test_supervisor_issue_repair_flow(
],
)
result = await async_setup_component(hass, "hassio", {})
assert result
assert await async_setup_component(hass, "hassio", {})
repair_issue = issue_registry.async_get_issue(domain="hassio", issue_id="1234")
assert repair_issue
@@ -119,9 +114,10 @@ async def test_supervisor_issue_repair_flow_with_multiple_suggestions(
hass: HomeAssistant,
aioclient_mock: AiohttpClientMocker,
hass_client: ClientSessionGenerator,
issue_registry: ir.IssueRegistry,
all_setup_requests,
) -> None:
"""Test fix flow for supervisor issue with multiple suggestions."""
issue_registry: ir.IssueRegistry = ir.async_get(hass)
mock_resolution_info(
aioclient_mock,
issues=[
@@ -148,8 +144,7 @@ async def test_supervisor_issue_repair_flow_with_multiple_suggestions(
],
)
result = await async_setup_component(hass, "hassio", {})
assert result
assert await async_setup_component(hass, "hassio", {})
repair_issue = issue_registry.async_get_issue(domain="hassio", issue_id="1234")
assert repair_issue
@@ -214,9 +209,10 @@ async def test_supervisor_issue_repair_flow_with_multiple_suggestions_and_confir
hass: HomeAssistant,
aioclient_mock: AiohttpClientMocker,
hass_client: ClientSessionGenerator,
issue_registry: ir.IssueRegistry,
all_setup_requests,
) -> None:
"""Test fix flow for supervisor issue with multiple suggestions and choice requires confirmation."""
issue_registry: ir.IssueRegistry = ir.async_get(hass)
mock_resolution_info(
aioclient_mock,
issues=[
@@ -243,8 +239,7 @@ async def test_supervisor_issue_repair_flow_with_multiple_suggestions_and_confir
],
)
result = await async_setup_component(hass, "hassio", {})
assert result
assert await async_setup_component(hass, "hassio", {})
repair_issue = issue_registry.async_get_issue(domain="hassio", issue_id="1234")
assert repair_issue
@@ -327,9 +322,10 @@ async def test_supervisor_issue_repair_flow_skip_confirmation(
hass: HomeAssistant,
aioclient_mock: AiohttpClientMocker,
hass_client: ClientSessionGenerator,
issue_registry: ir.IssueRegistry,
all_setup_requests,
) -> None:
"""Test confirmation skipped for fix flow for supervisor issue with one suggestion."""
issue_registry: ir.IssueRegistry = ir.async_get(hass)
mock_resolution_info(
aioclient_mock,
issues=[
@@ -350,8 +346,7 @@ async def test_supervisor_issue_repair_flow_skip_confirmation(
],
)
result = await async_setup_component(hass, "hassio", {})
assert result
assert await async_setup_component(hass, "hassio", {})
repair_issue = issue_registry.async_get_issue(domain="hassio", issue_id="1234")
assert repair_issue
@@ -406,9 +401,10 @@ async def test_mount_failed_repair_flow(
hass: HomeAssistant,
aioclient_mock: AiohttpClientMocker,
hass_client: ClientSessionGenerator,
issue_registry: ir.IssueRegistry,
all_setup_requests,
) -> None:
"""Test repair flow for mount_failed issue."""
issue_registry: ir.IssueRegistry = ir.async_get(hass)
mock_resolution_info(
aioclient_mock,
issues=[
@@ -435,8 +431,7 @@ async def test_mount_failed_repair_flow(
],
)
result = await async_setup_component(hass, "hassio", {})
assert result
assert await async_setup_component(hass, "hassio", {})
repair_issue = issue_registry.async_get_issue(domain="hassio", issue_id="1234")
assert repair_issue
@@ -499,3 +494,113 @@ async def test_mount_failed_repair_flow(
str(aioclient_mock.mock_calls[-1][1])
== "http://127.0.0.1/resolution/suggestion/1235"
)
@pytest.mark.parametrize(
"all_setup_requests", [{"include_addons": True}], indirect=True
)
async def test_supervisor_issue_docker_config_repair_flow(
hass: HomeAssistant,
aioclient_mock: AiohttpClientMocker,
hass_client: ClientSessionGenerator,
issue_registry: ir.IssueRegistry,
all_setup_requests,
) -> None:
"""Test fix flow for supervisor issue."""
mock_resolution_info(
aioclient_mock,
issues=[
{
"uuid": "1234",
"type": "docker_config",
"context": "system",
"reference": None,
"suggestions": [
{
"uuid": "1235",
"type": "execute_rebuild",
"context": "system",
"reference": None,
}
],
},
{
"uuid": "1236",
"type": "docker_config",
"context": "core",
"reference": None,
"suggestions": [
{
"uuid": "1237",
"type": "execute_rebuild",
"context": "core",
"reference": None,
}
],
},
{
"uuid": "1238",
"type": "docker_config",
"context": "addon",
"reference": "test",
"suggestions": [
{
"uuid": "1239",
"type": "execute_rebuild",
"context": "addon",
"reference": "test",
}
],
},
],
)
assert await async_setup_component(hass, "hassio", {})
repair_issue = issue_registry.async_get_issue(domain="hassio", issue_id="1234")
assert repair_issue
client = await hass_client()
resp = await client.post(
"/api/repairs/issues/fix",
json={"handler": "hassio", "issue_id": repair_issue.issue_id},
)
assert resp.status == HTTPStatus.OK
data = await resp.json()
flow_id = data["flow_id"]
assert data == {
"type": "form",
"flow_id": flow_id,
"handler": "hassio",
"step_id": "system_execute_rebuild",
"data_schema": [],
"errors": None,
"description_placeholders": {"components": "Home Assistant\n- test"},
"last_step": True,
}
resp = await client.post(f"/api/repairs/issues/fix/{flow_id}")
assert resp.status == HTTPStatus.OK
data = await resp.json()
flow_id = data["flow_id"]
assert data == {
"version": 1,
"type": "create_entry",
"flow_id": flow_id,
"handler": "hassio",
"description": None,
"description_placeholders": None,
}
assert not issue_registry.async_get_issue(domain="hassio", issue_id="1234")
assert aioclient_mock.mock_calls[-1][0] == "post"
assert (
str(aioclient_mock.mock_calls[-1][1])
== "http://127.0.0.1/resolution/suggestion/1235"
)