Skip to content

Commit 215cb7b

Browse files
committed
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]>
1 parent 9814da1 commit 215cb7b

File tree

1 file changed

+166
-20
lines changed

1 file changed

+166
-20
lines changed

files/image_config/config-setup/config-setup

+166-20
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
@@ -99,28 +103,123 @@ run_hookdir() {
99103
return $exit_status
100104
}
101105

106+
initalize_configdb()
107+
{
108+
# Create correct argument based on per-asic name space in multi-npu platforms
109+
if [[ ! -z "$2" ]]; then
110+
NAMESPACE_ARGUMENT=${NAMESPACE_OPTION}${NAMESPACE_PREFIX}$2
111+
IP_NETNS_CMD=${IP_NETNS_CMD_PREFIX}${NAMESPACE_PREFIX}$2
112+
else
113+
NAMESPACE_ARGUMENT=$2
114+
IP_NETNS_CMD=$2
115+
fi
116+
117+
if [ "$1" == "init" ]; then
118+
# case when config db need to be created/initialized from minigraph
119+
sonic-db-cli ${NAMESPACE_ARGUMENT} CONFIG_DB FLUSHDB
120+
sonic-cfggen -H -m -j ${INIT_CFG_JSON} ${NAMESPACE_ARGUMENT} --write-to-db
121+
sonic-db-cli ${NAMESPACE_ARGUMENT} CONFIG_DB SET "CONFIG_DB_INITIALIZED" "1"
122+
sonic-cfggen -d --print-data > ${CONFIG_DB_PATH}${CONFIG_DB_PREFIX}$2${CONFIG_DB_SUFFIX}
123+
if [[ ($NUM_ASIC -gt 1) && ( -z "$2") ]]; then
124+
return 0
125+
fi
126+
# this will be run only in per-asic namespace only in multi-npu platforms
127+
${IP_NETNS_CMD} config qos reload
128+
${IP_NETNS_CMD} pfcwd start_default
129+
elif [ "$1" == "reload" ]; then
130+
# case when config db is already present from previous image file system
131+
sonic-cfggen ${NAMESPACE_ARGUMENT} -j ${CONFIG_DB_PATH}${CONFIG_DB_PREFIX}$2${CONFIG_DB_SUFFIX} --write-to-db
132+
fi
133+
134+
return 0
135+
}
136+
configdb_migrator()
137+
{
138+
if [[ ! -z "$2" ]]; then
139+
NAMESPACE_ARGUMENT=${NAMESPACE_OPTION}${NAMESPACE_PREFIX}$2
140+
else
141+
NAMESPACE_ARGUMENT=$2
142+
fi
143+
144+
if [ "$1" == "init" ]; then
145+
# case when config db created/initialized from minigraph need to be migrated
146+
if [[ -x /usr/bin/db_migrator.py ]]; then
147+
# Set latest version number
148+
/usr/bin/db_migrator.py ${NAMESPACE_ARGUMENT} -o set_version
149+
fi
150+
elif [ "$1" == "reload" ]; then
151+
# case when config db is already present from previous image file system
152+
# need to be migrated
153+
if [[ -x /usr/bin/db_migrator.py ]]; then
154+
# Migrate the DB to the latest schema version if needed
155+
/usr/bin/db_migrator.py ${NAMESPACE_ARGUMENT} -o migrate
156+
fi
157+
fi
158+
}
159+
102160
# Reload minigraph.xml file on disk
103161
reload_minigraph()
104162
{
105163
echo "Reloading minigraph..."
106164
if [ ! -f /etc/sonic/init_cfg.json ]; then
107165
echo "{}" > /etc/sonic/init_cfg.json
108166
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"
167+
168+
# Initialize config db for single-npu platform and global config db for multi-npu
169+
# platforms
170+
initalize_configdb init ''
171+
asic_num=0
172+
while [[ ($asic_num -lt $NUM_ASIC) && ($NUM_ASIC -gt 1) ]]
173+
do
174+
# Intiialize per asic/namespace config db
175+
initalize_configdb init $asic_num
176+
((asic_num = asic_num + 1))
177+
done
112178
if [ -f /etc/sonic/acl.json ]; then
179+
# For acl the acl-loader command takes care for multi-npu platforms
113180
acl-loader update full /etc/sonic/acl.json
114181
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
182+
183+
# Initialize config db migrator for single-npu platform and global config db for multi-npu
184+
# platforms
185+
configdb_migrator init ''
186+
asic_num=0
187+
while [[ ($asic_num -lt $NUM_ASIC) && ($NUM_ASIC -gt 1) ]]
188+
do
189+
# Initialize config db migrator for per-asic namespace config db
190+
# in multi-npu platforms
191+
configdb_migrator init $asic_num
192+
((asic_num = asic_num + 1))
193+
done
122194
}
123195

