Skip to content

fix(analyze): return integer exit code from analyze_boot#6863

Open
nanookclaw wants to merge 1 commit intocanonical:mainfrom
nanookclaw:fix/analyze-boot-exit-code
Open

fix(analyze): return integer exit code from analyze_boot#6863
nanookclaw wants to merge 1 commit intocanonical:mainfrom
nanookclaw:fix/analyze-boot-exit-code

Conversation

@nanookclaw
Copy link
Copy Markdown

Problem

cloud-init analyze boot always exits with return code 1, even on successful analysis.

The user reports return_code=1 with stderr=successful, which is the symptom.

Root Cause

analyze_boot returns a string status code ("successful", "failure", or "container"). This return value flows through sub_mainmainsys.exit(). In Python, sys.exit(string) prints the string to stderr and exits with code 1 — even when the string is "successful".

Fix

Return an integer exit code instead of the string status code:

  • 0 for SUCCESS_CODE and CONTAINER_CODE (analysis succeeded)
  • 1 for FAIL_CODE (analysis failed)

This is consistent with the other analyze subcommands (analyze_blame, analyze_show, analyze_dump) which all return None, which sys.exit() correctly treats as exit code 0.

Testing

Updated tests/unittests/analyze/test_boot.py:

  • test_container_no_ci_log_line: asserts 1 == finish_code (was FAIL_CODE)
  • test_container_ci_log_line: asserts 0 == finish_code (was CONTAINER_CODE)

Fixes #4245

analyze_boot returned a string status_code ("successful", "failure",
"container") which sys.exit() interpreted as exit code 1, printing the
string to stderr. This caused -- Most Recent Boot Record --
    Kernel Started at: 2026-04-16 04:48:35.716519+00:00
    Kernel ended boot at: 2026-04-16 04:48:38.956376+00:00
    Kernel time to boot (seconds): 3.2398569583892822
    Cloud-init activated by systemd at: 2026-04-16 04:48:35.716519+00:00
    Time between Kernel end boot and Cloud-init activation (seconds): -3.2398569583892822
    Cloud-init start: 2024-11-20 00:52:10.535000+00:00 to always exit
with return code 1, even on successful analysis.

Return 0 for success/container and 1 for failure instead.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Wrong return_code in analyze boot

1 participant