Skip to content

[test gap] Add two test cases to cover lldp neighbors or interfaces incomplete scenarios#22420

Merged
StormLiangMS merged 11 commits intosonic-net:masterfrom
ZhaohuiS:Zhaohui/lldp_interface_test_gap
Mar 23, 2026
Merged

[test gap] Add two test cases to cover lldp neighbors or interfaces incomplete scenarios#22420
StormLiangMS merged 11 commits intosonic-net:masterfrom
ZhaohuiS:Zhaohui/lldp_interface_test_gap

Conversation

@ZhaohuiS
Copy link
Contributor

@ZhaohuiS ZhaohuiS commented Feb 14, 2026

Description of PR

Summary:
Fixes # (issue)
Address #22376

Type of change

  • Bug fix
  • Testbed and Framework(new/improvement)
  • New Test case
    • Skipped for non-supported platforms
  • Test case improvement

Back port request

  • 202205
  • 202305
  • 202311
  • 202405
  • 202411
  • 202505
  • 202511

Approach

What is the motivation for this PR?

To add 2 new test cases to check if all lldp neighbors exist and if all interfaces exists in lldpcli show interfaces.
We don't have a test case to cover the issue we found in PR: sonic-net/sonic-buildimage#25436

#22562 cover some scenarios, but not all of them. So I removed the test case in #22562 and add 2 test cases with more checks in this PR.

How did you do it?

1. test_lldp_interfaces

Purpose: Verify LLDP functionality across all interfaces without config reload

Key Features:

  • Validates LLDP table completeness
  • Verifies lldpcli interface discovery
  • Checks lldpctl_facts consistency
  • Validates chassis ID and capabilities
  • Active syslog monitoring via loganalyzer

Test Steps:

  1. Recording Phase: Capture all interfaces from show interface status
  2. LLDP Table Verification: Compare LLDP table with interface status (admin up, no PortChannels)
  3. lldpcli Verification: Compare lldpcli output with interface status (all interfaces, no PortChannels)
  4. lldpctl_facts Verification: Compare lldpctl_facts with interface status (admin up, no PortChannels)
  5. Consistency Check: Verify all lldpctl_facts interfaces exist in lldpcli
  6. Chassis Verification: Validate chassis MAC address and capabilities (Bridge: on, Router: on, Wlan: off, Station: off)

2. test_lldp_interface_config_reload

Purpose: Verify LLDP functionality persists correctly after config reload

Key Features:

Test Steps:

  1. Pre-Reload Recording: Capture all interfaces before config reload
  2. Config Reload: Perform safe config reload with interface checks
  3. Stabilization Wait: Wait for critical services and LLDP convergence
  4. LLDP Table Verification: Compare LLDP table with pre-reload interfaces (admin up, no PortChannels)
  5. lldpcli Verification: Compare lldpcli output with pre-reload interfaces (all interfaces, no PortChannels)
  6. lldpctl_facts Verification: Compare lldpctl_facts with pre-reload interfaces (admin up, no PortChannels)
  7. Consistency Check: Verify all lldpctl_facts interfaces exist in lldpcli
  8. Chassis Verification: Validate chassis MAC and capabilities remain correct

How did you verify/test it?

run it on testbed.

Any platform specific information?

Supported testbed topology if it's a new test case?

Documentation

@mssonicbld
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

ZhaohuiS added 2 commits March 3, 2026 12:12
…ncompete scenarios

Signed-off-by: Zhaohui Sun <zhaohuisun@microsoft.com>
Signed-off-by: Zhaohui Sun <zhaohuisun@microsoft.com>
@ZhaohuiS ZhaohuiS force-pushed the Zhaohui/lldp_interface_test_gap branch from 082f763 to b8102e8 Compare March 3, 2026 12:19
@mssonicbld
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the LLDP test suite in sonic-mgmt to close a test gap for scenarios where LLDP interface/neighbor discovery is incomplete (notably after config reload), aligning coverage with the failure mode described in issue #22376.

