[BMC] Add is_bmc() and get_bmc_host() SonicHost extensions#23199
[BMC] Add is_bmc() and get_bmc_host() SonicHost extensions#23199yxieca merged 2 commits intosonic-net:masterfrom
Conversation
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
StormLiangMS
left a comment
There was a problem hiding this comment.
@Blueve — A few issues to address:
-
CI FAILED: Both
Pre_test Static AnalysisandPre_test Validate Test Casesare failing. Must be fixed before merge. -
is_bmc()is not cached: Each call invokesself.get_running_config_facts()which runs a remote shell command. This gets called fromget_bmc_host()and thebmc_duthostfixture. Consider usingself.facts.get('platform')or a cached property to avoid repeated remote calls. -
get_bmc_host()returns bareSonicHost:SonicHost(self.duthosts.ansible_adhoc, bmc_host_hostname)creates a host without going through theDutHostsfactory, so it won't haveduthosts/tbinfocontext and won't be wrapped asMultiAsicSonicHosteven if applicable. Consider reusing a host fromself.duthostsif available. -
DEFAULT_ASIC_SERVICESmutation risk:.remove("teamd")on the class-level list could raiseValueErrorif it was already removed (e.g., byBackEndToRRouterinit). A defensiveif "teamd" in self.DEFAULT_ASIC_SERVICESguard would be safer.
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
/azpw run |
|
Retrying failed(or canceled) jobs... |
|
/azp run |
1 similar comment
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
1 similar comment
|
Azure Pipelines successfully started running 1 pipeline(s). |
- Add is_bmc() to SonicHost: checks DEVICE_METADATA.localhost.type for 'NetworkBmc' (cached via get_running_config_facts) - Add get_bmc_host() to MultiAsicSonicHost: resolves the host (CPU) side device from the 'bmc_host' field in testbed YAML and returns a SonicHost instance for cross-device verification in BMC tests - Create tests/bmc/ package with conftest.py providing bmc_duthost and bmc_host_side fixtures for BMC-specific test modules Co-authored-by: Copilot <[email protected]> Signed-off-by: Jing Kan <[email protected]>
BMC has no ASIC or data-plane, so remove bgp, swss, syncd and teamd from DEFAULT_ASIC_SERVICES when device_type is NetworkBmc. Remaining ASIC services: database, lldp. Host-level services (pmon, snmp) are handled by MultiAsicSonicHost._DEFAULT_SERVICES. Co-authored-by: Copilot <[email protected]> Signed-off-by: Jing Kan <[email protected]>
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
…#23199) What is the motivation for this PR?\nBMC tests need to:\n1. Determine if a DUT is a BMC device (is_bmc())\n2. Access the associated host (CPU) side from BMC tests to verify cross-device behavior like power cycling, reboot cause, and service state (get_bmc_host())\n\nHow did you do it?\n1. is_bmc() on SonicHost (tests/common/devices/sonic.py): Checks DEVICE_METADATA.localhost.type == 'NetworkBmc' from the device's running config. Uses the already-cached get_running_config_facts() so no extra SSH calls are needed.\n2. get_bmc_host() on MultiAsicSonicHost (tests/common/devices/multi_asic.py): Reads the bmc_host hostname from the testbed YAML (tbinfo) and creates a SonicHost instance for the host (CPU) side. Placed as an explicit method on MultiAsicSonicHost (before __getattr__ delegation) since it needs access to duthosts.tbinfo and duthosts.ansible_adhoc.\n3. BMC test fixtures (tests/bmc/conftest.py):\n - bmc_duthost: Gets the BMC DUT host and asserts it is a BMC\n - bmc_host_side: Gets the host (CPU) side SonicHost via get_bmc_host()\n\nHow did you verify/test it?\n- Verified is_bmc() follows the same pattern as existing device type checks (e.g., switch_type == "dpu" in SonicHost __init__)\n- Verified get_bmc_host() follows cross-device access patterns (e.g., get_supervisor_for_linecard() in dut_utils.py)\n- Verified get_bmc_host() is defined before __getattr__ in MultiAsicSonicHost so it takes priority over SonicHost delegation\n\nSigned-off-by:\nJing Kan <[email protected]>
…#23199) What is the motivation for this PR?\nBMC tests need to:\n1. Determine if a DUT is a BMC device (is_bmc())\n2. Access the associated host (CPU) side from BMC tests to verify cross-device behavior like power cycling, reboot cause, and service state (get_bmc_host())\n\nHow did you do it?\n1. is_bmc() on SonicHost (tests/common/devices/sonic.py): Checks DEVICE_METADATA.localhost.type == 'NetworkBmc' from the device's running config. Uses the already-cached get_running_config_facts() so no extra SSH calls are needed.\n2. get_bmc_host() on MultiAsicSonicHost (tests/common/devices/multi_asic.py): Reads the bmc_host hostname from the testbed YAML (tbinfo) and creates a SonicHost instance for the host (CPU) side. Placed as an explicit method on MultiAsicSonicHost (before __getattr__ delegation) since it needs access to duthosts.tbinfo and duthosts.ansible_adhoc.\n3. BMC test fixtures (tests/bmc/conftest.py):\n - bmc_duthost: Gets the BMC DUT host and asserts it is a BMC\n - bmc_host_side: Gets the host (CPU) side SonicHost via get_bmc_host()\n\nHow did you verify/test it?\n- Verified is_bmc() follows the same pattern as existing device type checks (e.g., switch_type == "dpu" in SonicHost __init__)\n- Verified get_bmc_host() follows cross-device access patterns (e.g., get_supervisor_for_linecard() in dut_utils.py)\n- Verified get_bmc_host() is defined before __getattr__ in MultiAsicSonicHost so it takes priority over SonicHost delegation\n\nSigned-off-by:\nJing Kan <[email protected]> Signed-off-by: selldinesh <[email protected]>
…#23199) What is the motivation for this PR?\nBMC tests need to:\n1. Determine if a DUT is a BMC device (is_bmc())\n2. Access the associated host (CPU) side from BMC tests to verify cross-device behavior like power cycling, reboot cause, and service state (get_bmc_host())\n\nHow did you do it?\n1. is_bmc() on SonicHost (tests/common/devices/sonic.py): Checks DEVICE_METADATA.localhost.type == 'NetworkBmc' from the device's running config. Uses the already-cached get_running_config_facts() so no extra SSH calls are needed.\n2. get_bmc_host() on MultiAsicSonicHost (tests/common/devices/multi_asic.py): Reads the bmc_host hostname from the testbed YAML (tbinfo) and creates a SonicHost instance for the host (CPU) side. Placed as an explicit method on MultiAsicSonicHost (before __getattr__ delegation) since it needs access to duthosts.tbinfo and duthosts.ansible_adhoc.\n3. BMC test fixtures (tests/bmc/conftest.py):\n - bmc_duthost: Gets the BMC DUT host and asserts it is a BMC\n - bmc_host_side: Gets the host (CPU) side SonicHost via get_bmc_host()\n\nHow did you verify/test it?\n- Verified is_bmc() follows the same pattern as existing device type checks (e.g., switch_type == "dpu" in SonicHost __init__)\n- Verified get_bmc_host() follows cross-device access patterns (e.g., get_supervisor_for_linecard() in dut_utils.py)\n- Verified get_bmc_host() is defined before __getattr__ in MultiAsicSonicHost so it takes priority over SonicHost delegation\n\nSigned-off-by:\nJing Kan <[email protected]>
…#23199) What is the motivation for this PR?\nBMC tests need to:\n1. Determine if a DUT is a BMC device (is_bmc())\n2. Access the associated host (CPU) side from BMC tests to verify cross-device behavior like power cycling, reboot cause, and service state (get_bmc_host())\n\nHow did you do it?\n1. is_bmc() on SonicHost (tests/common/devices/sonic.py): Checks DEVICE_METADATA.localhost.type == 'NetworkBmc' from the device's running config. Uses the already-cached get_running_config_facts() so no extra SSH calls are needed.\n2. get_bmc_host() on MultiAsicSonicHost (tests/common/devices/multi_asic.py): Reads the bmc_host hostname from the testbed YAML (tbinfo) and creates a SonicHost instance for the host (CPU) side. Placed as an explicit method on MultiAsicSonicHost (before __getattr__ delegation) since it needs access to duthosts.tbinfo and duthosts.ansible_adhoc.\n3. BMC test fixtures (tests/bmc/conftest.py):\n - bmc_duthost: Gets the BMC DUT host and asserts it is a BMC\n - bmc_host_side: Gets the host (CPU) side SonicHost via get_bmc_host()\n\nHow did you verify/test it?\n- Verified is_bmc() follows the same pattern as existing device type checks (e.g., switch_type == "dpu" in SonicHost __init__)\n- Verified get_bmc_host() follows cross-device access patterns (e.g., get_supervisor_for_linecard() in dut_utils.py)\n- Verified get_bmc_host() is defined before __getattr__ in MultiAsicSonicHost so it takes priority over SonicHost delegation\n\nSigned-off-by:\nJing Kan <[email protected]> Signed-off-by: opcoder0 <[email protected]>
Description of PR
Summary:
Add
is_bmc()andget_bmc_host()methods to support BMC test workflows, along with BMC-specific test fixtures. This enables test authors to identify BMC devices and interact with the associated host (CPU) side within the same test.This is part of the SONiC BMC test framework as described in the BMC High-Level Test Plan.
Type of change
Back port request
Approach
What is the motivation for this PR?
BMC tests need to:
is_bmc())get_bmc_host())How did you do it?
is_bmc()onSonicHost(tests/common/devices/sonic.py): ChecksDEVICE_METADATA.localhost.type == 'NetworkBmc'from the device's running config. Uses the already-cachedget_running_config_facts()so no extra SSH calls are needed.get_bmc_host()onMultiAsicSonicHost(tests/common/devices/multi_asic.py): Reads thebmc_hosthostname from the testbed YAML (tbinfo) and creates aSonicHostinstance for the host (CPU) side. Placed as an explicit method onMultiAsicSonicHost(before__getattr__delegation) since it needs access toduthosts.tbinfoandduthosts.ansible_adhoc.BMC test fixtures (
tests/bmc/conftest.py):bmc_duthost: Gets the BMC DUT host and asserts it is a BMCbmc_host_side: Gets the host (CPU) side SonicHost viaget_bmc_host()How did you verify/test it?
is_bmc()follows the same pattern as existing device type checks (e.g.,switch_type == "dpu"in SonicHost__init__)get_bmc_host()follows cross-device access patterns (e.g.,get_supervisor_for_linecard()indut_utils.py)get_bmc_host()is defined before__getattr__in MultiAsicSonicHost so it takes priority over SonicHost delegationAny platform specific information?
Applies to platforms with a BMC running SONiC OS where
DEVICE_METADATA.localhost.typeis set toNetworkBmc.Supported testbed topology if it is a new test case?
N/A - this PR adds framework utilities only. The
bmc_duthostandbmc_host_sidefixtures are available for BMC test modules undertests/bmc/.Documentation