|
| 1 | +#!/bin/bash |
| 2 | +## kola: |
| 3 | +## tags: "needs-internet skip-base-checks" |
| 4 | +## timeoutMin: 15 |
| 5 | +## # We've seen some OOM when 1024M is used in similar tests: |
| 6 | +## # https://github.com/coreos/fedora-coreos-tracker/issues/1506 |
| 7 | +## minMemory: 2048 |
| 8 | +## architectures: x86_64 |
| 9 | +## description: Verify kdump successfuly generates vmcore even after |
| 10 | +## replacing the kernel with kernel-rt. |
| 11 | + |
| 12 | +set -euo pipefail |
| 13 | + |
| 14 | +. $KOLA_EXT_DATA/commonlib.sh |
| 15 | + |
| 16 | +# Execute a command verbosely, i.e. echoing its arguments to stderr |
| 17 | +runv () { |
| 18 | + ( set -x ; "${@}" ) |
| 19 | +} |
| 20 | + |
| 21 | +basearch=$(arch) |
| 22 | + |
| 23 | +case "${AUTOPKGTEST_REBOOT_MARK:-}" in |
| 24 | +# first boot : install kernel-rt |
| 25 | +"") |
| 26 | + |
| 27 | + # in prow there isn't any repos in the image, so we use the centos stream repos |
| 28 | + if [ -z "$(ls -A /etc/yum.repos.d/)" ]; then |
| 29 | + if match_maj_ver "9"; then |
| 30 | + repo_name=c9s.repo |
| 31 | + if [ ! -e /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-Official ]; then |
| 32 | + runv curl -sSLf https://centos.org/keys/RPM-GPG-KEY-CentOS-Official-SHA256 -o /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-Official |
| 33 | + fi |
| 34 | + elif match_maj_ver "10"; then |
| 35 | + repo_name=c10s.repo |
| 36 | + if [ ! -e /etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial-SHA256 ]; then |
| 37 | + runv curl -sSLf https://centos.org/keys/RPM-GPG-KEY-CentOS-Official-SHA256 -o /etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial-SHA256 |
| 38 | + fi |
| 39 | + else |
| 40 | + fatal "Unhandled major RHEL/SCOS VERSION" |
| 41 | + fi |
| 42 | + |
| 43 | + runv cp "$KOLA_EXT_DATA/$repo_name" /etc/yum.repos.d/cs.repo |
| 44 | + fi |
| 45 | + # Enable nfv and rt repos |
| 46 | + runv sed -i '/\[nfv\]/,/^ *\[/ s/enabled=0/enabled=1/' /etc/yum.repos.d/*.repo |
| 47 | + runv sed -i '/\[rt\]/,/^ *\[/ s/enabled=0/enabled=1/' /etc/yum.repos.d/*.repo |
| 48 | + runv sed -i '/\[extras\-common\]/,/^ *\[/ s/enabled=1/enabled=0/' /etc/yum.repos.d/*.repo |
| 49 | + kernel_pkgs=("kernel-rt-core" "kernel-rt-modules" "kernel-rt-modules-extra" "kernel-rt-modules-core") |
| 50 | + args=() |
| 51 | + for x in ${kernel_pkgs}; do |
| 52 | + args+=(--install "${x}") |
| 53 | + done |
| 54 | + runv rpm-ostree override remove kernel{,-core,-modules,-modules-extra,-modules-core} "${args[@]}" |
| 55 | + # enable kdump and reboot |
| 56 | + # we don't enable kdump for the first boot to avoid building the initramfs twice |
| 57 | + systemctl enable kdump.service |
| 58 | + runv /tmp/autopkgtest-reboot 1 |
| 59 | + ;; |
| 60 | +# first reboot : confirm we have kernel-rt and kdump is active |
| 61 | +1) |
| 62 | + case $(uname -r) in |
| 63 | + *".${basearch}+rt") echo "ok kernel-rt" ;; |
| 64 | + *) |
| 65 | + runv uname -r |
| 66 | + runv rpm -q kernel-rt |
| 67 | + fatal "Failed to apply rt kernel override" |
| 68 | + ;; |
| 69 | + esac |
| 70 | + |
| 71 | + # use 240s for this since kdump can take a while to build its initramfs, |
| 72 | + # especially if the system is loaded |
| 73 | + if ! is_service_active kdump.service 240; then |
| 74 | + fatal "kdump.service failed to start" |
| 75 | + fi |
| 76 | + # Verify that the crashkernel reserved memory is large enough |
| 77 | + output=$(kdumpctl estimate) |
| 78 | + if grep -q "WARNING: Current crashkernel size is lower than recommended size" <<< "$output"; then |
| 79 | + fatal "The reserved crashkernel size is lower than recommended." |
| 80 | + fi |
| 81 | + |
| 82 | + kdump_path="/var/lib/kdump/initramfs-$(uname -r)kdump.img" |
| 83 | + |
| 84 | + if [[ ! -f "${kdump_path}" ]]; then |
| 85 | + fatal "kdump initrd not found at path ${kdump_path}" |
| 86 | + fi |
| 87 | + |
| 88 | + /tmp/autopkgtest-reboot-prepare 2 |
| 89 | + |
| 90 | + # Now we can crash the kernel |
| 91 | + echo "Triggering sysrq" |
| 92 | + sync |
| 93 | + echo 1 > /proc/sys/kernel/sysrq |
| 94 | + # This one will trigger kdump, which will write the kernel core, then reboot. |
| 95 | + echo c > /proc/sysrq-trigger |
| 96 | + # We shouldn't reach this point |
| 97 | + sleep 5 |
| 98 | + fatal "failed to invoke sysrq" |
| 99 | + ;; |
| 100 | +# second reboot : check for the memory dump |
| 101 | +2) |
| 102 | + kcore=$(find /var/crash -type f -name vmcore) |
| 103 | + if test -z "${kcore}"; then |
| 104 | + fatal "No kcore found in /var/crash" |
| 105 | + fi |
| 106 | + info=$(file "${kcore}") |
| 107 | + if ! [[ "${info}" =~ 'vmcore: Kdump'.*'system Linux' ]]; then |
| 108 | + fatal "vmcore does not appear to be a Kdump?" |
| 109 | + fi |
| 110 | + ;; |
| 111 | +*) |
| 112 | + fatal "Unhandled reboot mark ${AUTOPKGTEST_REBOOT_MARK:-}" |
| 113 | + ;; |
| 114 | +esac |
| 115 | + |
| 116 | +echo ok |
0 commit comments