Skip to content

Commit

Permalink
Avocado Jobs Keys
Browse files Browse the repository at this point in the history
Fix: Handle missing job data in 'avocado jobs list' command
- Updated 'handle_list_command' to use `job.get()` for safely accessing job data.
- If a key is missing, it now defaults to 'N/A' instead of causing a crash.

Reference:      #6067
Signed-off-by: Harvey Lynden <[email protected]>
  • Loading branch information
harvey0100 committed Dec 3, 2024
1 parent 91752d4 commit f0d92c0
Showing 1 changed file with 31 additions and 13 deletions.
44 changes: 31 additions & 13 deletions avocado/plugins/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,33 @@ def _print_job_tests(tests):
date_fmt = "%Y/%m/%d %H:%M:%S"
for test in tests:
status = test.get("status")
if status is None:
raise ValueError("Test status is missing - corrupted test data")

Check warning on line 59 in avocado/plugins/jobs.py

View check run for this annotation

Codecov / codecov/patch

avocado/plugins/jobs.py#L58-L59

Added lines #L58 - L59 were not covered by tests

decorator = output.TEST_STATUS_DECORATOR_MAPPING.get(status)
# Retrieve "end" for backward compatibility
end = datetime.fromtimestamp(test.get("actual_end", test.get("end")))
if decorator is None:
raise ValueError(

Check warning on line 63 in avocado/plugins/jobs.py

View check run for this annotation

Codecov / codecov/patch

avocado/plugins/jobs.py#L62-L63

Added lines #L62 - L63 were not covered by tests
f"Unknown test status '{status}' - corrupted test data"
)

end_timestamp = test.get("actual_end", test.get("end"))
if end_timestamp is not None:
end = datetime.fromtimestamp(end_timestamp).strftime(date_fmt)

Check warning on line 69 in avocado/plugins/jobs.py

View check run for this annotation

Codecov / codecov/patch

avocado/plugins/jobs.py#L67-L69

Added lines #L67 - L69 were not covered by tests
else:
end = "<unknown>"

Check warning on line 71 in avocado/plugins/jobs.py

View check run for this annotation

Codecov / codecov/patch

avocado/plugins/jobs.py#L71

Added line #L71 was not covered by tests

time_taken = test.get("time")
if time_taken is not None:
time_str = f"{float(time_taken):5f}"

Check warning on line 75 in avocado/plugins/jobs.py

View check run for this annotation

Codecov / codecov/patch

avocado/plugins/jobs.py#L73-L75

Added lines #L73 - L75 were not covered by tests
else:
time_str = "<unknown>"

Check warning on line 77 in avocado/plugins/jobs.py

View check run for this annotation

Codecov / codecov/patch

avocado/plugins/jobs.py#L77

Added line #L77 was not covered by tests

test_matrix.append(
(
test.get("id"),
end.strftime(date_fmt),
f"{float(test.get('time')):5f}",
decorator(status, ""),
test.get("id", "<unknown>"),
end,
time_str,
decorator(status, "") if decorator else "<unknown>",
)
)
header = (
Expand Down Expand Up @@ -118,13 +136,13 @@ def handle_list_command(jobs_results):
job = json.load(fp)
LOG_UI.info(
"%-40s %-26s %3s (%s/%s/%s/%s)",
job["job_id"],
job["start"],
job["total"],
job["pass"],
job["skip"],
job["errors"],
job["failures"],
job.get("job_id", "N/A"),
job.get("start", "N/A"),
job.get("total", "N/A"),
job.get("pass", "N/A"),
job.get("skip", "N/A"),
job.get("errors", "N/A"),
job.get("failures", "N/A"),
)

return exit_codes.AVOCADO_ALL_OK
Expand Down

0 comments on commit f0d92c0

Please sign in to comment.