Skip to content

Commit

Permalink
CLI enhancements to revtrieve data from TRANSCEIVER_FIRMWARE_INFO tab…
Browse files Browse the repository at this point in the history
…le (sonic-net#3177)

* Retrieve firmware version fields from TRANSCEIVER_FIRMWARE_INFO table

Signed-off-by: Mihir Patel <patelmi@microsoft.com>

* Fixed test failures

* Removed update_firmware_info_to_state_db function

* Revert "Removed update_firmware_info_to_state_db function"

This reverts commit 68f52a2.

---------

Signed-off-by: Mihir Patel <patelmi@microsoft.com>
  • Loading branch information
mihirpat1 committed Feb 28, 2024
1 parent aefb61b commit ba98c7f
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 18 deletions.
7 changes: 5 additions & 2 deletions scripts/sfpshow
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ class SFPShow(object):
return output

# Convert sfp info in DB to cli output string
def convert_sfp_info_to_output_string(self, sfp_info_dict):
def convert_sfp_info_to_output_string(self, sfp_info_dict, sfp_firmware_info_dict):
indent = ' ' * 8
output = ''
is_sfp_cmis = 'cmis_rev' in sfp_info_dict
Expand Down Expand Up @@ -333,6 +333,8 @@ class SFPShow(object):
output += '{}N/A\n'.format((indent * 2))
elif key == 'application_advertisement':
output += covert_application_advertisement_to_output_string(indent, sfp_info_dict)
elif key == 'active_firmware' or key == 'inactive_firmware':
output += '{}{}: {}\n'.format(indent, data_map[key], sfp_firmware_info_dict[key] if key in sfp_firmware_info_dict else 'N/A')
else:
output += '{}{}: {}\n'.format(indent, data_map[key], sfp_info_dict[key])

Expand Down Expand Up @@ -441,12 +443,13 @@ class SFPShow(object):
output = ''

sfp_info_dict = state_db.get_all(state_db.STATE_DB, 'TRANSCEIVER_INFO|{}'.format(interface_name))
sfp_firmware_info_dict = state_db.get_all(state_db.STATE_DB, 'TRANSCEIVER_FIRMWARE_INFO|{}'.format(interface_name))
if sfp_info_dict:
if sfp_info_dict['type'] == RJ45_PORT_TYPE:
output = 'SFP EEPROM is not applicable for RJ45 port\n'
else:
output = 'SFP EEPROM detected\n'
sfp_info_output = self.convert_sfp_info_to_output_string(sfp_info_dict)
sfp_info_output = self.convert_sfp_info_to_output_string(sfp_info_dict, sfp_firmware_info_dict)
output += sfp_info_output

if dump_dom:
Expand Down
11 changes: 6 additions & 5 deletions sfputil/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,6 @@
'encoding': 'Encoding',
'connector': 'Connector',
'application_advertisement': 'Application Advertisement',
'active_firmware': 'Active Firmware Version',
'inactive_firmware': 'Inactive Firmware Version',
'hardware_rev': 'Hardware Revision',
'media_interface_code': 'Media Interface Code',
'host_electrical_interface': 'Host Electrical Interface',
Expand Down Expand Up @@ -1316,9 +1314,12 @@ def update_firmware_info_to_state_db(port_name):
state_db = SonicV2Connector(use_unix_socket_path=False, namespace=namespace)
if state_db is not None:
state_db.connect(state_db.STATE_DB)
active_firmware, inactive_firmware = platform_chassis.get_sfp(physical_port).get_transceiver_info_firmware_versions()
state_db.set(state_db.STATE_DB, 'TRANSCEIVER_INFO|{}'.format(port_name), "active_firmware", active_firmware)
state_db.set(state_db.STATE_DB, 'TRANSCEIVER_INFO|{}'.format(port_name), "inactive_firmware", inactive_firmware)
transceiver_firmware_info_dict = platform_chassis.get_sfp(physical_port).get_transceiver_info_firmware_versions()
if transceiver_firmware_info_dict is not None:
active_firmware = transceiver_firmware_info_dict.get('active_firmware', 'N/A')
inactive_firmware = transceiver_firmware_info_dict.get('inactive_firmware', 'N/A')
state_db.set(state_db.STATE_DB, 'TRANSCEIVER_FIRMWARE_INFO|{}'.format(port_name), "active_firmware", active_firmware)
state_db.set(state_db.STATE_DB, 'TRANSCEIVER_FIRMWARE_INFO|{}'.format(port_name), "inactive_firmware", inactive_firmware)

# 'firmware' subgroup
@cli.group()
Expand Down
6 changes: 4 additions & 2 deletions tests/mock_tables/asic1/state_db.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@
"media_interface_technology" : "1550 nm DFB",
"vendor_rev" : "XX",
"cmis_rev" : "4.1",
"active_firmware" : "X.X",
"inactive_firmware" : "X.X",
"supported_max_tx_power" : "4.0",
"supported_min_tx_power" : "-22.9",
"supported_max_laser_freq" : "196100",
Expand Down Expand Up @@ -70,6 +68,10 @@
"vcclowalarm": "2.9700",
"vcclowwarning": "3.1349"
},
"TRANSCEIVER_FIRMWARE_INFO|Ethernet64": {
"active_firmware": "X.X",
"inactive_firmware": "X.X"
},
"CHASSIS_INFO|chassis 1": {
"psu_num": "2"
},
Expand Down
12 changes: 8 additions & 4 deletions tests/mock_tables/state_db.json
Original file line number Diff line number Diff line change
Expand Up @@ -684,16 +684,17 @@
"media_interface_technology" : "1550 nm DFB",
"vendor_rev" : "XX",
"cmis_rev" : "4.1",
"active_firmware" : "X.X",
"inactive_firmware" : "X.X",
"supported_max_tx_power" : "4.0",
"supported_min_tx_power" : "-22.9",
"supported_max_laser_freq" : "196100",
"supported_min_laser_freq" : "191300"
},
"TRANSCEIVER_FIRMWARE_INFO|Ethernet64": {
"active_firmware": "X.X",
"inactive_firmware": "X.X"
},
"TRANSCEIVER_INFO|Ethernet72": {
"active_apsel_hostlane4": "N/A",
"active_firmware": "0.0",
"is_replaceable": "True",
"application_advertisement": "{1: {'host_electrical_interface_id': 'IB NDR', 'module_media_interface_id': 'Copper cable', 'media_lane_count': 4, 'host_lane_count': 4, 'host_lane_assignment_options': 17}, 2: {'host_electrical_interface_id': 'IB SDR (Arch.Spec.Vol.2)', 'module_media_interface_id': 'Copper cable', 'media_lane_count': 4, 'host_lane_count': 4, 'host_lane_assignment_options': 17}}",
"host_electrical_interface": "N/A",
Expand All @@ -710,7 +711,6 @@
"supported_min_laser_freq": "N/A",
"serial": "serial1 ",
"active_apsel_hostlane7": "N/A",
"inactive_firmware": "N/A",
"active_apsel_hostlane1": "N/A",
"type": "OSFP 8X Pluggable Transceiver",
"cable_length": "1.0",
Expand Down Expand Up @@ -796,6 +796,10 @@
"txbiaslowalarm": "N/A",
"txbiaslowwarning": "N/A"
},
"TRANSCEIVER_FIRMWARE_INFO|Ethernet72": {
"active_firmware": "0.0",
"inactive_firmware": "N/A"
},
"TRANSCEIVER_STATUS|Ethernet0": {
"status": "67",
"error": "Blocking Error|High temperature"
Expand Down
6 changes: 1 addition & 5 deletions tests/sfputil_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,6 @@ def test_format_dict_value_to_string(self):
'specification_compliance': "sm_media_interface",
'dom_capability': "{'Tx_power_support': 'no', 'Rx_power_support': 'no', 'Voltage_support': 'no', 'Temp_support': 'no'}",
'nominal_bit_rate': '0',
'active_firmware': '0.1',
'inactive_firmware': '0.0',
'hardware_rev': '0.0',
'media_interface_code': '400ZR, DWDM, amplified',
'host_electrical_interface': '400GAUI-8 C2M (Annex 120E)',
Expand Down Expand Up @@ -184,7 +182,6 @@ def test_format_dict_value_to_string(self):
" Active App Selection Host Lane 6: 1\n"
" Active App Selection Host Lane 7: 1\n"
" Active App Selection Host Lane 8: 1\n"
" Active Firmware Version: 0.1\n"
" Application Advertisement: 400G CR8 - Host Assign (0x1) - Copper cable - Media Assign (0x2)\n"
" 200GBASE-CR4 (Clause 136) - Host Assign (Unknown) - Unknown - Media Assign (Unknown)\n"
" CMIS Revision: 5.0\n"
Expand All @@ -197,7 +194,6 @@ def test_format_dict_value_to_string(self):
" Host Lane Assignment Options: 1\n"
" Host Lane Count: 8\n"
" Identifier: QSFP-DD Double Density 8X Pluggable Transceiver\n"
" Inactive Firmware Version: 0.0\n"
" Length Cable Assembly(m): 0\n"
" Media Interface Code: 400ZR, DWDM, amplified\n"
" Media Interface Technology: C-band tunable laser\n"
Expand Down Expand Up @@ -1113,7 +1109,7 @@ def test_firmware_commit_cli(self):
def test_update_firmware_info_to_state_db(self, mock_chassis):
mock_sfp = MagicMock()
mock_chassis.get_sfp = MagicMock(return_value=mock_sfp)
mock_sfp.get_transceiver_info_firmware_versions.return_value = ['a.b.c', 'd.e.f']
mock_sfp.get_transceiver_info_firmware_versions.return_value = {'active_firmware' : 'a.b.c', 'inactive_firmware' : 'd.e.f'}

sfputil.update_firmware_info_to_state_db("Ethernet0")

Expand Down

0 comments on commit ba98c7f

Please sign in to comment.