Changes:

  • Replaces the prior test_lldp_after_config_reload with two new tests: one validating LLDP interface/chassis correctness without reload and one validating persistence after config reload.
  • Adds reusable helper functions to validate show lldp table, lldpcli show interfaces, lldpctl_facts, and chassis output consistency.
  • Adds syslog checking via loganalyzer match/ignore patterns for LLDP-specific errors.

@mssonicbld
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

- Replace 'if loganalyzer else None' with 'contextlib.nullcontext()' to
  avoid crash when loganalyzer is disabled (None is not a context manager)
- Use DEVICE_METADATA['localhost']['mac'] for T2 topology chassis-id
  instead of always using mgmt interface MAC, consistent with existing
  check_lldp_neighbor() logic

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Zhaohui Sun <zhaohuisun@microsoft.com>
@ZhaohuiS ZhaohuiS force-pushed the Zhaohui/lldp_interface_test_gap branch from 32643f0 to b11d285 Compare March 13, 2026 03:01
@mssonicbld
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@mssonicbld
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

On dualtor testbeds, some admin-up interfaces may not have LLDP
neighbors, causing false assertion failures. Change strict equality
check to only fail when LLDP/lldpctl table has unexpected extra
interfaces that are not admin-up or are PortChannels.

Signed-off-by: Zhaohui Sun <zhaohuisun@microsoft.com>
@ZhaohuiS ZhaohuiS force-pushed the Zhaohui/lldp_interface_test_gap branch from 87295e2 to b6397d5 Compare March 17, 2026 08:23
@mssonicbld
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

…-reload baseline

- Override match_regex for ALL DUTs (not just selected one) to only match
  LLDP-specific errors, since fixture teardown analyzes all DUTs
- Remove per-DUT ignore_regex for config reload (no longer needed with
  the override approach)
- Use pre-reload LLDP neighbor count as baseline for post-reload wait
  instead of computing expected count from interface status
- Improve error message in verify_lldp_table for clarity

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Zhaohui Sun <zhaohuisun@microsoft.com>
@mssonicbld
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

On KVM testbeds (asic_type='vs'), eth0 is a virtual management interface
with no LLDP neighbor on the other end, so it won't appear in LLDP table,
lldpcli interfaces, or lldpctl_facts. Make the eth0 assertions conditional:
- Physical testbeds: assert eth0 must be present (unchanged behavior)
- Virtual testbeds: log info message instead of failing

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Zhaohui Sun <zhaohuisun@microsoft.com>
@mssonicbld
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

SonicAsic has 'asic_index' as a property, not 'get_asic_index()' method.
This caused AttributeError on T2 multi-ASIC testbeds.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Zhaohui Sun <zhaohuisun@microsoft.com>
@mssonicbld
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

On multi-ASIC systems, 'docker exec lldp{N} lldpcli show interfaces' only
returns interfaces for ASIC N, but 'show interface status' returns all
interfaces across all ASICs. Filter intf_status_output to only include
ports belonging to the current ASIC before comparing with lldpcli output.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Zhaohui Sun <zhaohuisun@microsoft.com>
@mssonicbld
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

On multi-ASIC T2, each ASIC's lldp container reports its own ASIC-level
MAC from DEVICE_METADATA, not the global device MAC. Use asic.config_facts()
instead of duthost.config_facts() to get the correct expected chassis MAC
for multi-ASIC systems.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Zhaohui Sun <zhaohuisun@microsoft.com>
@mssonicbld
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@ZhaohuiS
Copy link
Contributor Author

@StormLiangMS @yxieca could you please help review?

Copy link
Collaborator

@StormLiangMS StormLiangMS left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall: Good quality — a few suggestions

The refactoring from a monolithic test into 4 reusable helpers (verify_lldp_table, verify_lldpcli_interfaces, verify_lldpctl_facts, verify_chassis_info) is well done. Multi-ASIC, virtual/KVM, and loganalyzer handling all look solid. KVM CI passed cleanly.

Feedback:

  1. LLDP table parsing (verify_lldp_table): Parsing show lldp table by splitting on whitespace is fragile — if a neighbor name contains spaces, parts[0] won't be the interface. Consider using duthost.show_and_parse("show lldp table") for more robust parsing, consistent with how intf_status_output is obtained.

  2. Duplicated chassis MAC logic: The chassis MAC computation block (T2 multi-ASIC vs single-ASIC vs non-T2) is duplicated in both test_lldp_interfaces and test_lldp_interfaces_config_reload. Consider extracting it into a helper like get_expected_chassis_mac(duthost, asic, tbinfo) to reduce duplication.

  3. Hardcoded capability assertions: The test asserts Wlan: off, Station: off for all platforms. Are there any SONiC deployments where these would differ? If so, consider making these configurable or conditional.

1. Use show_and_parse for LLDP table parsing instead of fragile
   whitespace splitting (verify_lldp_table)
2. Extract chassis MAC logic into get_expected_chassis_mac() helper
   to eliminate duplication between test_lldp_interfaces and
   test_lldp_interfaces_config_reload
3. Make Wlan/Station capability checks conditional - only assert
   'off' if the capability is reported (not all platforms list them)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Zhaohui Sun <zhaohuisun@microsoft.com>
@mssonicbld
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

…nd_parse

show_and_parse('show lldp table') may include separator lines ('-----')
and footer lines ('Total entries...') as parsed entries. Filter these out
by checking the localport value.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Zhaohui Sun <zhaohuisun@microsoft.com>
@mssonicbld
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@ZhaohuiS
Copy link
Contributor Author

Thanks @StormLiangMS for the thorough review! All 3 suggestions have been addressed in commit 802efe6:

  1. LLDP table parsing — Switched to show_and_parse("show lldp table") for robust parsing (also added filtering for separator/footer lines that show_and_parse may include).
  2. Chassis MAC helper — Extracted into get_expected_chassis_mac(duthost, asic, tbinfo) to eliminate duplication.
  3. Wlan/Station capabilities — Now conditional: only assert off if the capability is reported by the platform.

Verified all 5 tests pass on T1 physical testbed (testbed-bjw2-can-t1-7260-12, Arista 7260CX3).

Copy link
Collaborator

