Skip to content

Commit

Permalink
Revert "Improve the way to check port type of RJ45 port (#2249)"
Browse files Browse the repository at this point in the history
This reverts commit a1a09e4.
  • Loading branch information
yxieca committed Aug 12, 2022
1 parent 9b21903 commit 0df3ba8
Show file tree
Hide file tree
Showing 8 changed files with 122 additions and 210 deletions.
40 changes: 17 additions & 23 deletions scripts/intfutil
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ import os
import re
import sys

from natsort import natsorted
from tabulate import tabulate
from utilities_common import constants
from utilities_common import multi_asic as multi_asic_util
from utilities_common.intf_filter import parse_interface_in_filter
from sonic_py_common.interface import get_intf_longname

# mock the redis for unit test purposes #
try:
if os.environ["UTILITIES_UNIT_TESTING"] == "2":
Expand All @@ -13,23 +20,13 @@ try:
sys.path.insert(0, modules_path)
sys.path.insert(0, tests_path)
import mock_tables.dbconnector
from mock_platform_sfputil.mock_platform_sfputil import mock_platform_sfputil_helper
mock_platform_sfputil_helper()
if os.environ["UTILITIES_UNIT_TESTING_TOPOLOGY"] == "multi_asic":
import mock_tables.mock_multi_asic
mock_tables.dbconnector.load_namespace_config()

except KeyError:
pass

from natsort import natsorted
from tabulate import tabulate
from utilities_common import constants
from utilities_common import multi_asic as multi_asic_util
from utilities_common.intf_filter import parse_interface_in_filter
from utilities_common.platform_sfputil_helper import is_rj45_port, RJ45_PORT_TYPE
from sonic_py_common.interface import get_intf_longname

# ========================== Common interface-utils logic ==========================


Expand All @@ -52,7 +49,7 @@ PORT_RMT_ADV_SPEEDS = 'rmt_adv_speeds'
PORT_INTERFACE_TYPE = 'interface_type'
PORT_ADV_INTERFACE_TYPES = 'adv_interface_types'
PORT_TPID = "tpid"
OPTICS_TYPE_RJ45 = RJ45_PORT_TYPE
OPTICS_TYPE_RJ45 = 'RJ45'
PORT_LINK_TRAINING = 'link_training'
PORT_LINK_TRAINING_STATUS = 'link_training_status'

Expand Down Expand Up @@ -164,10 +161,10 @@ def appl_db_port_status_get(appl_db, intf_name, status_type):
if status is None:
return "N/A"
if status_type == PORT_SPEED and status != "N/A":
optics_type = port_optics_get(appl_db, intf_name, PORT_OPTICS_TYPE)
optics_type = state_db_port_optics_get(appl_db, intf_name, PORT_OPTICS_TYPE)
status = port_speed_parse(status, optics_type)
elif status_type == PORT_ADV_SPEEDS and status != "N/A" and status != "all":
optics_type = port_optics_get(appl_db, intf_name, PORT_OPTICS_TYPE)
optics_type = state_db_port_optics_get(appl_db, intf_name, PORT_OPTICS_TYPE)
speed_list = status.split(',')
new_speed_list = []
for s in natsorted(speed_list):
Expand All @@ -184,7 +181,7 @@ def state_db_port_status_get(db, intf_name, field):
if not status:
return "N/A"
if field in [PORT_RMT_ADV_SPEEDS] and status not in ["N/A", "all"]:
optics_type = port_optics_get(db, intf_name, PORT_OPTICS_TYPE)
optics_type = state_db_port_optics_get(db, intf_name, PORT_OPTICS_TYPE)
speed_list = status.split(',')
new_speed_list = []
for s in natsorted(speed_list):
Expand All @@ -201,7 +198,7 @@ def port_oper_speed_get(db, intf_name):
if oper_speed is None or oper_speed == "N/A" or oper_status != "up":
return appl_db_port_status_get(db, intf_name, PORT_SPEED)
else:
optics_type = port_optics_get(db, intf_name, PORT_OPTICS_TYPE)
optics_type = state_db_port_optics_get(db, intf_name, PORT_OPTICS_TYPE)
return port_speed_parse(oper_speed, optics_type)

def port_oper_speed_get_raw(db, intf_name):
Expand All @@ -214,17 +211,14 @@ def port_oper_speed_get_raw(db, intf_name):
speed = db.get(db.APPL_DB, PORT_STATUS_TABLE_PREFIX + intf_name, PORT_SPEED)
return speed

def port_optics_get(state_db, intf_name, type):
def state_db_port_optics_get(state_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:
if is_rj45_port(intf_name):
return OPTICS_TYPE_RJ45
else:
return "N/A"
return "N/A"
return optics_type

def merge_dicts(x,y):
Expand Down Expand Up @@ -331,13 +325,13 @@ def po_speed_dict(po_int_dict, appl_db):
# If no speed was returned, append None without format
po_list.append(None)
else:
optics_type = port_optics_get(appl_db, value[0], PORT_OPTICS_TYPE)
optics_type = state_db_port_optics_get(appl_db, value[0], PORT_OPTICS_TYPE)
interface_speed = port_speed_parse(interface_speed, optics_type)
po_list.append(interface_speed)
elif len(value) > 1:
for intf in value:
temp_speed = port_oper_speed_get_raw(appl_db, intf)
optics_type = port_optics_get(appl_db, intf, PORT_OPTICS_TYPE)
optics_type = state_db_port_optics_get(appl_db, intf, PORT_OPTICS_TYPE)
temp_speed = int(temp_speed) if temp_speed else 0
agg_speed_list.append(temp_speed)
interface_speed = sum(agg_speed_list)
Expand Down Expand Up @@ -483,7 +477,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),
port_optics_get(self.db, key, PORT_OPTICS_TYPE),
state_db_port_optics_get(self.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():
Expand Down
75 changes: 37 additions & 38 deletions scripts/sfpshow
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ from natsort import natsorted
from sonic_py_common.interface import front_panel_prefix, backplane_prefix, inband_prefix, recirc_prefix
from sonic_py_common import multi_asic
from tabulate import tabulate
from utilities_common import multi_asic as multi_asic_util

# Mock the redis DB for unit test purposes
try:
Expand All @@ -26,17 +27,12 @@ try:
sys.path.insert(0, modules_path)
sys.path.insert(0, test_path)
import mock_tables.dbconnector
from mock_platform_sfputil.mock_platform_sfputil import mock_platform_sfputil_helper
mock_platform_sfputil_helper()
if os.environ["UTILITIES_UNIT_TESTING_TOPOLOGY"] == "multi_asic":
import mock_tables.mock_multi_asic
mock_tables.dbconnector.load_namespace_config()
except KeyError:
pass

from utilities_common import multi_asic as multi_asic_util
from utilities_common.platform_sfputil_helper import is_rj45_port, RJ45_PORT_TYPE

# TODO: We should share these maps and the formatting functions between sfputil and sfpshow
QSFP_DATA_MAP = {
'model': 'Vendor PN',
Expand Down Expand Up @@ -219,6 +215,8 @@ QSFP_DD_DOM_VALUE_UNIT_MAP = {
'voltage': 'Volts'
}

RJ45_PORT_TYPE = 'RJ45'


def display_invalid_intf_eeprom(intf_name):
output = intf_name + ': SFP EEPROM Not detected\n'
Expand All @@ -233,6 +231,7 @@ def display_invalid_intf_presence(intf_name):


class SFPShow(object):

def __init__(self, intf_name, namespace_option, dump_dom=False):
super(SFPShow, self).__init__()
self.db = None
Expand Down Expand Up @@ -395,63 +394,63 @@ class SFPShow(object):
output = ''

sfp_info_dict = state_db.get_all(state_db.STATE_DB, 'TRANSCEIVER_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)
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_output = self.convert_dom_to_output_string(sfp_type, dom_info_dict)
output += dom_output
if sfp_info_dict['type'] == RJ45_PORT_TYPE:
output = 'SFP EEPROM is not applicable for RJ45 port\n'
else:
if is_rj45_port(interface_name):
output = 'SFP EEPROM is not applicable for RJ45 port\n'
else:
output = "SFP EEPROM Not detected\n"
output = '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_output = self.convert_dom_to_output_string(sfp_type, dom_info_dict)
output += dom_output

return output

@multi_asic_util.run_on_multi_asic
def get_eeprom(self):
if self.intf_name is not None:
self.intf_eeprom[self.intf_name] = self.convert_interface_sfp_info_to_cli_output_string(
self.db, self.intf_name, self.dump_dom)
presence = self.db.exists(self.db.STATE_DB, 'TRANSCEIVER_INFO|{}'.format(self.intf_name))
if presence:
self.intf_eeprom[self.intf_name] = self.convert_interface_sfp_info_to_cli_output_string(
self.db, self.intf_name, self.dump_dom)
else:
self.intf_eeprom[self.intf_name] = "SFP EEPROM Not detected\n"
else:
port_table_keys = self.db.keys(self.db.APPL_DB, "PORT_TABLE:*")
for i in port_table_keys:
interface = re.split(':', i, maxsplit=1)[-1].strip()
if interface and interface.startswith(front_panel_prefix()) and not interface.startswith((backplane_prefix(), inband_prefix(), recirc_prefix())):
self.intf_eeprom[interface] = self.convert_interface_sfp_info_to_cli_output_string(
self.db, interface, self.dump_dom)

def convert_interface_sfp_presence_state_to_cli_output_string(self, state_db, interface_name):
sfp_info_dict = state_db.get_all(self.db.STATE_DB, 'TRANSCEIVER_INFO|{}'.format(interface_name))
if sfp_info_dict:
output = 'Present'
else:
output = 'Not present'
return output
presence = self.db.exists(self.db.STATE_DB, 'TRANSCEIVER_INFO|{}'.format(interface))
if presence:
self.intf_eeprom[interface] = self.convert_interface_sfp_info_to_cli_output_string(
self.db, interface, self.dump_dom)
else:
self.intf_eeprom[interface] = "SFP EEPROM Not detected\n"


@multi_asic_util.run_on_multi_asic
def get_presence(self):
port_table = []

if self.intf_name is not None:
presence_string = self.convert_interface_sfp_presence_state_to_cli_output_string(self.db, self.intf_name)
port_table.append((self.intf_name, presence_string))
presence = self.db.exists(self.db.STATE_DB, 'TRANSCEIVER_INFO|{}'.format(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:
key = re.split(':', i, maxsplit=1)[-1].strip()
if key and key.startswith(front_panel_prefix()) and not key.startswith((backplane_prefix(), inband_prefix(), recirc_prefix())):
presence_string = self.convert_interface_sfp_presence_state_to_cli_output_string(self.db, key)
port_table.append((key, presence_string))
presence = self.db.exists(self.db.STATE_DB, 'TRANSCEIVER_INFO|{}'.format(key))
if presence:
port_table.append((key, 'Present'))
else:
port_table.append((key, 'Not present'))

self.table += port_table

Expand Down
Loading

0 comments on commit 0df3ba8

Please sign in to comment.