selftest: Show the path of dumped vmcore on test end

Make the test script print following line when the test is finished and vmcore is successfully dumped:

  You can retrive the verify the vmcore file using following command:
  ./scripts/copy-from-image.sh \
      /home/kasong/fedpkg/kexec-tools/tests/output/ssh-kdump/0-server.img \
      /var/crash/192.168.77.62-2020-09-02-05:16:26/vmcore.flat ./
  Kernel package verion is: kernel-core-5.6.6-300.fc32.x86_64

Also add a helper to copy files out of the VM image.

Signed-off-by: Kairui Song <kasong@redhat.com>
Acked-by: Dave Young <dyoung@redhat.com>
This commit is contained in:
Kairui Song 2020-07-31 15:34:42 +08:00
parent 978a849765
commit c44cdb6703
4 changed files with 58 additions and 7 deletions

View File

@ -0,0 +1,25 @@
#!/usr/bin/env bash
BASEDIR=$(realpath $(dirname "$0"))
. $BASEDIR/image-init-lib.sh
# Base image to copy from
BOOT_IMAGE=$1 && shift
if [ ! -e "$BOOT_IMAGE" ]; then
perror_exit "Image '$BOOT_IMAGE' not found"
else
BOOT_IMAGE=$(realpath "$BOOT_IMAGE")
fi
mount_image $BOOT_IMAGE
IMAGE_MNT=$(get_image_mount_root $BOOT_IMAGE)
SRC=
while [ $# -gt 1 ]; do
SRC="$SRC $IMAGE_MNT/$1"
shift
done
DST=$1
cp -rv $SRC $DST

View File

@ -164,10 +164,20 @@ mount_image() {
[ $? -ne 0 ] && perror_exit "failed to mount device '$mnt_dev'"
}
shell_in_image() {
local image=$1 && shift
get_image_mount_root() {
local image=$1
local root=${MNTS[$image]}
echo $root
if [ -z "$root" ]; then
return 1
fi
}
shell_in_image() {
local root=$(get_image_mount_root $1) && shift
pushd $root
$SHELL
@ -176,8 +186,7 @@ shell_in_image() {
}
inst_pkg_in_image() {
local image=$1 && shift
local root=${MNTS[$image]}
local root=$(get_image_mount_root $1) && shift
# LSB not available
# release_info=$($SUDO chroot $root /bin/bash -c "lsb_release -a")
@ -193,10 +202,8 @@ inst_pkg_in_image() {
}
run_in_image() {
local image=$1 && shift
local root=${MNTS[$image]}
local root=$(get_image_mount_root $1) && shift
echo $SUDO chroot $root /bin/bash -c $@ > /dev/stderr
$SUDO chroot $root /bin/bash -c "$@"
}

View File

@ -92,6 +92,8 @@ has_valid_vmcore_dir() {
fi
test_output "Found a valid vmcore in \"$vmcore_dir\""
test_output "VMCORE: $vmcore"
test_output "KERNEL VERSION: $(rpm -q kernel-core)"
return 0
}

View File

@ -88,6 +88,7 @@ for test_case in $testcases; do
echo "-------- Console log: $(get_test_console_file $script)"
echo "-------- Test log: $(get_test_output_file $script)"
test_outputs+="$(get_test_output_file $script) "
rm -f $(get_test_console_file $script)
rm -f $(get_test_output_file $script)
@ -104,6 +105,7 @@ for test_case in $testcases; do
echo "-------- Console log: $(get_test_console_file $script)"
echo "-------- Test log: $(get_test_output_file $script)"
test_outputs+="$(get_test_output_file $script) "
rm -f $(get_test_console_file $script)
rm -f $(get_test_output_file $script)
@ -116,10 +118,25 @@ for test_case in $testcases; do
fi
res="$(gather_test_result $test_outputs)"
[ $? -ne 0 ] && ret=$(expr $ret + 1)
results[$test_case]="$res"
echo -e "-------- Test finished: $test_case $res --------"
for script in $scripts; do
script="$testdir/$script"
output="$(get_test_output_file $script) "
image="$(get_test_image $script)"
vmcore="$(sed -n 's/^VMCORE: \(\S*\).*/\1/p' $output)"
kernel="$(sed -n 's/^KERNEL VERSION: \(\S*\).*/\1/p' $output)"
if [ -n "$vmcore" ]; then
echo "You can retrive the verify the vmcore file using following command:"
echo "./scripts/copy-from-image.sh \\"
echo " $image \\"
echo " $vmcore ./"
echo "Kernel package verion is: $kernel"
fi
done
done
echo "======== Test results ========"