26
26
27
27
# Initialize constants
28
28
UPDATEGRAPH_CONF=/etc/sonic/updategraph.conf
29
+ INIT_CFG_JSON=/etc/sonic/init_cfg.json
29
30
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
30
34
MINGRAPH_FILE=/etc/sonic/minigraph.xml
31
35
TMP_ZTP_CONFIG_DB_JSON=/tmp/ztp_config_db.json
32
36
FACTORY_DEFAULT_HOOKS=/etc/config-setup/factory-default-hooks.d
@@ -103,24 +107,16 @@ run_hookdir() {
103
107
reload_minigraph ()
104
108
{
105
109
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
122
112
}
123
113
114
+ # Reload exisitng config db file on disk
115
+ reload_configdb ()
116
+ {
117
+ echo " Reloading existing config db..."
118
+ config reload -y -n
119
+ }
124
120
# Restore SONiC configuration from a backup copy
125
121
function copy_config_files_and_directories()
126
122
{
@@ -281,15 +277,49 @@ copy_post_migration_hooks()
281
277
fi
282
278
}
283
279
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
+
284
311
# Perform configuration migration from backup copy.
285
312
# - This step is performed when a new image is installed and SONiC switch boots into it
286
313
do_config_migration ()
287
314
{
288
315
# 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"
290
317
291
318
# Migrate all configuration files from old to new
292
319
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)
293
323
294
324
# Migrate post-migration hooks
295
325
copy_post_migration_hooks
@@ -302,21 +332,14 @@ do_config_migration()
302
332
disable_updategraph
303
333
rm -f /tmp/pending_config_migration
304
334
exit 0
305
- elif [ -r ${CONFIG_DB_JSON} ] ; then
335
+ elif check_all_config_db_present ; then
306
336
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
313
338
# Disable updategraph
314
339
disable_updategraph
315
340
elif [ -r ${MINGRAPH_FILE} ]; then
316
341
echo " Use minigraph.xml from old system..."
317
342
reload_minigraph
318
- sonic-cfggen -d --print-data > ${CONFIG_DB_JSON}
319
-
320
343
# Disable updategraph
321
344
disable_updategraph
322
345
else
@@ -351,6 +374,14 @@ boot_config()
351
374
do_config_migration
352
375
fi
353
376
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
+
354
385
if [ -e /tmp/pending_config_initialization ] || [ -e ${CONFIG_SETUP_INITIALIZATION_FLAG} ]; then
355
386
do_config_initialization
356
387
fi
@@ -373,6 +404,13 @@ boot_config()
373
404
}
374
405
375
406
# ## 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
+
376
414
377
415
CMD=$1
378
416
# Default command is boot
0 commit comments