From a5819afffe5ca4f7cbd6d1d37f2fa0aba5e547c3 Mon Sep 17 00:00:00 2001 From: Scott McMillan Date: Sun, 29 Sep 2024 13:13:07 -0400 Subject: [PATCH 1/7] initial entries for test_host kdump and kexec tests running on separate machine --- tests/tests/test_host_kdump.sh | 106 +++++++++++++++++++++++++++++++++ tests/tests/test_host_kexec.sh | 69 +++++++++++++++++++++ 2 files changed, 175 insertions(+) create mode 100755 tests/tests/test_host_kdump.sh create mode 100755 tests/tests/test_host_kexec.sh diff --git a/tests/tests/test_host_kdump.sh b/tests/tests/test_host_kdump.sh new file mode 100755 index 0000000..c976eec --- /dev/null +++ b/tests/tests/test_host_kdump.sh @@ -0,0 +1,106 @@ +#!/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 . +# + +# sudo apt install linux-crashdump +# reboot +# kdump-config show +# cat /proc/cmdline --> verify crashkernel value in place +# validate cat /proc/sys/kernel/sysrq > 0 +# trigger crash --> sudo "echo c > /proc/sysrq-trigger" +# find crashdump in /var/crash + +if [ ! -v DEVICE_IP ]; then + DEVICE_IP="192.168.102.125" +fi + +echo "Installing linux-crashdump and rebooting" +ssh ubuntu@$DEVICE_IP sudo apt install linux-crashdump +if [ $? != 0 ]; then + echo "Can't install linux-crashdump" + exit -1 +fi + +ssh ubuntu@$DEVICE_IP sudo systemctl reboot +if [ $? != 0 ]; then + echo "Can't reboot" + exit -2 +fi + +sleep 30 +echo "Waiting for system to come back up" + +cnt=0 +until ssh ubuntu@$DEVICE_IP ls &> /dev/null; do sleep 1; cnt=$(expr $cnt + 1); if [ $cnt -gt 120 ]; then break; fi; done +if [ $cnt -gt 60 ]; then + echo "Timed out waiting for $DEVICE_IP to come back up ($cnt)" + exit -3 +fi +if [ $cnt == 0 ]; then + echo "$DEVICE_IP came back too quickly" + exit -4 +fi + +echo "System came back up" + +KDUMP_CONFIG="$(ssh ubuntu@$DEVICE_IP sudo kdump-config show)" +if [ $? != 0 ]; then + echo "Failed getting kdump config" + exit -5 +fi + +CMDLINE="$(ssh ubuntu@$DEVICE_IP cat /proc/cmdline)" +if [ $? != 0 ]; then + echo "Failed getting cmd line" + exit -6 +fi + +CRASH_DIR="$(ssh ubuntu@$DEVICE_IP ls /var/crash)" +if [ $? != 0 ]; then + echo "Failed getting crash directory" + exit -7 +fi + + +echo "Crashing system" +ssh ubuntu@$DEVICE_IP "echo c | sudo tee /proc/sysrq-trigger" & + +sleep 10 +echo "Waiting for system to come back up" + +cnt=0 +until ssh ubuntu@$DEVICE_IP ls &> /dev/null; do sleep 1; cnt=$(expr $cnt + 1); if [ $cnt -gt 120 ]; then break; fi; done +if [ $cnt -gt 60 ]; then + echo "Timed out waiting for $DEVICE_IP to come back up ($cnt)" + exit -9 +fi +if [ $cnt == 0 ]; then + echo "$DEVICE_IP came back too quickly" + exit -10 +fi + +echo "System came back up" +CRASH_DIR2="$(ssh ubuntu@$DEVICE_IP ls /var/crash)" +if [ $? != 0 ]; then + echo "Failed getting crash directory" + exit -11 +fi + +echo $CRASH_DIR +echo "----------------------------------------------------" +echo "----------------------------------------------------" +echo "----------------------------------------------------" +echo $CRASH_DIR2 diff --git a/tests/tests/test_host_kexec.sh b/tests/tests/test_host_kexec.sh new file mode 100755 index 0000000..39b2948 --- /dev/null +++ b/tests/tests/test_host_kexec.sh @@ -0,0 +1,69 @@ +#!/usr/bin/bash +# +# 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 . +# + +if [ ! -v DEVICE_IP ]; then + DEVICE_IP="192.168.102.125" +fi + +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 ubuntu@$DEVICE_IP ls $KERNEL > /dev/null +if [ $? != 0 ]; then + echo "Can't find $KERNEL" + exit -1 +fi + +ssh ubuntu@$DEVICE_IP ls $INITRD > /dev/null +if [ $? != 0 ]; then + echo "Can't find $INITRD" + exit -2 +fi + +CMDLINE="$(ssh ubuntu@$DEVICE_IP cat /proc/cmdline)" +if [ $? != 0 ]; then + echo "Failed getting command line" + exit -3 +fi + +echo "Calling kexec: ssh ubuntu@$DEVICE_IP sudo kexec -l $KERNEL --initrd=$INITRD --command-line=\"$CMDLINE\"" +ssh ubuntu@$DEVICE_IP sudo kexec -l $KERNEL --initrd=$INITRD --command-line=\"$CMDLINE\" +if [ $? != 0 ]; then + echo "Failed kexec load: ssh ubuntu@$DEVICE_IP sudo kexec -l $KERNEL --initrd=$INITRD --command-line=\"$CMDLINE\"" + exit -4 +fi + +echo "Running kexec -e in background" +ssh ubuntu@$DEVICE_IP sudo kexec -e & +sleep 10 +echo "Waiting for system to come back up" + +cnt=0 +until ssh ubuntu@$DEVICE_IP ls &> /dev/null; do sleep 1; cnt=$(expr $cnt + 1); if [ $cnt -gt 60 ]; then break; fi; done +if [ $cnt -gt 60 ]; then + echo "Timed out waiting for $DEVICE_IP to come back up ($cnt)" + exit -5 +fi +if [ $cnt == 0 ]; then + echo "$DEVICE_IP came back too quickly" + exit -6 +fi + +echo "Kexec Successfully Performed" + + From 999adce09b88ed0f4dec772f6a40483478f9d37f Mon Sep 17 00:00:00 2001 From: Scott McMillan Date: Sun, 29 Sep 2024 13:44:17 -0400 Subject: [PATCH 2/7] working scripts for kexec/kdump tests - bash scripts can be used in testflinger or somewhere else --- tests/tests/test_host_kdump.sh | 24 ++++++++++++++---------- tests/tests/test_host_kexec.sh | 2 ++ 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/tests/tests/test_host_kdump.sh b/tests/tests/test_host_kdump.sh index c976eec..635f9d5 100755 --- a/tests/tests/test_host_kdump.sh +++ b/tests/tests/test_host_kdump.sh @@ -56,25 +56,24 @@ fi echo "System came back up" -KDUMP_CONFIG="$(ssh ubuntu@$DEVICE_IP sudo kdump-config show)" +ssh ubuntu@$DEVICE_IP sudo kdump-config show if [ $? != 0 ]; then echo "Failed getting kdump config" exit -5 fi -CMDLINE="$(ssh ubuntu@$DEVICE_IP cat /proc/cmdline)" +ssh ubuntu@$DEVICE_IP cat /proc/cmdline if [ $? != 0 ]; then echo "Failed getting cmd line" exit -6 fi -CRASH_DIR="$(ssh ubuntu@$DEVICE_IP ls /var/crash)" +CRASH_DIR_BEFORE="$(ssh ubuntu@$DEVICE_IP ls /var/crash)" if [ $? != 0 ]; then echo "Failed getting crash directory" exit -7 fi - echo "Crashing system" ssh ubuntu@$DEVICE_IP "echo c | sudo tee /proc/sysrq-trigger" & @@ -93,14 +92,19 @@ if [ $cnt == 0 ]; then fi echo "System came back up" -CRASH_DIR2="$(ssh ubuntu@$DEVICE_IP ls /var/crash)" +CRASH_DIR_AFTER="$(ssh ubuntu@$DEVICE_IP ls /var/crash)" if [ $? != 0 ]; then echo "Failed getting crash directory" exit -11 fi -echo $CRASH_DIR -echo "----------------------------------------------------" -echo "----------------------------------------------------" -echo "----------------------------------------------------" -echo $CRASH_DIR2 +echo Before crash directory listing: $CRASH_DIR_BEFORE +echo After crash directory listing: $CRASH_DIR_AFTER + +# Verifyng crash directory are not the same (extra entry in place) +if [ "$CRASH_DIR_BEFORE" == "$CRASH_DIR_AFTER" ]; then + echo "Crash directories are the same" + exit -12 +fi + +echo "Success!" diff --git a/tests/tests/test_host_kexec.sh b/tests/tests/test_host_kexec.sh index 39b2948..b19dc25 100755 --- a/tests/tests/test_host_kexec.sh +++ b/tests/tests/test_host_kexec.sh @@ -1,5 +1,7 @@ #!/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. From 4dcca0b6de1bdb6554f3b6ed2a818ad96e9b4522 Mon Sep 17 00:00:00 2001 From: Scott McMillan Date: Sun, 29 Sep 2024 14:07:57 -0400 Subject: [PATCH 3/7] cleaning up some comments --- tests/tests/test_host_kdump.sh | 17 +++++------------ tests/tests/test_host_kexec.sh | 2 -- 2 files changed, 5 insertions(+), 14 deletions(-) diff --git a/tests/tests/test_host_kdump.sh b/tests/tests/test_host_kdump.sh index 635f9d5..2acc5b0 100755 --- a/tests/tests/test_host_kdump.sh +++ b/tests/tests/test_host_kdump.sh @@ -15,14 +15,6 @@ # this program. If not, see . # -# sudo apt install linux-crashdump -# reboot -# kdump-config show -# cat /proc/cmdline --> verify crashkernel value in place -# validate cat /proc/sys/kernel/sysrq > 0 -# trigger crash --> sudo "echo c > /proc/sysrq-trigger" -# find crashdump in /var/crash - if [ ! -v DEVICE_IP ]; then DEVICE_IP="192.168.102.125" fi @@ -54,7 +46,7 @@ if [ $cnt == 0 ]; then exit -4 fi -echo "System came back up" +echo "System came back up, printing out useful debug info" ssh ubuntu@$DEVICE_IP sudo kdump-config show if [ $? != 0 ]; then @@ -68,6 +60,7 @@ if [ $? != 0 ]; then exit -6 fi +# Get crash directory before to compare later CRASH_DIR_BEFORE="$(ssh ubuntu@$DEVICE_IP ls /var/crash)" if [ $? != 0 ]; then echo "Failed getting crash directory" @@ -75,7 +68,7 @@ if [ $? != 0 ]; then fi echo "Crashing system" -ssh ubuntu@$DEVICE_IP "echo c | sudo tee /proc/sysrq-trigger" & +ssh ubuntu@$DEVICE_IP "echo c | sudo tee /proc/sysrq-trigger" > /dev/null & sleep 10 echo "Waiting for system to come back up" @@ -101,10 +94,10 @@ fi echo Before crash directory listing: $CRASH_DIR_BEFORE echo After crash directory listing: $CRASH_DIR_AFTER -# Verifyng crash directory are not the same (extra entry in place) +# Verifyng 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 -12 fi -echo "Success!" +echo "Kdump Successfully Performed" diff --git a/tests/tests/test_host_kexec.sh b/tests/tests/test_host_kexec.sh index b19dc25..90905b8 100755 --- a/tests/tests/test_host_kexec.sh +++ b/tests/tests/test_host_kexec.sh @@ -67,5 +67,3 @@ if [ $cnt == 0 ]; then fi echo "Kexec Successfully Performed" - - From 49834af5bd0588025ff659bb50199732297263c7 Mon Sep 17 00:00:00 2001 From: Scott McMillan Date: Mon, 30 Sep 2024 15:15:47 -0400 Subject: [PATCH 4/7] responding to PR comments --- tests/tests/test_host_kdump.sh | 9 +++++---- tests/tests/test_host_kexec.sh | 7 ++++--- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/tests/tests/test_host_kdump.sh b/tests/tests/test_host_kdump.sh index 2acc5b0..6615560 100755 --- a/tests/tests/test_host_kdump.sh +++ b/tests/tests/test_host_kdump.sh @@ -16,7 +16,8 @@ # if [ ! -v DEVICE_IP ]; then - DEVICE_IP="192.168.102.125" + echo "Must define DEVICE_IP" + exit -13 fi echo "Installing linux-crashdump and rebooting" @@ -32,12 +33,12 @@ if [ $? != 0 ]; then exit -2 fi -sleep 30 +sleep 15 echo "Waiting for system to come back up" cnt=0 until ssh ubuntu@$DEVICE_IP ls &> /dev/null; do sleep 1; cnt=$(expr $cnt + 1); if [ $cnt -gt 120 ]; then break; fi; done -if [ $cnt -gt 60 ]; then +if [ $cnt -gt 120 ]; then echo "Timed out waiting for $DEVICE_IP to come back up ($cnt)" exit -3 fi @@ -75,7 +76,7 @@ echo "Waiting for system to come back up" cnt=0 until ssh ubuntu@$DEVICE_IP ls &> /dev/null; do sleep 1; cnt=$(expr $cnt + 1); if [ $cnt -gt 120 ]; then break; fi; done -if [ $cnt -gt 60 ]; then +if [ $cnt -gt 120 ]; then echo "Timed out waiting for $DEVICE_IP to come back up ($cnt)" exit -9 fi diff --git a/tests/tests/test_host_kexec.sh b/tests/tests/test_host_kexec.sh index 90905b8..5f95d6a 100755 --- a/tests/tests/test_host_kexec.sh +++ b/tests/tests/test_host_kexec.sh @@ -16,7 +16,8 @@ # if [ ! -v DEVICE_IP ]; then - DEVICE_IP="192.168.102.125" + echo "Must define DEVICE_IP" + exit -13 fi echo "Getting information for kexec call" @@ -56,8 +57,8 @@ sleep 10 echo "Waiting for system to come back up" cnt=0 -until ssh ubuntu@$DEVICE_IP ls &> /dev/null; do sleep 1; cnt=$(expr $cnt + 1); if [ $cnt -gt 60 ]; then break; fi; done -if [ $cnt -gt 60 ]; then +until ssh ubuntu@$DEVICE_IP ls &> /dev/null; do sleep 1; cnt=$(expr $cnt + 1); if [ $cnt -gt 120 ]; then break; fi; done +if [ $cnt -gt 120 ]; then echo "Timed out waiting for $DEVICE_IP to come back up ($cnt)" exit -5 fi From 02a58b56aedb94c13bd9861d5142e76b0bc351b8 Mon Sep 17 00:00:00 2001 From: Scott McMillan Date: Tue, 1 Oct 2024 08:46:53 -0400 Subject: [PATCH 5/7] stop using refined return codes and just return -1 --- tests/tests/test_host_kdump.sh | 22 +++++++++++----------- tests/tests/test_host_kexec.sh | 12 ++++++------ 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/tests/tests/test_host_kdump.sh b/tests/tests/test_host_kdump.sh index 6615560..10bd0ae 100755 --- a/tests/tests/test_host_kdump.sh +++ b/tests/tests/test_host_kdump.sh @@ -17,7 +17,7 @@ if [ ! -v DEVICE_IP ]; then echo "Must define DEVICE_IP" - exit -13 + exit -1 fi echo "Installing linux-crashdump and rebooting" @@ -30,7 +30,7 @@ fi ssh ubuntu@$DEVICE_IP sudo systemctl reboot if [ $? != 0 ]; then echo "Can't reboot" - exit -2 + exit -1 fi sleep 15 @@ -40,11 +40,11 @@ cnt=0 until ssh ubuntu@$DEVICE_IP ls &> /dev/null; do sleep 1; cnt=$(expr $cnt + 1); if [ $cnt -gt 120 ]; then break; fi; done if [ $cnt -gt 120 ]; then echo "Timed out waiting for $DEVICE_IP to come back up ($cnt)" - exit -3 + exit -1 fi if [ $cnt == 0 ]; then echo "$DEVICE_IP came back too quickly" - exit -4 + exit -1 fi echo "System came back up, printing out useful debug info" @@ -52,20 +52,20 @@ echo "System came back up, printing out useful debug info" ssh ubuntu@$DEVICE_IP sudo kdump-config show if [ $? != 0 ]; then echo "Failed getting kdump config" - exit -5 + exit -1 fi ssh ubuntu@$DEVICE_IP cat /proc/cmdline if [ $? != 0 ]; then echo "Failed getting cmd line" - exit -6 + exit -1 fi # Get crash directory before to compare later CRASH_DIR_BEFORE="$(ssh ubuntu@$DEVICE_IP ls /var/crash)" if [ $? != 0 ]; then echo "Failed getting crash directory" - exit -7 + exit -1 fi echo "Crashing system" @@ -78,18 +78,18 @@ cnt=0 until ssh ubuntu@$DEVICE_IP ls &> /dev/null; do sleep 1; cnt=$(expr $cnt + 1); if [ $cnt -gt 120 ]; then break; fi; done if [ $cnt -gt 120 ]; then echo "Timed out waiting for $DEVICE_IP to come back up ($cnt)" - exit -9 + exit -1 fi if [ $cnt == 0 ]; then echo "$DEVICE_IP came back too quickly" - exit -10 + exit -1 fi echo "System came back up" CRASH_DIR_AFTER="$(ssh ubuntu@$DEVICE_IP ls /var/crash)" if [ $? != 0 ]; then echo "Failed getting crash directory" - exit -11 + exit -1 fi echo Before crash directory listing: $CRASH_DIR_BEFORE @@ -98,7 +98,7 @@ echo After crash directory listing: $CRASH_DIR_AFTER # Verifyng 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 -12 + exit -1 fi echo "Kdump Successfully Performed" diff --git a/tests/tests/test_host_kexec.sh b/tests/tests/test_host_kexec.sh index 5f95d6a..deebe2d 100755 --- a/tests/tests/test_host_kexec.sh +++ b/tests/tests/test_host_kexec.sh @@ -17,7 +17,7 @@ if [ ! -v DEVICE_IP ]; then echo "Must define DEVICE_IP" - exit -13 + exit -1 fi echo "Getting information for kexec call" @@ -35,20 +35,20 @@ fi ssh ubuntu@$DEVICE_IP ls $INITRD > /dev/null if [ $? != 0 ]; then echo "Can't find $INITRD" - exit -2 + exit -1 fi CMDLINE="$(ssh ubuntu@$DEVICE_IP cat /proc/cmdline)" if [ $? != 0 ]; then echo "Failed getting command line" - exit -3 + exit -1 fi echo "Calling kexec: ssh ubuntu@$DEVICE_IP sudo kexec -l $KERNEL --initrd=$INITRD --command-line=\"$CMDLINE\"" ssh ubuntu@$DEVICE_IP sudo kexec -l $KERNEL --initrd=$INITRD --command-line=\"$CMDLINE\" if [ $? != 0 ]; then echo "Failed kexec load: ssh ubuntu@$DEVICE_IP sudo kexec -l $KERNEL --initrd=$INITRD --command-line=\"$CMDLINE\"" - exit -4 + exit -1 fi echo "Running kexec -e in background" @@ -60,11 +60,11 @@ cnt=0 until ssh ubuntu@$DEVICE_IP ls &> /dev/null; do sleep 1; cnt=$(expr $cnt + 1); if [ $cnt -gt 120 ]; then break; fi; done if [ $cnt -gt 120 ]; then echo "Timed out waiting for $DEVICE_IP to come back up ($cnt)" - exit -5 + exit -1 fi if [ $cnt == 0 ]; then echo "$DEVICE_IP came back too quickly" - exit -6 + exit -1 fi echo "Kexec Successfully Performed" From 134ab39eb51e89af2426cceb14963e23aa8e9ea2 Mon Sep 17 00:00:00 2001 From: Scott McMillan Date: Tue, 1 Oct 2024 11:40:46 -0400 Subject: [PATCH 6/7] Using set -e and taking in other PR comments --- tests/tests/test_host_kdump.sh | 54 +++++++++------------------------- tests/tests/test_host_kexec.sh | 30 +++++-------------- 2 files changed, 21 insertions(+), 63 deletions(-) diff --git a/tests/tests/test_host_kdump.sh b/tests/tests/test_host_kdump.sh index 10bd0ae..3667a60 100755 --- a/tests/tests/test_host_kdump.sh +++ b/tests/tests/test_host_kdump.sh @@ -15,90 +15,64 @@ # this program. If not, see . # +SSH_OPTIONS=" -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" + if [ ! -v DEVICE_IP ]; then echo "Must define DEVICE_IP" - exit -1 + exit 1 fi echo "Installing linux-crashdump and rebooting" +set -e ssh ubuntu@$DEVICE_IP sudo apt install linux-crashdump -if [ $? != 0 ]; then - echo "Can't install linux-crashdump" - exit -1 -fi - ssh ubuntu@$DEVICE_IP sudo systemctl reboot -if [ $? != 0 ]; then - echo "Can't reboot" - exit -1 -fi - sleep 15 -echo "Waiting for system to come back up" +echo "Waiting for system to come back up" cnt=0 until ssh ubuntu@$DEVICE_IP ls &> /dev/null; do sleep 1; cnt=$(expr $cnt + 1); if [ $cnt -gt 120 ]; then break; fi; done if [ $cnt -gt 120 ]; then echo "Timed out waiting for $DEVICE_IP to come back up ($cnt)" - exit -1 + exit 1 fi if [ $cnt == 0 ]; then - echo "$DEVICE_IP came back too quickly" - exit -1 + echo "$DEVICE_IP came back quickly, likely did not reboot as expected" + exit 1 fi echo "System came back up, printing out useful debug info" ssh ubuntu@$DEVICE_IP sudo kdump-config show -if [ $? != 0 ]; then - echo "Failed getting kdump config" - exit -1 -fi - ssh ubuntu@$DEVICE_IP cat /proc/cmdline -if [ $? != 0 ]; then - echo "Failed getting cmd line" - exit -1 -fi # Get crash directory before to compare later CRASH_DIR_BEFORE="$(ssh ubuntu@$DEVICE_IP ls /var/crash)" -if [ $? != 0 ]; then - echo "Failed getting crash directory" - exit -1 -fi echo "Crashing system" ssh ubuntu@$DEVICE_IP "echo c | sudo tee /proc/sysrq-trigger" > /dev/null & - sleep 10 -echo "Waiting for system to come back up" +echo "Waiting for system to come back up" cnt=0 until ssh ubuntu@$DEVICE_IP ls &> /dev/null; do sleep 1; cnt=$(expr $cnt + 1); if [ $cnt -gt 120 ]; then break; fi; done if [ $cnt -gt 120 ]; then echo "Timed out waiting for $DEVICE_IP to come back up ($cnt)" - exit -1 + exit 1 fi if [ $cnt == 0 ]; then - echo "$DEVICE_IP came back too quickly" - exit -1 + echo "$DEVICE_IP came back quickly, likely did not crash as expected" + exit 1 fi echo "System came back up" CRASH_DIR_AFTER="$(ssh ubuntu@$DEVICE_IP ls /var/crash)" -if [ $? != 0 ]; then - echo "Failed getting crash directory" - exit -1 -fi - echo Before crash directory listing: $CRASH_DIR_BEFORE echo After crash directory listing: $CRASH_DIR_AFTER -# Verifyng crash directory are not the same (extra entry should be in place) +# 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 + exit 1 fi echo "Kdump Successfully Performed" diff --git a/tests/tests/test_host_kexec.sh b/tests/tests/test_host_kexec.sh index deebe2d..c71b353 100755 --- a/tests/tests/test_host_kexec.sh +++ b/tests/tests/test_host_kexec.sh @@ -15,56 +15,40 @@ # this program. If not, see . # +SSH_OPTIONS=" -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" + if [ ! -v DEVICE_IP ]; then echo "Must define DEVICE_IP" - exit -1 + 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 ubuntu@$DEVICE_IP ls $KERNEL > /dev/null -if [ $? != 0 ]; then - echo "Can't find $KERNEL" - exit -1 -fi - ssh ubuntu@$DEVICE_IP ls $INITRD > /dev/null -if [ $? != 0 ]; then - echo "Can't find $INITRD" - exit -1 -fi - CMDLINE="$(ssh ubuntu@$DEVICE_IP cat /proc/cmdline)" -if [ $? != 0 ]; then - echo "Failed getting command line" - exit -1 -fi echo "Calling kexec: ssh ubuntu@$DEVICE_IP sudo kexec -l $KERNEL --initrd=$INITRD --command-line=\"$CMDLINE\"" ssh ubuntu@$DEVICE_IP sudo kexec -l $KERNEL --initrd=$INITRD --command-line=\"$CMDLINE\" -if [ $? != 0 ]; then - echo "Failed kexec load: ssh ubuntu@$DEVICE_IP sudo kexec -l $KERNEL --initrd=$INITRD --command-line=\"$CMDLINE\"" - exit -1 -fi echo "Running kexec -e in background" ssh ubuntu@$DEVICE_IP sudo kexec -e & sleep 10 + echo "Waiting for system to come back up" cnt=0 until ssh ubuntu@$DEVICE_IP ls &> /dev/null; do sleep 1; cnt=$(expr $cnt + 1); if [ $cnt -gt 120 ]; then break; fi; done if [ $cnt -gt 120 ]; then echo "Timed out waiting for $DEVICE_IP to come back up ($cnt)" - exit -1 + exit 1 fi if [ $cnt == 0 ]; then echo "$DEVICE_IP came back too quickly" - exit -1 + exit 1 fi echo "Kexec Successfully Performed" From 09beade5530cad73a37dc7ebe03bf71647f289a0 Mon Sep 17 00:00:00 2001 From: Scott McMillan Date: Tue, 1 Oct 2024 14:40:05 -0400 Subject: [PATCH 7/7] adding SSH_OPTIONS in properly and changing code to use ssh to determine when the system went down instead of a timeout --- tests/tests/test_host_kdump.sh | 70 +++++++++++++++++++++------------- tests/tests/test_host_kexec.sh | 43 ++++++++++++--------- 2 files changed, 70 insertions(+), 43 deletions(-) diff --git a/tests/tests/test_host_kdump.sh b/tests/tests/test_host_kdump.sh index 3667a60..3da3671 100755 --- a/tests/tests/test_host_kdump.sh +++ b/tests/tests/test_host_kdump.sh @@ -24,48 +24,66 @@ fi echo "Installing linux-crashdump and rebooting" set -e -ssh ubuntu@$DEVICE_IP sudo apt install linux-crashdump -ssh ubuntu@$DEVICE_IP sudo systemctl reboot -sleep 15 +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 ubuntu@$DEVICE_IP ls &> /dev/null; do sleep 1; cnt=$(expr $cnt + 1); if [ $cnt -gt 120 ]; then break; fi; done -if [ $cnt -gt 120 ]; then - echo "Timed out waiting for $DEVICE_IP to come back up ($cnt)" - exit 1 -fi -if [ $cnt == 0 ]; then - echo "$DEVICE_IP came back quickly, likely did not reboot as expected" - exit 1 -fi +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 ubuntu@$DEVICE_IP sudo kdump-config show -ssh ubuntu@$DEVICE_IP cat /proc/cmdline +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 ubuntu@$DEVICE_IP "echo c | sudo tee /proc/sysrq-trigger" > /dev/null & -sleep 10 +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 ubuntu@$DEVICE_IP ls &> /dev/null; do sleep 1; cnt=$(expr $cnt + 1); if [ $cnt -gt 120 ]; then break; fi; done -if [ $cnt -gt 120 ]; then - echo "Timed out waiting for $DEVICE_IP to come back up ($cnt)" - exit 1 -fi -if [ $cnt == 0 ]; then - echo "$DEVICE_IP came back quickly, likely did not crash as expected" - exit 1 -fi +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 ubuntu@$DEVICE_IP ls /var/crash)" +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 diff --git a/tests/tests/test_host_kexec.sh b/tests/tests/test_host_kexec.sh index c71b353..a289972 100755 --- a/tests/tests/test_host_kexec.sh +++ b/tests/tests/test_host_kexec.sh @@ -23,32 +23,41 @@ if [ ! -v DEVICE_IP ]; then 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 ubuntu@$DEVICE_IP ls $KERNEL > /dev/null -ssh ubuntu@$DEVICE_IP ls $INITRD > /dev/null -CMDLINE="$(ssh ubuntu@$DEVICE_IP cat /proc/cmdline)" +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 ubuntu@$DEVICE_IP sudo kexec -l $KERNEL --initrd=$INITRD --command-line=\"$CMDLINE\"" -ssh ubuntu@$DEVICE_IP sudo kexec -l $KERNEL --initrd=$INITRD --command-line=\"$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 ubuntu@$DEVICE_IP sudo kexec -e & -sleep 10 +ssh $SSH_OPTIONS ubuntu@$DEVICE_IP sudo kexec -e & -echo "Waiting for system to come back up" +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 ubuntu@$DEVICE_IP ls &> /dev/null; do sleep 1; cnt=$(expr $cnt + 1); if [ $cnt -gt 120 ]; then break; fi; done -if [ $cnt -gt 120 ]; then - echo "Timed out waiting for $DEVICE_IP to come back up ($cnt)" - exit 1 -fi -if [ $cnt == 0 ]; then - echo "$DEVICE_IP came back too quickly" - exit 1 -fi +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"