From c370285fdbc1374fa20bdbd0d19e83cfb43b831f Mon Sep 17 00:00:00 2001 From: Yong Zhao Date: Thu, 13 Feb 2020 14:43:31 -0800 Subject: [PATCH 1/4] [sonic-cfggen] Change the configuration file loading orders and first loading the init_cfg.json and then loading config_db.json. Signed-off-by: Yong Zhao --- files/build_templates/docker_image_ctl.j2 | 2 +- files/image_config/config-setup/config-setup | 2 +- files/image_config/updategraph/updategraph | 2 +- files/scripts/configdb-load.sh | 2 +- platform/p4/docker-sonic-p4/start.sh | 2 +- platform/vs/docker-sonic-vs/start.sh | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/files/build_templates/docker_image_ctl.j2 b/files/build_templates/docker_image_ctl.j2 index 2777a26c8edf..b4a59ed37f79 100644 --- a/files/build_templates/docker_image_ctl.j2 +++ b/files/build_templates/docker_image_ctl.j2 @@ -108,7 +108,7 @@ function postStartAction() else # If there is a config db dump file, load it if [ -r /etc/sonic/config_db.json ]; then - sonic-cfggen -j /etc/sonic/config_db.json --write-to-db + sonic-cfggen -j /etc/sonic/init_cfg.json -j /etc/sonic/config_db.json --write-to-db fi if [[ "$BOOT_TYPE" == "fast" ]]; then diff --git a/files/image_config/config-setup/config-setup b/files/image_config/config-setup/config-setup index f19abd266e95..2e7c10a3087c 100755 --- a/files/image_config/config-setup/config-setup +++ b/files/image_config/config-setup/config-setup @@ -107,7 +107,7 @@ reload_minigraph() echo "{}" > /etc/sonic/init_cfg.json fi sonic-db-cli CONFIG_DB FLUSHDB - sonic-cfggen -H -m -j /etc/sonic/init_cfg.json --write-to-db + sonic-cfggen -H -j /etc/sonic/init_cfg.json -m --write-to-db sonic-db-cli CONFIG_DB SET "CONFIG_DB_INITIALIZED" "1" if [ -f /etc/sonic/acl.json ]; then acl-loader update full /etc/sonic/acl.json diff --git a/files/image_config/updategraph/updategraph b/files/image_config/updategraph/updategraph index a24d452b1ad2..36c2a44f2b1d 100755 --- a/files/image_config/updategraph/updategraph +++ b/files/image_config/updategraph/updategraph @@ -7,7 +7,7 @@ reload_minigraph() echo "{}" > /etc/sonic/init_cfg.json fi sonic-db-cli CONFIG_DB FLUSHDB - sonic-cfggen -H -m -j /etc/sonic/init_cfg.json --write-to-db + sonic-cfggen -H -j /etc/sonic/init_cfg.json -m --write-to-db sonic-db-cli CONFIG_DB SET "CONFIG_DB_INITIALIZED" "1" if [ -f /etc/sonic/acl.json ]; then acl-loader update full /etc/sonic/acl.json diff --git a/files/scripts/configdb-load.sh b/files/scripts/configdb-load.sh index e7080eb40f3d..ba4d0f2d53d1 100755 --- a/files/scripts/configdb-load.sh +++ b/files/scripts/configdb-load.sh @@ -7,7 +7,7 @@ done # If there is a config db dump file, load it if [ -r /etc/sonic/config_db.json ]; then - sonic-cfggen -j /etc/sonic/config_db.json --write-to-db + sonic-cfggen -j /etc/sonic/init_cfg.json -j /etc/sonic/config_db.json --write-to-db fi sonic-db-cli CONFIG_DB SET "CONFIG_DB_INITIALIZED" "1" diff --git a/platform/p4/docker-sonic-p4/start.sh b/platform/p4/docker-sonic-p4/start.sh index c9cf4528bedd..e3251bb2f4e5 100755 --- a/platform/p4/docker-sonic-p4/start.sh +++ b/platform/p4/docker-sonic-p4/start.sh @@ -11,7 +11,7 @@ SYSTEM_MAC_ADDRESS=$(ip link show eth0 | grep ether | awk '{print $2}') sonic-cfggen -a '{"DEVICE_METADATA":{"localhost": {"mac": "'$SYSTEM_MAC_ADDRESS'"}}}' --print-data > /etc/sonic/init_cfg.json if [ -f /etc/sonic/config_db.json ]; then - sonic-cfggen -j /etc/sonic/config_db.json -j /etc/sonic/init_cfg.json --print-data > /tmp/config_db.json + sonic-cfggen -j /etc/sonic/init_cfg.json -j /etc/sonic/config_db.json --print-data > /tmp/config_db.json mv /tmp/config_db.json /etc/sonic/config_db.json else sonic-cfggen -j /etc/sonic/init_cfg.json --print-data > /etc/sonic/config_db.json diff --git a/platform/vs/docker-sonic-vs/start.sh b/platform/vs/docker-sonic-vs/start.sh index dd9fee4deb3d..f8fcf974b65c 100755 --- a/platform/vs/docker-sonic-vs/start.sh +++ b/platform/vs/docker-sonic-vs/start.sh @@ -13,7 +13,7 @@ SYSTEM_MAC_ADDRESS=$(ip link show eth0 | grep ether | awk '{print $2}') sonic-cfggen -a '{"DEVICE_METADATA":{"localhost": {"mac": "'$SYSTEM_MAC_ADDRESS'"}}}' --print-data > /etc/sonic/init_cfg.json if [ -f /etc/sonic/config_db.json ]; then - sonic-cfggen -j /etc/sonic/config_db.json -j /etc/sonic/init_cfg.json --print-data > /tmp/config_db.json + sonic-cfggen -j /etc/sonic/init_cfg.json -j /etc/sonic/config_db.json --print-data > /tmp/config_db.json mv /tmp/config_db.json /etc/sonic/config_db.json else # generate and merge buffers configuration into config file From 807ed8a2db0b3b5ee98b61844c4465de9a4c1a3a Mon Sep 17 00:00:00 2001 From: Yong Zhao Date: Thu, 13 Feb 2020 18:06:00 -0800 Subject: [PATCH 2/4] [sonic-cfggen] Undo the changes for the command sonic-cfggen -H -m -j /etc/sonic/init_cfg.json. Signed-off-by: Yong Zhao --- files/image_config/config-setup/config-setup | 2 +- files/image_config/updategraph/updategraph | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/files/image_config/config-setup/config-setup b/files/image_config/config-setup/config-setup index 2e7c10a3087c..f19abd266e95 100755 --- a/files/image_config/config-setup/config-setup +++ b/files/image_config/config-setup/config-setup @@ -107,7 +107,7 @@ reload_minigraph() echo "{}" > /etc/sonic/init_cfg.json fi sonic-db-cli CONFIG_DB FLUSHDB - sonic-cfggen -H -j /etc/sonic/init_cfg.json -m --write-to-db + sonic-cfggen -H -m -j /etc/sonic/init_cfg.json --write-to-db sonic-db-cli CONFIG_DB SET "CONFIG_DB_INITIALIZED" "1" if [ -f /etc/sonic/acl.json ]; then acl-loader update full /etc/sonic/acl.json diff --git a/files/image_config/updategraph/updategraph b/files/image_config/updategraph/updategraph index 36c2a44f2b1d..a24d452b1ad2 100755 --- a/files/image_config/updategraph/updategraph +++ b/files/image_config/updategraph/updategraph @@ -7,7 +7,7 @@ reload_minigraph() echo "{}" > /etc/sonic/init_cfg.json fi sonic-db-cli CONFIG_DB FLUSHDB - sonic-cfggen -H -j /etc/sonic/init_cfg.json -m --write-to-db + sonic-cfggen -H -m -j /etc/sonic/init_cfg.json --write-to-db sonic-db-cli CONFIG_DB SET "CONFIG_DB_INITIALIZED" "1" if [ -f /etc/sonic/acl.json ]; then acl-loader update full /etc/sonic/acl.json From 4828153e3eec1de82b8deb2b7a45fb0f3a7c2083 Mon Sep 17 00:00:00 2001 From: Yong Zhao Date: Mon, 2 Mar 2020 11:36:09 -0800 Subject: [PATCH 3/4] [sonic_cfggen] Add a logic to determine whether the files config_db.json and init_cfg.json are existing. Otherwise sonic-cfggen will only load one of them if it does exist. Signed-off-by: Yong Zhao --- files/build_templates/docker_image_ctl.j2 | 9 +++++++-- files/scripts/configdb-load.sh | 9 +++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/files/build_templates/docker_image_ctl.j2 b/files/build_templates/docker_image_ctl.j2 index b4a59ed37f79..4872b385de1f 100644 --- a/files/build_templates/docker_image_ctl.j2 +++ b/files/build_templates/docker_image_ctl.j2 @@ -106,9 +106,14 @@ function postStartAction() if [[ ("$BOOT_TYPE" == "warm" || "$BOOT_TYPE" == "fastfast") && -f $WARM_DIR/dump.rdb ]]; then rm -f $WARM_DIR/dump.rdb else - # If there is a config db dump file, load it - if [ -r /etc/sonic/config_db.json ]; then + # If there are init_cfg.json and config_db.json dump files, load them. Otherwise + # loading one of them if it exists. + if [[ -r /etc/sonic/init_cfg.json ]] && [[ -r /etc/sonic/config_db.json ]]; then sonic-cfggen -j /etc/sonic/init_cfg.json -j /etc/sonic/config_db.json --write-to-db + elif [ -r /etc/sonic/init_cfg.json ]; then + sonic-cfggen -j /etc/sonic/init_cfg.json --write-to-db + elif [ -r /etc/sonic/config_db.json ]; then + sonic-cfggen -j /etc/sonic/config_db.json --write-to-db fi if [[ "$BOOT_TYPE" == "fast" ]]; then diff --git a/files/scripts/configdb-load.sh b/files/scripts/configdb-load.sh index ba4d0f2d53d1..bf0890177fb6 100755 --- a/files/scripts/configdb-load.sh +++ b/files/scripts/configdb-load.sh @@ -5,9 +5,14 @@ until [[ $(redis-cli ping | grep -c PONG) -gt 0 ]]; do sleep 1; done -# If there is a config db dump file, load it -if [ -r /etc/sonic/config_db.json ]; then +# If there are init_cfg.json and config_db.json dump files, load them. Otherwise, +# loading one of them if it exists. +if [[ -r /etc/sonic/init_cfg.json ]] && [[ -r /etc/sonic/config_db.json ]]; then sonic-cfggen -j /etc/sonic/init_cfg.json -j /etc/sonic/config_db.json --write-to-db +elif [ -r /etc/sonic/init_cfg.json ]; then + sonic-cfggen -j /etc/sonic/init_cfg.json --write-to-db +elif [ -r /etc/sonic/config_db.json ]; then + sonic-cfggen -j /etc/sonic/config_db.json --write-to-db fi sonic-db-cli CONFIG_DB SET "CONFIG_DB_INITIALIZED" "1" From 9d3104c45b9621be31d730fe63aa842bd4ba9c51 Mon Sep 17 00:00:00 2001 From: Yong Zhao Date: Mon, 2 Mar 2020 12:04:31 -0800 Subject: [PATCH 4/4] [sonic-cfggen] Change the logic at line 111 if init_cfg.json and config_db.json exit, we will load them. Otherwise we only load config_db.json. Signed-off-by: Yong Zhao --- files/build_templates/docker_image_ctl.j2 | 15 +++++++-------- files/scripts/configdb-load.sh | 15 +++++++-------- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/files/build_templates/docker_image_ctl.j2 b/files/build_templates/docker_image_ctl.j2 index 4872b385de1f..995e9f2391e4 100644 --- a/files/build_templates/docker_image_ctl.j2 +++ b/files/build_templates/docker_image_ctl.j2 @@ -106,14 +106,13 @@ function postStartAction() if [[ ("$BOOT_TYPE" == "warm" || "$BOOT_TYPE" == "fastfast") && -f $WARM_DIR/dump.rdb ]]; then rm -f $WARM_DIR/dump.rdb else - # If there are init_cfg.json and config_db.json dump files, load them. Otherwise - # loading one of them if it exists. - if [[ -r /etc/sonic/init_cfg.json ]] && [[ -r /etc/sonic/config_db.json ]]; then - sonic-cfggen -j /etc/sonic/init_cfg.json -j /etc/sonic/config_db.json --write-to-db - elif [ -r /etc/sonic/init_cfg.json ]; then - sonic-cfggen -j /etc/sonic/init_cfg.json --write-to-db - elif [ -r /etc/sonic/config_db.json ]; then - sonic-cfggen -j /etc/sonic/config_db.json --write-to-db + # If there is a config_db.json dump file, load it. + if [ -r /etc/sonic/config_db.json ]; then + if [ -r /etc/sonic/init_cfg.json ]; then + sonic-cfggen -j /etc/sonic/init_cfg.json -j /etc/sonic/config_db.json --write-to-db + else + sonic-cfggen -j /etc/sonic/config_db.json --write-to-db + fi fi if [[ "$BOOT_TYPE" == "fast" ]]; then diff --git a/files/scripts/configdb-load.sh b/files/scripts/configdb-load.sh index bf0890177fb6..b1bf761371bf 100755 --- a/files/scripts/configdb-load.sh +++ b/files/scripts/configdb-load.sh @@ -5,14 +5,13 @@ until [[ $(redis-cli ping | grep -c PONG) -gt 0 ]]; do sleep 1; done -# If there are init_cfg.json and config_db.json dump files, load them. Otherwise, -# loading one of them if it exists. -if [[ -r /etc/sonic/init_cfg.json ]] && [[ -r /etc/sonic/config_db.json ]]; then - sonic-cfggen -j /etc/sonic/init_cfg.json -j /etc/sonic/config_db.json --write-to-db -elif [ -r /etc/sonic/init_cfg.json ]; then - sonic-cfggen -j /etc/sonic/init_cfg.json --write-to-db -elif [ -r /etc/sonic/config_db.json ]; then - sonic-cfggen -j /etc/sonic/config_db.json --write-to-db +# If there is a config_db.json dump file, load it. +if [ -r /etc/sonic/config_db.json ]; then + if [ -r /etc/sonic/init_cfg.json ]; then + sonic-cfggen -j /etc/sonic/init_cfg.json -j /etc/sonic/config_db.json --write-to-db + else + sonic-cfggen -j /etc/sonic/config_db.json --write-to-db + fi fi sonic-db-cli CONFIG_DB SET "CONFIG_DB_INITIALIZED" "1"