Resolution: API call for run check manual (#2719)

This commit is contained in:
Pascal Vizeli 2021-03-15 10:33:06 +01:00 committed by GitHub
parent 059233c111
commit b1232c0d8d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 0 deletions

View File

@ -231,6 +231,7 @@ class RestAPI(CoreSysAttributes):
web.post(
"/resolution/check/{check}/options", api_resolution.options_check
),
web.post("/resolution/check/{check}/run", api_resolution.run_check),
web.post(
"/resolution/suggestion/{suggestion}",
api_resolution.apply_suggestion,

View File

@ -93,3 +93,13 @@ class APIResoulution(CoreSysAttributes):
check.enabled = body[ATTR_ENABLED]
self.sys_resolution.save_data()
@api_process
async def run_check(self, request: web.Request) -> None:
"""Execute a backend check."""
try:
check = self.sys_resolution.check.get(request.match_info.get("check"))
except ResolutionNotFound:
raise APIError("The supplied check slug is not available") from None
await check()

View File

@ -8,6 +8,7 @@ from supervisor.const import (
ATTR_SUGGESTIONS,
ATTR_UNHEALTHY,
ATTR_UNSUPPORTED,
CoreState,
)
from supervisor.coresys import CoreSys
from supervisor.exceptions import ResolutionError
@ -117,3 +118,16 @@ async def test_api_resolution_check_options(coresys: CoreSys, api_client):
f"/resolution/check/{free_space.slug}/options", json={"enabled": True}
)
assert free_space.enabled
@pytest.mark.asyncio
async def test_api_resolution_check_run(coresys: CoreSys, api_client):
"""Test client API with run check."""
coresys.core.state = CoreState.RUNNING
free_space = coresys.resolution.check.get("free_space")
free_space.run_check = AsyncMock()
await api_client.post(f"/resolution/check/{free_space.slug}/run")
assert free_space.run_check.called