From b1232c0d8d287fc75330bf04b288c86c0a76bb95 Mon Sep 17 00:00:00 2001 From: Pascal Vizeli Date: Mon, 15 Mar 2021 10:33:06 +0100 Subject: [PATCH] Resolution: API call for run check manual (#2719) --- supervisor/api/__init__.py | 1 + supervisor/api/resolution.py | 10 ++++++++++ tests/api/test_resolution.py | 14 ++++++++++++++ 3 files changed, 25 insertions(+) diff --git a/supervisor/api/__init__.py b/supervisor/api/__init__.py index fc0fa4817..1a4686839 100644 --- a/supervisor/api/__init__.py +++ b/supervisor/api/__init__.py @@ -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, diff --git a/supervisor/api/resolution.py b/supervisor/api/resolution.py index 988896d6f..e9033d536 100644 --- a/supervisor/api/resolution.py +++ b/supervisor/api/resolution.py @@ -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() diff --git a/tests/api/test_resolution.py b/tests/api/test_resolution.py index b155d8912..66dcfaea6 100644 --- a/tests/api/test_resolution.py +++ b/tests/api/test_resolution.py @@ -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