Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Front panel port name regex #2127

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions pfc/main.py
Original file line number Diff line number Diff line change
@@ -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']
Expand Down Expand Up @@ -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')])

Expand Down
4 changes: 3 additions & 1 deletion pfcwd/main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import importlib
import os
import sys
import re

import click
import utilities_common.cli as clicommon
Expand All @@ -11,6 +12,7 @@
from utilities_common import constants
from utilities_common.general import load_db_config
from sonic_py_common import logger
from swsscommon.swsscommon import FRONT_PANEL_PORT_PREFIX_REGEX

SYSLOG_IDENTIFIER = "config"

Expand Down Expand Up @@ -83,7 +85,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:
Expand Down
3 changes: 2 additions & 1 deletion scripts/ipintutil
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os
import subprocess
import sys
import re

import netaddr
import netifaces
Expand Down Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions scripts/sfpshow
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -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 utilities_common.sfp_helper import covert_application_advertisement_to_output_string
from utilities_common.sfp_helper import QSFP_DATA_MAP
Expand Down Expand Up @@ -411,7 +411,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())):
self.intf_eeprom[interface] = self.convert_interface_sfp_info_to_cli_output_string(
self.db, interface, self.dump_dom)

Expand All @@ -424,6 +424,7 @@ class SFPShow(object):
return output



@multi_asic_util.run_on_multi_asic
def get_presence(self):
port_table = []
Expand All @@ -435,7 +436,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_string = self.convert_interface_sfp_presence_state_to_cli_output_string(self.db, key)
port_table.append((key, presence_string))

Expand Down
5 changes: 3 additions & 2 deletions sfputil/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import os
import sys
import re
import natsort
import ast
import time
Expand All @@ -17,7 +18,7 @@
import sonic_platform
import sonic_platform_base.sonic_sfp.sfputilhelper
from sonic_platform_base.sfp_base import SfpBase
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 utilities_common.sfp_helper import covert_application_advertisement_to_output_string
Expand Down Expand Up @@ -484,7 +485,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:
Expand Down
7 changes: 5 additions & 2 deletions utilities_common/intf_filter.py
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -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]
Expand Down
4 changes: 3 additions & 1 deletion utilities_common/platform_sfputil_helper.py
Original file line number Diff line number Diff line change
@@ -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
platform_chassis = None
Expand Down Expand Up @@ -54,7 +56,7 @@ def platform_sfputil_read_porttab_mappings():

def logical_port_name_to_physical_port_list(port_name):
try:
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:
Expand Down