Apply suggestion failures fail supervisor repair (#113372)
parent
6832611550
commit
6d903300be
|
@ -263,10 +263,7 @@ async def async_update_core(
|
|||
@bind_hass
|
||||
@_api_bool
|
||||
async def async_apply_suggestion(hass: HomeAssistant, suggestion_uuid: str) -> dict:
|
||||
"""Apply a suggestion from supervisor's resolution center.
|
||||
|
||||
The caller of the function should handle HassioAPIError.
|
||||
"""
|
||||
"""Apply a suggestion from supervisor's resolution center."""
|
||||
hassio: HassIO = hass.data[DOMAIN]
|
||||
command = f"/resolution/suggestion/{suggestion_uuid}"
|
||||
return await hassio.send_command(command, timeout=None)
|
||||
|
|
|
@ -19,7 +19,7 @@ from .const import (
|
|||
PLACEHOLDER_KEY_REFERENCE,
|
||||
SupervisorIssueContext,
|
||||
)
|
||||
from .handler import HassioAPIError, async_apply_suggestion
|
||||
from .handler import async_apply_suggestion
|
||||
from .issues import Issue, Suggestion
|
||||
|
||||
SUGGESTION_CONFIRMATION_REQUIRED = {"system_execute_reboot"}
|
||||
|
@ -110,12 +110,9 @@ class SupervisorIssueRepairFlow(RepairsFlow):
|
|||
if not confirmed and suggestion.key in SUGGESTION_CONFIRMATION_REQUIRED:
|
||||
return self._async_form_for_suggestion(suggestion)
|
||||
|
||||
try:
|
||||
await async_apply_suggestion(self.hass, suggestion.uuid)
|
||||
except HassioAPIError:
|
||||
return self.async_abort(reason="apply_suggestion_fail")
|
||||
|
||||
return self.async_create_entry(data={})
|
||||
if await async_apply_suggestion(self.hass, suggestion.uuid):
|
||||
return self.async_create_entry(data={})
|
||||
return self.async_abort(reason="apply_suggestion_fail")
|
||||
|
||||
@staticmethod
|
||||
def _async_step(
|
||||
|
|
|
@ -41,6 +41,7 @@ def mock_resolution_info(
|
|||
unsupported: list[str] | None = None,
|
||||
unhealthy: list[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."""
|
||||
aioclient_mock.get(
|
||||
|
@ -77,7 +78,7 @@ def mock_resolution_info(
|
|||
for suggestion in suggestions:
|
||||
aioclient_mock.post(
|
||||
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(
|
||||
hass: HomeAssistant,
|
||||
aioclient_mock: AiohttpClientMocker,
|
||||
|
|
Loading…
Reference in New Issue