Skip to content

Commit

Permalink
add actual podman tests, start using trap
Browse files Browse the repository at this point in the history
  • Loading branch information
nazunalika committed Nov 14, 2023
1 parent f5a4d2f commit 3529b7a
Show file tree
Hide file tree
Showing 13 changed files with 73 additions and 24 deletions.
2 changes: 1 addition & 1 deletion func/core/pkg_acl/10-test-acl-functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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}"
3 changes: 1 addition & 2 deletions func/core/pkg_archive/10-bzip.sh
Original file line number Diff line number Diff line change
@@ -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" <<EOF
testing text
Expand All @@ -23,5 +24,3 @@ fi
grep -q 'testing text' "${FILE}"

r_checkExitStatus $?

/bin/rm -f "${FILE}*"
7 changes: 3 additions & 4 deletions func/core/pkg_archive/21-gzip-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ r_log "archive" "Test gzip/zcat/gunzip"
FILE=/var/tmp/gzip-test.txt
MD5HASH=e6331c582fbad6653832860f469f7d1b

# clean up
trap '/bin/rm $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
Expand Down Expand Up @@ -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
4 changes: 2 additions & 2 deletions func/core/pkg_archive/22-gzexe.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 <<EOF
Expand All @@ -18,5 +20,3 @@ r_log "archive" "Test gzexe"
r_log "archive" "Check that it actually runs"
$FILE | grep -q "Hello!"
r_checkExitStatus $?

/bin/rm -f $FILE* 2>/dev/null
3 changes: 1 addition & 2 deletions func/core/pkg_archive/23-zcmp-zdiff.sh
Original file line number Diff line number Diff line change
@@ -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 <<EOF
Expand All @@ -15,5 +16,3 @@ r_log "archive" "Check zcmp"

r_log "archive" "Check zdiff"
/bin/zdiff ${BASEFILE}.1.gz ${BASEFILE}.2.gz || r_checkExitStatus 1

/bin/rm -f ${BASEFILE}*
3 changes: 1 addition & 2 deletions func/core/pkg_archive/24-zforce.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
r_log "archive" "Testing zforce"

BASEFILE="/var/tmp/abcdefg"
trap '/bin/rm "$BASEFILE.gz"' EXIT
/bin/rm $BASEFILE* &>/dev/null

cat > $BASEFILE <<EOF
Expand All @@ -14,5 +15,3 @@ mv $BASEFILE.gz $BASEFILE
zforce $BASEFILE || r_checkExitStatus 1
[ -e "$BASEFILE.gz" ]
r_checkExitStatus $?

/bin/rm "$BASEFILE.gz"
3 changes: 1 addition & 2 deletions func/core/pkg_archive/25-zgrep.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/bin/bash
r_log "archive" "Testing zgrep"
BASEFILE=/var/tmp/zgreptest
trap '/bin/rm $BASEFILE*' EXIT
/bin/rm $BASEFILE* &> /dev/null

cat > $BASEFILE <<EOF
Expand All @@ -11,5 +12,3 @@ gzip $BASEFILE

zgrep -q 'Green Obsidian' $BASEFILE.gz
r_checkExitStatus $?

/bin/rm $BASEFILE*
3 changes: 1 addition & 2 deletions func/core/pkg_archive/30-tar.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ r_log "archive" "Test tar create and extract"
TARDIR="/var/tmp/tartest"
FILE1="$TARDIR/test.1.txt"
FILE2="$TARDIR/test.2.txt"
trap '/bin/rm -rf /var/tmp/tarfile.tar $TARDIR' EXIT

mkdir -p $TARDIR
cat > $FILE1 <<EOF
Expand Down Expand Up @@ -32,5 +33,3 @@ if [ $RES1 == 0 ] && [ $RES2 == 0 ]; then
fi

r_checkExitStatus $ret_val

/bin/rm -rf /var/tmp/tarfile.tar $TARDIR
3 changes: 1 addition & 2 deletions func/core/pkg_archive/40-xzcmp-xzdiff.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/bin/bash
r_log "archive" "Check xzcmp and xzdiff"
BASEFILE="/var/tmp/xztest"
trap '/bin/rm -f ${BASEFILE}*' EXIT
/bin/rm -f ${BASEFILE}

cat > ${BASEFILE}.1 <<EOF
Expand All @@ -15,5 +16,3 @@ r_log "archive" "Check xzcmp"

r_log "archive" "Check xzdiff"
/bin/zdiff ${BASEFILE}.1.xz ${BASEFILE}.2.xz || r_checkExitStatus 1

/bin/rm -f ${BASEFILE}*
5 changes: 2 additions & 3 deletions func/core/pkg_archive/40-zip.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ r_log "archive" "Test zip create and extract"
ZIPDIR="/var/tmp/ziptest"
FILE1="$ZIPDIR/test.1.txt"
FILE2="$ZIPDIR/test.2.txt"
trap '/bin/rm -rf /var/tmp/zipfile.zip $ZIPDIR' EXIT

mkdir -p $ZIPDIR
cat > $FILE1 <<EOF
Expand Down Expand Up @@ -31,6 +32,4 @@ if [ $RES1 == 0 ] && [ $RES2 == 0 ]; then
ret_val=0
fi

r_checkExitStatus $ret_val

/bin/rm -rf /var/tmp/zipfile.zip $ZIPDIR
r_checkExitStatus "$ret_val"
5 changes: 3 additions & 2 deletions func/core/pkg_archive/50-lzop.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
r_log "archive" "Testing lzop compress and decompress"

LZOFILE=/var/tmp/obsidian.txt
trap '/bin/rm ${LZOFILE}' EXIT

echo 'Green Obsidian is the release name' > ${LZOFILE}

Expand All @@ -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"
28 changes: 28 additions & 0 deletions func/core/pkg_podman/10-test-podman.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
28 changes: 28 additions & 0 deletions func/core/pkg_podman/11-test-podman-socket.sh
Original file line number Diff line number Diff line change
@@ -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 <<EOF
set -e
export XDG_RUNTIME_DIR=/run/user/\$(id -u)
systemctl --user enable --now podman.socket
podman --url unix://run/user/\$(id -u)/podman/podman.sock run --name port-mapping-test -d -p 8080:80 docker.io/nginx
pid=\$(systemctl --user show --property MainPID --value podman.service)
while [ "\${pid}" -ne 0 ] && [ -d /proc/\${pid} ]; do sleep 1; echo "Waiting for podman to exit"; done
podman --url unix://run/user/\$(id -u)/podman/podman.sock ps | grep -q -e port-mapping-test
podman --url unix://run/user/\$(id -u)/podman/podman.sock container rm -f port-mapping-test
systemctl --user disable --now podman.socket
EOF

ret_val=$?

if [ "$ret_val" -ne 0 ]; then
cat "${tmpoutput}"
r_checkExitStatus 1
fi
r_checkExitStatus 0

0 comments on commit 3529b7a

Please sign in to comment.