@StormLiangMS StormLiangMS left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@StormLiangMS StormLiangMS merged commit 6f38722 into sonic-net:master Mar 23, 2026
17 checks passed
vrajeshe pushed a commit to vrajeshe/sonic-mgmt that referenced this pull request Mar 23, 2026
…ncomplete scenarios (sonic-net#22420)

What is the motivation for this PR?
To add 2 new test cases to check if all lldp neighbors exist and if all interfaces exists in lldpcli show interfaces.
We don't have a test case to cover the issue we found in PR: sonic-net/sonic-buildimage#25436

sonic-net#22562 cover some scenarios, but not all of them. So I removed the test case in sonic-net#22562 and add 2 test cases with more checks in this PR.

How did you do it?
1. test_lldp_interfaces
Purpose: Verify LLDP functionality across all interfaces without config reload

Key Features:

Validates LLDP table completeness
Verifies lldpcli interface discovery
Checks lldpctl_facts consistency
Validates chassis ID and capabilities
Active syslog monitoring via loganalyzer
Test Steps:

Recording Phase: Capture all interfaces from show interface status
LLDP Table Verification: Compare LLDP table with interface status (admin up, no PortChannels)
lldpcli Verification: Compare lldpcli output with interface status (all interfaces, no PortChannels)
lldpctl_facts Verification: Compare lldpctl_facts with interface status (admin up, no PortChannels)
Consistency Check: Verify all lldpctl_facts interfaces exist in lldpcli
Chassis Verification: Validate chassis MAC address and capabilities (Bridge: on, Router: on, Wlan: off, Station: off)
2. test_lldp_interface_config_reload
Purpose: Verify LLDP functionality persists correctly after config reload

Key Features:

Tests LLDP recovery after config reload
Validates interface persistence
Ensures neighbor rediscovery
Monitors for LLDP-specific errors while ignoring expected reload errors
Addresses the core issue from GitHub [test gap] check lldp neighbors after config reload sonic-net#22376
Test Steps:

Pre-Reload Recording: Capture all interfaces before config reload
Config Reload: Perform safe config reload with interface checks
Stabilization Wait: Wait for critical services and LLDP convergence
LLDP Table Verification: Compare LLDP table with pre-reload interfaces (admin up, no PortChannels)
lldpcli Verification: Compare lldpcli output with pre-reload interfaces (all interfaces, no PortChannels)
lldpctl_facts Verification: Compare lldpctl_facts with pre-reload interfaces (admin up, no PortChannels)
Consistency Check: Verify all lldpctl_facts interfaces exist in lldpcli
Chassis Verification: Validate chassis MAC and capabilities remain correct
How did you verify/test it?
run it on testbed.

Signed-off-by: Zhaohui Sun <zhaohuisun@microsoft.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Venkata Gouri Rajesh Etla <vrajeshe@cisco.com>
ravaliyel pushed a commit to ravaliyel/sonic-mgmt that referenced this pull request Mar 27, 2026
…ncomplete scenarios (sonic-net#22420)

What is the motivation for this PR?
To add 2 new test cases to check if all lldp neighbors exist and if all interfaces exists in lldpcli show interfaces.
We don't have a test case to cover the issue we found in PR: sonic-net/sonic-buildimage#25436

sonic-net#22562 cover some scenarios, but not all of them. So I removed the test case in sonic-net#22562 and add 2 test cases with more checks in this PR.

How did you do it?
1. test_lldp_interfaces
Purpose: Verify LLDP functionality across all interfaces without config reload

Key Features:

Validates LLDP table completeness
Verifies lldpcli interface discovery
Checks lldpctl_facts consistency
Validates chassis ID and capabilities
Active syslog monitoring via loganalyzer
Test Steps:

Recording Phase: Capture all interfaces from show interface status
LLDP Table Verification: Compare LLDP table with interface status (admin up, no PortChannels)
lldpcli Verification: Compare lldpcli output with interface status (all interfaces, no PortChannels)
lldpctl_facts Verification: Compare lldpctl_facts with interface status (admin up, no PortChannels)
Consistency Check: Verify all lldpctl_facts interfaces exist in lldpcli
Chassis Verification: Validate chassis MAC address and capabilities (Bridge: on, Router: on, Wlan: off, Station: off)
2. test_lldp_interface_config_reload
Purpose: Verify LLDP functionality persists correctly after config reload

Key Features:

Tests LLDP recovery after config reload
Validates interface persistence
Ensures neighbor rediscovery
Monitors for LLDP-specific errors while ignoring expected reload errors
Addresses the core issue from GitHub [test gap] check lldp neighbors after config reload sonic-net#22376
Test Steps:

Pre-Reload Recording: Capture all interfaces before config reload
Config Reload: Perform safe config reload with interface checks
Stabilization Wait: Wait for critical services and LLDP convergence
LLDP Table Verification: Compare LLDP table with pre-reload interfaces (admin up, no PortChannels)
lldpcli Verification: Compare lldpcli output with pre-reload interfaces (all interfaces, no PortChannels)
lldpctl_facts Verification: Compare lldpctl_facts with pre-reload interfaces (admin up, no PortChannels)
Consistency Check: Verify all lldpctl_facts interfaces exist in lldpcli
Chassis Verification: Validate chassis MAC and capabilities remain correct
How did you verify/test it?
run it on testbed.

Signed-off-by: Zhaohui Sun <zhaohuisun@microsoft.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.

4 participants