From 02b013fc6a20b3725bfe02eda982e841bf6be038 Mon Sep 17 00:00:00 2001 From: Itamar Talmon Date: Thu, 24 Feb 2022 11:24:35 +0200 Subject: [PATCH] Added support for front panel port prefix regex --- sonic_platform_base/sonic_sfp/sfputilbase.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/sonic_platform_base/sonic_sfp/sfputilbase.py b/sonic_platform_base/sonic_sfp/sfputilbase.py index 760ababa1..e3ef29de4 100644 --- a/sonic_platform_base/sonic_sfp/sfputilbase.py +++ b/sonic_platform_base/sonic_sfp/sfputilbase.py @@ -16,6 +16,7 @@ from portconfig import get_port_config from sonic_py_common import device_info from sonic_py_common.interface import backplane_prefix, inband_prefix, recirc_prefix + from swsscommon.swsscommon import FRONT_PANEL_PORT_REGEX from sonic_eeprom import eeprom_dts from .sff8472 import sff8472InterfaceId # Dot module supports both Python 2 and Python 3 using explicit relative import methods @@ -510,12 +511,19 @@ def read_porttab_mappings(self, porttabfile, asic_inst=0): elif "asic_port_name" not in title and len(line.split()) >= 4: fp_port_index = int(line.split()[3]) else: - fp_port_index = portname.split("Ethernet").pop() + front_panel_prefix_match = re.match(FRONT_PANEL_PORT_REGEX, portname) + if not front_panel_prefix_match: + continue + front_panel_prefix = front_panel_prefix_match.group(1) + fp_port_index = portname.split(front_panel_prefix).pop() fp_port_index = int(fp_port_index.split("s").pop(0))/4 else: # Parsing logic for older 'portmap.ini' file (portname, bcm_port) = line.split("=")[1].split(",")[:2] - - fp_port_index = portname.split("Ethernet").pop() + front_panel_prefix_match = re.match(FRONT_PANEL_PORT_REGEX, portname) + if not front_panel_prefix_match: + continue + front_panel_prefix = front_panel_prefix_match.group(1) + fp_port_index = portname.split(front_panel_prefix).pop() fp_port_index = int(fp_port_index.split("s").pop(0))/4 if ((len(self.sfp_ports) > 0) and (fp_port_index not in self.sfp_ports)):