Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fast-reboot]: Refactor fast-reboot script. Store the dumps in /host #208

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is better to use argparser to add option, easy to use, give you options, and helps.

https://docs.python.org/2/howto/argparse.html

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. In this case the script is used from another script only. So I decided to use fastest method.

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