From 7a200493de2d9e5dd881d9a79b6b757bce88d84e Mon Sep 17 00:00:00 2001 From: Stepan Blyschak Date: Tue, 21 Nov 2023 17:48:10 +0200 Subject: [PATCH] [config-chassisdb] use cached variables No cache: ``` root@arc-switch1004:/home/admin# time bash -x /usr/bin/config-chassisdb + config_chassis_db + startdb_file=/etc/sonic/chassisdb.conf + '[' '!' -e /etc/sonic/chassisdb.conf ']' ++ sonic-cfggen -H -v DEVICE_METADATA.localhost.platform + platform=x86_64-mlnx_msn2700-r0 + chassis_config=/usr/share/sonic/device/x86_64-mlnx_msn2700-r0/chassisdb.conf + '[' '!' -e /usr/share/sonic/device/x86_64-mlnx_msn2700-r0/chassisdb.conf ']' + echo 'no chassisdb.conf found, bypass config-chassisdb service' no chassisdb.conf found, bypass config-chassisdb service + exit 0 real 0m0.512s user 0m0.429s sys 0m0.058s ``` With cache: ``` root@arc-switch1004:/home/admin# time bash -x /usr/bin/config-chassisdb + '[' -f /etc/sonic/sonic-environment ']' + . /etc/sonic/sonic-environment ++ SONIC_VERSION=202305_RC.32-da745b71d_Internal ++ PLATFORM=x86_64-mlnx_msn2700-r0 ++ HWSKU=Mellanox-SN2700-D48C8 ++ DEVICE_TYPE=ToRRouter ++ ASIC_TYPE=mellanox + config_chassis_db + startdb_file=/etc/sonic/chassisdb.conf + '[' '!' -e /etc/sonic/chassisdb.conf ']' + platform=x86_64-mlnx_msn2700-r0 + chassis_config=/usr/share/sonic/device/x86_64-mlnx_msn2700-r0/chassisdb.conf + '[' '!' -e /usr/share/sonic/device/x86_64-mlnx_msn2700-r0/chassisdb.conf ']' + echo 'no chassisdb.conf found, bypass config-chassisdb service' no chassisdb.conf found, bypass config-chassisdb service + exit 0 real 0m0.017s user 0m0.005s sys 0m0.008s ``` Signed-off-by: Stepan Blyschak --- files/image_config/config-chassisdb/config-chassisdb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/files/image_config/config-chassisdb/config-chassisdb b/files/image_config/config-chassisdb/config-chassisdb index 3bdcf0a0fbe2..f64443b274f3 100755 --- a/files/image_config/config-chassisdb/config-chassisdb +++ b/files/image_config/config-chassisdb/config-chassisdb @@ -27,7 +27,7 @@ config_chassis_db() { startdb_file="/etc/sonic/chassisdb.conf" [ ! -e $startdb_file ] || rm $startdb_file - platform=$(sonic-cfggen -H -v DEVICE_METADATA.localhost.platform) + platform=${PLATFORM:-`sonic-cfggen -H -v DEVICE_METADATA.localhost.platform`} # database-chassis services will start when $chassis_config file exists chassis_config="/usr/share/sonic/device/$platform/chassisdb.conf" if [ ! -e $chassis_config ]; then @@ -54,6 +54,9 @@ config_chassis_db() { fi } +# read SONiC immutable variables +[ -f /etc/sonic/sonic-environment ] && . /etc/sonic/sonic-environment + config_chassis_db exit 0