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

[multi-asic] Port the fix to get the PCI_id from asic.conf from 201911 --> master #7513

Merged
merged 1 commit into from
May 7, 2021
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
9 changes: 7 additions & 2 deletions src/sonic-config-engine/sonic-cfggen
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -380,7 +380,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']
Expand Down
23 changes: 23 additions & 0 deletions src/sonic-py-common/sonic_py_common/multi_asic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down