Skip to content

[chassis_base] Import device_info and fix chassis_base_test imports (fixes 202608 build) - #130

Merged
Ying Xie (yxieca) merged 1 commit into
Azure:202608from
yxieca:yxieca/202608-chassis-base-device-info-import
Aug 24, 2026
Merged

Ying Xie (yxieca) merged 1 commit into
Azure:202608from
yxieca:yxieca/202608-chassis-base-device-info-import

Conversation

@yxieca

Copy link
Copy Markdown

Description

202608 currently fails to build. PR #128 backported upstream sonic-net/sonic-platform-common#731 (Provide BMC defaults for system status LED methods in ChassisBase) into this branch. The cherry-pick applied without conflict, but it landed code that depends on imports 202608 does not have:

File Symbol used Imported? Result
sonic_platform_base/chassis_base.py device_info (3 call sites) NameError
tests/chassis_base_test.py mock module import fails
tests/chassis_base_test.py chassis_base module import fails

Because the decorators are evaluated at class-body time, pytest cannot even collect tests/chassis_base_test.py.

Why the import is missing

Upstream gets device_info in chassis_base.py from sonic-net/sonic-platform-common#700 ([CPO] Extend ChassisBase to support CPO ports), which added it in order to call device_info.get_cpo_data(). It was later hardened by sonic-net/sonic-platform-common#734 (Allow device_info import to fail in chassis_base.py).

Neither was backported to 202608. PR #128's description states:

The methods use the module-level device_info import that chassis_base.py already has

That is true on master, but not on 202608. The description was carried over verbatim from the upstream PR by the automated backport, so the missing prerequisite went unnoticed.

What this PR does

Backports only the import from #734, and adds the two missing test imports.

Deliberately not included:

  • the CPO hunks of #700/#734 (cpo_data/construct_cpo_devices) — 202608 has no CPO support, and this is a build fix, not a feature backport
  • the CPO-only assertions inside #734's regression test (mock_get_cpo_data, get_num_cpos)

The try/except ImportError form is kept rather than a plain import so this hunk matches upstream master byte-for-byte, meaning future 202605202608 auto-merges will not conflict here. It also matches the contract asserted by #128's own test_system_led_no_device_info, which exercises the device_info is None path.

Motivation and Context

Unblocks the 202608 sonic-buildimage build.

How Has This Been Tested?

  • python -m py_compile passes on both files
  • pyflakes reports no undefined names (previously mock and chassis_base were undefined)
  • test_device_info_import_failure covers the device_info is None path

Note: 202607, 202601 and other branches carrying #128-style backports may have the same gap; not checked here.

PR Azure#128 backported upstream sonic-net/sonic-platform-common#731 ("Provide
BMC defaults for system status LED methods in ChassisBase") into 202608.
The cherry-pick applied without conflict, but it landed code that depends
on imports 202608 does not have, breaking the build:

  * sonic_platform_base/chassis_base.py references `device_info` in
    initizalize_system_led(), set_status_led() and get_status_led(), but
    never imports it -> NameError.
  * tests/chassis_base_test.py uses `mock` and the `chassis_base`
    module in the new tests, but imports neither -> the module fails to
    import and pytest cannot collect the file.

Upstream carries that import from sonic-net/sonic-platform-common#700
("[CPO] Extend ChassisBase to support CPO ports"), later hardened by
sonic-net/sonic-platform-common#734 ("Allow device_info import to fail in
chassis_base.py"). Neither was backported to 202608, so PR Azure#128's premise
that chassis_base.py "already has" the import does not hold on this branch.

Backport only the import from #734, keeping the try/except form so the
file matches upstream master and future 202605 -> 202608 merges do not
conflict here. The CPO hunks of #700/#734 are deliberately left out: 202608
has no CPO support, and this is a build fix, not a feature backport.

The regression test from #734 is included, minus its CPO-only assertions.

(cherry picked from commit 20ce85f04bbcbb0dd0f37c15e4c2ce5fb31f9dfb, partial)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: ae309a30-f718-45f3-804d-645a8384d80d
Signed-off-by: Ying Xie <ying.xie@microsoft.com>
@yxieca
Ying Xie (yxieca) merged commit 1fe670a into Azure:202608 Aug 24, 2026
2 checks passed
@yxieca
Ying Xie (yxieca) deleted the yxieca/202608-chassis-base-device-info-import branch August 24, 2026 16:37
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