Skip to content

Commit

Permalink
Address Review Comments of using pyhton based config load_minigraph/
Browse files Browse the repository at this point in the history
config save/config reload from shell scripts so that we don't duplicate
code. Also while running from shell we will skip stop/start services
done by those commands.
  • Loading branch information
abdosi committed May 20, 2020
1 parent d0f07b0 commit 2a64192
Showing 1 changed file with 3 additions and 104 deletions.
107 changes: 3 additions & 104 deletions files/image_config/config-setup/config-setup
Original file line number Diff line number Diff line change
Expand Up @@ -103,117 +103,19 @@ run_hookdir() {
return $exit_status
}

initalize_configdb()
{
NAMESPACE_ARGUMENT=''
IP_NETNS_CMD=''
# Create correct argument based on per-asic name space in multi-npu platforms
if [[ $# -eq 2 ]]; then
NAMESPACE_ARGUMENT=${NAMESPACE_OPTION}${NAMESPACE_PREFIX}$2
IP_NETNS_CMD=${IP_NETNS_CMD_PREFIX}${NAMESPACE_PREFIX}$2
fi

if [[ "$1" == "init" ]]; then
# case when config db need to be created/initialized from minigraph
sonic-db-cli ${NAMESPACE_ARGUMENT} CONFIG_DB FLUSHDB
sonic-cfggen -H -m -j ${INIT_CFG_JSON} ${NAMESPACE_ARGUMENT} --write-to-db
sonic-db-cli ${NAMESPACE_ARGUMENT} CONFIG_DB SET "CONFIG_DB_INITIALIZED" "1"
sonic-cfggen ${NAMESPACE_ARGUMENT} -d --print-data > ${CONFIG_DB_PATH}${CONFIG_DB_PREFIX}$2${CONFIG_DB_SUFFIX}
if [[ ($NUM_ASIC -gt 1) && ($# -eq 1) ]]; then
return 0
fi
# this will be run only in per-asic namespace only in multi-npu platforms
${IP_NETNS_CMD} config qos reload
${IP_NETNS_CMD} pfcwd start_default
elif [[ "$1" == "reload" ]]; then
# case when config db is already present from previous image file system
sonic-cfggen ${NAMESPACE_ARGUMENT} -j ${CONFIG_DB_PATH}${CONFIG_DB_PREFIX}$2${CONFIG_DB_SUFFIX} --write-to-db
fi

return 0
}
configdb_migrator()
{
NAMESPACE_ARGUMENT=''
# Create correct argument based on per-asic name space in multi-npu platforms
if [[ $# -eq 2 ]]; then
NAMESPACE_ARGUMENT=${NAMESPACE_OPTION}${NAMESPACE_PREFIX}$2
fi

if [[ "$1" == "init" ]]; then
# case when config db created/initialized from minigraph need to be migrated
if [[ -x /usr/bin/db_migrator.py ]]; then
# Set latest version number
/usr/bin/db_migrator.py ${NAMESPACE_ARGUMENT} -o set_version
fi
elif [[ "$1" == "reload" ]]; then
# case when config db is already present from previous image file system
# need to be migrated
if [[ -x /usr/bin/db_migrator.py ]]; then
# Migrate the DB to the latest schema version if needed
/usr/bin/db_migrator.py ${NAMESPACE_ARGUMENT} -o migrate
fi
fi
}

# Reload minigraph.xml file on disk
reload_minigraph()
{
echo "Reloading minigraph..."
if [ ! -f /etc/sonic/init_cfg.json ]; then
echo "{}" > /etc/sonic/init_cfg.json
fi

# Initialize config db for single-npu platform and global config db for multi-npu
# platforms
initalize_configdb init
asic_num=0
while [[ ($asic_num -lt $NUM_ASIC) && ($NUM_ASIC -gt 1) ]]; do
# Intiialize per asic/namespace config db
initalize_configdb init $asic_num
((asic_num = asic_num + 1))
done
if [[ -f /etc/sonic/acl.json ]]; then
# For acl the acl-loader command takes care for multi-npu platforms
acl-loader update full /etc/sonic/acl.json
fi

# Initialize config db migrator for single-npu platform and global config db for multi-npu
# platforms
configdb_migrator init
asic_num=0
while [[ ($asic_num -lt $NUM_ASIC) && ($NUM_ASIC -gt 1) ]]; do
# Initialize config db migrator for per-asic namespace config db
# in multi-npu platforms
configdb_migrator init $asic_num
((asic_num = asic_num + 1))
done
config load_minigraph -y -n
config save -y
}

# Reload exisitng config db file on disk
reload_configdb()
{
echo "Reloading existing config db..."
# Reload existing config db for single-npu platform and global config db for multi-npu
# platforms
initalize_configdb reload
asic_num=0
while [[ ($asic_num -lt $NUM_ASIC) && ($NUM_ASIC -gt 1) ]]; do
# Reload exisitng per asic/namespace config db
initalize_configdb reload $asic_num
((asic_num = asic_num + 1))
done

# Initialize existing config db migrator for single-npu platform and global config db for multi-npu
# platforms
configdb_migrator reload
asic_num=0
while [[ ($asic_num -lt $NUM_ASIC) && ($NUM_ASIC -gt 1) ]]; do
# Initialize existing config db migrator for single-npu platform and global config db for multi-npu
# platforms
configdb_migrator reload $asic_num
((asic_num = asic_num + 1))
done
config reload -y -n
}
# Restore SONiC configuration from a backup copy
function copy_config_files_and_directories()
Expand Down Expand Up @@ -509,9 +411,6 @@ if [[ -f "$ASIC_CONF" ]]; then
source $ASIC_CONF
fi

NAMESPACE_OPTION='-n '
NAMESPACE_PREFIX='asic'
IP_NETNS_CMD_PREFIX='sudo ip netns exec '

CMD=$1
# Default command is boot
Expand Down

0 comments on commit 2a64192

Please sign in to comment.