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 20c1469
Showing 1 changed file with 33 additions and 13 deletions.
46 changes: 33 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)

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

View check run for this annotation

Codecov / codecov/patch

avocado/plugins/jobs.py#L60-L62

Added lines #L60 - L62 were not covered by tests
else:
end = "N/A"

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

View check run for this annotation

Codecov / codecov/patch

avocado/plugins/jobs.py#L64

Added line #L64 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 68 in avocado/plugins/jobs.py

View check run for this annotation

Codecov / codecov/patch

avocado/plugins/jobs.py#L66-L68

Added lines #L66 - L68 were not covered by tests
else:
time_str = "N/A"

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

View check run for this annotation

Codecov / codecov/patch

avocado/plugins/jobs.py#L70

Added line #L70 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", "N/A"),
end,
time_str,
decorator(status, "") if decorator else "N/A",
)
)
header = (
Expand Down Expand Up @@ -116,15 +127,24 @@ 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")

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

View check run for this annotation

Codecov / codecov/patch

avocado/plugins/jobs.py#L131-L137

Added lines #L131 - L137 were not covered by tests

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
Expand Down

0 comments on commit 20c1469

Please sign in to comment.