Skip to content

Commit bb60e2b

Browse files
committed
Changes to support config-setup service for multi-npu (#4609)
* Changes to support config-setup service for multi-npu platforms. For Multi-npu we are not supporting as of now config initializtion and ZTP. It will support creating config db from minigraph or using config db from previous file system Signed-off-by: Abhishek Dosi <[email protected]> * Address Review Comments. * Address Review comments * Address Review Comments of using pyhton based config load_minigraph/ 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. * Updated to use python command so no code duplication.
1 parent 7bd7756 commit bb60e2b

File tree

2 files changed

+66
-46
lines changed

2 files changed

+66
-46
lines changed

files/image_config/config-setup/config-setup

+64-26
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@
2626

2727
# Initialize constants
2828
UPDATEGRAPH_CONF=/etc/sonic/updategraph.conf
29+
INIT_CFG_JSON=/etc/sonic/init_cfg.json
2930
CONFIG_DB_JSON=/etc/sonic/config_db.json
31+
CONFIG_DB_PATH=/etc/sonic/
32+
CONFIG_DB_PREFIX=config_db
33+
CONFIG_DB_SUFFIX=.json
3034
MINGRAPH_FILE=/etc/sonic/minigraph.xml
3135
TMP_ZTP_CONFIG_DB_JSON=/tmp/ztp_config_db.json
3236
FACTORY_DEFAULT_HOOKS=/etc/config-setup/factory-default-hooks.d
@@ -103,24 +107,16 @@ run_hookdir() {
103107
reload_minigraph()
104108
{
105109
echo "Reloading minigraph..."
106-
if [ ! -f /etc/sonic/init_cfg.json ]; then
107-
echo "{}" > /etc/sonic/init_cfg.json
108-
fi
109-
sonic-db-cli CONFIG_DB FLUSHDB
110-
sonic-cfggen -H -m -j /etc/sonic/init_cfg.json --write-to-db
111-
sonic-db-cli CONFIG_DB SET "CONFIG_DB_INITIALIZED" "1"
112-
if [ -f /etc/sonic/acl.json ]; then
113-
acl-loader update full /etc/sonic/acl.json
114-
fi
115-
config qos reload
116-
pfcwd start_default
117-
118-
if [[ -x /usr/bin/db_migrator.py ]]; then
119-
# Set latest version number
120-
/usr/bin/db_migrator.py -o set_version
121-
fi
110+
config load_minigraph -y -n
111+
config save -y
122112
}
123113

114+
# Reload exisitng config db file on disk
115+
reload_configdb()
116+
{
117+
echo "Reloading existing config db..."
118+
config reload -y -n
119+
}
124120
# Restore SONiC configuration from a backup copy
125121
function copy_config_files_and_directories()
126122
{
@@ -281,15 +277,49 @@ copy_post_migration_hooks()
281277
fi
282278
}
283279

280+
# Get the list of config db for both
281+
# single and multi-npu platforms
282+
get_config_db_file_list()
283+
{
284+
config_db_file_list=${CONFIG_DB_PREFIX}${CONFIG_DB_SUFFIX}
285+
asic_num=0
286+
while [[ ($asic_num -lt $NUM_ASIC) && ($NUM_ASIC -gt 1) ]]; do
287+
config_db_file_list+=' '${CONFIG_DB_PREFIX}$asic_num${CONFIG_DB_SUFFIX}
288+
((asic_num = asic_num + 1))
289+
done
290+
291+
echo $config_db_file_list
292+
}
293+
# Check if all needed config db are prsesnt for both
294+
# single and multi-npu platforms
295+
check_all_config_db_present()
296+
{
297+
if [[ ! -r ${CONFIG_DB_JSON} ]]; then
298+
return 1
299+
fi
300+
asic_num=0
301+
while [[ ($asic_num -lt $NUM_ASIC) && ($NUM_ASIC -gt 1) ]]; do
302+
if [[ ! -r ${CONFIG_DB_PATH}${CONFIG_DB_PREFIX}$asic_num${CONFIG_DB_SUFFIX} ]]; then
303+
return 1
304+
fi
305+
((asic_num = asic_num + 1))
306+
done
307+
308+
return 0
309+
}
310+
284311
# Perform configuration migration from backup copy.
285312
# - This step is performed when a new image is installed and SONiC switch boots into it
286313
do_config_migration()
287314
{
288315
# Identify list of files to migrate
289-
copy_list="minigraph.xml snmp.yml acl.json config_db.json frr"
316+
copy_list="minigraph.xml snmp.yml acl.json frr"
290317

291318
# Migrate all configuration files from old to new
292319
copy_config_files_and_directories $copy_list
320+
321+
# Migrate all config_db from old to new
322+
copy_config_files_and_directories $(get_config_db_file_list)
293323

294324
# Migrate post-migration hooks
295325
copy_post_migration_hooks
@@ -302,21 +332,14 @@ do_config_migration()
302332
disable_updategraph
303333
rm -f /tmp/pending_config_migration
304334
exit 0
305-
elif [ -r ${CONFIG_DB_JSON} ]; then
335+
elif check_all_config_db_present; then
306336
echo "Use config_db.json from old system..."
307-
sonic-cfggen -j ${CONFIG_DB_JSON} --write-to-db
308-
309-
if [[ -x /usr/bin/db_migrator.py ]]; then
310-
# Migrate the DB to the latest schema version if needed
311-
/usr/bin/db_migrator.py -o migrate
312-
fi
337+
reload_configdb
313338
# Disable updategraph
314339
disable_updategraph
315340
elif [ -r ${MINGRAPH_FILE} ]; then
316341
echo "Use minigraph.xml from old system..."
317342
reload_minigraph
318-
sonic-cfggen -d --print-data > ${CONFIG_DB_JSON}
319-
320343
# Disable updategraph
321344
disable_updategraph
322345
else
@@ -351,6 +374,14 @@ boot_config()
351374
do_config_migration
352375
fi
353376

377+
# For multi-npu platfrom we don't support config initlaiztion. Assumption
378+
# is there should be existing minigraph or config_db from previous image
379+
# file system to trigger. pending_config_initialization will remain set
380+
# for multi-npu platforms if we reach this case.
381+
if [[ ($NUM_ASIC -gt 1) ]]; then
382+
return 0
383+
fi
384+
354385
if [ -e /tmp/pending_config_initialization ] || [ -e ${CONFIG_SETUP_INITIALIZATION_FLAG} ]; then
355386
do_config_initialization
356387
fi
@@ -373,6 +404,13 @@ boot_config()
373404
}
374405

375406
### Execution starts here ###
407+
PLATFORM=`sonic-cfggen -H -v DEVICE_METADATA.localhost.platform`
408+
# Parse the device specific asic conf file, if it exists
409+
ASIC_CONF=/usr/share/sonic/device/$PLATFORM/asic.conf
410+
if [[ -f "$ASIC_CONF" ]]; then
411+
source $ASIC_CONF
412+
fi
413+
376414

377415
CMD=$1
378416
# Default command is boot

files/image_config/updategraph/updategraph

+2-20
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,8 @@
33
reload_minigraph()
44
{
55
echo "Reloading minigraph..."
6-
if [ ! -f /etc/sonic/init_cfg.json ]; then
7-
echo "{}" > /etc/sonic/init_cfg.json
8-
fi
9-
sonic-db-cli CONFIG_DB FLUSHDB
10-
sonic-cfggen -H -m -j /etc/sonic/init_cfg.json --write-to-db
11-
sonic-db-cli CONFIG_DB SET "CONFIG_DB_INITIALIZED" "1"
12-
if [ -f /etc/sonic/acl.json ]; then
13-
acl-loader update full /etc/sonic/acl.json
14-
fi
15-
config qos reload
16-
DEVICE_TYPE=`sonic-cfggen -m -v DEVICE_METADATA.localhost.type`
17-
if [ "${DEVICE_TYPE}" != "MgmtToRRouter" ]; then
18-
pfcwd start_default
19-
fi
20-
21-
if [[ -x /usr/bin/db_migrator.py ]]; then
22-
# Set latest version number
23-
/usr/bin/db_migrator.py -o set_version
24-
fi
6+
config load_minigraph -y -n
7+
config save -y
258
}
269

2710
if [ ! -f /etc/sonic/updategraph.conf ]; then
@@ -141,7 +124,6 @@ else
141124
fi
142125

143126
reload_minigraph
144-
sonic-cfggen -d --print-data > /etc/sonic/config_db.json
145127

146128
# Mark as disabled after graph is successfully downloaded
147129
sed -i "/enabled=/d" /etc/sonic/updategraph.conf

0 commit comments

Comments
 (0)