mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-11-19 14:36:22 -05:00
A failed upgrade is shown on the upgrade page instead of redirecting home (#955)
* A failed upgrade is shown on the upgrade page instead of redirecting home
A failed upgrade restarts the services it stopped, so the upgrade page saw
them come back and redirected home as if the upgrade had worked. The
Controller now reports how the last run of a script ended
(GET /api/scripts/{name}/result, from systemd's Result and exit status),
and the upgrade page reads it before redirecting. A failure turns the
banner red, gives the exit code, opens the output, and offers a link back.
Only a run the page has seen start counts, because the result of an
earlier run is still reported until the new run begins.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* An upgrade's result survives the daemon-reload it does
The upgrade reinstalls its unit and reloads systemd, which clears the run's
timestamps but keeps Result and the exit status. A failure is now known
from those alone, and the result reports whether the script is running, so
the upgrade page waits on that instead of on a timestamp that may never come.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
d88db90ce9
commit
19ff59d5e0
6 changed files with 317 additions and 11 deletions
|
|
@ -13,6 +13,7 @@ class TestDockerModeRejectsScriptsEndpoints:
|
|||
@pytest.mark.parametrize("method,endpoint", [
|
||||
("post", "/api/scripts/repair/start"),
|
||||
("get", "/api/scripts/repair/output"),
|
||||
("get", "/api/scripts/upgrade/result"),
|
||||
])
|
||||
def test_action_rejected_in_docker(self, test_client_docker_mode, method, endpoint):
|
||||
response = getattr(test_client_docker_mode, method)(endpoint)
|
||||
|
|
@ -166,3 +167,22 @@ class TestScriptsOutputEndpoint:
|
|||
|
||||
|
||||
# OpenAPI endpoint-presence tests are consolidated in test_api.py::TestOpenAPI.
|
||||
|
||||
|
||||
class TestScriptResultEndpoint:
|
||||
"""Tests for /api/scripts/{name}/result, which the upgrade page reads before calling an upgrade done."""
|
||||
|
||||
def test_reports_failed_upgrade(self, test_client):
|
||||
result = {
|
||||
"script_name": "upgrade", "running": False, "finished": True, "success": False, "result": "exit-code", "exit_status": 5,
|
||||
"finished_at": "2026-11-08T15:22:32+00:00",
|
||||
}
|
||||
with mock.patch("controller.api.scripts.get_script_result", return_value=result):
|
||||
response = test_client.get("/api/scripts/upgrade/result")
|
||||
assert response.status_code == 200
|
||||
assert response.json() == result
|
||||
|
||||
def test_unknown_script_is_404(self, test_client):
|
||||
with mock.patch("controller.api.scripts.get_script_result", return_value=None):
|
||||
response = test_client.get("/api/scripts/nonexistent/result")
|
||||
assert response.status_code == 404
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue