[Mellanox] Centralize BMC init gate in initialize_bmc()#2
Open
william8545 wants to merge 1 commit into
Open
Conversation
The is_platform_with_bmc() gate lived in initialize_components(), but get_bmc() -> _initialize_bmc() also calls initialize_bmc() directly, bypassing it. Move the gate into initialize_bmc() so every caller goes through a single check and non-BMC platforms skip importing the bmc module. No behavior change: get_bmc() still returns None on non-BMC. Signed-off-by: William Tsai <willtsai@nvidia.com>
oleksandrivantsiv
approved these changes
Jun 24, 2026
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.
Why I did it
The
is_platform_with_bmc()gate was only ininitialize_components(), butget_bmc()→_initialize_bmc()callsinitialize_bmc()directly, bypassing that gate. As a result, on non-BMC platforms theget_bmc()path still imports thebmcmodule and probes for a BMC. This is a cleanup; the externally observable behavior does not change.Work item tracking
How I did it
Moved the
is_platform_with_bmc()check intoinitialize_bmc()itself (early return that leaves_bmcasNone) and dropped the now-redundant gate ininitialize_components(). All callers —get_bmc(),get_num_components(),get_all_components()— now go through one authoritative gate, so non-BMC platforms never import thebmcmodule. The chassis unit test is updated to match.How to verify it
Run the chassis unit test:
pytest platform/mellanox/mlnx-platform-api/tests/test_chassis.py -k test_initialize_components_bmcOn a non-BMC Mellanox platform,
config bmcandshow platformstill report the BMC as unavailable; on a BMC platform the behavior is unchanged.Which release branch to backport (provide reason below if selected)
Tested branch (Please provide the tested image version)
Description for the changelog
[Mellanox] Centralize the BMC initialization gate in initialize_bmc()
Link to config_db schema for YANG module changes
N/A - no config_db or YANG model changes.
A picture of a cute animal (not mandatory but encouraged)
🦦