Skip to content

Commit 380345f

Browse files
authored
Merge pull request sonic-net#165 from mssonicbld/sonicbld/202412-merge
```<br>* 4899593 - (HEAD -> 202412) Merge branch '202411' of https://github.com/sonic-net/sonic-utilities into 202412 (2025-04-15) [Sonic Automation] * 606a90a - (origin/202411) Fixed syslog error "ERR python3:- validateNamespace: Initialize global.." for sfpshow (sonic-net#3849) (2025-04-15) [mssonicbld]<br>```
2 parents cd1be5b + 4899593 commit 380345f

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed

scripts/sfpshow

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ from typing import Dict
1515
import click
1616
from natsort import natsorted
1717
from sonic_py_common import multi_asic
18+
from utilities_common.general import load_db_config
1819
from utilities_common.sfp_helper import covert_application_advertisement_to_output_string
1920
from utilities_common.sfp_helper import (
2021
QSFP_DATA_MAP,
@@ -738,4 +739,5 @@ def status(port, namespace):
738739

739740

740741
if __name__ == "__main__":
742+
load_db_config()
741743
cli()

tests/sfp_test.py

+65
Original file line numberDiff line numberDiff line change
@@ -1033,6 +1033,35 @@ def setup_class(cls):
10331033
os.environ["UTILITIES_UNIT_TESTING"] = "2"
10341034
os.environ["UTILITIES_UNIT_TESTING_TOPOLOGY"] = "multi_asic"
10351035

1036+
def test_sfp_presence_without_ns(self):
1037+
runner = CliRunner()
1038+
result = runner.invoke(
1039+
show.cli.commands["interfaces"].commands["transceiver"].commands["presence"], ['Ethernet0'])
1040+
expected = """Port Presence
1041+
--------- ----------
1042+
Ethernet0 Present
1043+
"""
1044+
assert result.exit_code == 0
1045+
assert result.output == expected
1046+
1047+
result = runner.invoke(
1048+
show.cli.commands["interfaces"].commands["transceiver"].commands["presence"], ['Ethernet4'])
1049+
expected = """Port Presence
1050+
--------- -----------
1051+
Ethernet4 Not present
1052+
"""
1053+
assert result.exit_code == 0
1054+
assert result.output == expected
1055+
1056+
result = runner.invoke(
1057+
show.cli.commands["interfaces"].commands["transceiver"].commands["presence"], ['Ethernet200'])
1058+
expected = """Port Presence
1059+
----------- -----------
1060+
Ethernet200 Not present
1061+
"""
1062+
assert result.exit_code == 1
1063+
assert result.output == expected
1064+
10361065
@patch.object(show_module.interfaces.click.Choice, 'convert', MagicMock(return_value='asic0'))
10371066
def test_sfp_presence_with_ns(self):
10381067
runner = CliRunner()
@@ -1077,6 +1106,19 @@ def test_sfp_eeprom_with_ns(self):
10771106
expected = "Ethernet200: SFP EEPROM Not detected"
10781107
assert result_lines == expected
10791108

1109+
def test_sfp_eeprom_without_ns(self):
1110+
runner = CliRunner()
1111+
result = runner.invoke(
1112+
show.cli.commands["interfaces"].commands["transceiver"].commands["eeprom"], ['Ethernet0'])
1113+
assert result.exit_code == 0
1114+
assert "\n".join([line.rstrip() for line in result.output.split('\n')]) == test_sfp_eeprom_output
1115+
1116+
result = runner.invoke(
1117+
show.cli.commands["interfaces"].commands["transceiver"].commands["eeprom"], ['Ethernet4'])
1118+
result_lines = result.output.strip('\n')
1119+
expected = "Ethernet4: SFP EEPROM Not detected"
1120+
assert result_lines == expected
1121+
10801122
@patch.object(show_module.interfaces.click.Choice, 'convert', MagicMock(return_value='asic0'))
10811123
def test_qsfp_dd_pm_with_ns(self):
10821124
runner = CliRunner()
@@ -1085,6 +1127,14 @@ def test_qsfp_dd_pm_with_ns(self):
10851127
expected = "Ethernet0: Transceiver performance monitoring not applicable"
10861128
assert result_lines == expected
10871129

1130+
def test_qsfp_dd_pm_without_ns(self):
1131+
runner = CliRunner()
1132+
result = runner.invoke(
1133+
show.cli.commands["interfaces"].commands["transceiver"].commands["pm"], ['Ethernet0'])
1134+
result_lines = result.output.strip('\n')
1135+
expected = "Ethernet0: Transceiver performance monitoring not applicable"
1136+
assert result_lines == expected
1137+
10881138
@patch.object(show_module.interfaces.click.Choice, 'convert', MagicMock(return_value='asic0'))
10891139
def test_qsfp_dd_status_with_ns(self):
10901140
runner = CliRunner()
@@ -1093,13 +1143,28 @@ def test_qsfp_dd_status_with_ns(self):
10931143
expected = "Ethernet0: Transceiver status info not applicable"
10941144
assert result_lines == expected
10951145

1146+
def test_qsfp_dd_status_without_ns(self):
1147+
runner = CliRunner()
1148+
result = runner.invoke(
1149+
show.cli.commands["interfaces"].commands["transceiver"].commands["status"], ['Ethernet0'])
1150+
result_lines = result.output.strip('\n')
1151+
expected = "Ethernet0: Transceiver status info not applicable"
1152+
assert result_lines == expected
1153+
10961154
@patch.object(show_module.interfaces.click.Choice, 'convert', MagicMock(return_value='asic1'))
10971155
def test_cmis_sfp_info_with_ns(self):
10981156
runner = CliRunner()
10991157
result = runner.invoke(show.cli.commands["interfaces"].commands["transceiver"].commands["info"], ['Ethernet64', '-n', 'asic1'])
11001158
assert result.exit_code == 0
11011159
assert "\n".join([ l.rstrip() for l in result.output.split('\n')]) == test_cmis_eeprom_output
11021160

1161+
def test_cmis_sfp_info_without_ns(self):
1162+
runner = CliRunner()
1163+
result = runner.invoke(
1164+
show.cli.commands["interfaces"].commands["transceiver"].commands["info"], ['Ethernet64'])
1165+
assert result.exit_code == 0
1166+
assert "\n".join([line.rstrip() for line in result.output.split('\n')]) == test_cmis_eeprom_output
1167+
11031168
def test_sfp_eeprom_all(self):
11041169
runner = CliRunner()
11051170
result = runner.invoke(show.cli.commands["interfaces"].commands["transceiver"].commands["eeprom"])

0 commit comments

Comments
 (0)