-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Parser changes to support parsing of multi-asic device minigraph #4222
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
Changes from 26 commits
3ce843a
ff6aa99
b784c81
9b4039e
d4fe8e0
53c6693
a9a06a8
9c9f8c2
5b6892e
78a2bf7
ce84879
882c251
4ae22be
30024ba
9744b85
4f4be8c
0895629
0b90dae
15228c1
0432f92
ebf2e8b
520c43b
110d1b8
247370b
cd3a678
06983e4
17a0d04
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,8 @@ | |
import yaml | ||
import subprocess | ||
import re | ||
|
||
from natsort import natsorted | ||
import glob | ||
DOCUMENTATION = ''' | ||
--- | ||
module: sonic_device_util | ||
|
@@ -17,6 +18,9 @@ | |
TODO: this file shall be renamed and moved to other places in future | ||
to have it shared with multiple applications. | ||
''' | ||
SONIC_DEVICE_PATH = '/usr/share/sonic/device' | ||
NPU_NAME_PREFIX = 'asic' | ||
NAMESPACE_PATH_GLOB = '/run/netns/*' | ||
def get_machine_info(): | ||
if not os.path.isfile('/host/machine.conf'): | ||
return None | ||
|
@@ -27,7 +31,38 @@ def get_machine_info(): | |
if len(tokens) < 2: | ||
continue | ||
machine_vars[tokens[0]] = tokens[1].strip() | ||
return machine_vars | ||
return machine_vars | ||
|
||
def get_npu_id_from_name(npu_name): | ||
if npu_name.startswith(NPU_NAME_PREFIX): | ||
return npu_name[len(NPU_NAME_PREFIX):] | ||
else: | ||
return None | ||
|
||
def get_num_npus(): | ||
platform = get_platform_info(get_machine_info()) | ||
asic_conf_file_path = os.path.join(SONIC_DEVICE_PATH, platform, 'asic.conf') | ||
if not os.path.isfile(asic_conf_file_path): | ||
return 1 | ||
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].lower() == 'num_asic': | ||
num_npus = tokens[1].strip() | ||
return num_npus | ||
|
||
def get_namespaces(): | ||
""" | ||
In a multi NPU platform, each NPU is in a Linux Namespace. | ||
This method returns list of all the Namespace present on the device | ||
""" | ||
ns_list = [] | ||
for path in glob.glob(NAMESPACE_PATH_GLOB): | ||
ns = os.path.basename(path) | ||
ns_list.append(ns) | ||
return natsorted(ns_list) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no need to sort here. you do not know what order the user wants There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function is used mainly by CLI, in that case it is better if namespace list is sorted |
||
|
||
def get_platform_info(machine_info): | ||
if machine_info != None: | ||
|
@@ -51,7 +86,7 @@ def get_sonic_version_info(): | |
def valid_mac_address(mac): | ||
return bool(re.match("^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$", mac)) | ||
|
||
def get_system_mac(): | ||
def get_system_mac(namespace=None): | ||
version_info = get_sonic_version_info() | ||
|
||
if (version_info['asic_type'] == 'mellanox'): | ||
|
@@ -73,10 +108,14 @@ def get_system_mac(): | |
# Try valid mac in eeprom, else fetch it from eth0 | ||
platform = get_platform_info(get_machine_info()) | ||
hwsku = get_machine_info()['onie_machine'] | ||
profile_cmd = 'cat /usr/share/sonic/device/' + platform +'/'+ hwsku +'/profile.ini | cut -f2 -d=' | ||
profile_cmd = 'cat' + SONIC_DEVICE_PATH + '/' + platform +'/'+ hwsku +'/profile.ini | cut -f2 -d=' | ||
hw_mac_entry_cmds = [ profile_cmd, "sudo decode-syseeprom -m", "ip link show eth0 | grep ether | awk '{print $2}'" ] | ||
else: | ||
hw_mac_entry_cmds = [ "ip link show eth0 | grep ether | awk '{print $2}'" ] | ||
mac_address_cmd = "cat /sys/class/net/eth0/address" | ||
if namespace is not None: | ||
mac_address_cmd = "sudo ip netns exec {} {}".format(namespace, mac_address_cmd) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what is the container eth0 mac address? how can make sure it is unique? is it randomly generated? i think it is hard to guarantee the mac is unique across different system in the dc and we could end up with duplicate macs. for frontend chip, you can still use the eth0 mac, only for backend chip you can use for docker generated mac. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The container eth0 mac is a dummy mac. Corresponding change in sonic-cfggen
|
||
|
||
hw_mac_entry_cmds = [mac_address_cmd] | ||
|
||
for get_mac_cmd in hw_mac_entry_cmds: | ||
proc = subprocess.Popen(get_mac_cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i do not see this function used anywhere else in you code, in the multi npu system, why not use asic.conf to derive the namepsace you have on the system? why use ip netns list to query?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The plan is use this function by CLI commands.
Today the namespace are names as "asicX" , it could change in the future so didn't want to generate the name from asic.conf here.