From 91e667211022b3bc7eaa27169d5820bda9053b8c Mon Sep 17 00:00:00 2001 From: Daniel Hilst <392820+dhilst@users.noreply.github.com> Date: Sat, 24 Oct 2026 20:36:08 -0300 Subject: [PATCH] fix(xcat-test): the diskless cases fail when the kernel mounts binfmt_misc The diskless cases snapshot the mount table before genimage and after it and require the two to be identical, ignoring only fusectl. The comparison is there to catch a bind mount genimage leaves inside the root image, which is worth catching. It also fails for mounts the kernel makes on its own. binfmt_misc is an autofs stub that becomes a real mount the first time a process reads /proc/sys/fs/binfmt_misc, and tracefs appears under /sys/kernel/debug the first time anything opens debugfs tracing. On openeuler22.03sp4 both appeared during genimage and failed reg_linux_diskless_installation_flat four minutes into a 1168 second case, while the provisioning that followed succeeded and the node reached booted. The single fusectl exclusion shows the same class was met once before and patched by name. mount_snapshot.sh drops the mounts whose mount POINT is under /proc or /sys, which is where the kernel keeps its on-demand mounts, and the three cases take their snapshots through it. Dropping them by filesystem TYPE would hide the leak the comparison exists for, because a leaked genimage bind is itself a proc or sysfs mount. fusectl needs no exclusion of its own any more. mount_snapshot.bats covers both directions. Taking the filter out fails the two ignore-the-kernel assertions and keeps both leak assertions; filtering by type instead of by mount point fails only the leaked-bind assertion. A test-only commit would skip rather than fail, because require_repo_file skips when the script is absent, so the proof is those two mutations. Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com> --- .../testcase/commoncmd/mount_snapshot.sh | 30 ++++++++ .../installation/SN_diskless_setup_case | 6 +- .../reg_linux_diskless_installation_flat | 12 +-- ...kless_installation_flat_postscripts_failed | 6 +- xCAT-test/bats/mount_snapshot.bats | 74 +++++++++++++++++++ 5 files changed, 116 insertions(+), 12 deletions(-) create mode 100755 xCAT-test/autotest/testcase/commoncmd/mount_snapshot.sh create mode 100644 xCAT-test/bats/mount_snapshot.bats diff --git a/xCAT-test/autotest/testcase/commoncmd/mount_snapshot.sh b/xCAT-test/autotest/testcase/commoncmd/mount_snapshot.sh new file mode 100755 index 0000000000..75460dc94c --- /dev/null +++ b/xCAT-test/autotest/testcase/commoncmd/mount_snapshot.sh @@ -0,0 +1,30 @@ +#!/bin/sh +# +# mount_snapshot.sh [] +# +# Print the mount table without the kernel's own on-demand mounts, so the diskless cases can +# compare a snapshot taken before genimage with one taken after it. +# +# genimage bind mounts /proc, /sys and /dev inside the root image. A bind it fails to remove +# leaves the next image built on top of the host, so comparing the two snapshots is worth doing. +# +# What the comparison must not assert is that nothing else mounted anything meanwhile. +# binfmt_misc is an autofs stub that becomes a real mount the first time a process reads +# /proc/sys/fs/binfmt_misc, and tracefs appears under /sys/kernel/debug the first time anything +# opens debugfs tracing. Both are the kernel's doing and both can happen during genimage. On one +# openEuler 22.03 run both did, and the case failed four minutes in while the provisioning that +# followed succeeded. +# +# Filtering by filesystem type would hide the leak this guards, because a leaked genimage bind IS +# a proc or sysfs mount. The mount POINT separates them: the kernel keeps its on-demand mounts +# inside /proc and /sys, and a leaked bind sits under the root image directory. +# +# With a file argument, filter that file instead of asking the kernel, so the filter is testable. + +set -e + +if [ $# -ge 1 ]; then + cat -- "$1" +else + mount +fi | awk '$3 !~ /^\/(proc|sys)(\/|$)/' | sort diff --git a/xCAT-test/autotest/testcase/installation/SN_diskless_setup_case b/xCAT-test/autotest/testcase/installation/SN_diskless_setup_case index 9efe3f987d..d0e7b6d344 100644 --- a/xCAT-test/autotest/testcase/installation/SN_diskless_setup_case +++ b/xCAT-test/autotest/testcase/installation/SN_diskless_setup_case @@ -74,13 +74,13 @@ check:rc==0 cmd:osimage="__GETNODEATTR($$SN,os)__-__GETNODEATTR($$SN,arch)__-netboot-service";otherpkglist=$(lsdef -t osimage $osimage -i otherpkglist -c|awk -F"=" '{print $2}'); cat $otherpkglist cmd:if [ ! -d /tmp/mountoutput ]; then mkdir -p /tmp/mountoutput; fi -cmd:mount |sort > /tmp/mountoutput/file.org +cmd:/opt/xcat/share/xcat/tools/autotest/testcase/commoncmd/mount_snapshot.sh > /tmp/mountoutput/file.org cmd:genimage __GETNODEATTR($$SN,os)__-__GETNODEATTR($$SN,arch)__-netboot-service check:rc==0 -cmd:mount |sort > /tmp/mountoutput/file.new -cmd:diff -y /tmp/mountoutput/file.org /tmp/mountoutput/file.new --ignore-matching-lines="fusectl" +cmd:/opt/xcat/share/xcat/tools/autotest/testcase/commoncmd/mount_snapshot.sh > /tmp/mountoutput/file.new +cmd:diff -y /tmp/mountoutput/file.org /tmp/mountoutput/file.new check:rc==0 cmd:rm -rf /tmp/mountoutput diff --git a/xCAT-test/autotest/testcase/installation/reg_linux_diskless_installation_flat b/xCAT-test/autotest/testcase/installation/reg_linux_diskless_installation_flat index b736721928..a38545435b 100644 --- a/xCAT-test/autotest/testcase/installation/reg_linux_diskless_installation_flat +++ b/xCAT-test/autotest/testcase/installation/reg_linux_diskless_installation_flat @@ -31,16 +31,16 @@ cmd:if [[ -f /test.synclist ]] ;then mv -f /test.synclist /test.synclist.bak;fi; cmd:echo "/test.synclist -> /test.synclist" > /test.synclist;chdef -t osimage -o __GETNODEATTR($$CN,os)__-__GETNODEATTR($$CN,arch)__-netboot-compute synclists=/test.synclist check:rc==0 cmd:if [ ! -d /tmp/mountoutput ]; then mkdir -p /tmp/mountoutput; fi -cmd:mount |sort > /tmp/mountoutput/file.org +cmd:/opt/xcat/share/xcat/tools/autotest/testcase/commoncmd/mount_snapshot.sh > /tmp/mountoutput/file.org cmd:cat /tmp/mountoutput/file.org cmd:if [[ "__GETNODEATTR($$CN,os)__" =~ "ubuntu18.04.2" ]] && [[ "__GETNODEATTR($$CN,arch)__" =~ ppc64(el|le) ]] && [[ "__GETNODEATTR($$CN,mgt)__" =~ "kvm" ]] ; then mkdir -p /install/custom/netboot/ubuntu; sed -e 's@linux-image-generic-hwe-18.04@linux-image-generic@g' /install/custom/netboot/ubuntu/compute.ubuntu18.04.2.ppc64el.pkglist; chdef -t osimage -o __GETNODEATTR($$CN,os)__-__GETNODEATTR($$CN,arch)__-netboot-compute pkglist=/install/custom/netboot/ubuntu/compute.ubuntu18.04.2.ppc64el.pkglist; fi cmd:if [[ "__GETNODEATTR($$CN,os)__" =~ "ubuntu16.04.5" ]] && [[ "__GETNODEATTR($$CN,arch)__" =~ "x86" ]]; then chdef -t osimage -o __GETNODEATTR($$CN,os)__-__GETNODEATTR($$CN,arch)__-netboot-compute -p pkgdir="http://archive.ubuntu.com/ubuntu xenial universe main,http://archive.ubuntu.com/ubuntu xenial-updates universe main,http://security.ubuntu.com/ubuntu xenial-security main restricted";fi cmd:lsdef -t osimage -o __GETNODEATTR($$CN,os)__-__GETNODEATTR($$CN,arch)__-netboot-compute cmd:genimage __GETNODEATTR($$CN,os)__-__GETNODEATTR($$CN,arch)__-netboot-compute check:rc==0 -cmd:mount |sort > /tmp/mountoutput/file.new +cmd:/opt/xcat/share/xcat/tools/autotest/testcase/commoncmd/mount_snapshot.sh > /tmp/mountoutput/file.new cmd:cat /tmp/mountoutput/file.new -cmd:diff /tmp/mountoutput/file.org /tmp/mountoutput/file.new --ignore-matching-lines="fusectl" +cmd:diff /tmp/mountoutput/file.org /tmp/mountoutput/file.new check:rc==0 cmd:rm -rf /tmp/mountoutput cmd:packimage __GETNODEATTR($$CN,os)__-__GETNODEATTR($$CN,arch)__-netboot-compute @@ -148,16 +148,16 @@ cmd:if [[ -f /test.synclist ]] ;then mv -f /test.synclist /test.synclist.bak;fi; cmd:echo "/test.synclist -> /test.synclist" > /test.synclist;chdef -t osimage -o __GETNODEATTR($$CN,os)__-__GETNODEATTR($$CN,arch)__-netboot-compute synclists=/test.synclist check:rc==0 cmd:if [ ! -d /tmp/mountoutput ]; then mkdir -p /tmp/mountoutput; fi -cmd:mount |sort > /tmp/mountoutput/file.org +cmd:/opt/xcat/share/xcat/tools/autotest/testcase/commoncmd/mount_snapshot.sh > /tmp/mountoutput/file.org cmd:cat /tmp/mountoutput/file.org cmd:if [[ "__GETNODEATTR($$CN,os)__" =~ "ubuntu18.04.2" ]] && [[ "__GETNODEATTR($$CN,arch)__" =~ ppc64(el|le) ]] && [[ "__GETNODEATTR($$CN,mgt)__" =~ "kvm" ]] ; then mkdir -p /install/custom/netboot/ubuntu; sed -e 's@linux-image-generic-hwe-18.04@linux-image-generic@g' /install/custom/netboot/ubuntu/compute.ubuntu18.04.2.ppc64el.pkglist; chdef -t osimage -o __GETNODEATTR($$CN,os)__-__GETNODEATTR($$CN,arch)__-netboot-compute pkglist=/install/custom/netboot/ubuntu/compute.ubuntu18.04.2.ppc64el.pkglist; fi cmd:if [[ "__GETNODEATTR($$CN,os)__" =~ "ubuntu16.04.5" ]] && [[ "__GETNODEATTR($$CN,arch)__" =~ "x86" ]]; then chdef -t osimage -o __GETNODEATTR($$CN,os)__-__GETNODEATTR($$CN,arch)__-netboot-compute -p pkgdir="http://archive.ubuntu.com/ubuntu xenial universe main,http://archive.ubuntu.com/ubuntu xenial-updates universe main,http://security.ubuntu.com/ubuntu xenial-security main restricted";fi cmd:lsdef -t osimage -o __GETNODEATTR($$CN,os)__-__GETNODEATTR($$CN,arch)__-netboot-compute cmd:genimage __GETNODEATTR($$CN,os)__-__GETNODEATTR($$CN,arch)__-netboot-compute check:rc==0 -cmd:mount |sort > /tmp/mountoutput/file.new +cmd:/opt/xcat/share/xcat/tools/autotest/testcase/commoncmd/mount_snapshot.sh > /tmp/mountoutput/file.new cmd:cat /tmp/mountoutput/file.new -cmd:diff /tmp/mountoutput/file.org /tmp/mountoutput/file.new --ignore-matching-lines="fusectl" +cmd:diff /tmp/mountoutput/file.org /tmp/mountoutput/file.new check:rc==0 cmd:rm -rf /tmp/mountoutput diff --git a/xCAT-test/autotest/testcase/installation/reg_linux_diskless_installation_flat_postscripts_failed b/xCAT-test/autotest/testcase/installation/reg_linux_diskless_installation_flat_postscripts_failed index 41391a68f0..57064246ed 100644 --- a/xCAT-test/autotest/testcase/installation/reg_linux_diskless_installation_flat_postscripts_failed +++ b/xCAT-test/autotest/testcase/installation/reg_linux_diskless_installation_flat_postscripts_failed @@ -35,15 +35,15 @@ cmd:rootimgdir=`lsdef -t osimage __GETNODEATTR($$CN,os)__-__GETNODEATTR($$CN,arc check:rc==0 cmd:if [ ! -d /tmp/mountoutput ]; then mkdir -p /tmp/mountoutput; fi -cmd:mount |sort > /tmp/mountoutput/file.org +cmd:/opt/xcat/share/xcat/tools/autotest/testcase/commoncmd/mount_snapshot.sh > /tmp/mountoutput/file.org cmd:cat /tmp/mountoutput/file.org cmd:if [[ "__GETNODEATTR($$CN,os)__" =~ "ubuntu16.04.5" ]] && [[ "__GETNODEATTR($$CN,arch)__" =~ "x86" ]]; then chdef -t osimage -o __GETNODEATTR($$CN,os)__-__GETNODEATTR($$CN,arch)__-netboot-compute -p pkgdir="http://archive.ubuntu.com/ubuntu xenial universe main,http://archive.ubuntu.com/ubuntu xenial-updates universe main,http://security.ubuntu.com/ubuntu xenial-security main restricted";fi cmd:lsdef -t osimage -o __GETNODEATTR($$CN,os)__-__GETNODEATTR($$CN,arch)__-netboot-compute cmd:genimage __GETNODEATTR($$CN,os)__-__GETNODEATTR($$CN,arch)__-netboot-compute check:rc==0 -cmd:mount |sort > /tmp/mountoutput/file.new +cmd:/opt/xcat/share/xcat/tools/autotest/testcase/commoncmd/mount_snapshot.sh > /tmp/mountoutput/file.new cmd:cat /tmp/mountoutput/file.new -cmd:diff /tmp/mountoutput/file.org /tmp/mountoutput/file.new --ignore-matching-lines="fusectl" +cmd:diff /tmp/mountoutput/file.org /tmp/mountoutput/file.new check:rc==0 cmd:rm -rf /tmp/mountoutput cmd:packimage __GETNODEATTR($$CN,os)__-__GETNODEATTR($$CN,arch)__-netboot-compute diff --git a/xCAT-test/bats/mount_snapshot.bats b/xCAT-test/bats/mount_snapshot.bats new file mode 100644 index 0000000000..b2b1fffc4d --- /dev/null +++ b/xCAT-test/bats/mount_snapshot.bats @@ -0,0 +1,74 @@ +#!/usr/bin/env bats +# +# Drive mount_snapshot.sh, which the diskless cases use to compare the mount table before and +# after genimage. The comparison exists to catch a bind mount genimage leaves inside the root +# image, and it must keep catching one. +# +# The snapshots below are real lines from an openEuler 22.03 management node. On that run +# binfmt_misc and tracefs appeared between the two snapshots and failed the case, so the first +# test holds down that they are ignored. The second test is the one that matters: a leaked +# genimage bind must still be reported, which is why filtering by filesystem type is wrong. + +load 'helpers/shell_source' + +ROOTIMG=/install/netboot/openeuler22.03sp4/x86_64/compute/rootimg + +setup() +{ + SCRIPT="$(require_repo_file 'xCAT-test/autotest/testcase/commoncmd/mount_snapshot.sh')" + BEFORE="${BATS_TEST_TMPDIR}/file.org" + AFTER="${BATS_TEST_TMPDIR}/file.new" + + cat >"$BEFORE" <>"$AFTER" <>"$AFTER" + + run diff <("$SCRIPT" "$BEFORE") <("$SCRIPT" "$AFTER") + [ "$status" -ne 0 ] + [[ "$output" == *"$ROOTIMG/proc"* ]] +} + +# An ordinary mount outside /proc and /sys is the other half of the same requirement. +@test "an NFS mount left behind is still reported" { + cp "$BEFORE" "$AFTER" + printf '192.0.2.1:/install on /mnt/install type nfs4 (rw,relatime)\n' >>"$AFTER" + + run diff <("$SCRIPT" "$BEFORE") <("$SCRIPT" "$AFTER") + [ "$status" -ne 0 ] + [[ "$output" == *"/mnt/install"* ]] +} + +@test "the snapshot keeps the real mounts and drops only the kernel's own" { + run "$SCRIPT" "$BEFORE" + [ "$status" -eq 0 ] + [[ "$output" == *" on / type xfs"* ]] + [[ "$output" == *" on /run type tmpfs"* ]] + [[ "$output" == *" on /dev type devtmpfs"* ]] + refute_grep -q ' on /proc ' <<<"$output" + refute_grep -q ' on /sys ' <<<"$output" + refute_grep -q '/sys/kernel/tracing' <<<"$output" +}