diff --git a/scripts/intfutil b/scripts/intfutil index 9600b6a8ff..0a2ff09d7c 100755 --- a/scripts/intfutil +++ b/scripts/intfutil @@ -147,13 +147,27 @@ def appl_db_port_status_get(appl_db, intf_name, status_type): status = ','.join(new_speed_list) return status -def state_db_port_optics_get(state_db, intf_name, type): +def state_db_port_optics_get(state_db, config_db, intf_name, type): """ Get optic type info for port """ full_table_id = PORT_TRANSCEIVER_TABLE_PREFIX + intf_name optics_type = state_db.get(state_db.STATE_DB, full_table_id, type) if optics_type is None: + try: + import sonic_platform + ports_dict = config_db.get_table('PORT') + index = int(ports_dict[intf_name]['index']) + platform_chassis = sonic_platform.platform.Platform().get_chassis() + parent_port = platform_chassis.get_sfp(index).get_name() + except: + parent_port = intf_name + + if parent_port != intf_name: + parent_full_table_id = PORT_TRANSCEIVER_TABLE_PREFIX + parent_port + optics_type = state_db.get(state_db.STATE_DB, parent_full_table_id, type) + if optics_type is not None: + return optics_type return "N/A" return optics_type @@ -411,7 +425,7 @@ class IntfStatus(object): config_db_vlan_port_keys_get(self.combined_int_to_vlan_po_dict, self.front_panel_ports_list, key), appl_db_port_status_get(self.db, key, PORT_OPER_STATUS), appl_db_port_status_get(self.db, key, PORT_ADMIN_STATUS), - state_db_port_optics_get(self.db, key, PORT_OPTICS_TYPE), + state_db_port_optics_get(self.db, self.config_db, key, PORT_OPTICS_TYPE), appl_db_port_status_get(self.db, key, PORT_PFC_ASYM_STATUS))) for po, value in self.portchannel_speed_dict.items(): diff --git a/scripts/sfpshow b/scripts/sfpshow index d05268f74d..d1e588658a 100755 --- a/scripts/sfpshow +++ b/scripts/sfpshow @@ -387,31 +387,55 @@ class SFPShow(object): return output_dom # Convert sfp info and dom sensor info in DB to cli output string - def convert_interface_sfp_info_to_cli_output_string(self, state_db, interface_name, dump_dom): + def convert_interface_sfp_info_to_cli_output_string(self, state_db, interface_name, parent_name, dump_dom): output = '' - sfp_info_dict = state_db.get_all(state_db.STATE_DB, 'TRANSCEIVER_INFO|{}'.format(interface_name)) + sfp_info_dict = state_db.get_all(state_db.STATE_DB, 'TRANSCEIVER_INFO|{}'.format(parent_name)) output = interface_name + ': ' + 'SFP EEPROM detected' + '\n' sfp_info_output = self.convert_sfp_info_to_output_string(sfp_info_dict) output += sfp_info_output if dump_dom: sfp_type = sfp_info_dict['type'] - dom_info_dict = state_db.get_all(state_db.STATE_DB, 'TRANSCEIVER_DOM_SENSOR|{}'.format(interface_name)) + dom_info_dict = state_db.get_all(state_db.STATE_DB, 'TRANSCEIVER_DOM_SENSOR|{}'.format(parent_name)) dom_output = self.convert_dom_to_output_string(sfp_type, dom_info_dict) output += dom_output return output + def get_presence_from_parent_port(self, intf_name): + try: + import sonic_platform + intf_port_table = self.db.get_all(self.db.APPL_DB, 'PORT_TABLE:{}'.format(intf_name)) + index = int(intf_port_table['index']) + platform_chassis = sonic_platform.platform.Platform().get_chassis() + parent_port = platform_chassis.get_sfp(index).get_name() + except: + parent_port = intf_name + + if parent_port == intf_name: + return(False, None) + else: + presence = self.db.exists(self.db.STATE_DB, 'TRANSCEIVER_INFO|{}'.format(parent_port)) + if presence: + return(True, parent_port) + else: + return(False, None) + @multi_asic_util.run_on_multi_asic def get_eeprom(self): if self.intf_name is not None: presence = self.db.exists(self.db.STATE_DB, 'TRANSCEIVER_INFO|{}'.format(self.intf_name)) if presence: self.output = self.convert_interface_sfp_info_to_cli_output_string( - self.db, self.intf_name, self.dump_dom) + self.db, self.intf_name, self.intf_name, self.dump_dom) else: - self.output += (self.intf_name + ': ' + 'SFP EEPROM Not detected' + '\n') + (presence, parent_port) = self.get_presence_from_parent_port(self.intf_name) + if presence: + self.output = self.convert_interface_sfp_info_to_cli_output_string( + self.db, self.intf_name, parent_port, self.dump_dom) + else: + self.output += (self.intf_name + ': ' + 'SFP EEPROM Not detected' + '\n') else: port_table_keys = self.db.keys(self.db.APPL_DB, "PORT_TABLE:*") sorted_table_keys = natsorted(port_table_keys) @@ -421,9 +445,14 @@ class SFPShow(object): presence = self.db.exists(self.db.STATE_DB, 'TRANSCEIVER_INFO|{}'.format(interface)) if presence: self.output += self.convert_interface_sfp_info_to_cli_output_string( - self.db, interface, self.dump_dom) + self.db, interface, interface, self.dump_dom) else: - self.output += (interface + ': ' + 'SFP EEPROM Not detected' + '\n') + (presence, parent_port) = self.get_presence_from_parent_port(interface) + if presence: + self.output += self.convert_interface_sfp_info_to_cli_output_string( + self.db, interface, parent_port, self.dump_dom) + else: + self.output += (interface + ': ' + 'SFP EEPROM Not detected' + '\n') self.output += '\n' @@ -436,7 +465,11 @@ class SFPShow(object): if presence: port_table.append((self.intf_name, 'Present')) else: - port_table.append((self.intf_name, 'Not present')) + (presence, parent_port) = self.get_presence_from_parent_port(self.intf_name) + if presence: + port_table.append((self.intf_name, 'Present')) + else: + port_table.append((self.intf_name, 'Not present')) else: port_table_keys = self.db.keys(self.db.APPL_DB, "PORT_TABLE:*") for i in port_table_keys: @@ -446,7 +479,11 @@ class SFPShow(object): if presence: port_table.append((key, 'Present')) else: - port_table.append((key, 'Not present')) + (presence, parent_port) = self.get_presence_from_parent_port(key) + if presence: + port_table.append((key, 'Present')) + else: + port_table.append((key, 'Not present')) self.table += port_table