diff --git a/src/sonic-config-engine/minigraph.py b/src/sonic-config-engine/minigraph.py index 4a60cd4edc..7965ed9358 100644 --- a/src/sonic-config-engine/minigraph.py +++ b/src/sonic-config-engine/minigraph.py @@ -1753,6 +1753,15 @@ def parse_asic_sub_role(filename, asic_name): sub_role, _, _, _ = parse_asic_meta(child, asic_name) return sub_role +def parse_asic_switch_type(filename, asic_name): + if os.path.isfile(filename): + root = ET.parse(filename).getroot() + for child in root: + if child.tag == str(QName(ns, "MetadataDeclaration")): + _, _, switch_type, _ = parse_asic_meta(child, asic_name) + return switch_type + return None + def parse_asic_meta_get_devices(root): local_devices = [] diff --git a/src/sonic-config-engine/sonic-cfggen b/src/sonic-config-engine/sonic-cfggen index cb878037df..bf93ad849f 100755 --- a/src/sonic-config-engine/sonic-cfggen +++ b/src/sonic-config-engine/sonic-cfggen @@ -29,7 +29,7 @@ import yaml from collections import OrderedDict from config_samples import generate_sample_config, get_available_config from functools import partial -from minigraph import minigraph_encoder, parse_xml, parse_device_desc_xml, parse_asic_sub_role +from minigraph import minigraph_encoder, parse_xml, parse_device_desc_xml, parse_asic_sub_role, parse_asic_switch_type 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, get_asic_device_id @@ -363,13 +363,17 @@ def main(): # the minigraph file must be provided to get the mac address for backend asics + # or switch_type chassis_packet if args.platform_info: asic_role = None + switch_type = None if asic_name is not None: if args.minigraph is not None: asic_role = parse_asic_sub_role(args.minigraph, asic_name) + switch_type = parse_asic_switch_type(args.minigraph, asic_name) - if asic_role is not None and asic_role.lower() == "backend": + if ((switch_type is not None and switch_type.lower() == "chassis-packet") or + (asic_role is not None and asic_role.lower() == "backend")): mac = device_info.get_system_mac(namespace=asic_name) else: mac = device_info.get_system_mac() diff --git a/src/sonic-py-common/sonic_py_common/device_info.py b/src/sonic-py-common/sonic_py_common/device_info.py index 0b58a4231a..550b190922 100644 --- a/src/sonic-py-common/sonic_py_common/device_info.py +++ b/src/sonic-py-common/sonic_py_common/device_info.py @@ -492,6 +492,14 @@ def get_system_mac(namespace=None): else: profile_cmd = "false" hw_mac_entry_cmds = ["sudo decode-syseeprom -m", profile_cmd, "ip link show eth0 | grep ether | awk '{print $2}'"] + elif (version_info['asic_type'] == 'cisco-8000'): + # Try to get valid MAC from profile.ini first, else fetch it from syseeprom or eth0 + platform = get_platform() + if namespace is not None: + profile_cmd = 'cat ' + HOST_DEVICE_PATH + '/' + platform + '/profile.ini | grep ' + namespace + 'switchMacAddress | cut -f2 -d=' + else: + profile_cmd = "false" + hw_mac_entry_cmds = [profile_cmd, "sudo decode-syseeprom -m", "ip link show eth0 | grep ether | awk '{print $2}'"] else: mac_address_cmd = "cat /sys/class/net/eth0/address" if namespace is not None: