Skip to content

Commit 0df3ba8

Browse files
committed
Revert "Improve the way to check port type of RJ45 port (#2249)"
This reverts commit a1a09e4.
1 parent 9b21903 commit 0df3ba8

File tree

8 files changed

+122
-210
lines changed

8 files changed

+122
-210
lines changed

scripts/intfutil

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ import os
55
import re
66
import sys
77

8+
from natsort import natsorted
9+
from tabulate import tabulate
10+
from utilities_common import constants
11+
from utilities_common import multi_asic as multi_asic_util
12+
from utilities_common.intf_filter import parse_interface_in_filter
13+
from sonic_py_common.interface import get_intf_longname
14+
815
# mock the redis for unit test purposes #
916
try:
1017
if os.environ["UTILITIES_UNIT_TESTING"] == "2":
@@ -13,23 +20,13 @@ try:
1320
sys.path.insert(0, modules_path)
1421
sys.path.insert(0, tests_path)
1522
import mock_tables.dbconnector
16-
from mock_platform_sfputil.mock_platform_sfputil import mock_platform_sfputil_helper
17-
mock_platform_sfputil_helper()
1823
if os.environ["UTILITIES_UNIT_TESTING_TOPOLOGY"] == "multi_asic":
1924
import mock_tables.mock_multi_asic
2025
mock_tables.dbconnector.load_namespace_config()
2126

2227
except KeyError:
2328
pass
2429

25-
from natsort import natsorted
26-
from tabulate import tabulate
27-
from utilities_common import constants
28-
from utilities_common import multi_asic as multi_asic_util
29-
from utilities_common.intf_filter import parse_interface_in_filter
30-
from utilities_common.platform_sfputil_helper import is_rj45_port, RJ45_PORT_TYPE
31-
from sonic_py_common.interface import get_intf_longname
32-
3330
# ========================== Common interface-utils logic ==========================
3431

3532

@@ -52,7 +49,7 @@ PORT_RMT_ADV_SPEEDS = 'rmt_adv_speeds'
5249
PORT_INTERFACE_TYPE = 'interface_type'
5350
PORT_ADV_INTERFACE_TYPES = 'adv_interface_types'
5451
PORT_TPID = "tpid"
55-
OPTICS_TYPE_RJ45 = RJ45_PORT_TYPE
52+
OPTICS_TYPE_RJ45 = 'RJ45'
5653
PORT_LINK_TRAINING = 'link_training'
5754
PORT_LINK_TRAINING_STATUS = 'link_training_status'
5855

@@ -164,10 +161,10 @@ def appl_db_port_status_get(appl_db, intf_name, status_type):
164161
if status is None:
165162
return "N/A"
166163
if status_type == PORT_SPEED and status != "N/A":
167-
optics_type = port_optics_get(appl_db, intf_name, PORT_OPTICS_TYPE)
164+
optics_type = state_db_port_optics_get(appl_db, intf_name, PORT_OPTICS_TYPE)
168165
status = port_speed_parse(status, optics_type)
169166
elif status_type == PORT_ADV_SPEEDS and status != "N/A" and status != "all":
170-
optics_type = port_optics_get(appl_db, intf_name, PORT_OPTICS_TYPE)
167+
optics_type = state_db_port_optics_get(appl_db, intf_name, PORT_OPTICS_TYPE)
171168
speed_list = status.split(',')
172169
new_speed_list = []
173170
for s in natsorted(speed_list):
@@ -184,7 +181,7 @@ def state_db_port_status_get(db, intf_name, field):
184181
if not status:
185182
return "N/A"
186183
if field in [PORT_RMT_ADV_SPEEDS] and status not in ["N/A", "all"]:
187-
optics_type = port_optics_get(db, intf_name, PORT_OPTICS_TYPE)
184+
optics_type = state_db_port_optics_get(db, intf_name, PORT_OPTICS_TYPE)
188185
speed_list = status.split(',')
189186
new_speed_list = []
190187
for s in natsorted(speed_list):
@@ -201,7 +198,7 @@ def port_oper_speed_get(db, intf_name):
201198
if oper_speed is None or oper_speed == "N/A" or oper_status != "up":
202199
return appl_db_port_status_get(db, intf_name, PORT_SPEED)
203200
else:
204-
optics_type = port_optics_get(db, intf_name, PORT_OPTICS_TYPE)
201+
optics_type = state_db_port_optics_get(db, intf_name, PORT_OPTICS_TYPE)
205202
return port_speed_parse(oper_speed, optics_type)
206203

207204
def port_oper_speed_get_raw(db, intf_name):
@@ -214,17 +211,14 @@ def port_oper_speed_get_raw(db, intf_name):
214211
speed = db.get(db.APPL_DB, PORT_STATUS_TABLE_PREFIX + intf_name, PORT_SPEED)
215212
return speed
216213

217-
def port_optics_get(state_db, intf_name, type):
214+
def state_db_port_optics_get(state_db, intf_name, type):
218215
"""
219216
Get optic type info for port
220217
"""
221218
full_table_id = PORT_TRANSCEIVER_TABLE_PREFIX + intf_name
222219
optics_type = state_db.get(state_db.STATE_DB, full_table_id, type)
223220
if optics_type is None:
224-
if is_rj45_port(intf_name):
225-
return OPTICS_TYPE_RJ45
226-
else:
227-
return "N/A"
221+
return "N/A"
228222
return optics_type
229223

230224
def merge_dicts(x,y):
@@ -331,13 +325,13 @@ def po_speed_dict(po_int_dict, appl_db):
331325
# If no speed was returned, append None without format
332326
po_list.append(None)
333327
else:
334-
optics_type = port_optics_get(appl_db, value[0], PORT_OPTICS_TYPE)
328+
optics_type = state_db_port_optics_get(appl_db, value[0], PORT_OPTICS_TYPE)
335329
interface_speed = port_speed_parse(interface_speed, optics_type)
336330
po_list.append(interface_speed)
337331
elif len(value) > 1:
338332
for intf in value:
339333
temp_speed = port_oper_speed_get_raw(appl_db, intf)
340-
optics_type = port_optics_get(appl_db, intf, PORT_OPTICS_TYPE)
334+
optics_type = state_db_port_optics_get(appl_db, intf, PORT_OPTICS_TYPE)
341335
temp_speed = int(temp_speed) if temp_speed else 0
342336
agg_speed_list.append(temp_speed)
343337
interface_speed = sum(agg_speed_list)
@@ -483,7 +477,7 @@ class IntfStatus(object):
483477
config_db_vlan_port_keys_get(self.combined_int_to_vlan_po_dict, self.front_panel_ports_list, key),
484478
appl_db_port_status_get(self.db, key, PORT_OPER_STATUS),
485479
appl_db_port_status_get(self.db, key, PORT_ADMIN_STATUS),
486-
port_optics_get(self.db, key, PORT_OPTICS_TYPE),
480+
state_db_port_optics_get(self.db, key, PORT_OPTICS_TYPE),
487481
appl_db_port_status_get(self.db, key, PORT_PFC_ASYM_STATUS)))
488482

489483
for po, value in self.portchannel_speed_dict.items():

scripts/sfpshow

Lines changed: 37 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ from natsort import natsorted
1717
from sonic_py_common.interface import front_panel_prefix, backplane_prefix, inband_prefix, recirc_prefix
1818
from sonic_py_common import multi_asic
1919
from tabulate import tabulate
20+
from utilities_common import multi_asic as multi_asic_util
2021

2122
# Mock the redis DB for unit test purposes
2223
try:
@@ -26,17 +27,12 @@ try:
2627
sys.path.insert(0, modules_path)
2728
sys.path.insert(0, test_path)
2829
import mock_tables.dbconnector
29-
from mock_platform_sfputil.mock_platform_sfputil import mock_platform_sfputil_helper
30-
mock_platform_sfputil_helper()
3130
if os.environ["UTILITIES_UNIT_TESTING_TOPOLOGY"] == "multi_asic":
3231
import mock_tables.mock_multi_asic
3332
mock_tables.dbconnector.load_namespace_config()
3433
except KeyError:
3534
pass
3635

