Skip to content

Commit

Permalink
Kdump improvements (sonic-net#1284)
Browse files Browse the repository at this point in the history
- Added support for reporting kdump reboot cause to detect and report
a kernel crash
- Added additional commands to sonic-kdump-config wrapper script to
dump Kdump configuration and status information in JSON format
- Automatically save Kdump configuration in startup configuration file.
This is an added convenience to the user as Kdump configuration changes
require a system reboot and user is expected to save the configuration so
that they are activated post reboot.
- Additional bug fixes and improvements to allow hostcfgd to process Kdump
configuration changes in ConfigDB. sonic-kdump-config script will write to
ConfigDB.
- Moved kdump CLI commands to a dedicated file

Signed-off-by: Rajendra Dendukuri <rajendra.dendukuri@broadcom.com>
  • Loading branch information
rajendra-dendukuri committed Dec 4, 2020
1 parent 9a17108 commit 042254e
Show file tree
Hide file tree
Showing 6 changed files with 320 additions and 89 deletions.
44 changes: 44 additions & 0 deletions config/kdump.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import os
import click
import utilities_common.cli as clicommon
from swsssdk import ConfigDBConnector

@click.group(cls=clicommon.AbbreviationGroup, name="kdump")
def kdump():
""" Configure kdump """
if os.geteuid() != 0:
exit("Root privileges are required for this operation")

@kdump.command()
def disable():
"""Disable kdump operation"""
config_db = ConfigDBConnector()
if config_db is not None:
config_db.connect()
config_db.mod_entry("KDUMP", "config", {"enabled": "false"})

@kdump.command()
def enable():
"""Enable kdump operation"""
config_db = ConfigDBConnector()
if config_db is not None:
config_db.connect()
config_db.mod_entry("KDUMP", "config", {"enabled": "true"})

@kdump.command()
@click.argument('kdump_memory', metavar='<kdump_memory>', required=True)
def memory(kdump_memory):
"""Set memory allocated for kdump capture kernel"""
config_db = ConfigDBConnector()
if config_db is not None:
config_db.connect()
config_db.mod_entry("KDUMP", "config", {"memory": kdump_memory})

@kdump.command('num-dumps')
@click.argument('kdump_num_dumps', metavar='<kdump_num_dumps>', required=True, type=int)
def num_dumps(kdump_num_dumps):
"""Set max number of dump files for kdump"""
config_db = ConfigDBConnector()
if config_db is not None:
config_db.connect()
config_db.mod_entry("KDUMP", "config", {"num_dumps": kdump_num_dumps})
46 changes: 2 additions & 44 deletions config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from . import chassis_modules
from . import console
from . import feature
from . import kdump
from . import kube
from . import mlnx
from . import muxcable
Expand Down Expand Up @@ -878,6 +879,7 @@ def config(ctx):
config.add_command(chassis_modules.chassis_modules)
config.add_command(console.console)
config.add_command(feature.feature)
config.add_command(kdump.kdump)
config.add_command(kube.kubernetes)
config.add_command(muxcable.muxcable)
config.add_command(nat.nat)
Expand Down Expand Up @@ -1901,50 +1903,6 @@ def shutdown():
"""Shut down BGP session(s)"""
pass

@config.group(cls=clicommon.AbbreviationGroup)
def kdump():
""" Configure kdump """
if os.geteuid() != 0:
exit("Root privileges are required for this operation")

@kdump.command()
def disable():
"""Disable kdump operation"""
config_db = ConfigDBConnector()
if config_db is not None:
config_db.connect()
config_db.mod_entry("KDUMP", "config", {"enabled": "false"})
clicommon.run_command("sonic-kdump-config --disable")

@kdump.command()
def enable():
"""Enable kdump operation"""
config_db = ConfigDBConnector()
if config_db is not None:
config_db.connect()
config_db.mod_entry("KDUMP", "config", {"enabled": "true"})
clicommon.run_command("sonic-kdump-config --enable")

@kdump.command()
@click.argument('kdump_memory', metavar='<kdump_memory>', required=True)
def memory(kdump_memory):
"""Set memory allocated for kdump capture kernel"""
config_db = ConfigDBConnector()
if config_db is not None:
config_db.connect()
config_db.mod_entry("KDUMP", "config", {"memory": kdump_memory})
clicommon.run_command("sonic-kdump-config --memory %s" % kdump_memory)

@kdump.command('num-dumps')
@click.argument('kdump_num_dumps', metavar='<kdump_num_dumps>', required=True, type=int)
def num_dumps(kdump_num_dumps):
"""Set max number of dump files for kdump"""
config_db = ConfigDBConnector()
if config_db is not None:
config_db.connect()
config_db.mod_entry("KDUMP", "config", {"num_dumps": kdump_num_dumps})
clicommon.run_command("sonic-kdump-config --num_dumps %d" % kdump_num_dumps)

# 'all' subcommand
@shutdown.command()
@click.option('-v', '--verbose', is_flag=True, help="Enable verbose output")
Expand Down
21 changes: 15 additions & 6 deletions scripts/reboot
Original file line number Diff line number Diff line change
@@ -1,19 +1,28 @@
#!/bin/bash
DEVPATH="/usr/share/sonic/device"
PLAT_REBOOT="platform_reboot"
REBOOT_CAUSE_FILE="/host/reboot-cause/reboot-cause.txt"
REBOOT_TIME=$(date)

# Reboot immediately if we run the kdump capture kernel
VMCORE_FILE=/proc/vmcore
if [ -e $VMCORE_FILE -a -s $VMCORE_FILE ]; then
echo "We have a /proc/vmcore, then we just kdump'ed"
/sbin/reboot
echo "We have a /proc/vmcore, then we just kdump'ed"
echo "User issued 'kdump' command [User: kdump, Time: ${REBOOT_TIME}]" > ${REBOOT_CAUSE_FILE}
sync
PLATFORM=$(grep -oP 'platform=\K\S+' /proc/cmdline)
if [ ! -z "${PLATFORM}" -a -x ${DEVPATH}/${PLATFORM}/${PLAT_REBOOT} ]; then
exec ${DEVPATH}/${PLATFORM}/${PLAT_REBOOT}
fi
# If no platform-specific reboot tool, just run /sbin/reboot
/sbin/reboot
echo 1 > /proc/sys/kernel/sysrq
echo b > /proc/sysrq-trigger
fi

REBOOT_USER=$(logname)
REBOOT_TIME=$(date)
PLATFORM=$(sonic-cfggen -H -v DEVICE_METADATA.localhost.platform)
ASIC_TYPE=$(sonic-cfggen -y /etc/sonic/sonic_version.yml -v asic_type)
DEVPATH="/usr/share/sonic/device"
PLAT_REBOOT="platform_reboot"
REBOOT_CAUSE_FILE="/host/reboot-cause/reboot-cause.txt"
VERBOSE=no
EXIT_NEXT_IMAGE_NOT_EXISTS=4
EXIT_SONIC_INSTALLER_VERIFY_REBOOT=21
Expand Down
Loading

0 comments on commit 042254e

Please sign in to comment.