forked from sonic-net/sonic-buildimage
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[LLDP] Fix lldpshow script to enable display multiple MAC addresses o…
…n the same remote physical interface (sonic-net#1657) Scenario: 1- remote interface has 2 MACs on the same physical interface. 2- "show lldp table" command displays one entry for only one MAC address Root cause: "show lldp table" command uses lldpshow script to get, parse and display data from the lldp open source package (lldpctl script). lldpctl script returns a proper info about the 2 MACs but the issue is with the lldpshow script parser where it built a dictionary which its key is the local physical interface. Therefore when having 2 MACs, lldpctl will return 2 entries but the lldpshow parser will overwrite the first enrty. Fix: Change the key to be a string of "interface#MAC". This will enable having 2 entries for 2 different MAC addresses. In addition: - update display_sum()-->get_summary_output() to return a string instead of printing it directly. this to allow checking the returned value inside the new unit test. - add a new unit test for this scenario. Signed-off-by: Basim Shalata <basims@nvidia.com>
- Loading branch information
1 parent
0d53b7a
commit 54b74a2
Showing
2 changed files
with
107 additions
and
20 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import os | ||
|
||
from click.testing import CliRunner | ||
from utilities_common.general import load_module_from_source | ||
|
||
test_path = os.path.dirname(os.path.abspath(__file__)) | ||
modules_path = os.path.dirname(test_path) | ||
scripts_path = os.path.join(modules_path, "scripts") | ||
|
||
# Load the file under test | ||
lldpshow_path = os.path.join(scripts_path, 'lldpshow') | ||
lldpshow = load_module_from_source('lldpshow', lldpshow_path) | ||
|
||
# Expected output for 2 remote MACs on same physical interface | ||
expected_2MACs_Ethernet0_output = \ | ||
('Capability codes: (R) Router, (B) Bridge, (O) Other\n' | ||
'LocalPort RemoteDevice RemotePortID Capability ' | ||
'RemotePortDescr\n' | ||
'----------- -------------- ----------------- ------------ ' | ||
'-----------------\n' | ||
'Ethernet0 dummy 00:00:00:00:00:01 BR First MAC\n' | ||
'Ethernet0 dummy 00:00:00:00:00:02 R Second MAC\n' | ||
'--------------------------------------------------\n' | ||
'Total entries displayed: 2') | ||
|
||
expected_lldpctl_xml_output = \ | ||
['<?xml version="1.0" encoding="UTF-8"?>\n\ | ||
<lldp label="LLDP neighbors">\n\ | ||
<interface label="Interface" name="Ethernet0" via="LLDP" rid="2" age="7 days, 22:11:33">\n\ | ||
<chassis label="Chassis">\n\ | ||
<id label="ChassisID" type="mac">00:00:00:00:00:01</id>\n\ | ||
<name label="SysName">dummy</name>\n\ | ||
<descr label="SysDescr">NA</descr>\n\ | ||
<mgmt-ip label="MgmtIP">00:00:00:00:00:00</mgmt-ip>\n\ | ||
<capability label="Capability" type="Bridge" enabled="on"/>\n\ | ||
<capability label="Capability" type="Router" enabled="on"/>\n\ | ||
<capability label="Capability" type="Wlan" enabled="off"/>\n\ | ||
<capability label="Capability" type="Station" enabled="off"/>\n\ | ||
</chassis>\n\ | ||
<port label="Port">\n\ | ||
<id label="PortID" type="mac">00:00:00:00:00:01</id>\n\ | ||
<descr label="PortDescr">First MAC</descr>\n\ | ||
<ttl label="TTL">120</ttl>\n\ | ||
</port>\n\ | ||
</interface>\n\ | ||
<interface label="Interface" name="Ethernet0" via="LLDP" rid="4" age="7 days, 22:11:34">\n\ | ||
<chassis label="Chassis">\n\ | ||
<id label="ChassisID" type="mac">00:00:00:00:00:02</id>\n\ | ||
<name label="SysName">dummy</name>\n\ | ||
<descr label="SysDescr">NA</descr>\n\ | ||
<mgmt-ip label="MgmtIP">00:00:00:00:00:00</mgmt-ip>\n\ | ||
<capability label="Capability" type="Router" enabled="on"/>\n\ | ||
</chassis>\n\ | ||
<port label="Port">\n\ | ||
<id label="PortID" type="mac">00:00:00:00:00:02</id>\n\ | ||
<descr label="PortDescr">Second MAC</descr>\n\ | ||
<ttl label="TTL">120</ttl>\n\ | ||
</port>\n\ | ||
</interface>\n\ | ||
</lldp>\n'] | ||
|
||
class TestLldp(object): | ||
@classmethod | ||
def setup_class(cls): | ||
print("SETUP") | ||
|
||
def test_show_lldp_2_macs_same_phy_interface(self): | ||
runner = CliRunner() | ||
# Create lldpshow instance | ||
lldp = lldpshow.Lldpshow() | ||
# Mock lldpraw to check new functionality in parse_info() | ||
lldp.lldpraw = expected_lldpctl_xml_output | ||
lldp.parse_info(lldp_detail_info=False) | ||
output_summary = lldp.get_summary_output(lldp_detail_info=False) | ||
assert output_summary == expected_2MACs_Ethernet0_output | ||
|
||
@classmethod | ||
def teardown_class(cls): | ||
print("TEARDOWN") |