forked from sonic-net/sonic-buildimage
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[fast-reboot] Check if ASIC config has changed before warm reboot (so…
…nic-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
- Loading branch information
Showing
3 changed files
with
104 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
#!/bin/bash -e | ||
|
||
# Exit codes | ||
ASIC_CONFIG_UNCHANGED=0 | ||
ASIC_CONFIG_CHANGED=1 | ||
SRC_ASIC_CONFIG_NOT_FOUND=2 | ||
DST_ASIC_CONFIG_NOT_FOUND=3 | ||
|
||
# Logging utilities | ||
function error() | ||
{ | ||
logger -p user.err "$@" | ||
} | ||
|
||
function debug() | ||
{ | ||
logger -p user.info "$@" | ||
} | ||
|
||
# Retrieve the source ASIC config checksum from the source image | ||
# Exits with error SRC_ASIC_CONFIG_NOT_FOUND if the checksum is not found | ||
function GetSourceASICConfigChecksum() | ||
{ | ||
if [[ ! -f "/etc/sonic/asic_config_checksum" ]]; then | ||
error "ASIC config not found in src image, can't verify changes" | ||
exit "${SRC_ASIC_CONFIG_NOT_FOUND}" | ||
fi | ||
} | ||
|
||
# Retrieve the destination ASIC config checksum from the destination image | ||
# Exits with error DST_ASIC_CONFIG_NOT_FOUND if the checksum is not found | ||
function GetDestinationASICConfigChecksum() | ||
{ | ||
DST_IMAGE_PATH="/host/image-${DST_SONIC_IMAGE#SONiC-OS-}" | ||
FS_PATH="${DST_IMAGE_PATH}/fs.squashfs" | ||
FS_MOUNTPOINT="/tmp/image-${DST_SONIC_IMAGE#SONiC-OS-}-fs" | ||
|
||
# Verify that the destination image exists | ||
if [[ ! -d ${DST_IMAGE_PATH} ]]; then | ||
error "ASIC config not found in dst image, can't verify changes" | ||
exit "${DST_ASIC_CONFIG_NOT_FOUND}" | ||
fi | ||
|
||
mkdir "${FS_MOUNTPOINT}" | ||
mount -t squashfs "${FS_PATH}" "${FS_MOUNTPOINT}" | ||
|
||
if [[ ! -f "${FS_MOUNTPOINT}/etc/sonic/asic_config_checksum" ]]; then | ||
error "ASIC config not found in dst image, can't verify changes" | ||
umount "${FS_MOUNTPOINT}" | ||
rm -rf "${FS_MOUNTPOINT}" | ||
exit "${DST_ASIC_CONFIG_NOT_FOUND}" | ||
fi | ||
|
||
cp "${FS_MOUNTPOINT}/etc/sonic/asic_config_checksum" /tmp/dst_asic_config_checksum | ||
umount "${FS_MOUNTPOINT}" | ||
rm -rf "${FS_MOUNTPOINT}" | ||
} | ||
|
||
# Confirm that the src and dst ASIC config checksums match | ||
# Exits with ASIC_CONFIG_CHANGED if the checksums differ | ||
function ConfirmASICConfigChecksumsMatch() | ||
{ | ||
SRC_CONFIG_CHECKSUM=$(cat /etc/sonic/asic_config_checksum) | ||
DST_CONFIG_CHECKSUM=$(cat /tmp/dst_asic_config_checksum) | ||
if [[ "${SRC_CONFIG_CHECKSUM}" != "${DST_CONFIG_CHECKSUM}" ]]; then | ||
error "ASIC config may have changed, checksum failed" | ||
exit "${ASIC_CONFIG_CHANGED}" | ||
fi | ||
} | ||
|
||
# Main starts here | ||
debug "Checking that ASIC configuration has not changed" | ||
|
||
SRC_SONIC_IMAGE="$(sonic_installer list | grep "Current: " | cut -f2 -d' ')" | ||
DST_SONIC_IMAGE="$(sonic_installer list | grep "Next: " | cut -f2 -d' ')" | ||
if [[ "${SRC_SONIC_IMAGE}" == "${DST_SONIC_IMAGE}" ]]; then | ||
debug "ASIC config unchanged, src and dst SONiC version are the same" | ||
exit "${ASIC_CONFIG_UNCHANGED}" | ||
fi | ||
|
||
GetSourceASICConfigChecksum | ||
GetDestinationASICConfigChecksum | ||
ConfirmASICConfigChecksumsMatch | ||
|
||
debug "ASIC config unchanged, checksum passed" | ||
exit "${ASIC_CONFIG_UNCHANGED}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters