[docker-orchagent] Call sonic-cfggen Once (#4936)

Optimizing number of calls made to sonic-cfggen during service
start up as it adds to total system boot up time.

signed-off-by: Tamer Ahmed <tamer.ahmed@microsoft.com>

**- Why I did it**
sonic-cfggen call is slow and it adds to system start up time

**- How I did it**
places all required variable into single template and called into sonic-cfggen using this template

**- How to verify it**
***-Test 1***
there is an average saving of .5 to 1 sec between old script and new script
```
root@str-s6000-acs-14:/# time ./orchagent_old.sh
/usr/bin/orchagent -d /var/log/swss -b 8192 -m f4:8e:38:16:bc:8d

real	0m3.546s
user	0m2.365s
sys	0m0.585s

root@str-s6000-acs-14:/# time ./orchagent_new.sh
/usr/bin/orchagent -d /var/log/swss -b 8192 -m f4:8e:38:16:bc:8d

real	0m2.058s
user	0m1.650s
sys	0m0.363s
```
***-Test 2***
Built an image with this change and orchagent is running with intended params:
```
admin@str-s6000-acs-14:~$ ps -ef | grep orchagent
root      2988  1901  1 02:09 pts/0    00:00:02 /usr/bin/orchagent -d /var/log/swss -b 8192 -m f4:8e:38:16:bc:8d
```

signed-off-by: Tamer Ahmed <tamer.ahmed@microsoft.com>
This commit is contained in:
Tamer Ahmed 2020-07-14 15:36:47 -07:00 committed by Abhishek Dosi
parent dd26117bf2
commit 755319c37c
2 changed files with 20 additions and 6 deletions

View File

@ -1,10 +1,18 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# Export platform information. Required to be able to write EXIT_SWSS_VARS_FILE_NOT_FOUND=1
# vendor specific code. SWSS_VARS_FILE=/usr/share/sonic/templates/swss_vars.j2
export platform=`sonic-cfggen -y /etc/sonic/sonic_version.yml -v asic_type`
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 if [ "$MAC_ADDRESS" == "None" ] || [ -z "$MAC_ADDRESS" ]; then
MAC_ADDRESS=$(ip link show eth0 | grep ether | awk '{print $2}') MAC_ADDRESS=$(ip link show eth0 | grep ether | awk '{print $2}')
logger "Mac address not found in Device Metadata, Falling back to eth0" 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... # 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" # OR could be PCI device ID's which will be strings like "03:00.0"
# depending on what the SAI/SDK expects. # 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" ] if [ -n "$asic_id" ]
then then
ORCHAGENT_ARGS+="-i $asic_id " ORCHAGENT_ARGS+="-i $asic_id "
@ -54,7 +62,7 @@ elif [ "$platform" == "mellanox" ]; then
elif [ "$platform" == "innovium" ]; then elif [ "$platform" == "innovium" ]; then
ORCHAGENT_ARGS+="-m $MAC_ADDRESS" ORCHAGENT_ARGS+="-m $MAC_ADDRESS"
else 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" ORCHAGENT_ARGS+="-m $MAC_ADDRESS"
fi fi

View File

@ -0,0 +1,6 @@
{
"asic_type": "{{ asic_type }}",
"asic_id": "{{ DEVICE_METADATA.localhost.asic_id }}",
"mac": "{{ DEVICE_METADATA.localhost.mac }}"
}