From 3529b7a5e15926272fd91000b6bb0fd2980c58f6 Mon Sep 17 00:00:00 2001 From: Louis Abel Date: Mon, 13 Nov 2023 17:14:57 -0700 Subject: [PATCH] add actual podman tests, start using trap --- func/core/pkg_acl/10-test-acl-functions.sh | 2 +- func/core/pkg_archive/10-bzip.sh | 3 +- func/core/pkg_archive/21-gzip-test.sh | 7 ++--- func/core/pkg_archive/22-gzexe.sh | 4 +-- func/core/pkg_archive/23-zcmp-zdiff.sh | 3 +- func/core/pkg_archive/24-zforce.sh | 3 +- func/core/pkg_archive/25-zgrep.sh | 3 +- func/core/pkg_archive/30-tar.sh | 3 +- func/core/pkg_archive/40-xzcmp-xzdiff.sh | 3 +- func/core/pkg_archive/40-zip.sh | 5 ++-- func/core/pkg_archive/50-lzop.sh | 5 ++-- func/core/pkg_podman/10-test-podman.sh | 28 +++++++++++++++++++ func/core/pkg_podman/11-test-podman-socket.sh | 28 +++++++++++++++++++ 13 files changed, 73 insertions(+), 24 deletions(-) diff --git a/func/core/pkg_acl/10-test-acl-functions.sh b/func/core/pkg_acl/10-test-acl-functions.sh index e4c1783..340f81c 100755 --- a/func/core/pkg_acl/10-test-acl-functions.sh +++ b/func/core/pkg_acl/10-test-acl-functions.sh @@ -2,6 +2,7 @@ ACLFILE=/tmp/testfile_acl r_log "acl" "Test that the acl get and set functions work" touch "${ACLFILE}" +trap '/bin/rm -f ${ACLFILE}' EXIT # Use setfacl for readonly r_log "acl" "Set readonly ACL for the user nobody" @@ -12,4 +13,3 @@ r_log "acl" "Verifying that the nobody user is set to read only" getfacl "${ACLFILE}" | grep -q 'user:nobody:r--' r_checkExitStatus $? -/bin/rm -f "${ACLFILE}" diff --git a/func/core/pkg_archive/10-bzip.sh b/func/core/pkg_archive/10-bzip.sh index 9e7b90d..e7b7108 100755 --- a/func/core/pkg_archive/10-bzip.sh +++ b/func/core/pkg_archive/10-bzip.sh @@ -1,6 +1,7 @@ #!/bin/bash r_log "archive" "Test bzip/bzcat/bunzip" FILE=/var/tmp/bziptest.txt +trap '/bin/rm -f ${FILE}' EXIT cat > "$FILE" < /dev/null && /bin/rm -rf /var/tmp/gziptest &> /dev/null' EXIT + # Double check that stuff is cleared out /bin/rm $FILE* &> /dev/null /bin/rm -rf /var/tmp/gziptest &> /dev/null @@ -107,7 +110,3 @@ tar -czf $FILE.tgz $FILE &> /dev/null gunzip $FILE.tgz [ -e $FILE.tar ] r_checkExitStatus $? - -# clean up -/bin/rm $FILE* &> /dev/null -/bin/rm -rf /var/tmp/gziptest &> /dev/null diff --git a/func/core/pkg_archive/22-gzexe.sh b/func/core/pkg_archive/22-gzexe.sh index 9aa1b77..8aa1e14 100755 --- a/func/core/pkg_archive/22-gzexe.sh +++ b/func/core/pkg_archive/22-gzexe.sh @@ -2,6 +2,8 @@ r_log "archive" "Checking gzexe" r_log "archive" "Creating archive" FILE=/var/tmp/gzexe-test-script +trap '/bin/rm -f $FILE* 2>/dev/null' EXIT + /bin/rm -f $FILE* &>/dev/null cat > $FILE </dev/null diff --git a/func/core/pkg_archive/23-zcmp-zdiff.sh b/func/core/pkg_archive/23-zcmp-zdiff.sh index d176a58..378bbe9 100755 --- a/func/core/pkg_archive/23-zcmp-zdiff.sh +++ b/func/core/pkg_archive/23-zcmp-zdiff.sh @@ -1,6 +1,7 @@ #!/bin/bash r_log "archive" "Check zcmp and zdiff" BASEFILE="/var/tmp/gziptest" +trap '/bin/rm -f ${BASEFILE}*' EXIT /bin/rm -f ${BASEFILE} cat > ${BASEFILE}.1 </dev/null cat > $BASEFILE < /dev/null cat > $BASEFILE < $FILE1 < ${BASEFILE}.1 < $FILE1 < ${LZOFILE} @@ -13,5 +14,5 @@ lzop -d ${LZOFILE}.lzo -o ${LZOFILE} /bin/rm ${LZOFILE}.lzo grep -q 'Green Obsidian' ${LZOFILE} - -/bin/rm ${LZOFILE} +ret_val="$?" +r_checkExitStatus "$ret_val" diff --git a/func/core/pkg_podman/10-test-podman.sh b/func/core/pkg_podman/10-test-podman.sh index 759f91d..3cfc20b 100755 --- a/func/core/pkg_podman/10-test-podman.sh +++ b/func/core/pkg_podman/10-test-podman.sh @@ -2,3 +2,31 @@ r_log "podman" "Testing podman" +test_to_run=( + "podman version" + "podman info" + "podman run --rm quay.io/rockylinux/rockylinux:${RL_VER}" + "podman system service -t 1" + "touch ${HOME}/test.txt && \ + podman run --rm --privileged -v ${HOME}/test.txt:/test.txt quay.io/rockylinux/rockylinux:${RL_VER} bash -c 'echo HELLO > /test.txt' && \ + grep -qe 'HELLO' ${HOME}/test.txt && \ + rm -f ${HOME}/test.txt" + "printf \"FROM quay.io/rockylinux/rockylinux:${RL_VER}\nCMD echo 'HELLO'\n\" > ${HOME}/Containerfile && \ + podman build -t test:latest -f ${HOME}/Containerfile && \ + podman image rm localhost/test:latest && \ + rm -rf ${HOME}/Containerfile" +) + +tmpoutput="$(mktemp)" +trap 'rm -f ${tmpoutput}' EXIT + +for command in "${test_to_run[@]}"; do + r_log "podman" "Running $0: ${command}" + if ! eval "${command}" > "${tmpoutput}" 2>&1; then + r_log "podman" "${command} has failed." + cat "${tmpoutput}" + exit 1 + else + r_checkExitStatus 0 + fi +done diff --git a/func/core/pkg_podman/11-test-podman-socket.sh b/func/core/pkg_podman/11-test-podman-socket.sh index 2f37acf..57562ad 100755 --- a/func/core/pkg_podman/11-test-podman-socket.sh +++ b/func/core/pkg_podman/11-test-podman-socket.sh @@ -1,3 +1,31 @@ #!/bin/bash r_log "podman" "Testing podman sockets" + +useradd podman-remote +loginctl enable-linger podman-remote +tmpoutput="$(mktemp)" + +trap 'loginctl terminate-user podman-remote && loginctl disable-linger podman-remote && sleep 1 && userdel -r podman-remote && rm -f ${tmpoutput}' EXIT + +sleep 3 + +su -l podman-remote > "${tmpoutput}" 2>&1 <