Skip to content

Commit 4024019

Browse files
authored
[fast-reboot] Check if ASIC config has changed before warm reboot (sonic-net#621)
[fast-reboot] Check if ASIC config has changed before fast reboot * Adds script to compare checksums for config files between SONiC images * Adds pre-check to fast reboot script to confirm config files match before performing fast reboot Signed-off-by: Danny Allen <daall@microsoft.com> * Fix formatting * Incorporate feedback * Add check for reboot type and override ability * Clean up error checking
1 parent fefa45c commit 4024019

File tree

3 files changed

+104
-0
lines changed

3 files changed

+104
-0
lines changed

scripts/asic_config_check

+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
#!/bin/bash -e
2+
3+
# Exit codes
4+
ASIC_CONFIG_UNCHANGED=0
5+
ASIC_CONFIG_CHANGED=1
6+
SRC_ASIC_CONFIG_NOT_FOUND=2
7+
DST_ASIC_CONFIG_NOT_FOUND=3
8+
9+
# Logging utilities
10+
function error()
11+
{
12+
logger -p user.err "$@"
13+
}
14+
15+
function debug()
16+
{
17+
logger -p user.info "$@"
18+
}
19+
20+
# Retrieve the source ASIC config checksum from the source image
21+
# Exits with error SRC_ASIC_CONFIG_NOT_FOUND if the checksum is not found
22+
function GetSourceASICConfigChecksum()
23+
{
24+
if [[ ! -f "/etc/sonic/asic_config_checksum" ]]; then
25+
error "ASIC config not found in src image, can't verify changes"
26+
exit "${SRC_ASIC_CONFIG_NOT_FOUND}"
27+
fi
28+
}
29+
30+
# Retrieve the destination ASIC config checksum from the destination image
31+
# Exits with error DST_ASIC_CONFIG_NOT_FOUND if the checksum is not found
32+
function GetDestinationASICConfigChecksum()
33+
{
34+
DST_IMAGE_PATH="/host/image-${DST_SONIC_IMAGE#SONiC-OS-}"
35+
FS_PATH="${DST_IMAGE_PATH}/fs.squashfs"
36+
FS_MOUNTPOINT="/tmp/image-${DST_SONIC_IMAGE#SONiC-OS-}-fs"
37+
38+
# Verify that the destination image exists
39+
if [[ ! -d ${DST_IMAGE_PATH} ]]; then
40+
error "ASIC config not found in dst image, can't verify changes"
41+
exit "${DST_ASIC_CONFIG_NOT_FOUND}"
42+
fi
43+
44+
mkdir "${FS_MOUNTPOINT}"
45+
mount -t squashfs "${FS_PATH}" "${FS_MOUNTPOINT}"
46+
47+
if [[ ! -f "${FS_MOUNTPOINT}/etc/sonic/asic_config_checksum" ]]; then
48+
error "ASIC config not found in dst image, can't verify changes"
49+
umount "${FS_MOUNTPOINT}"
50+
rm -rf "${FS_MOUNTPOINT}"
51+
exit "${DST_ASIC_CONFIG_NOT_FOUND}"
52+
fi
53+
54+
cp "${FS_MOUNTPOINT}/etc/sonic/asic_config_checksum" /tmp/dst_asic_config_checksum
55+
umount "${FS_MOUNTPOINT}"
56+
rm -rf "${FS_MOUNTPOINT}"
57+
}
58+
59+
# Confirm that the src and dst ASIC config checksums match
60+
# Exits with ASIC_CONFIG_CHANGED if the checksums differ
61+
function ConfirmASICConfigChecksumsMatch()
62+
{
63+
SRC_CONFIG_CHECKSUM=$(cat /etc/sonic/asic_config_checksum)
64+
DST_CONFIG_CHECKSUM=$(cat /tmp/dst_asic_config_checksum)
65+
if [[ "${SRC_CONFIG_CHECKSUM}" != "${DST_CONFIG_CHECKSUM}" ]]; then
66+
error "ASIC config may have changed, checksum failed"
67+
exit "${ASIC_CONFIG_CHANGED}"
68+
fi
69+
}
70+
71+
# Main starts here
72+
debug "Checking that ASIC configuration has not changed"
73+
74+
SRC_SONIC_IMAGE="$(sonic_installer list | grep "Current: " | cut -f2 -d' ')"
75+
DST_SONIC_IMAGE="$(sonic_installer list | grep "Next: " | cut -f2 -d' ')"
76+
if [[ "${SRC_SONIC_IMAGE}" == "${DST_SONIC_IMAGE}" ]]; then
77+
debug "ASIC config unchanged, src and dst SONiC version are the same"
78+
exit "${ASIC_CONFIG_UNCHANGED}"
79+
fi
80+
81+
GetSourceASICConfigChecksum
82+
GetDestinationASICConfigChecksum
83+
ConfirmASICConfigChecksumsMatch
84+
85+
debug "ASIC config unchanged, checksum passed"
86+
exit "${ASIC_CONFIG_UNCHANGED}"

scripts/fast-reboot

+17
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,23 @@ function reboot_pre_check()
250250
debug "Next image ${NEXT_SONIC_IMAGE} doesn't exist ..."
251251
exit ${EXIT_NEXT_IMAGE_NOT_EXISTS}
252252
fi
253+
254+
# Make sure ASIC configuration has not changed between images
255+
ASIC_CONFIG_CHECK_SCRIPT="/usr/bin/asic_config_check"
256+
ASIC_CONFIG_CHECK_SUCCESS=0
257+
if [[ "$REBOOT_TYPE" = "warm-reboot" || "$REBOOT_TYPE" = "fastfast-reboot" ]]; then
258+
ASIC_CONFIG_CHECK_EXIT_CODE=0
259+
${ASIC_CONFIG_CHECK_SCRIPT} || ASIC_CONFIG_CHECK_EXIT_CODE=$?
260+
261+
if [[ "${ASIC_CONFIG_CHECK_EXIT_CODE}" != "${ASIC_CONFIG_CHECK_SUCCESS}" ]]; then
262+
if [[ x"${FORCE}" == x"yes" ]]; then
263+
debug "Ignoring ASIC config checksum failure..."
264+
else
265+
error "ASIC config may have changed: errno=${ASIC_CONFIG_CHECK_EXIT_CODE}"
266+
exit "${EXIT_FAILURE}"
267+
fi
268+
fi
269+
fi
253270
}
254271
255272
function unload_kernel()

setup.py

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
},
5353
scripts=[
5454
'scripts/aclshow',
55+
'scripts/asic_config_check',
5556
'scripts/boot_part',
5657
'scripts/coredump-compress',
5758
'scripts/db_migrator.py',

0 commit comments

Comments
 (0)