diff --git a/selfprivacy_api/jobs/upgrade_system.py b/selfprivacy_api/jobs/upgrade_system.py index f766f7e..940efdb 100644 --- a/selfprivacy_api/jobs/upgrade_system.py +++ b/selfprivacy_api/jobs/upgrade_system.py @@ -43,10 +43,11 @@ def check_running_status(job: Job, unit_name: str): ) return True if status == ServiceStatus.FAILED: + log_lines = get_last_log_lines(unit_name, 10) Jobs.update( job=job, status=JobStatus.ERROR, - error="System rebuild failed.", + error="System rebuild failed. Last log lines:\n" + "\n".join(log_lines), ) return True if status == ServiceStatus.ACTIVE: @@ -87,10 +88,12 @@ def rebuild_system_task(job: Job, upgrade: bool = False): interval=START_INTERVAL, ) except TimeoutError: + log_lines = get_last_log_lines(unit_name, 10) Jobs.update( job=job, status=JobStatus.ERROR, - error="System rebuild timed out.", + error="System rebuild timed out. Last log lines:\n" + + "\n".join(log_lines), ) return Jobs.update( @@ -106,10 +109,12 @@ def rebuild_system_task(job: Job, upgrade: bool = False): interval=RUN_INTERVAL, ) except TimeoutError: + log_lines = get_last_log_lines(unit_name, 10) Jobs.update( job=job, status=JobStatus.ERROR, - error="System rebuild timed out.", + error="System rebuild timed out. Last log lines:\n" + + "\n".join(log_lines), ) return diff --git a/tests/test_graphql/test_system_nixos_tasks.py b/tests/test_graphql/test_system_nixos_tasks.py index a9d2380..b50223e 100644 --- a/tests/test_graphql/test_system_nixos_tasks.py +++ b/tests/test_graphql/test_system_nixos_tasks.py @@ -182,6 +182,10 @@ def test_graphql_system_rebuild_failed( fp.register(["systemctl", "show", unit_name], stdout="ActiveState=failed") + fp.register( + ["journalctl", "-u", unit_name, "-n", "10", "-o", "cat"], stdout="Some error" + ) + response = authorized_client.post( "/graphql", json={