Skip to content

Commit

Permalink
If fast-reboot-dump gives an error, don't continue with fast-reboot (s…
Browse files Browse the repository at this point in the history
…onic-net#515)

* If fast-reboot-dump gives an error, don't continue with fast-reboot
  • Loading branch information
pavel-shirshov authored Apr 18, 2019
1 parent d8ae337 commit 24dc5de
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 11 deletions.
23 changes: 17 additions & 6 deletions scripts/fast-reboot
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down Expand Up @@ -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 $@
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
25 changes: 20 additions & 5 deletions scripts/fast-reboot-dump.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

0 comments on commit 24dc5de

Please sign in to comment.