Skip to content

Commit

Permalink
[fast-reboot] Check if ASIC config has changed before warm reboot (so…
Browse files Browse the repository at this point in the history
…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
daall authored Sep 3, 2019
1 parent fefa45c commit 4024019
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 0 deletions.
86 changes: 86 additions & 0 deletions scripts/asic_config_check
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}"
17 changes: 17 additions & 0 deletions scripts/fast-reboot
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,23 @@ function reboot_pre_check()
debug "Next image ${NEXT_SONIC_IMAGE} doesn't exist ..."
exit ${EXIT_NEXT_IMAGE_NOT_EXISTS}
fi
# Make sure ASIC configuration has not changed between images
ASIC_CONFIG_CHECK_SCRIPT="/usr/bin/asic_config_check"
ASIC_CONFIG_CHECK_SUCCESS=0
if [[ "$REBOOT_TYPE" = "warm-reboot" || "$REBOOT_TYPE" = "fastfast-reboot" ]]; then
ASIC_CONFIG_CHECK_EXIT_CODE=0
${ASIC_CONFIG_CHECK_SCRIPT} || ASIC_CONFIG_CHECK_EXIT_CODE=$?
if [[ "${ASIC_CONFIG_CHECK_EXIT_CODE}" != "${ASIC_CONFIG_CHECK_SUCCESS}" ]]; then
if [[ x"${FORCE}" == x"yes" ]]; then
debug "Ignoring ASIC config checksum failure..."
else
error "ASIC config may have changed: errno=${ASIC_CONFIG_CHECK_EXIT_CODE}"
exit "${EXIT_FAILURE}"
fi
fi
fi
}
function unload_kernel()
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
},
scripts=[
'scripts/aclshow',
'scripts/asic_config_check',
'scripts/boot_part',
'scripts/coredump-compress',
'scripts/db_migrator.py',
Expand Down

0 comments on commit 4024019

Please sign in to comment.