Skip to content

Commit

Permalink
Merge pull request #237 from canonical/pek852_kexec_kdump_host_tests
Browse files Browse the repository at this point in the history
Adding kexec/kdump tests for the host. This requires the host to be rebooted effectively multiple times. So, this was written as a shell script that can be used, eventually, in testflinger, or in a runner.
  • Loading branch information
spmcmillan authored Oct 1, 2024
2 parents b1848f4 + 09beade commit 9851592
Show file tree
Hide file tree
Showing 2 changed files with 159 additions and 0 deletions.
96 changes: 96 additions & 0 deletions tests/tests/test_host_kdump.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
#!/usr/bin/bash
#
# Copyright 2024 Canonical Ltd.
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 3, as published
# by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
# SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with
# this program. If not, see <http://www.gnu.org/licenses/>.
#

SSH_OPTIONS=" -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null"

if [ ! -v DEVICE_IP ]; then
echo "Must define DEVICE_IP"
exit 1
fi

echo "Installing linux-crashdump and rebooting"
set -e
ssh $SSH_OPTIONS ubuntu@$DEVICE_IP sudo apt install linux-crashdump
ssh $SSH_OPTIONS ubuntu@$DEVICE_IP sudo systemctl reboot

echo "Waiting for system to go down"
cnt=0
until ! ssh -o ConnectTimeout=2 $SSH_OPTIONS ubuntu@$DEVICE_IP ls &> /dev/null; do
sleep 1;
cnt=$(expr $cnt + 1);
if [ $cnt -gt 30 ]; then
echo "$DEVICE_IP did not reboot"
exit 1
fi
done

echo "Waiting for system to come back up"
cnt=0
until ssh -o ConnectTimeout=2 $SSH_OPTIONS ubuntu@$DEVICE_IP ls &> /dev/null; do
sleep 1;
cnt=$(expr $cnt + 1);
if [ $cnt -gt 120 ]; then
echo "Timed out waiting for $DEVICE_IP to come back up ($cnt)"
exit 1
fi
done

echo "System came back up, printing out useful debug info"

ssh $SSH_OPTIONS ubuntu@$DEVICE_IP sudo kdump-config show
ssh $SSH_OPTIONS ubuntu@$DEVICE_IP cat /proc/cmdline

# Get crash directory before to compare later
CRASH_DIR_BEFORE="$(ssh ubuntu@$DEVICE_IP ls /var/crash)"

echo "Crashing system"
ssh $SSH_OPTIONS ubuntu@$DEVICE_IP "echo c | sudo tee /proc/sysrq-trigger" > /dev/null &

echo "Waiting for system to go down"
cnt=0
until ! ssh -o ConnectTimeout=2 $SSH_OPTIONS ubuntu@$DEVICE_IP ls &> /dev/null; do
sleep 1;
cnt=$(expr $cnt + 1);
if [ $cnt -gt 30 ]; then
echo "$DEVICE_IP did not reboot"
exit 1
fi
done

echo "Waiting for system to come back up"
cnt=0
until ssh -o ConnectTimeout=2 $SSH_OPTIONS ubuntu@$DEVICE_IP ls &> /dev/null; do
sleep 1;
cnt=$(expr $cnt + 1);
if [ $cnt -gt 120 ]; then
echo "Timed out waiting for $DEVICE_IP to come back up ($cnt)"
exit 1
fi
done

echo "System came back up"
CRASH_DIR_AFTER="$(ssh $SSH_OPTIONS ubuntu@$DEVICE_IP ls /var/crash)"
echo Before crash directory listing: $CRASH_DIR_BEFORE
echo After crash directory listing: $CRASH_DIR_AFTER

# Verifying crash directory are not the same (extra entry should be in place)
if [ "$CRASH_DIR_BEFORE" == "$CRASH_DIR_AFTER" ]; then
echo "Crash directories are the same"
exit 1
fi

echo "Kdump Successfully Performed"
63 changes: 63 additions & 0 deletions tests/tests/test_host_kexec.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/usr/bin/bash
#
# Copyright 2024 Canonical Ltd.
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 3, as published
# by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
# SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with
# this program. If not, see <http://www.gnu.org/licenses/>.
#

SSH_OPTIONS=" -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null"

if [ ! -v DEVICE_IP ]; then
echo "Must define DEVICE_IP"
exit 1
fi

set -e

echo "Getting information for kexec call"
UNAME_RELEASE="$(ssh ubuntu@$DEVICE_IP uname -r)"
KERNEL="/boot/vmlinuz-$UNAME_RELEASE"
INITRD="/boot/initrd.img-$UNAME_RELEASE"
ssh $SSH_OPTIONS ubuntu@$DEVICE_IP ls $KERNEL > /dev/null
ssh $SSH_OPTIONS ubuntu@$DEVICE_IP ls $INITRD > /dev/null
CMDLINE="$(ssh $SSH_OPTIONS ubuntu@$DEVICE_IP cat /proc/cmdline)"

echo "Calling kexec: ssh $SSH_OPTIONS ubuntu@$DEVICE_IP sudo kexec -l $KERNEL --initrd=$INITRD --command-line=\"$CMDLINE\""
ssh $SSH_OPTIONS ubuntu@$DEVICE_IP sudo kexec -l $KERNEL --initrd=$INITRD --command-line=\"$CMDLINE\"

echo "Running kexec -e in background"
ssh $SSH_OPTIONS ubuntu@$DEVICE_IP sudo kexec -e &

echo "Waiting for system to go down"
cnt=0
until ! ssh -o ConnectTimeout=2 $SSH_OPTIONS ubuntu@$DEVICE_IP ls &> /dev/null; do
sleep 1;
cnt=$(expr $cnt + 1);
if [ $cnt -gt 30 ]; then
echo "$DEVICE_IP did not reboot"
exit 1
fi
done

echo "Waiting for system to come back up"
cnt=0
until ssh -o ConnectTimeout=2 $SSH_OPTIONS ubuntu@$DEVICE_IP ls &> /dev/null; do
sleep 1;
cnt=$(expr $cnt + 1);
if [ $cnt -gt 120 ]; then
echo "Timed out waiting for $DEVICE_IP to come back up ($cnt)"
exit 1
fi
done

echo "Kexec Successfully Performed"

0 comments on commit 9851592

Please sign in to comment.