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

Github Action test #1

Open
wants to merge 21 commits into
base: rawhide
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: kexec-tools tests

on: pull_request

jobs:
format-check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- run: wget https://github.com/mvdan/sh/releases/download/v3.4.3/shfmt_v3.4.3_linux_amd64 -O /usr/local/bin/shfmt && chmod +x /usr/local/bin/shfmt
- run: shfmt -d *.sh kdumpctl mk*dumprd

static-analysis:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- run: curl -L -O https://github.com/koalaman/shellcheck/releases/download/v0.8.0/shellcheck-v0.8.0.linux.x86_64.tar.xz && tar -xJf shellcheck-v0.8.0.linux.x86_64.tar.xz
# Currently, for kexec-tools, there is need for shellcheck to require
# the sourced file to give correct warnings about the checked file
- run: shellcheck-v0.8.0/shellcheck --exclude=1090,1091 *.sh spec/*.sh kdumpctl mk*dumprd

unit-tests:
runs-on: ubuntu-latest
container: docker.io/fedora:latest
steps:
- uses: actions/checkout@v2
- run: sudo dnf install -y make dracut grubby hostname
- run: curl -L -O https://github.com/shellspec/shellspec/archive/latest.tar.gz && tar -xzf latest.tar.gz
- run: cd shellspec-latest && sudo make install
- run: shellspec

integration-tests:
runs-on: self-hosted
timeout-minutes: 45
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}-${{ matrix.container }}-${{ matrix.test }}
cancel-in-progress: true
strategy:
matrix:
container: [
"fedora:36",
]
fail-fast: false
container:
image: ghcr.io/coiby/${{ matrix.container }}
options: "--privileged -v /dev:/dev -v /lib/modules:/lib/modules:ro"
steps:
- name: "Checkout Repository"
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: "${{ matrix.container }} kdump tests"
run: bash ./tools/run-integration-tests.sh
4 changes: 3 additions & 1 deletion dracut-early-kdump-module-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ prepare_kernel_initrd() {

prepare_kdump_bootinfo

# $kernel is a variable from dracut
# shellcheck disable=SC2154 # $kernel is a variable from dracut
if [[ $KDUMP_KERNELVER != "$kernel" ]]; then
dwarn "Using kernel version '$KDUMP_KERNELVER' for early kdump," \
"but the initramfs is generated for kernel version '$kernel'"
Expand Down Expand Up @@ -54,12 +54,14 @@ install() {
inst_script "/lib/kdump/kdump-lib.sh" "/lib/kdump-lib.sh"
inst_script "/lib/kdump/kdump-lib-initramfs.sh" "/lib/kdump/kdump-lib-initramfs.sh"
inst_script "/lib/kdump/kdump-logger.sh" "/lib/kdump-logger.sh"
# shellcheck disable=SC2154 # $moddir is a variable from dracut
inst_hook cmdline 00 "$moddir/early-kdump.sh"
inst_binary "$KDUMP_KERNEL"
inst_binary "$KDUMP_INITRD"

ln_r "$KDUMP_KERNEL" "/boot/kernel-earlykdump"
ln_r "$KDUMP_INITRD" "/boot/initramfs-earlykdump"

# shellcheck disable=SC2154 # $initdir is a variable from dracut
chmod -x "${initdir}/$KDUMP_KERNEL"
}
87 changes: 43 additions & 44 deletions dracut-early-kdump.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,70 +15,69 @@ EARLY_KEXEC_ARGS=""

# initiate the kdump logger
if ! dlog_init; then
echo "failed to initiate the kdump logger."
exit 1
echo "failed to initiate the kdump logger."
exit 1
fi

prepare_parameters()
{
EARLY_KDUMP_CMDLINE=$(prepare_cmdline "${KDUMP_COMMANDLINE}" "${KDUMP_COMMANDLINE_REMOVE}" "${KDUMP_COMMANDLINE_APPEND}")
EARLY_KDUMP_KERNEL="/boot/kernel-earlykdump"
EARLY_KDUMP_INITRD="/boot/initramfs-earlykdump"
EARLY_KDUMP_CMDLINE=$(prepare_cmdline "${KDUMP_COMMANDLINE}" "${KDUMP_COMMANDLINE_REMOVE}" "${KDUMP_COMMANDLINE_APPEND}")
EARLY_KDUMP_KERNEL="/boot/kernel-earlykdump"
EARLY_KDUMP_INITRD="/boot/initramfs-earlykdump"
}

early_kdump_load()
{
if ! check_kdump_feasibility; then
return 1
fi
if ! check_kdump_feasibility; then
return 1
fi

if is_fadump_capable; then
dwarn "WARNING: early kdump doesn't support fadump."
return 1
fi
if is_fadump_capable; then
dwarn "WARNING: early kdump doesn't support fadump."
return 1
fi

if is_kernel_loaded "kdump"; then
return 1
fi
if is_kernel_loaded "kdump"; then
return 1
fi

prepare_parameters
prepare_parameters

EARLY_KEXEC_ARGS=$(prepare_kexec_args "${KEXEC_ARGS}")
EARLY_KEXEC_ARGS=$(prepare_kexec_args "${KEXEC_ARGS}")

if is_secure_boot_enforced; then
dinfo "Secure Boot is enabled. Using kexec file based syscall."
EARLY_KEXEC_ARGS="$EARLY_KEXEC_ARGS -s"
fi
if is_secure_boot_enforced; then
dinfo "Secure Boot is enabled. Using kexec file based syscall."
EARLY_KEXEC_ARGS="$EARLY_KEXEC_ARGS -s"
fi

# Here, only output the messages, but do not save these messages
# to a file because the target disk may not be mounted yet, the
# earlykdump is too early.
ddebug "earlykdump: $KEXEC ${EARLY_KEXEC_ARGS} $standard_kexec_args \
# Here, only output the messages, but do not save these messages
# to a file because the target disk may not be mounted yet, the
# earlykdump is too early.
ddebug "earlykdump: $KEXEC ${EARLY_KEXEC_ARGS} $standard_kexec_args \
--command-line=$EARLY_KDUMP_CMDLINE --initrd=$EARLY_KDUMP_INITRD \
$EARLY_KDUMP_KERNEL"

# shellcheck disable=SC2086
if $KEXEC $EARLY_KEXEC_ARGS $standard_kexec_args \
--command-line="$EARLY_KDUMP_CMDLINE" \
--initrd=$EARLY_KDUMP_INITRD $EARLY_KDUMP_KERNEL; then
dinfo "kexec: loaded early-kdump kernel"
return 0
else
derror "kexec: failed to load early-kdump kernel"
return 1
fi
# shellcheck disable=SC2086 # $EARLY_KEXEC_ARGS depends on word splitting
if $KEXEC $EARLY_KEXEC_ARGS $standard_kexec_args \
--command-line="$EARLY_KDUMP_CMDLINE" \
--initrd=$EARLY_KDUMP_INITRD $EARLY_KDUMP_KERNEL; then
dinfo "kexec: loaded early-kdump kernel"
return 0
else
derror "kexec: failed to load early-kdump kernel"
return 1
fi
}

set_early_kdump()
{
if getargbool 0 rd.earlykdump; then
dinfo "early-kdump is enabled."
early_kdump_load
else
dinfo "early-kdump is disabled."
fi

return 0
if getargbool 0 rd.earlykdump; then
dinfo "early-kdump is enabled."
early_kdump_load
else
dinfo "early-kdump is disabled."
fi

return 0
}

set_early_kdump
6 changes: 2 additions & 4 deletions dracut-fadump-init-fadump.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ if [ -f /proc/device-tree/rtas/ibm,kernel-dump ] || [ -f /proc/device-tree/ibm,o
mount -t ramfs ramfs /newroot

if [ $ROOTFS_IS_RAMFS ]; then
for FILE in $(ls -A /fadumproot/); do
mv /fadumproot/$FILE /newroot/
done
find /fadumproot/ -mindepth 1 -maxdepth 1 -exec mv {} /newroot/ \;
exec switch_root /newroot /init
else
mkdir /newroot/sys /newroot/proc /newroot/dev /newroot/run /newroot/oldroot
Expand All @@ -37,7 +35,7 @@ if [ -f /proc/device-tree/rtas/ibm,kernel-dump ] || [ -f /proc/device-tree/ibm,o
case $mp in
/oldroot/*) umount -d "$mp" && loop=1 ;;
esac
done </proc/mounts
done < /proc/mounts
done
umount -d -l oldroot

Expand Down
2 changes: 2 additions & 0 deletions dracut-fadump-module-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ depends() {
}

install() {
# shellcheck disable=SC2154 # $initdir is a dracut variable
mv -f "$initdir/init" "$initdir/init.dracut"
# shellcheck disable=SC2154 # $moddir is a dracut variable
inst_script "$moddir/init-fadump.sh" /init
chmod a+x "$initdir/init"

Expand Down
27 changes: 17 additions & 10 deletions dracut-kdump.sh
Original file line number Diff line number Diff line change
Expand Up @@ -307,12 +307,12 @@ do_failure_action()
do_final_action()
{
dinfo "Executing final action $FINAL_ACTION"
eval $FINAL_ACTION
eval "$FINAL_ACTION"
}

do_dump()
{
eval $DUMP_INSTRUCTION
eval "$DUMP_INSTRUCTION"
_ret=$?

if [ $_ret -ne 0 ]; then
Expand Down Expand Up @@ -393,7 +393,7 @@ dump_raw()
dump_ssh()
{
_ret=0
_ssh_opt="-i $1 -o BatchMode=yes -o StrictHostKeyChecking=yes"
_ssh_opts="-i $1 -o BatchMode=yes -o StrictHostKeyChecking=yes"
_ssh_dir="$KDUMP_PATH/$HOST_IP-$DATEDIR"
if is_ipv6_address "$2"; then
_scp_address=${2%@*}@"[${2#*@}]"
Expand All @@ -404,29 +404,33 @@ dump_ssh()
dinfo "saving to $2:$_ssh_dir"

cat /var/lib/random-seed > /dev/urandom
ssh -q $_ssh_opt "$2" mkdir -p "$_ssh_dir" || return 1
# shellcheck disable=SC2086 # need to word-split $_ssh_opts
ssh -q $_ssh_opts "$2" mkdir -p "$_ssh_dir" || return 1

save_vmcore_dmesg_ssh "$DMESG_COLLECTOR" "$_ssh_dir" "$_ssh_opt" "$2"
save_vmcore_dmesg_ssh "$DMESG_COLLECTOR" "$_ssh_dir" "$_ssh_opts" "$2"

dinfo "saving vmcore"

KDUMP_LOG_DEST=$2:$_ssh_dir/
KDUMP_LOG_OP="scp -q $_ssh_opt '$KDUMP_LOG_FILE' '$_scp_address:$_ssh_dir/'"
KDUMP_LOG_OP="scp -q $_ssh_opts '$KDUMP_LOG_FILE' '$_scp_address:$_ssh_dir/'"

save_opalcore_ssh "$_ssh_dir" "$_ssh_opt" "$2" "$_scp_address"
save_opalcore_ssh "$_ssh_dir" "$_ssh_opts" "$2" "$_scp_address"

if [ "${CORE_COLLECTOR%%[[:blank:]]*}" = "scp" ]; then
scp -q $_ssh_opt /proc/vmcore "$_scp_address:$_ssh_dir/vmcore-incomplete"
# shellcheck disable=SC2086 # need to word-split $_ssh_opts
scp -q $_ssh_opts /proc/vmcore "$_scp_address:$_ssh_dir/vmcore-incomplete"
_ret=$?
_vmcore="vmcore"
else
$CORE_COLLECTOR /proc/vmcore | ssh $_ssh_opt "$2" "umask 0077 && dd bs=512 of='$_ssh_dir/vmcore-incomplete'"
# shellcheck disable=SC2086,SC2029 # need to word-split $_ssh_opts and expand $_ssh_dir
$CORE_COLLECTOR /proc/vmcore | ssh $_ssh_opts "$2" "umask 0077 && dd bs=512 of='$_ssh_dir/vmcore-incomplete'"
_ret=$?
_vmcore="vmcore.flat"
fi

if [ $_ret -eq 0 ]; then
ssh $_ssh_opt "$2" "mv '$_ssh_dir/vmcore-incomplete' '$_ssh_dir/$_vmcore'"
# shellcheck disable=SC2086,SC2029 # need to word-split $_ssh_opts and expand $_ssh_dir
ssh $_ssh_opts "$2" "mv '$_ssh_dir/vmcore-incomplete' '$_ssh_dir/$_vmcore'"
_ret=$?
if [ $_ret -ne 0 ]; then
derror "moving vmcore failed, exitcode:$_ret"
Expand Down Expand Up @@ -457,11 +461,13 @@ save_opalcore_ssh()

dinfo "saving opalcore:$OPALCORE to $3:$1"

# shellcheck disable=SC2086 # need to word-split $2
if ! scp $2 $OPALCORE "$4:$1/opalcore-incomplete"; then
derror "saving opalcore failed"
return 1
fi

# shellcheck disable=SC2086,SC2029 # need to word-split $1 and expand $2
ssh $2 "$3" mv "$1/opalcore-incomplete" "$1/opalcore"
dinfo "saving opalcore complete"
return 0
Expand All @@ -474,6 +480,7 @@ save_opalcore_ssh()
save_vmcore_dmesg_ssh()
{
dinfo "saving vmcore-dmesg.txt to $4:$2"
# shellcheck disable=SC2086,SC2029 # need to word-split $3 and expand $2
if $1 /proc/vmcore | ssh $3 "$4" "umask 0077 && dd of='$2/vmcore-dmesg-incomplete.txt'"; then
ssh -q $3 "$4" mv "$2/vmcore-dmesg-incomplete.txt" "$2/vmcore-dmesg.txt"
dinfo "saving vmcore-dmesg.txt complete"
Expand Down
17 changes: 13 additions & 4 deletions dracut-module-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ _get_kdump_netifs() {
}

kdump_module_init() {
# shellcheck disable=SC2154 # $initdir is a dracut variable
if ! [[ -d "${initdir}/tmp" ]]; then
mkdir -p "${initdir}/tmp"
fi
Expand All @@ -21,6 +22,7 @@ kdump_module_init() {
}

check() {
# shellcheck disable=SC2154 # $debug is a dracut variable
[[ $debug ]] && set -x
#kdumpctl sets this explicitly
if [[ -z $IN_KDUMP ]] || [[ ! -f /etc/kdump.conf ]]; then
Expand All @@ -35,6 +37,7 @@ depends() {
kdump_module_init

add_opt_module() {
# shellcheck disable=SC2154 # $omit_dracutmodules is a dracut variable
[[ " $omit_dracutmodules " != *\ $1\ * ]] && _dep="$_dep $1"
}

Expand Down Expand Up @@ -823,6 +826,7 @@ kdump_check_iscsi_targets() {
[[ -d iscsi_session ]] && kdump_setup_iscsi_device "$PWD"
}

# shellcheck disable=SC2154 # $hostonly and $mount_needs are from dracut
[[ $hostonly ]] || [[ $mount_needs ]] && {
for_each_host_dev_and_slaves_all kdump_check_setup_iscsi
}
Expand Down Expand Up @@ -877,6 +881,7 @@ get_pcs_fence_kdump_nodes() {
for node in ${nodelist}; do
# convert $node from 'uname="nodeX"' to 'nodeX'
eval "$node"
# shellcheck disable=SC2154 # $uname from dracut
nodename="$uname"
# Skip its own node name
if is_localhost "$nodename"; then
Expand Down Expand Up @@ -975,10 +980,12 @@ kdump_install_systemd_conf() {
# unneccessary memory consumption and make console output more useful.
# Only do so for non fadump image.
mkdir -p "${initdir}/etc/systemd/journald.conf.d"
echo "[Journal]" > "${initdir}/etc/systemd/journald.conf.d/kdump.conf"
echo "Storage=volatile" >> "${initdir}/etc/systemd/journald.conf.d/kdump.conf"
echo "ReadKMsg=no" >> "${initdir}/etc/systemd/journald.conf.d/kdump.conf"
echo "ForwardToConsole=yes" >> "${initdir}/etc/systemd/journald.conf.d/kdump.conf"
{
echo "[Journal]"
echo "Storage=volatile"
echo "ReadKMsg=no"
echo "ForwardToConsole=yes"
} > "${initdir}/etc/systemd/journald.conf.d/kdump.conf"
}

remove_cpu_online_rule() {
Expand Down Expand Up @@ -1011,6 +1018,7 @@ install() {
kdump_install_random_seed
fi
dracut_install -o /etc/adjtime /etc/localtime
# shellcheck disable=SC2154 # $uname and ${initdir} from dracut
inst "$moddir/monitor_dd_progress" "/kdumpscripts/monitor_dd_progress"
chmod +x "${initdir}/kdumpscripts/monitor_dd_progress"
inst "/bin/dd" "/bin/dd"
Expand All @@ -1030,6 +1038,7 @@ install() {
inst "/lib/kdump/kdump-lib-initramfs.sh" "/lib/kdump-lib-initramfs.sh"
inst "/lib/kdump/kdump-logger.sh" "/lib/kdump-logger.sh"
inst "$moddir/kdump.sh" "/usr/bin/kdump.sh"
# shellcheck disable=SC2154 # $systemdsystemunitdir from dracut
inst "$moddir/kdump-capture.service" "$systemdsystemunitdir/kdump-capture.service"
systemctl -q --root "$initdir" add-wants initrd.target kdump-capture.service
# Replace existing emergency service and emergency target
Expand Down
6 changes: 3 additions & 3 deletions kdump-dep-generator.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
dest_dir="/tmp"

if [ -n "$1" ]; then
dest_dir=$1
dest_dir=$1
fi

systemd_dir=/usr/lib/systemd/system
kdump_wants=$dest_dir/kdump.service.wants

if is_ssh_dump_target; then
mkdir -p $kdump_wants
ln -sf $systemd_dir/network-online.target $kdump_wants/
mkdir -p "$kdump_wants"
ln -sf $systemd_dir/network-online.target "$kdump_wants"/
fi
Loading