Skip to content

Commit ce51df2

Browse files
authored
Fixed syslog error "ERR python3:- validateNamespace: Initialize global.." for sfpshow (sonic-net#3753)
* Fixed "ERR python3:- validateNamespace: Initialize global DB config" for sfpshow Signed-off-by: Anand Mehra [email protected] * Update Signed-off-by: anamehra <[email protected]> * Update sfp_test.py * Update sfpshow --------- Signed-off-by: Anand Mehra [email protected] Signed-off-by: anamehra <[email protected]>
1 parent ef857ad commit ce51df2

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
@@ -1023,6 +1023,35 @@ def setup_class(cls):
10231023
os.environ["UTILITIES_UNIT_TESTING"] = "2"
10241024
os.environ["UTILITIES_UNIT_TESTING_TOPOLOGY"] = "multi_asic"
10251025

1026+
def test_sfp_presence_without_ns(self):
1027+
runner = CliRunner()
1028+
result = runner.invoke(
1029+
show.cli.commands["interfaces"].commands["transceiver"].commands["presence"], ['Ethernet0'])
1030+
expected = """Port Presence
1031+
--------- ----------
1032+
Ethernet0 Present
1033+
"""
1034+
assert result.exit_code == 0
1035+
assert result.output == expected
1036+
1037+
result = runner.invoke(
1038+
show.cli.commands["interfaces"].commands["transceiver"].commands["presence"], ['Ethernet4'])
1039+
expected = """Port Presence
1040+
--------- -----------
1041+
Ethernet4 Not present
1042+
"""
1043+
assert result.exit_code == 0
1044+
assert result.output == expected
1045+
1046+
result = runner.invoke(
1047+
show.cli.commands["interfaces"].commands["transceiver"].commands["presence"], ['Ethernet200'])
1048+
expected = """Port Presence
1049+
----------- -----------
1050+
Ethernet200 Not present
1051+
"""
1052+
assert result.exit_code == 1
1053+
assert result.output == expected
1054+
10261055
@patch.object(show_module.interfaces.click.Choice, 'convert', MagicMock(return_value='asic0'))
10271056
def test_sfp_presence_with_ns(self):
10281057
runner = CliRunner()
@@ -1067,6 +1096,19 @@ def test_sfp_eeprom_with_ns(self):
10671096
expected = "Ethernet200: SFP EEPROM Not detected"
10681097
assert result_lines == expected
10691098

1099+
def test_sfp_eeprom_without_ns(self):
1100+
runner = CliRunner()
1101+
result = runner.invoke(
1102+
show.cli.commands["interfaces"].commands["transceiver"].commands["eeprom"], ['Ethernet0'])
1103+
assert result.exit_code == 0
1104+
assert "\n".join([line.rstrip() for line in result.output.split('\n')]) == test_sfp_eeprom_output
1105+
1106+
result = runner.invoke(
1107+
show.cli.commands["interfaces"].commands["transceiver"].commands["eeprom"], ['Ethernet4'])
1108+
result_lines = result.output.strip('\n')
1109+
expected = "Ethernet4: SFP EEPROM Not detected"
1110+
assert result_lines == expected
1111+
10701112
@patch.object(show_module.interfaces.click.Choice, 'convert', MagicMock(return_value='asic0'))
10711113
def test_qsfp_dd_pm_with_ns(self):
10721114
runner = CliRunner()
@@ -1075,6 +1117,14 @@ def test_qsfp_dd_pm_with_ns(self):
10751117
expected = "Ethernet0: Transceiver performance monitoring not applicable"
10761118
assert result_lines == expected
10771119

1120+
def test_qsfp_dd_pm_without_ns(self):
1121+
runner = CliRunner()
1122+
result = runner.invoke(
1123+
show.cli.commands["interfaces"].commands["transceiver"].commands["pm"], ['Ethernet0'])
1124+
result_lines = result.output.strip('\n')
1125+
expected = "Ethernet0: Transceiver performance monitoring not applicable"
1126+
assert result_lines == expected
1127+
10781128
@patch.object(show_module.interfaces.click.Choice, 'convert', MagicMock(return_value='asic0'))
10791129
def test_qsfp_dd_status_with_ns(self):
10801130
runner = CliRunner()
@@ -1083,13 +1133,28 @@ def test_qsfp_dd_status_with_ns(self):
10831133
expected = "Ethernet0: Transceiver status info not applicable"
10841134
assert result_lines == expected
10851135

1136+
def test_qsfp_dd_status_without_ns(self):
1137+
runner = CliRunner()
1138+
result = runner.invoke(
1139+
show.cli.commands["interfaces"].commands["transceiver"].commands["status"], ['Ethernet0'])
1140+
result_lines = result.output.strip('\n')
1141+
expected = "Ethernet0: Transceiver status info not applicable"
1142+
assert result_lines == expected
1143+
10861144
@patch.object(show_module.interfaces.click.Choice, 'convert', MagicMock(return_value='asic1'))
10871145
def test_cmis_sfp_info_with_ns(self):
10881146
runner = CliRunner()
10891147
result = runner.invoke(show.cli.commands["interfaces"].commands["transceiver"].commands["info"], ['Ethernet64', '-n', 'asic1'])
10901148
assert result.exit_code == 0
10911149
assert "\n".join([ l.rstrip() for l in result.output.split('\n')]) == test_cmis_eeprom_output
10921150

1151+
def test_cmis_sfp_info_without_ns(self):
1152+
runner = CliRunner()
1153+
result = runner.invoke(
1154+
show.cli.commands["interfaces"].commands["transceiver"].commands["info"], ['Ethernet64'])
1155+
assert result.exit_code == 0
1156+
assert "\n".join([line.rstrip() for line in result.output.split('\n')]) == test_cmis_eeprom_output
1157+
10931158
def test_sfp_eeprom_all(self):
10941159
runner = CliRunner()
10951160
result = runner.invoke(show.cli.commands["interfaces"].commands["transceiver"].commands["eeprom"])

0 commit comments

Comments
 (0)