Skip to content

Fix UnboundLocalError in KexecSuite._wait_for_reconnect#4312

Merged
LiliDeng merged 2 commits intomainfrom
copilot/fix-unboundlocalerror-kexec
Mar 2, 2026
Merged

Fix UnboundLocalError in KexecSuite._wait_for_reconnect#4312
LiliDeng merged 2 commits intomainfrom
copilot/fix-unboundlocalerror-kexec

Conversation

Copy link
Contributor

Copilot AI commented Mar 2, 2026

KexecSuite.verify_kexec_reboot_direct crashes with UnboundLocalError: cannot access local variable 'current_boot_time' because current_boot_time is only assigned inside the try block — when kexec drops the SSH connection (the expected path), an exception is caught and the variable is never set, causing failures on subsequent references.

Fix

Initialize current_boot_time = last_boot_time before the reconnect loop, matching the identical pattern in lisa/tools/reboot.py:

# Before
timer = create_timer()
connected: bool = False
tried_times: int = 0
while ...:
    try:
        node.close()
        current_boot_time = self._get_last_boot_time(node)  # never reached on disconnect
        ...
    except Exception:
        ...
    log.debug(f"reconnected with uptime: {current_boot_time}")  # UnboundLocalError here

# After
timer = create_timer()
connected: bool = False
tried_times: int = 0
current_boot_time = last_boot_time  # safe default before loop
while ...:
    ...

The initialization also ensures the post-loop if last_boot_time == current_boot_time check correctly identifies a failed reboot when reconnection never succeeded.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

…ng current_boot_time

Co-authored-by: LiliDeng <10083705+LiliDeng@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix UnboundLocalError for current_boot_time in KexecSuite Fix UnboundLocalError in KexecSuite._wait_for_reconnect Mar 2, 2026
@LiliDeng LiliDeng marked this pull request as ready for review March 2, 2026 07:08
@LiliDeng LiliDeng merged commit df0d71d into main Mar 2, 2026
58 checks passed
@LiliDeng LiliDeng deleted the copilot/fix-unboundlocalerror-kexec branch March 2, 2026 07:32
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.

2 participants