From 24dc5de3158d05227623f653a70f4e1751fccf3d Mon Sep 17 00:00:00 2001 From: pavel-shirshov Date: Thu, 18 Apr 2019 11:36:00 -0700 Subject: [PATCH] If fast-reboot-dump gives an error, don't continue with fast-reboot (#515) * If fast-reboot-dump gives an error, don't continue with fast-reboot --- scripts/fast-reboot | 23 +++++++++++++++++------ scripts/fast-reboot-dump.py | 25 ++++++++++++++++++++----- 2 files changed, 37 insertions(+), 11 deletions(-) diff --git a/scripts/fast-reboot b/scripts/fast-reboot index c7d4fb29e10b..f768333d61e2 100755 --- a/scripts/fast-reboot +++ b/scripts/fast-reboot @@ -24,6 +24,7 @@ EXIT_FILE_SYSTEM_FULL=3 EXIT_NEXT_IMAGE_NOT_EXISTS=4 EXIT_ORCHAGENT_SHUTDOWN=10 EXIT_SYNCD_SHUTDOWN=11 +EXIT_FAST_REBOOT_DUMP_FAILURE=12 function error() { @@ -251,6 +252,14 @@ function reboot_pre_check() fi } +function unload_kernel() +{ + # Unload the previously loaded kernel if any loaded + if [[ "$(cat /sys/kernel/kexec_loaded)" -eq 1 ]]; then + /sbin/kexec -u + fi +} + # main starts here parseOptions $@ @@ -292,11 +301,7 @@ case "$REBOOT_TYPE" in ;; esac -# Unload the previously loaded kernel if any loaded -if [[ "$(cat /sys/kernel/kexec_loaded)" -eq 1 ]] -then - /sbin/kexec -u -fi +unload_kernel setup_reboot_variables @@ -336,7 +341,13 @@ if [[ "$REBOOT_TYPE" = "fast-reboot" ]]; then # Dump the ARP and FDB tables to files also as default routes for both IPv4 and IPv6 # into /host/fast-reboot mkdir -p /host/fast-reboot - /usr/bin/fast-reboot-dump.py -t /host/fast-reboot + FAST_REBOOT_DUMP_RC=0 + /usr/bin/fast-reboot-dump.py -t /host/fast-reboot || FAST_REBOOT_DUMP_RC=$? + if [[ FAST_REBOOT_DUMP_RC -ne 0 ]]; then + error "Failed to run fast-reboot-dump.py. Exit code: $FAST_REBOOT_DUMP_RC" + unload_kernel + exit "${EXIT_FAST_REBOOT_DUMP_FAILURE}" + fi fi init_warm_reboot_states diff --git a/scripts/fast-reboot-dump.py b/scripts/fast-reboot-dump.py index ee86eef57522..83387ad7550d 100644 --- a/scripts/fast-reboot-dump.py +++ b/scripts/fast-reboot-dump.py @@ -9,6 +9,8 @@ from fcntl import ioctl import binascii import argparse +import syslog +import traceback ARP_CHUNK = binascii.unhexlify('08060001080006040001') # defines a part of the packet for ARP Request @@ -267,14 +269,27 @@ def main(): root_dir = args.target if not os.path.isdir(root_dir): print "Target directory '%s' not found" % root_dir - sys.exit(1) + return 3 all_available_macs, map_mac_ip_per_vlan = generate_fdb_entries(root_dir + '/fdb.json') arp_entries = generate_arp_entries(root_dir + '/arp.json', all_available_macs) generate_default_route_entries(root_dir + '/default_routes.json') garp_send(arp_entries, map_mac_ip_per_vlan) - - return - + return 0 if __name__ == '__main__': - main() + res = 0 + try: + syslog.openlog('fast-reboot-dump') + res = main() + except KeyboardInterrupt: + syslog.syslog(syslog.LOG_NOTICE, "SIGINT received. Quitting") + res = 1 + except Exception as e: + syslog.syslog(syslog.LOG_ERR, "Got an exception %s: Traceback: %s" % (str(e), traceback.format_exc())) + res = 2 + finally: + syslog.closelog() + try: + sys.exit(res) + except SystemExit: + os._exit(res)