Skip to content

Commit

Permalink
Refactor fast-reboot script. Generate fast-reboot-dumps into configur…
Browse files Browse the repository at this point in the history
…able directory (#208)
  • Loading branch information
pavel-shirshov authored Feb 23, 2018
1 parent b87ea44 commit 461470b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 25 deletions.
27 changes: 11 additions & 16 deletions scripts/fast-reboot
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#!/bin/bash

# Check root privileges
if [ "$EUID" -ne 0 ]
if [[ "$EUID" -ne 0 ]]
then
echo "Please run as root"
exit
fi


# Unload the previously loaded kernel if any loaded
if [ "$(cat /sys/kernel/kexec_loaded)" -eq 1 ]
if [[ "$(cat /sys/kernel/kexec_loaded)" -eq 1 ]]
then
/sbin/kexec -u
fi
Expand All @@ -27,33 +27,28 @@ sonic_asic_type=$(sonic-cfggen -y /etc/sonic/sonic_version.yml -v asic_type)
/sbin/kexec -l "$KERNEL_IMAGE" --initrd="$INITRD" --append="$BOOT_OPTIONS"

# Dump the ARP and FDB tables to files also as default routes for both IPv4 and IPv6
/usr/bin/fast-reboot-dump.py
docker cp /tmp/fdb.json swss:/
docker cp /tmp/arp.json swss:/
if [ -e /tmp/default_routes.json ]
then
docker cp /tmp/default_routes.json swss:/
fi
# into /host/fast-reboot
mkdir -p /host/fast-reboot
/usr/bin/fast-reboot-dump.py /host/fast-reboot

# Kill bgpd to enable graceful restart of BGP
docker exec -ti bgp killall -9 watchquagga
# Kill bgpd to start the bgp graceful restart procedure
docker exec -ti bgp killall -9 zebra
docker exec -ti bgp killall -9 bgpd

# Kill lldp, otherwise it sends informotion about reboot
docker kill lldp
docker kill lldp > /dev/null

# Kill teamd, otherwise it gets down all LAGs
docker kill teamd
docker kill teamd > /dev/null

# Kill other containers to make reboot faster
docker ps -qa | xargs docker kill
# Kill other containers to make the reboot faster
docker ps -q | xargs docker kill > /dev/null

# Stop the docker container engine. Otherwise we will have a broken docker storage
systemctl stop docker.service

# Stop opennsl modules for Broadcom platform
if [ "$sonic_asic_type" = 'broadcom' ];
if [[ "$sonic_asic_type" = 'broadcom' ]];
then
service_name=$(systemctl list-units --plain --no-pager --no-legend --type=service | grep opennsl | cut -f 1 -d' ')
systemctl stop "$service_name"
Expand Down
18 changes: 9 additions & 9 deletions scripts/fast-reboot-dump.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import json
import socket
import struct
import sys
import os
from fcntl import ioctl
import binascii
Expand Down Expand Up @@ -244,18 +245,17 @@ def generate_default_route_entries(filename):

db.close(db.APPL_DB)

if len(default_routes_output) > 0:
with open(filename, 'w') as fp:
json.dump(default_routes_output, fp, indent=2, separators=(',', ': '))
else:
if os.path.isfile(filename):
os.unlink(filename)
with open(filename, 'w') as fp:
json.dump(default_routes_output, fp, indent=2, separators=(',', ': '))


def main():
all_available_macs, map_mac_ip_per_vlan = generate_fdb_entries('/tmp/fdb.json')
arp_entries = generate_arp_entries('/tmp/arp.json', all_available_macs)
generate_default_route_entries('/tmp/default_routes.json')
root_dir = '/tmp'
if len(sys.argv) > 1 and os.path.isdir(sys.argv[1]):
root_dir = sys.argv[1]
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
Expand Down

0 comments on commit 461470b

Please sign in to comment.