mirror of
https://github.com/home-assistant/core.git
synced 2025-07-27 15:17:35 +00:00
Apply suggestion failures fail supervisor repair (#113372)
This commit is contained in:
parent
6832611550
commit
6d903300be
@ -263,10 +263,7 @@ async def async_update_core(
|
|||||||
@bind_hass
|
@bind_hass
|
||||||
@_api_bool
|
@_api_bool
|
||||||
async def async_apply_suggestion(hass: HomeAssistant, suggestion_uuid: str) -> dict:
|
async def async_apply_suggestion(hass: HomeAssistant, suggestion_uuid: str) -> dict:
|
||||||
"""Apply a suggestion from supervisor's resolution center.
|
"""Apply a suggestion from supervisor's resolution center."""
|
||||||
|
|
||||||
The caller of the function should handle HassioAPIError.
|
|
||||||
"""
|
|
||||||
hassio: HassIO = hass.data[DOMAIN]
|
hassio: HassIO = hass.data[DOMAIN]
|
||||||
command = f"/resolution/suggestion/{suggestion_uuid}"
|
command = f"/resolution/suggestion/{suggestion_uuid}"
|
||||||
return await hassio.send_command(command, timeout=None)
|
return await hassio.send_command(command, timeout=None)
|
||||||
|
@ -19,7 +19,7 @@ from .const import (
|
|||||||
PLACEHOLDER_KEY_REFERENCE,
|
PLACEHOLDER_KEY_REFERENCE,
|
||||||
SupervisorIssueContext,
|
SupervisorIssueContext,
|
||||||
)
|
)
|
||||||
from .handler import HassioAPIError, async_apply_suggestion
|
from .handler import async_apply_suggestion
|
||||||
from .issues import Issue, Suggestion
|
from .issues import Issue, Suggestion
|
||||||
|
|
||||||
SUGGESTION_CONFIRMATION_REQUIRED = {"system_execute_reboot"}
|
SUGGESTION_CONFIRMATION_REQUIRED = {"system_execute_reboot"}
|
||||||
@ -110,12 +110,9 @@ class SupervisorIssueRepairFlow(RepairsFlow):
|
|||||||
if not confirmed and suggestion.key in SUGGESTION_CONFIRMATION_REQUIRED:
|
if not confirmed and suggestion.key in SUGGESTION_CONFIRMATION_REQUIRED:
|
||||||
return self._async_form_for_suggestion(suggestion)
|
return self._async_form_for_suggestion(suggestion)
|
||||||
|
|
||||||
try:
|
if await async_apply_suggestion(self.hass, suggestion.uuid):
|
||||||
await async_apply_suggestion(self.hass, suggestion.uuid)
|
return self.async_create_entry(data={})
|
||||||
except HassioAPIError:
|
return self.async_abort(reason="apply_suggestion_fail")
|
||||||
return self.async_abort(reason="apply_suggestion_fail")
|
|
||||||
|
|
||||||
return self.async_create_entry(data={})
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _async_step(
|
def _async_step(
|
||||||
|
@ -41,6 +41,7 @@ def mock_resolution_info(
|
|||||||
unsupported: list[str] | None = None,
|
unsupported: list[str] | None = None,
|
||||||
unhealthy: list[str] | None = None,
|
unhealthy: list[str] | None = None,
|
||||||
issues: list[dict[str, str]] | None = None,
|
issues: list[dict[str, str]] | None = None,
|
||||||
|
suggestion_result: str = "ok",
|
||||||
):
|
):
|
||||||
"""Mock resolution/info endpoint with unsupported/unhealthy reasons and/or issues."""
|
"""Mock resolution/info endpoint with unsupported/unhealthy reasons and/or issues."""
|
||||||
aioclient_mock.get(
|
aioclient_mock.get(
|
||||||
@ -77,7 +78,7 @@ def mock_resolution_info(
|
|||||||
for suggestion in suggestions:
|
for suggestion in suggestions:
|
||||||
aioclient_mock.post(
|
aioclient_mock.post(
|
||||||
f"http://127.0.0.1/resolution/suggestion/{suggestion['uuid']}",
|
f"http://127.0.0.1/resolution/suggestion/{suggestion['uuid']}",
|
||||||
json={"result": "ok"},
|
json={"result": suggestion_result},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -396,6 +396,78 @@ async def test_supervisor_issue_repair_flow_skip_confirmation(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
async def test_mount_failed_repair_flow_error(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
aioclient_mock: AiohttpClientMocker,
|
||||||
|
hass_client: ClientSessionGenerator,
|
||||||
|
issue_registry: ir.IssueRegistry,
|
||||||
|
all_setup_requests,
|
||||||
|
) -> None:
|
||||||
|
"""Test repair flow fails when repair fails to apply."""
|
||||||
|
mock_resolution_info(
|
||||||
|
aioclient_mock,
|
||||||
|
issues=[
|
||||||
|
{
|
||||||
|
"uuid": "1234",
|
||||||
|
"type": "mount_failed",
|
||||||
|
"context": "mount",
|
||||||
|
"reference": "backup_share",
|
||||||
|
"suggestions": [
|
||||||
|
{
|
||||||
|
"uuid": "1235",
|
||||||
|
"type": "execute_reload",
|
||||||
|
"context": "mount",
|
||||||
|
"reference": "backup_share",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"uuid": "1236",
|
||||||
|
"type": "execute_remove",
|
||||||
|
"context": "mount",
|
||||||
|
"reference": "backup_share",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
suggestion_result=False,
|
||||||
|
)
|
||||||
|
|
||||||
|
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"]
|
||||||
|
|
||||||
|
resp = await client.post(
|
||||||
|
f"/api/repairs/issues/fix/{flow_id}",
|
||||||
|
json={"next_step_id": "mount_execute_reload"},
|
||||||
|
)
|
||||||
|
|
||||||
|
assert resp.status == HTTPStatus.OK
|
||||||
|
data = await resp.json()
|
||||||
|
|
||||||
|
flow_id = data["flow_id"]
|
||||||
|
assert data == {
|
||||||
|
"type": "abort",
|
||||||
|
"flow_id": flow_id,
|
||||||
|
"handler": "hassio",
|
||||||
|
"reason": "apply_suggestion_fail",
|
||||||
|
"result": None,
|
||||||
|
"description_placeholders": None,
|
||||||
|
}
|
||||||
|
|
||||||
|
assert issue_registry.async_get_issue(domain="hassio", issue_id="1234")
|
||||||
|
|
||||||
|
|
||||||
async def test_mount_failed_repair_flow(
|
async def test_mount_failed_repair_flow(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
aioclient_mock: AiohttpClientMocker,
|
aioclient_mock: AiohttpClientMocker,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user