Controller logs: an unparseable since is a 400, not empty logs (#953)

journalctl exits 1 with nothing on stdout when it cannot parse --since
(a bare "1h" is one such value); the controller returned that empty
stdout as the logs, with a 200.  A failed journalctl is now an error:
400 when it could not parse since, 500 otherwise.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
lrnselfreliance 2026-11-08 08:01:27 -07:00 • committed by Roland
parent d25ebb9e63
commit f3f762ef1b
No known key found for this signature in database
GPG key ID: 1BA620CE6C9A4680
4 changed files with 51 additions and 3 deletions

View file

@ -342,6 +342,23 @@ class TestGetServiceLogs:
assert "1h" in call_args
def test_unparseable_since_is_an_error(self):
"""journalctl exits 1 and prints nothing to stdout for a since it cannot parse (like a bare "1h");
that is an invalid since, not an empty log."""
with mock.patch("subprocess.run") as mock_run:
mock_run.return_value = mock.Mock(returncode=1, stdout="", stderr="Failed to parse timestamp: 1h\n")
result = get_service_logs("wrolpi-api", lines=50, since="1h")
assert result["error"] == "Failed to parse timestamp: 1h"
assert result["invalid_since"] is True
def test_journalctl_failure_is_an_error(self):
"""Any other failure of journalctl is reported, not returned as empty logs."""
with mock.patch("subprocess.run") as mock_run:
mock_run.return_value = mock.Mock(returncode=1, stdout="", stderr="Failed to open journal\n")
result = get_service_logs("wrolpi-api", lines=50)
assert result["error"] == "Failed to open journal"
assert not result.get("invalid_since")
class TestDiscoverRunningWrolpiServices:
"""Tests for discover_wrolpi_services function."""