mirror of
https://github.com/xcat2/xcat-core.git
synced 2026-11-25 03:42:14 +00:00
91e6672110
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>
75 lines
3.1 KiB
Bash
75 lines
3.1 KiB
Bash
#!/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"
|
|
}
|