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" +}