Skip to content
Merged
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
10 changes: 5 additions & 5 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ container:
steps:
- task: DownloadPipelineArtifact@2
inputs:
source: specific
project: build
pipeline: 1
artifact: sonic-buildimage.vs
source: 'specific'
project: 'build'
pipeline: 142
artifact: 'sonic-buildimage.vs'
runVersion: 'latestFromBranch'
runBranch: 'refs/heads/master'
runBranch: 'refs/heads/202012'
displayName: "Download artifacts from latest sonic-buildimage build"

- script: |
Expand Down
107 changes: 66 additions & 41 deletions sonic_platform_base/sonic_sfp/sfputilhelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@
import os
import re
import sys
import ast
import json
from collections import OrderedDict

from natsort import natsorted
from portconfig import get_port_config
from sonic_py_common import device_info
from sonic_py_common import device_info, multi_asic
from sonic_py_common.interface import backplane_prefix

except ImportError as e:
Expand Down Expand Up @@ -45,6 +47,25 @@ class SfpUtilHelper(object):
def __init__(self):
pass

def get_port_mapping(self, asic_inst):
try:
if multi_asic.is_multi_asic():
ports_data = multi_asic.get_port_table_for_asic("{}{}".format(multi_asic.ASIC_NAME_PREFIX, asic_inst))
else:
ports_data = multi_asic.get_port_table_for_asic(multi_asic.DEFAULT_NAMESPACE)
except Exception as e:
return None

ports = ast.literal_eval(json.dumps(ports_data))
for port in ports.keys():
if "index" not in ports[port]:
print("Failed to get port config: invalid port entry {}: index field doesn't exist".format(port),
file=sys.stderr
)
return None

return ports

def read_porttab_mappings(self, porttabfile, asic_inst=0):
logical = []
logical_to_physical = {}
Expand All @@ -55,51 +76,55 @@ def read_porttab_mappings(self, porttabfile, asic_inst=0):
port_pos_in_file = 0
parse_fmt_port_config_ini = False
parse_fmt_platform_json = False
parse_fmt_config_db = False

ports = self.get_port_mapping(asic_inst)

parse_fmt_port_config_ini = (os.path.basename(porttabfile) == PORT_CONFIG_INI)
parse_fmt_platform_json = (os.path.basename(porttabfile) == PLATFORM_JSON)
parse_fmt_config_db = ports is not None

(platform, hwsku) = device_info.get_platform_and_hwsku()
if(parse_fmt_platform_json):
ports, _, _ = get_port_config(hwsku, platform)
if not ports:
print('Failed to get port config', file=sys.stderr)
sys.exit(1)
else:
logical_list = []
for intf in ports.keys():
logical_list.append(intf)

logical = natsorted(logical_list, key=lambda y: y.lower())
logical_to_physical, physical_to_logical = OrderedDict(), OrderedDict()

for intf_name in logical:
bcm_port = str(port_pos_in_file)

if 'index' in ports[intf_name].keys():
fp_port_index = int(ports[intf_name]['index'])
logical_to_physical[intf_name] = [fp_port_index]

if physical_to_logical.get(fp_port_index) is None:
physical_to_logical[fp_port_index] = [intf_name]
else:
physical_to_logical[fp_port_index].append(intf_name)

# Mapping of logical port names available on a system to ASIC instance
self.logical_to_asic[intf_name] = asic_inst
port_pos_in_file +=1

self.logical = logical
self.logical_to_physical = logical_to_physical
self.physical_to_logical = physical_to_logical

"""
print("logical: {}".format(self.logical))
print("logical to physical: {}".format(self.logical_to_physical))
print("physical to logical: {}".format( self.physical_to_logical))
"""
return None
if (parse_fmt_config_db or parse_fmt_platform_json):
if not parse_fmt_config_db:
platform, hwsku = device_info.get_platform_and_hwsku()
ports, _, _ = get_port_config(hwsku, platform, porttabfile)
if not ports:
print('Failed to get port config', file=sys.stderr)
sys.exit(1)

logical_list = []
for intf in ports.keys():
logical_list.append(intf)

logical = natsorted(logical_list, key=lambda y: y.lower())
logical_to_physical, physical_to_logical = OrderedDict(), OrderedDict()

for intf_name in logical:
bcm_port = str(port_pos_in_file)

if 'index' in ports[intf_name].keys():
fp_port_index = int(ports[intf_name]['index'])
logical_to_physical[intf_name] = [fp_port_index]

if physical_to_logical.get(fp_port_index) is None:
physical_to_logical[fp_port_index] = [intf_name]
else:
physical_to_logical[fp_port_index].append(intf_name)

# Mapping of logical port names available on a system to ASIC instance
self.logical_to_asic[intf_name] = asic_inst
port_pos_in_file +=1

self.logical = logical
self.logical_to_physical = logical_to_physical
self.physical_to_logical = physical_to_logical

"""
print("logical: {}".format(self.logical))
print("logical to physical: {}".format(self.logical_to_physical))
print("physical to logical: {}".format( self.physical_to_logical))
"""
return None

try:
f = open(porttabfile)
Expand Down