fix: propagate handler failures to CLI exit codes - #585
Open
sadsfae wants to merge 1 commit into
Open
Conversation
execute_badfish() discarded the False return value from ~20 handler calls, so the CLI exited 0 even when an operation failed. Capture each operation-failure handler's return and set result=False (the channel already used by boot_to), which drives main() to exit 1. Wrapped handlers (False == operation failed): check_schedule_job_status, reset_idrac, reset_bmc, get_power_consumed_watts, list_interfaces, list_gpu, mount_virtual_media, unmount_virtual_media, set_bios_password, remove_bios_password, get_scp_targets, export_scp, import_scp, get_nic_fqdds, get_nic_attribute(_info), set_nic_attribute. Informational-False handlers intentionally left untouched: check_virtual_media (False = nothing mounted = success), check_remote_image (False = not attached/unsupported), list_job_queue, check_boot, take_screenshot (raises), get_sriov_mode, power-state queries. Note: failures are routed through result=False rather than raising BadfishException because every wrapped handler already logs its own specific error before returning False; raising would duplicate the error line and break existing CLI-output assertions. fixes: #568
Codecov Report✅ All modified and coverable lines are covered by tests.
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #568
Summary
execute_badfish()insrc/badfish/main.pyinvoked most handlers with a bareawait badfish.<handler>(), discarding their return value. When a handler returnedFalseto signal a failed operation,resultstayedTrueand the CLI exited0(success) even though the command actually failed.This change captures each operation-failure handler's return value and, on
False, setsresult = False, which drivesmain()to return exit code1. Success (returningTrue, orNonein a few handlers) leavesresult = True-> exit0.Wrapped handlers (False == operation failed)
check_schedule_job_statusreset_idracreset_bmcget_power_consumed_wattslist_interfaceslist_gpumount_virtual_mediaunmount_virtual_mediaset_bios_passwordremove_bios_passwordget_scp_targetsexport_scpimport_scpget_nic_fqddsget_nic_attribute/get_nic_attribute_infoset_nic_attributeInformational-False handlers intentionally left untouched
A
Falsereturn does not mean a failure for these, so they must continue to exit 0:check_virtual_media—False= no virtual media mounted (not an error)check_remote_image—False= not attached / unsupported (informational)list_job_queuecheck_boottake_screenshot— already raisesBadfishExceptionon failureget_sriov_modeget_power_state)Design note
Failures are propagated via the
result = Falsechannel — the same channel the already-fixedboot_topath uses — rather than raisingBadfishException. Every wrapped handler already logs its own specific error before returningFalse; raising an exception through the dispatch would emit a duplicate error line and break existing CLI-output assertions.result = Falseproduces a single clean error message and still yields exit code1.Tests
Added
tests/test_exit_code_propagation.py(35 cases) proving:False->execute_badfishreturns("host", False)-> CLI exit 1True-> exit 0Noneon success (e.g.set_bios_password) are not misreported as failurescheck_virtual_media/check_remote_imagereturningFalseare not treated as failuresVerified:
PYTHONPATH=src python -m pytest tests/test_exit_code_propagation.py -v-> 35 passedPYTHONPATH=src python -m pytest tests/ -q-> 491 passed, 1 pre-existing unrelated failure (tests/test_progress.py::test_terminal_renders_progress_when_enabled)