Skip to content

Commit f2b7621

Browse files
authored
[SfpUtil] sfp eeprom with option dom is not working on Xcvrs with flat memory (sonic-net#3385)
Signed-off-by: Mihir Patel <[email protected]>
1 parent fd3096c commit f2b7621

File tree

2 files changed

+87
-0
lines changed

2 files changed

+87
-0
lines changed

sfputil/main.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -673,6 +673,20 @@ def eeprom(port, dump_dom, namespace):
673673
output += convert_sfp_info_to_output_string(xcvr_info)
674674

675675
if dump_dom:
676+
try:
677+
api = platform_chassis.get_sfp(physical_port).get_xcvr_api()
678+
except NotImplementedError:
679+
output += "API is currently not implemented for this platform\n"
680+
click.echo(output)
681+
sys.exit(ERROR_NOT_IMPLEMENTED)
682+
if api is None:
683+
output += "API is none while getting DOM info!\n"
684+
click.echo(output)
685+
sys.exit(ERROR_NOT_IMPLEMENTED)
686+
else:
687+
if api.is_flat_memory():
688+
output += "DOM values not supported for flat memory module\n"
689+
continue
676690
try:
677691
xcvr_dom_info = platform_chassis.get_sfp(physical_port).get_transceiver_bulk_status()
678692
except NotImplementedError:

tests/sfputil_test.py

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,46 @@
2020
ERROR_NOT_IMPLEMENTED = 5
2121
ERROR_INVALID_PORT = 6
2222

23+
FLAT_MEMORY_MODULE_EEPROM_SFP_INFO_DICT = {
24+
'type': 'QSFP28 or later',
25+
'type_abbrv_name': 'QSFP28',
26+
'manufacturer': 'Mellanox',
27+
'model': 'MCP1600-C003',
28+
'vendor_rev': 'A2',
29+
'serial': 'MT1636VS10561',
30+
'vendor_oui': '00-02-c9',
31+
'vendor_date': '2016-07-18',
32+
'connector': 'No separable connector',
33+
'encoding': '64B66B',
34+
'ext_identifier': 'Power Class 1(1.5W max)',
35+
'ext_rateselect_compliance': 'QSFP+ Rate Select Version 1',
36+
'cable_type': 'Length Cable Assembly(m)',
37+
'cable_length': '3',
38+
'application_advertisement': 'N/A',
39+
'specification_compliance': "{'10/40G Ethernet Compliance Code': '40GBASE-CR4'}",
40+
'dom_capability': "{'Tx_power_support': 'no', 'Rx_power_support': 'no',\
41+
'Voltage_support': 'no', 'Temp_support': 'no'}",
42+
'nominal_bit_rate': '255'
43+
}
44+
FLAT_MEMORY_MODULE_EEPROM = """Ethernet16: SFP EEPROM detected
45+
Application Advertisement: N/A
46+
Connector: No separable connector
47+
Encoding: 64B66B
48+
Extended Identifier: Power Class 1(1.5W max)
49+
Extended RateSelect Compliance: QSFP+ Rate Select Version 1
50+
Identifier: QSFP28 or later
51+
Length Cable Assembly(m): 3
52+
Nominal Bit Rate(100Mbs): 255
53+
Specification compliance:
54+
10/40G Ethernet Compliance Code: 40GBASE-CR4
55+
Vendor Date Code(YYYY-MM-DD Lot): 2016-07-18
56+
Vendor Name: Mellanox
57+
Vendor OUI: 00-02-c9
58+
Vendor PN: MCP1600-C003
59+
Vendor Rev: A2
60+
Vendor SN: MT1636VS10561
61+
"""
62+
2363
class TestSfputil(object):
2464
def test_format_dict_value_to_string(self):
2565
sorted_key_table = [
@@ -585,6 +625,39 @@ def test_show_eeprom_RJ45(self, mock_chassis):
585625
expected_output = "Ethernet16: SFP EEPROM is not applicable for RJ45 port\n\n\n"
586626
assert result.output == expected_output
587627

628+
@patch('sfputil.main.logical_port_to_physical_port_index', MagicMock(return_value=1))
629+
@patch('sfputil.main.logical_port_name_to_physical_port_list', MagicMock(return_value=[1]))
630+
@patch('sfputil.main.platform_sfputil', MagicMock(is_logical_port=MagicMock(return_value=1)))
631+
@patch('sfputil.main.is_port_type_rj45', MagicMock(return_value=False))
632+
@pytest.mark.parametrize("exception, xcvr_api_none, expected_output", [
633+
(None, False, '''DOM values not supported for flat memory module\n\n'''),
634+
(NotImplementedError, False, '''API is currently not implemented for this platform\n\n'''),
635+
(None, True, '''API is none while getting DOM info!\n\n''')
636+
])
637+
@patch('sfputil.main.platform_chassis')
638+
def test_show_eeprom_dom_conditions(self, mock_chassis, exception, xcvr_api_none, expected_output):
639+
mock_sfp = MagicMock()
640+
mock_sfp.get_presence.return_value = True
641+
mock_sfp.get_transceiver_info.return_value = FLAT_MEMORY_MODULE_EEPROM_SFP_INFO_DICT
642+
mock_chassis.get_sfp.return_value = mock_sfp
643+
644+
if exception:
645+
mock_chassis.get_sfp().get_xcvr_api.side_effect = exception
646+
elif xcvr_api_none:
647+
mock_chassis.get_sfp().get_xcvr_api.return_value = None
648+
else:
649+
mock_api = MagicMock()
650+
mock_chassis.get_sfp().get_xcvr_api.return_value = mock_api
651+
652+
runner = CliRunner()
653+
result = runner.invoke(sfputil.cli.commands['show'].commands['eeprom'], ["-p", "Ethernet16", "-d"])
654+
655+
if exception or xcvr_api_none:
656+
assert result.exit_code == ERROR_NOT_IMPLEMENTED
657+
else:
658+
assert result.exit_code == 0
659+
assert result.output == FLAT_MEMORY_MODULE_EEPROM + expected_output
660+
588661
@patch('sfputil.main.platform_chassis')
589662
@patch('sfputil.main.platform_sfputil', MagicMock(is_logical_port=MagicMock(return_value=0)))
590663
def test_show_eeprom_hexdump_invalid_port(self, mock_chassis):

0 commit comments

Comments
 (0)