Updates to move the function get_asic_device_id() into the sonic-py-common. (#5204)

Update the name from get_npu_device_id() -to get_asic_device_id() and move from device_info.py, to the new file multi_asic.py in sonic-py-common so that it references to the correct valid constants.
This commit is contained in:
judyjoseph 2020-08-18 10:18:07 -07:00 committed by GitHub
parent 04aaeb1390
commit 91c61e31ad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 4 deletions

View File

@ -42,8 +42,7 @@ from minigraph import parse_device_desc_xml
from minigraph import parse_asic_sub_role
from portconfig import get_port_config
from sonic_py_common.device_info import get_platform, get_system_mac
from sonic_py_common.device_info import get_npu_device_id
from sonic_py_common.multi_asic import get_asic_id_from_name, is_multi_asic
from sonic_py_common.multi_asic import get_asic_id_from_name, is_multi_asic, get_asic_device_id
from config_samples import generate_sample_config
from config_samples import get_available_config
from swsssdk import SonicV2Connector, ConfigDBConnector, SonicDBConfig
@ -315,7 +314,7 @@ def main():
}}}
# The ID needs to be passed to the SAI to identify the asic.
if asic_name is not None:
device_id = get_npu_device_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)

View File

@ -129,6 +129,34 @@ def get_asic_id_from_name(asic_name):
else:
return None
# Get the ASIC id from the asic.conf file.
def get_asic_device_id(asic_id):
platform = get_platform()
if not platform:
return None
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_namespaces_from_linux():
"""
@ -297,4 +325,4 @@ def is_bgp_session_internal(bgp_neigh_ip, namespace=None):
return True
else:
return False
return False
return False