Port the fix to get the PCI_id from asic.conf file from 201911 --> master branch (#7513)

Port the fix to get the pci_device ID from asic.conf file and update the "asic_id" field in DEVICE_METADATA with the pci_device_Id.

Ref: https://github.com/Azure/sonic-buildimage/pull/4705
This commit is contained in:
judyjoseph 2021-05-07 09:47:26 -07:00 committed by Qi Luo
parent 9a89c1beee
commit 4ec5f8e850
2 changed files with 30 additions and 2 deletions

View File

@ -41,7 +41,7 @@ from functools import partial
from minigraph import minigraph_encoder, parse_xml, parse_device_desc_xml, parse_asic_sub_role
from portconfig import get_port_config, get_breakout_mode
from redis_bcc import RedisBytecodeCache
from sonic_py_common.multi_asic import get_asic_id_from_name
from sonic_py_common.multi_asic import get_asic_id_from_name, get_asic_device_id
from sonic_py_common import device_info
from swsscommon.swsscommon import SonicV2Connector, ConfigDBConnector, SonicDBConfig, ConfigDBPipeConnector
@ -377,7 +377,12 @@ def main():
}}}
# The ID needs to be passed to the SAI to identify the asic.
if asic_name is not None:
hardware_data['DEVICE_METADATA']['localhost'].update(asic_id=asic_id)
device_id = get_asic_device_id(asic_id)
# if the device_id obtained is None, exit with error
if device_id is None:
print('Failed to get device ID for', asic_name, file=sys.stderr)
sys.exit(1)
hardware_data['DEVICE_METADATA']['localhost'].update(asic_id=device_id)
deep_update(data, hardware_data)
paths = ['/', '/usr/share/sonic/templates']

View File

@ -137,6 +137,29 @@ def get_asic_id_from_name(asic_name):
else:
raise ValueError('Unknown asic namespace name {}'.format(asic_name))
def get_asic_device_id(asic_id):
# Get asic.conf file
asic_conf_file_path = get_asic_conf_file_path()
if asic_conf_file_path is None:
return None
# In a multi-asic device we need to have the file "asic.conf" updated with the asic instance
# and the corresponding device id which could be pci_id. Below is an eg: for a 2 ASIC platform/sku.
# DEV_ID_ASIC_0=03:00.0
# DEV_ID_ASIC_1=04:00.0
device_str = "DEV_ID_ASIC_{}".format(asic_id)
with open(asic_conf_file_path) as asic_conf_file:
for line in asic_conf_file:
tokens = line.split('=')
if len(tokens) < 2:
continue
if tokens[0] == device_str:
device_id = tokens[1].strip()
return device_id
return None
def get_current_namespace(pid=None):
"""