Skip to content

Commit 2a64192

Browse files
committed
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.
1 parent d0f07b0 commit 2a64192

File tree

1 file changed

+3
-104
lines changed

1 file changed

+3
-104
lines changed

files/image_config/config-setup/config-setup

+3-104
Original file line numberDiff line numberDiff line change
@@ -103,117 +103,19 @@ run_hookdir() {
103103
return $exit_status
104104
}
105105

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

193114
# Reload exisitng config db file on disk
194115
reload_configdb()
195116
{
196117
echo "Reloading existing config db..."
197-
# Reload existing config db for single-npu platform and global config db for multi-npu
198-
# platforms
199-
initalize_configdb reload
200-
asic_num=0
201-
while [[ ($asic_num -lt $NUM_ASIC) && ($NUM_ASIC -gt 1) ]]; do
202-
# Reload exisitng per asic/namespace config db
203-
initalize_configdb reload $asic_num
204-
((asic_num = asic_num + 1))
205-
done
206-
207-
# Initialize existing config db migrator for single-npu platform and global config db for multi-npu
208-
# platforms
209-
configdb_migrator reload
210-
asic_num=0
211-
while [[ ($asic_num -lt $NUM_ASIC) && ($NUM_ASIC -gt 1) ]]; do
212-
# Initialize existing config db migrator for single-npu platform and global config db for multi-npu
213-
# platforms
214-
configdb_migrator reload $asic_num
215-
((asic_num = asic_num + 1))
216-
done
118+
config reload -y -n
217119
}
218120
# Restore SONiC configuration from a backup copy
219121
function copy_config_files_and_directories()
@@ -509,9 +411,6 @@ if [[ -f "$ASIC_CONF" ]]; then
509411
source $ASIC_CONF
510412
fi
511413

512-
NAMESPACE_OPTION='-n '
513-
NAMESPACE_PREFIX='asic'
514-
IP_NETNS_CMD_PREFIX='sudo ip netns exec '
515414

516415
CMD=$1
517416
# Default command is boot

0 commit comments

Comments
 (0)