Skip to content

Collect module EEPROM data in dump #3009

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions scripts/generate_dump
Original file line number Diff line number Diff line change
Expand Up @@ -1126,7 +1126,7 @@ collect_mellanox_dfw_dumps() {
local sdk_dump_path=`cat /usr/share/sonic/device/${platform}/${hwsku}/sai.profile|grep "SAI_DUMP_STORE_PATH"|cut -d = -f2`

if [[ ! -d $sdk_dump_path ]]; then
# This would mean the SAI_DUMP_STORE_PATH is not mounted on the host and is only accessible though the container
# This would mean the SAI_DUMP_STORE_PATH is not mounted on the host and is only accessible though the container
# This is a bad design and not recommended But there is nothing which restricts against it and thus the special handling
if [[ "$( docker container inspect -f '{{.State.Running}}' syncd )" == "true" ]]; then
$RM $V -rf /tmp/dfw-sdk-dumps
Expand Down Expand Up @@ -1382,7 +1382,7 @@ collect_barefoot() {
for file in $(find /tmp/bf_logs -type f); do
save_file "${file}" log true
done
}
}

###############################################################################
# Collect Cisco-8000 specific information
Expand Down Expand Up @@ -1728,6 +1728,7 @@ main() {
save_cmd "show interface transceiver presence" "interface.xcvrs.presence" &
save_cmd "show interface transceiver eeprom --dom" "interface.xcvrs.eeprom" &
save_cmd "show ip interface -d all" "ip.interface" &
save_cmd "sfputil show eeprom-hexdump-all" "interface.xcvrs.eeprom.raw" &
wait

save_cmd "lldpctl" "lldpctl" &
Expand Down Expand Up @@ -1851,7 +1852,7 @@ main() {

save_to_tar

save_sai_failure_dump
save_sai_failure_dump

if [[ "$asic" = "mellanox" ]]; then
collect_mellanox_dfw_dumps
Expand Down
31 changes: 29 additions & 2 deletions sfputil/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -821,6 +821,33 @@ def hexdump(indent, data, mem_address):

return result


# 'eeprom-hexdump-all' subcommand
@show.command()
def eeprom_hexdump_all():
"""Display EEPROM hexdump of SFP transceiver(s) for all modules"""
lines = []

for index, sfp in enumerate(platform_chassis.get_all_sfps()):
try:
presence = sfp.get_presence()
if not presence:
lines.append(f'\nModule {index + 1} not present')
else:
lines.append(f'\nEEPROM hexdump for module {index + 1}')
eeprom_data = sfp.dump_eeprom()
if eeprom_data is None:
lines.append(' N/A\n')
else:
lines.append(eeprom_data)
except NotImplementedError:
lines.append(f'\nModule {index + 1} not supported')
except Exception as e:
lines.append(f'\nModule {index + 1} get EEPROM failed: {e}')

click.echo('\n'.join(lines))


# 'presence' subcommand
@show.command()
@click.option('-p', '--port', metavar='<port_name>', help="Display SFP presence for port <port_name> only")
Expand Down Expand Up @@ -1253,10 +1280,10 @@ def is_fw_switch_done(port_name):
status = -1 # Abnormal status.
elif (ImageARunning == 1) and (ImageACommitted == 0): # ImageA is running, but not committed.
click.echo("FW images switch successful : ImageA is running")
status = 1 # run_firmware is done.
status = 1 # run_firmware is done.
elif (ImageBRunning == 1) and (ImageBCommitted == 0): # ImageB is running, but not committed.
click.echo("FW images switch successful : ImageB is running")
status = 1 # run_firmware is done.
status = 1 # run_firmware is done.
else: # No image is running, or running and committed image is same.
click.echo("FW info error : Failed to switch into uncommitted image!")
status = -1 # Failure for Switching images.
Expand Down
33 changes: 32 additions & 1 deletion tests/sfputil_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ def test_convert_sfp_info_to_output_string(self, sfp_info_dict, expected_output)
Vcc: 3.2577Volts
ModuleThresholdValues:
'''
),
),
(
'QSFP-DD Double Density 8X Pluggable Transceiver',
{
Expand Down Expand Up @@ -780,6 +780,37 @@ def side_effect(offset, num_bytes):
assert result.exit_code == 0
assert result.output == expected_output

@patch('sfputil.main.platform_chassis')
def test_eeprom_hexdump_all(self, mock_chassis):
sfp_list = [MagicMock() for x in range(5)]
sfp_list[0].get_presence = MagicMock(return_value=False)
sfp_list[1].get_presence = MagicMock(side_effect=NotImplementedError)
sfp_list[2].get_presence = MagicMock(side_effect=RuntimeError('error'))
sfp_list[3].get_presence = MagicMock(return_value=True)
sfp_list[3].dump_eeprom = MagicMock(return_value=None)
sfp_list[4].get_presence = MagicMock(return_value=True)
sfp_list[4].dump_eeprom = MagicMock(return_value=' Hello')
mock_chassis.get_all_sfps.return_value = sfp_list
runner = CliRunner()
result = runner.invoke(sfputil.cli.commands['show'].commands['eeprom-hexdump-all'])
assert result.exit_code == 0
expected_output = """
Module 1 not present

Module 2 not supported

Module 3 get EEPROM failed: error

EEPROM hexdump for module 4
N/A


EEPROM hexdump for module 5
Hello
"""
print(result.output)
assert result.output == expected_output

@patch('sfputil.main.logical_port_name_to_physical_port_list', MagicMock(return_value=1))
@patch('sfputil.main.is_port_type_rj45', MagicMock(return_value=True))
@patch('sfputil.main.platform_sfputil', MagicMock(is_logical_port=MagicMock(return_value=1)))
Expand Down