37-
from utilities_common import multi_asic as multi_asic_util
38-
from utilities_common.platform_sfputil_helper import is_rj45_port, RJ45_PORT_TYPE
39-
4036
# TODO: We should share these maps and the formatting functions between sfputil and sfpshow
4137
QSFP_DATA_MAP = {
4238
'model': 'Vendor PN',
@@ -219,6 +215,8 @@ QSFP_DD_DOM_VALUE_UNIT_MAP = {
219215
'voltage': 'Volts'
220216
}
221217

218+
RJ45_PORT_TYPE = 'RJ45'
219+
222220

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

234232

235233
class SFPShow(object):
234+
236235
def __init__(self, intf_name, namespace_option, dump_dom=False):
237236
super(SFPShow, self).__init__()
238237
self.db = None
@@ -395,63 +394,63 @@ class SFPShow(object):
395394
output = ''
396395

397396
sfp_info_dict = state_db.get_all(state_db.STATE_DB, 'TRANSCEIVER_INFO|{}'.format(interface_name))
398-
if sfp_info_dict:
399-
if sfp_info_dict['type'] == RJ45_PORT_TYPE:
400-
output = 'SFP EEPROM is not applicable for RJ45 port\n'
401-
else:
402-
output = 'SFP EEPROM detected\n'
403-
sfp_info_output = self.convert_sfp_info_to_output_string(sfp_info_dict)
404-
output += sfp_info_output
405-
406-
if dump_dom:
407-
sfp_type = sfp_info_dict['type']
408-
dom_info_dict = state_db.get_all(state_db.STATE_DB, 'TRANSCEIVER_DOM_SENSOR|{}'.format(interface_name))
409-
dom_output = self.convert_dom_to_output_string(sfp_type, dom_info_dict)
410-
output += dom_output
397+
if sfp_info_dict['type'] == RJ45_PORT_TYPE:
398+
output = 'SFP EEPROM is not applicable for RJ45 port\n'
411399
else:
412-
if is_rj45_port(interface_name):
413-
output = 'SFP EEPROM is not applicable for RJ45 port\n'
414-
else:
415-
output = "SFP EEPROM Not detected\n"
400+
output = 'SFP EEPROM detected\n'
401+
sfp_info_output = self.convert_sfp_info_to_output_string(sfp_info_dict)
402+
output += sfp_info_output
403+
404+
if dump_dom:
405+
sfp_type = sfp_info_dict['type']
406+
dom_info_dict = state_db.get_all(state_db.STATE_DB, 'TRANSCEIVER_DOM_SENSOR|{}'.format(interface_name))
407+
dom_output = self.convert_dom_to_output_string(sfp_type, dom_info_dict)
408+
output += dom_output
416409

417410
return output
418411

419412
@multi_asic_util.run_on_multi_asic
420413
def get_eeprom(self):
421414
if self.intf_name is not None:
422-
self.intf_eeprom[self.intf_name] = self.convert_interface_sfp_info_to_cli_output_string(
423-
self.db, self.intf_name, self.dump_dom)
415+
presence = self.db.exists(self.db.STATE_DB, 'TRANSCEIVER_INFO|{}'.format(self.intf_name))
416+
if presence:
417+
self.intf_eeprom[self.intf_name] = self.convert_interface_sfp_info_to_cli_output_string(
418+
self.db, self.intf_name, self.dump_dom)
419+
else:
420+
self.intf_eeprom[self.intf_name] = "SFP EEPROM Not detected\n"
424421
else:
425422
port_table_keys = self.db.keys(self.db.APPL_DB, "PORT_TABLE:*")
426423
for i in port_table_keys:
427424
interface = re.split(':', i, maxsplit=1)[-1].strip()
428425
if interface and interface.startswith(front_panel_prefix()) and not interface.startswith((backplane_prefix(), inband_prefix(), recirc_prefix())):
429-
self.intf_eeprom[interface] = self.convert_interface_sfp_info_to_cli_output_string(
430-
self.db, interface, self.dump_dom)
431-
432-
def convert_interface_sfp_presence_state_to_cli_output_string(self, state_db, interface_name):
433-
sfp_info_dict = state_db.get_all(self.db.STATE_DB, 'TRANSCEIVER_INFO|{}'.format(interface_name))
434-
if sfp_info_dict:
435-
output = 'Present'
436-
else:
437-
output = 'Not present'
438-
return output
426+
presence = self.db.exists(self.db.STATE_DB, 'TRANSCEIVER_INFO|{}'.format(interface))
427+
if presence:
428+
self.intf_eeprom[interface] = self.convert_interface_sfp_info_to_cli_output_string(
429+
self.db, interface, self.dump_dom)
430+
else:
431+
self.intf_eeprom[interface] = "SFP EEPROM Not detected\n"
439432

440433

441434
@multi_asic_util.run_on_multi_asic
442435
def get_presence(self):
443436
port_table = []
444437

445438
if self.intf_name is not None:
446-
presence_string = self.convert_interface_sfp_presence_state_to_cli_output_string(self.db, self.intf_name)
447-
port_table.append((self.intf_name, presence_string))
439+
presence = self.db.exists(self.db.STATE_DB, 'TRANSCEIVER_INFO|{}'.format(self.intf_name))
440+
if presence:
441+
port_table.append((self.intf_name, 'Present'))
442+
else:
443+
port_table.append((self.intf_name, 'Not present'))
448444
else:
449445
port_table_keys = self.db.keys(self.db.APPL_DB, "PORT_TABLE:*")
450446
for i in port_table_keys:
451447
key = re.split(':', i, maxsplit=1)[-1].strip()
452448
if key and key.startswith(front_panel_prefix()) and not key.startswith((backplane_prefix(), inband_prefix(), recirc_prefix())):
453-
presence_string = self.convert_interface_sfp_presence_state_to_cli_output_string(self.db, key)
454-
port_table.append((key, presence_string))
449+
presence = self.db.exists(self.db.STATE_DB, 'TRANSCEIVER_INFO|{}'.format(key))
450+
if presence:
451+
port_table.append((key, 'Present'))
452+
else:
453+
port_table.append((key, 'Not present'))
455454

456455
self.table += port_table
457456

0 commit comments

Comments
 (0)