196+
# Reload exisitng config db file on disk
197+
reload_configdb()
198+
{
199+
echo "Reloading existing config db..."
200+
# Reload existing config db for single-npu platform and global config db for multi-npu
201+
# platforms
202+
initalize_configdb reload ''
203+
asic_num=0
204+
while [[ ($asic_num -lt $NUM_ASIC) && ($NUM_ASIC -gt 1) ]]
205+
do
206+
# Reload exisitng per asic/namespace config db
207+
initalize_configdb reload $asic_num
208+
((asic_num = asic_num + 1))
209+
done
210+
211+
# Initialize existing config db migrator for single-npu platform and global config db for multi-npu
212+
# platforms
213+
configdb_migrator reload ''
214+
asic_num=0
215+
while [[ ($asic_num -lt $NUM_ASIC) && ($NUM_ASIC -gt 1) ]]
216+
do
217+
# Initialize existing config db migrator for single-npu platform and global config db for multi-npu
218+
# platforms
219+
configdb_migrator reload $asic_num
220+
((asic_num = asic_num + 1))
221+
done
222+
}
124223
# Restore SONiC configuration from a backup copy
125224
function copy_config_files_and_directories()
126225
{
@@ -281,15 +380,51 @@ copy_post_migration_hooks()
281380
fi
282381
}
283382

383+
# Get the list of config db for both
384+
# single and multi-npu platforms
385+
get_config_db_file_list()
386+
{
387+
config_db_file_list=${CONFIG_DB_PREFIX}${CONFIG_DB_SUFFIX}
388+
asic_num=0
389+
while [[ ($asic_num -lt $NUM_ASIC) && ($NUM_ASIC -gt 1) ]]
390+
do
391+
config_db_file_list+=' '${CONFIG_DB_PREFIX}$asic_num${CONFIG_DB_SUFFIX}
392+
((asic_num = asic_num + 1))
393+
done
394+
395+
echo $config_db_file_list
396+
}
397+
# Check if all needed config db are prsesnt for both
398+
# single and multi-npu platforms
399+
check_config_db_present()
400+
{
401+
if [[ ! -r ${CONFIG_DB_JSON} ]]; then
402+
return 1
403+
fi
404+
asic_num=0
405+
while [[ ($asic_num -lt $NUM_ASIC) && ($NUM_ASIC -gt 1) ]]
406+
do
407+
if [[ ! -r ${CONFIG_DB_PATH}${CONFIG_DB_PREFIX}$asic_num${CONFIG_DB_SUFFIX} ]]; then
408+
return 1
409+
fi
410+
((asic_num = asic_num + 1))
411+
done
412+
413+
return 0
414+
}
415+
284416
# Perform configuration migration from backup copy.
285417
# - This step is performed when a new image is installed and SONiC switch boots into it
286418
do_config_migration()
287419
{
288420
# Identify list of files to migrate
289-
copy_list="minigraph.xml snmp.yml acl.json config_db.json frr"
421+
copy_list="minigraph.xml snmp.yml acl.json frr"
290422

291423
# Migrate all configuration files from old to new
292424
copy_config_files_and_directories $copy_list
425+
426+
# Migrate all config_db from old to new
427+
copy_config_files_and_directories $(get_config_db_file_list)
293428

294429
# Migrate post-migration hooks
295430
copy_post_migration_hooks
@@ -302,21 +437,14 @@ do_config_migration()
302437
disable_updategraph
303438
rm -f /tmp/pending_config_migration
304439
exit 0
305-
elif [ -r ${CONFIG_DB_JSON} ]; then
440+
elif check_config_db_present; then
306441
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
442+
reload_configdb
313443
# Disable updategraph
314444
disable_updategraph
315445
elif [ -r ${MINGRAPH_FILE} ]; then
316446
echo "Use minigraph.xml from old system..."
317447
reload_minigraph
318-
sonic-cfggen -d --print-data > ${CONFIG_DB_JSON}
319-
320448
# Disable updategraph
321449
disable_updategraph
322450
else
@@ -351,6 +479,14 @@ boot_config()
351479
do_config_migration
352480
fi
353481

482+
# For multi-npu platfrom we don't support config initlaiztion. Assumption
483+
# is there should be existing minigraph or config_db from previous image
484+
# file system to trigger. pending_config_initialization will remain set
485+
# for multi-npu platforms if we reach this case.
486+
if [[ ($NUM_ASIC -gt 1) ]]; then
487+
return 0
488+
fi
489+
354490
if [ -e /tmp/pending_config_initialization ] || [ -e ${CONFIG_SETUP_INITIALIZATION_FLAG} ]; then
355491
do_config_initialization
356492
fi
@@ -373,6 +509,16 @@ boot_config()
373509
}
374510

375511
### Execution starts here ###
512+
PLATFORM=`sonic-cfggen -H -v DEVICE_METADATA.localhost.platform`
513+
# Parse the device specific asic conf file, if it exists
514+
ASIC_CONF=/usr/share/sonic/device/$PLATFORM/asic.conf
515+
if [ -f "$ASIC_CONF" ]; then
516+
source $ASIC_CONF
517+
fi
518+
519+
NAMESPACE_OPTION='-n '
520+
NAMESPACE_PREFIX='asic'
521+
IP_NETNS_CMD_PREFIX='sudo ip netns exec '
376522

377523
CMD=$1
378524
# Default command is boot

0 commit comments

Comments
 (0)