2
0
mirror of https://github.com/xcat2/xcat-core.git synced 2026-11-21 09:52:17 +00:00

Merge pull request #7987 from VersatusHPC/fix/diskless-mount-snapshot-kernel-mounts

fix(xcat-test): the diskless cases fail when the kernel mounts binfmt_misc
This commit is contained in:
Daniel Hilst
2026-10-29 14:32:18 -03:00
committed by GitHub
5 changed files with 116 additions and 12 deletions
+30
View File
@@ -0,0 +1,30 @@
#!/bin/sh
#
# mount_snapshot.sh [<file>]
#
# 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
@@ -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
@@ -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' </opt/xcat/share/xcat/netboot/ubuntu/compute.ubuntu18.04.2.ppc64el.pkglist >/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' </opt/xcat/share/xcat/netboot/ubuntu/compute.ubuntu18.04.2.ppc64el.pkglist >/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
@@ -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
+74
View File
@@ -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" <<EOF
/dev/vda2 on / type xfs (rw,relatime,attr2,inode64,logbufs=8,logbsize=32k,noquota)
devtmpfs on /dev type devtmpfs (rw,nosuid,size=4096k,nr_inodes=1048576,mode=755)
proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)
sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime)
systemd-1 on /proc/sys/fs/binfmt_misc type autofs (rw,relatime,fd=34,pgrp=1,timeout=0)
tmpfs on /run type tmpfs (rw,nosuid,nodev,size=1985536k,mode=755)
tracefs on /sys/kernel/tracing type tracefs (rw,nosuid,nodev,noexec,relatime)
EOF
}
# The kernel may mount either of these at any moment. Neither is xCAT's doing.
@test "an on-demand kernel mount appearing during genimage is ignored" {
cp "$BEFORE" "$AFTER"
cat >>"$AFTER" <<EOF
binfmt_misc on /proc/sys/fs/binfmt_misc type binfmt_misc (rw,nosuid,nodev,noexec,relatime)
tracefs on /sys/kernel/debug/tracing type tracefs (rw,nosuid,nodev,noexec,relatime)
EOF
diff <("$SCRIPT" "$BEFORE") <("$SCRIPT" "$AFTER")
}
# The discriminator. A leaked bind is a proc mount, so a type filter would drop it and the
# comparison could never fail again.
@test "a bind mount genimage left inside the root image is still reported" {
cp "$BEFORE" "$AFTER"
printf 'proc on %s/proc type proc (rw,nosuid,nodev,noexec,relatime)\n' "$ROOTIMG" >>"$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"
}