From 20f26de89ae47b20aeac7fab64b9569359395878 Mon Sep 17 00:00:00 2001 From: Itamar Talmon Date: Wed, 23 Feb 2022 14:01:01 +0200 Subject: [PATCH] Add support for front panel port prefix regex --- pfc/main.py | 5 +++-- pfcwd/main.py | 4 +++- scripts/ipintutil | 3 ++- scripts/sfpshow | 6 +++--- sfputil/main.py | 5 +++-- utilities_common/intf_filter.py | 7 +++++-- utilities_common/platform_sfputil_helper.py | 4 +++- 7 files changed, 22 insertions(+), 12 deletions(-) diff --git a/pfc/main.py b/pfc/main.py index b31d3c755e..2d128cbec4 100644 --- a/pfc/main.py +++ b/pfc/main.py @@ -1,9 +1,10 @@ #!/usr/bin/env python3 import click -from swsscommon.swsscommon import ConfigDBConnector +from swsscommon.swsscommon import ConfigDBConnector, FRONT_PANEL_PORT_PREFIX_REGEX from tabulate import tabulate from natsort import natsorted +import re ALL_PRIORITIES = [str(x) for x in range(8)] PRIORITY_STATUS = ['on', 'off'] @@ -39,7 +40,7 @@ def showPfcAsym(interface): if i: key = i.split('|')[-1] - if key and key.startswith('Ethernet'): + if key and re.match(FRONT_PANEL_PORT_PREFIX_REGEX, key): entry = configdb.get_entry('PORT', key) table.append([key, entry.get('pfc_asym', 'N/A')]) diff --git a/pfcwd/main.py b/pfcwd/main.py index 4d3e73fb75..550ad9a615 100644 --- a/pfcwd/main.py +++ b/pfcwd/main.py @@ -1,6 +1,7 @@ import importlib import os import sys +import re import click import utilities_common.cli as clicommon @@ -10,6 +11,7 @@ from utilities_common import multi_asic as multi_asic_util from utilities_common import constants from sonic_py_common import logger +from swsscommon.swsscommon import FRONT_PANEL_PORT_PREFIX_REGEX SYSLOG_IDENTIFIER = "config" @@ -82,7 +84,7 @@ def get_all_ports(db, namespace=None, display=constants.DISPLAY_ALL): # Get list of physical ports port_names = {} for i in all_port_names: - if i.startswith('Ethernet'): + if re.search(FRONT_PANEL_PORT_PREFIX_REGEX, i): port_names[i] = all_port_names[i] display_ports = list(port_names.keys()) if display == constants.DISPLAY_EXTERNAL: diff --git a/scripts/ipintutil b/scripts/ipintutil index 5eb1f66524..c6d1b3d58d 100755 --- a/scripts/ipintutil +++ b/scripts/ipintutil @@ -3,6 +3,7 @@ import os import subprocess import sys +import re import netaddr import netifaces @@ -55,7 +56,7 @@ def get_bgp_peer(): def skip_ip_intf_display(interface, display_option): if display_option != constants.DISPLAY_ALL: - if interface.startswith('Ethernet') and multi_asic.is_port_internal(interface): + if re.search(swsscommon.FRONT_PANEL_PORT_PREFIX_REGEX, interface) and multi_asic.is_port_internal(interface): return True elif interface.startswith('PortChannel') and multi_asic.is_port_channel_internal(interface): return True diff --git a/scripts/sfpshow b/scripts/sfpshow index 9e06333277..ebf8707ae5 100755 --- a/scripts/sfpshow +++ b/scripts/sfpshow @@ -14,7 +14,7 @@ from typing import Dict import click from natsort import natsorted -from sonic_py_common.interface import front_panel_prefix, backplane_prefix, inband_prefix, recirc_prefix +from sonic_py_common.interface import front_panel_prefix_regex, 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 @@ -417,7 +417,7 @@ class SFPShow(object): 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())): + if interface and re.search(front_panel_prefix_regex(), interface) and not interface.startswith((backplane_prefix(), inband_prefix(), recirc_prefix())): 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( @@ -440,7 +440,7 @@ class SFPShow(object): 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())): + if key and re.search(front_panel_prefix_regex(), key) and not key.startswith((backplane_prefix(), inband_prefix(), recirc_prefix())): presence = self.db.exists(self.db.STATE_DB, 'TRANSCEIVER_INFO|{}'.format(key)) if presence: port_table.append((key, 'Present')) diff --git a/sfputil/main.py b/sfputil/main.py index 68b91a9998..9d8d1ce036 100644 --- a/sfputil/main.py +++ b/sfputil/main.py @@ -7,6 +7,7 @@ import os import sys +import re import natsort import ast import time @@ -16,7 +17,7 @@ import click import sonic_platform import sonic_platform_base.sonic_sfp.sfputilhelper -from swsscommon.swsscommon import SonicV2Connector +from swsscommon.swsscommon import SonicV2Connector, FRONT_PANEL_PORT_PREFIX_REGEX from natsort import natsorted from sonic_py_common import device_info, logger, multi_asic from tabulate import tabulate @@ -481,7 +482,7 @@ def get_physical_port_name(logical_port, physical_port, ganged): def logical_port_name_to_physical_port_list(port_name): - if port_name.startswith("Ethernet"): + if re.search(FRONT_PANEL_PORT_PREFIX_REGEX, port_name): if platform_sfputil.is_logical_port(port_name): return platform_sfputil.get_logical_to_physical(port_name) else: diff --git a/utilities_common/intf_filter.py b/utilities_common/intf_filter.py index be5ddaed8f..62dde04c16 100755 --- a/utilities_common/intf_filter.py +++ b/utilities_common/intf_filter.py @@ -1,6 +1,7 @@ # Interface filtering functions +import re +from swsscommon.swsscommon import FRONT_PANEL_PORT_PREFIX_REGEX -SONIC_PORT_NAME_PREFIX = "Ethernet" SONIC_LAG_NAME_PREFIX = "PortChannel" def parse_interface_in_filter(intf_filter): @@ -13,10 +14,12 @@ def parse_interface_in_filter(intf_filter): for x in fs: if '-' in x: # handle range - if not x.startswith(SONIC_PORT_NAME_PREFIX) and not x.startswith(SONIC_LAG_NAME_PREFIX): + if not re.search(FRONT_PANEL_PORT_PREFIX_REGEX, x) and not x.startswith(SONIC_LAG_NAME_PREFIX): continue if x.startswith(SONIC_PORT_NAME_PREFIX): intf = SONIC_PORT_NAME_PREFIX + if x.startswith(SONIC_IB_PORT_NAME_PREFIX): + intf = SONIC_IB_PORT_NAME_PREFIX if x.startswith(SONIC_LAG_NAME_PREFIX): intf = SONIC_LAG_NAME_PREFIX start = x.split('-')[0].split(intf,1)[1] diff --git a/utilities_common/platform_sfputil_helper.py b/utilities_common/platform_sfputil_helper.py index a7f4477660..fba306c61e 100644 --- a/utilities_common/platform_sfputil_helper.py +++ b/utilities_common/platform_sfputil_helper.py @@ -1,9 +1,11 @@ import sys +import re import click from . import cli as clicommon from sonic_py_common import multi_asic, device_info +from swsscommon.swsscommon import FRONT_PANEL_PORT_PREFIX_REGEX platform_sfputil = None @@ -43,7 +45,7 @@ def platform_sfputil_read_porttab_mappings(): def logical_port_name_to_physical_port_list(port_name): - if port_name.startswith("Ethernet"): + if re.search(FRONT_PANEL_PORT_PREFIX_REGEX, port_name): if platform_sfputil.is_logical_port(port_name): return platform_sfputil.get_logical_to_physical(port_name) else: