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 2, 2024
1 parent 9bc4760 commit 0b017e6
Showing 1 changed file with 35 additions and 13 deletions.
48 changes: 35 additions & 13 deletions avocado/plugins/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,25 @@ def _print_job_tests(tests):
for test in tests:
status = test.get("status")
decorator = output.TEST_STATUS_DECORATOR_MAPPING.get(status)
# Retrieve "end" for backward compatibility
end = datetime.fromtimestamp(test.get("actual_end", test.get("end")))

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

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

test_matrix.append(
(
test.get("id"),
end.strftime(date_fmt),
f"{float(test.get('time')):5f}",
decorator(status, ""),
test.get("id", "N/A"),
end,
time_str,
decorator(status, "") if decorator else "N/A",
)
)
header = (
Expand Down Expand Up @@ -116,19 +127,30 @@ def handle_list_command(jobs_results):
for filename in jobs_results.values():
with open(filename, "r", encoding="utf-8") as fp:
job = json.load(fp)

job_id = job.get("job_id", "N/A")
start_time = job.get("start", "N/A")
total_tests = job.get("total", "N/A")
passed = job.get("pass", "N/A")
skipped = job.get("skip", "N/A")
errors = job.get("errors", "N/A")
failures = job.get("failures", "N/A")

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_id,
start_time,
total_tests,
passed,
skipped,
errors,
failures,
)

return exit_codes.AVOCADO_ALL_OK



def handle_show_command(self, config):
"""Called when 'avocado jobs show' command is executed."""

Expand Down

0 comments on commit 0b017e6

Please sign in to comment.