diff --git a/dockers/docker-orchagent/orchagent.sh b/dockers/docker-orchagent/orchagent.sh index 917205f3eb..a68f2d70fb 100755 --- a/dockers/docker-orchagent/orchagent.sh +++ b/dockers/docker-orchagent/orchagent.sh @@ -1,10 +1,18 @@ #!/usr/bin/env bash -# Export platform information. Required to be able to write -# vendor specific code. -export platform=`sonic-cfggen -y /etc/sonic/sonic_version.yml -v asic_type` +EXIT_SWSS_VARS_FILE_NOT_FOUND=1 +SWSS_VARS_FILE=/usr/share/sonic/templates/swss_vars.j2 -MAC_ADDRESS=$(sonic-cfggen -d -v 'DEVICE_METADATA.localhost.mac') +if [ ! -f "$SWSS_VARS_FILE" ]; then + echo "SWSS vars template file not found" + exit $EXIT_SWSS_VARS_FILE_NOT_FOUND +fi + +# Retrieve SWSS vars from sonic-cfggen +SWSS_VARS=$(sonic-cfggen -d -y /etc/sonic/sonic_version.yml -t $SWSS_VARS_FILE) +platform=$(echo $SWSS_VARS | jq -r '.asic_type') + +MAC_ADDRESS=$(echo $SWSS_VARS | jq -r '.mac') if [ "$MAC_ADDRESS" == "None" ] || [ -z "$MAC_ADDRESS" ]; then MAC_ADDRESS=$(ip link show eth0 | grep ether | awk '{print $2}') logger "Mac address not found in Device Metadata, Falling back to eth0" @@ -27,7 +35,7 @@ ORCHAGENT_ARGS+="-b 8192 " # ID field could be integers just to denote the asic instance like 0,1,2... # OR could be PCI device ID's which will be strings like "03:00.0" # depending on what the SAI/SDK expects. -asic_id=`sonic-cfggen -d -v DEVICE_METADATA.localhost.asic_id` +asic_id=$(echo $SWSS_VARS | jq -r '.asic_id') if [ -n "$asic_id" ] then ORCHAGENT_ARGS+="-i $asic_id " @@ -51,7 +59,7 @@ elif [ "$platform" == "mellanox" ]; then elif [ "$platform" == "innovium" ]; then ORCHAGENT_ARGS+="-m $MAC_ADDRESS" else - MAC_ADDRESS=`sonic-cfggen -d -v 'DEVICE_METADATA.localhost.mac'` + # Should we use the fallback MAC in case it is not found in Device.Metadata ORCHAGENT_ARGS+="-m $MAC_ADDRESS" fi diff --git a/dockers/docker-orchagent/swss_vars.j2 b/dockers/docker-orchagent/swss_vars.j2 new file mode 100644 index 0000000000..0a0b2712f4 --- /dev/null +++ b/dockers/docker-orchagent/swss_vars.j2 @@ -0,0 +1,6 @@ +{ + "asic_type": "{{ asic_type }}", + "asic_id": "{{ DEVICE_METADATA.localhost.asic_id }}", + "mac": "{{ DEVICE_METADATA.localhost.mac }}" +} +