Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Mrfai committed Sep 25, 2022
1 parent 78e467e commit 88cc45f
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 66 deletions.
4 changes: 3 additions & 1 deletion debian/tests/config-space
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ set -e

. ./debian/tests/common.sh

# needs fai-doc
fai-mk-configspace

# test the results of the commands called
chk-file $CS/class/50-host-classes
chk-file $CS/scripts/GRUB_EFI/10-setup
chk-file $CS/disk_config/FAIBASE
chk-file $CS/etc/rc.local/FAISERVER
17 changes: 11 additions & 6 deletions debian/tests/control
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
Tests: config-space utils
Tests: utils
Depends: fai-server, fai-doc
Architecture: amd64

Tests: nfsroot dirinstall
Tests: config-space nfsroot dirinstall
Restrictions: isolation-container needs-root needs-internet
Depends: fai-server, fai-doc
Architecture: amd64

Tests: fai-mirror
Restrictions: isolation-container needs-internet
Depends: fai-server, fai-doc, reprepro, binutils
Architecture: amd64

Tests: fai-cd
Restrictions: isolation-container needs-root needs-internet
Depends: fai-server, fai-doc, reprepro, xorriso, squashfs-tools, binutils
Restrictions: isolation-machine needs-root
Depends: fai-server, fai-doc, xorriso, squashfs-tools, binutils, dosfstools, mtools
Architecture: amd64

Tests: diskimage
Restrictions: isolation-container needs-root needs-internet
Depends: fai-server, fai-doc, reprepro, xorriso, squashfs-tools, binutils, fai-setup-storage
Restrictions: isolation-container needs-root needs-internet skippable
Depends: fai-server, fai-doc, reprepro, binutils, fai-setup-storage, qemu-utils
Architecture: amd64

17 changes: 8 additions & 9 deletions debian/tests/dirinstall
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
#! /bin/bash

# test fai dirinstall

set -eu

. ./debian/tests/common.sh

# test fai dirinstall

trap "cp -avL dirinstall.log $AUTOPKGTEST_ARTIFACTS" INT QUIT EXIT
cd "$AUTOPKGTEST_TMP"

ch=/srv/chroot
cl="DEBIAN,AMD64,FAIBASE,DHCPC,DEMO,LAST"
export NIC1=dummy
LC_ALL=C fai -v dirinstall -c $cl -s file://$CS $ch >& dirinstall.log

chk-size $ch 800


# test the results of the commands called
chk-size $ch 780
chk-size $ch/boot 30

# chroot into and execute some commands
Expand All @@ -36,8 +39,4 @@ if grep -q FAILED dirinstall.log; then
error "dirinstall failed. See dirinstall.log"
fi

# check if $ch is unset or /
#rm -rf $ch

echo rm -rf $ch
cp -avpL /var/log/fai/localhost/last-dirinstall/dirinstall.log dirinstall.log $AUTOPKGTEST_ARTIFACTS
rm -rf $ch
28 changes: 17 additions & 11 deletions debian/tests/diskimage
Original file line number Diff line number Diff line change
@@ -1,22 +1,30 @@
#! /bin/bash

# fai-diskimage
# Depends fai-setup-storage
# apt -o APT::Install-Suggests=0 -o APT::Install-Recommends=0 install fai-setup-storage

set -e

. ./debian/tests/common.sh

cd "$AUTOPKGTEST_TMP"

# add skippable
# check if I can mount loop devices
# if not suported, exit 77

# check if we can use loop devices
trap 'exit 77' ERR ABRT EXIT QUIT
qemu-img create test.raw 10M
loop=$(losetup -P -f --show test.raw)
echo "LOOP: $loop"
losetp -d $loop
rm test.raw
trap - ERR ABRT EXIT QUIT

# fai-diskimage
# Depends fai-setup-storage
# apt -o APT::Install-Suggests=0 -o APT::Install-Recommends=0 install fai-setup-storage
trap "cp -vap /var/log/fai/cloud3 $AUTOPKGTEST_ARTIFACTS" INT QUIT EXIT

cl="DEBIAN,BUSTER64,AMD64,FAIBASE,GRUB_PC,DHCPC,DEMO,CLOUD,LAST"
LC_ALL=C fai-diskimage -vu cloud3 -S2G -c$cl cloud.raw


# test the results of the commands called
chk-size cloud.raw 900

mount -oloop,offset=1048576 cloud.raw /mnt
Expand All @@ -27,6 +35,4 @@ if grep -q FAILED $ch/var/log/fai/cloud3/last/status.log; then
error "fai-diskimage failed. See status.log"
fi

cp -vap /var/log/fai/cloud3 $AUTOPKGTEST_ARTIFACTS

# rm cloud.raw
rm cloud.raw
32 changes: 8 additions & 24 deletions debian/tests/fai-cd
Original file line number Diff line number Diff line change
@@ -1,42 +1,26 @@
#! /bin/bash

# test fai-cd

set -e

. ./debian/tests/common.sh

trap "cp -vp fai-cd.log $AUTOPKGTEST_ARTIFACTS" INT QUIT EXIT
cd "$AUTOPKGTEST_TMP"

# test fai-mirror and fai-cd

# fai-mirror
fai-mirror -s$CS -m1 -xARM64,I386,CENTOS,UBUNTU,FOCAL,CLOUD,CHROOT,STANDARD,NONFREE,GNOME mirror >& mirror.log
# - - - - - - - - - - - - - - - - -
fai-cd -Jm /tmp/mirror faicd64-small.iso >& fai-cd.log
echo fai-cd exit code: $?

chk-size mirror 900
find mirror -name \*.deb > pkg.list
n=$(wc -l pkg.list | awk '{ print $1}')
if [ $n -lt 1300 ]; then
error "fai-mirror includes too few packages. Only $n found."
fi

# check some package names in the mirror
pkgs="linux-image- dracut-network_ xfce4-taskmanager_ gnome-shell_ gnome-terminal_ xfdesktop4_"
for p in $pkgs ; do
grep /$p pkg.list
done

# - - - - - - - - - - - - - - - - -
# fai-cd
fai-cd -c$csdir -fJm mirror faicd64-small.iso >& fai-cd.log

# check size of ISO
# test the results of the commands called
chk-size faicd64-small.iso 700

# more test after mounting the ISO
# mount -oloop faicd64-small.iso /mnt
# umount /mnt
# chk-size /mnt/boot/initrd.img 30


# rm faicd64-small.iso mirror.log fai-cd.log pkg.list

cp -vp mirror.log fai-cd.log $AUTOPKGTEST_ARTIFACTS
# rm faicd64-small.iso fai-cd.log
34 changes: 34 additions & 0 deletions debian/tests/fai-mirror
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#! /bin/bash

. ./debian/tests/common.sh
error=0; trap 'error=$(($?>$error?$?:$error))' ERR # save maximum error code
trap "cp -vp mirror.log $AUTOPKGTEST_ARTIFACTS" INT QUIT EXIT
cd "$AUTOPKGTEST_TMP"

mdir=/tmp/mirror
fai-mirror -s$CS -m1 -xARM64,I386,ROCKY,UBUNTU,FOCAL,CLOUD,CHROOT,STANDARD,NONFREE,GNOME $mdir >& mirror.log

# test the results of the commands called
s=$(du -sm --exclude aptcache --exclude db $mdir | awk '{print $1}')
if [ $s -lt 420 ]; then
error "$mdir is too small: $s MB"
else
echo "OK: $mdir size is $s MB"
fi

find $mdir -name \*.deb > pkg.list
n=$(wc -l pkg.list | awk '{ print $1}')
if [ $n -lt 800 ]; then
error "fai-mirror includes too few packages. Only $n found."
else
echo "OK. Number of packages found in mirror: $n"
fi

# check some package names in the mirror
pkgs="linux-image- dracut-network_ xfce4-taskmanager_ xfdesktop4_ syslinux-common_ lvm2_"
for p in $pkgs ; do
echo Search for $p
grep /$p pkg.list
done

exit $error
11 changes: 6 additions & 5 deletions debian/tests/nfsroot
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
set -e

. ./debian/tests/common.sh

cd "$AUTOPKGTEST_TMP"
trap "cp -vp /var/log/fai/fai-make-nfsroot.log nfsroot.log $AUTOPKGTEST_ARTIFACTS" INT QUIT EXIT

fai-make-nfsroot -gv > nfsroot.log
echo "exit code fai-make-nfsroot: $?"

# test the results of the commands called
chk-size $N 700

grep 'fai-make-nfsroot finished properly.' nfsroot.log
Expand All @@ -18,8 +21,8 @@ chk-file $TFTP/pxelinux.0
chk-file $TFTP/syslinux.efi
chk-size $N/boot/initrd.img* 40

$N/usr/bin/lsinitrd -m $N/initrd.img | grep livenet
$N/usr/bin/lsinitrd $N/initrd.img | grep mount.nfs
chroot $N /usr/bin/lsinitrd -m /initrd.img | grep livenet
chroot $N /usr/bin/lsinitrd /initrd.img | grep mount.nfs

# - - - - - - - - - - - - - - - - -
# fai-chboot
Expand All @@ -30,5 +33,3 @@ fai-chboot -Iv -f verbose,sshd,createvt,menu -u nfs://faiserver/$CS localhost 2>

chk-file $TFTP/pxelinux.cfg/test.tmpl
chk-file $TFTP/pxelinux.cfg/7F000001

cp -vp /var/log/fai/fai-make-nfsroot.log nfsroot.log $AUTOPKGTEST_ARTIFACTS
19 changes: 9 additions & 10 deletions debian/tests/utils
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
#! /bin/bash

# test some FAI utilities

set -e

. ./debian/tests/common.sh

# test some FAI utilities

cd "$AUTOPKGTEST_TMP"

echo "7565a01bd35f31ba82ab55c978c1b755 testfile" > testfile.md5sum
Expand All @@ -17,17 +16,17 @@ md5sum -c testfile.md5sum

fai-link linka testfile
fai-link linka testfile
fai-sed 's/testfile/XXX/' testfile.md5sum
fai-sed 's/testfile/AAA/' testfile.md5sum
fai-sed -E 's/testfile/XXX/' testfile.md5sum
mv testfile XXX
fai-sed 's/testfile/newfile/' testfile.md5sum
fai-sed 's/testfile/AAA/' testfile.md5sum
fai-sed -E 's/testfile/newfile/' testfile.md5sum
mv testfile newfile
md5sum -c testfile.md5sum

# test if symlink was created
fai-sed 's/XXX/linkb/' testfile.md5sum
fai-link linkb XXX
fai-sed 's/newfile/linkb/' testfile.md5sum
fai-link linkb newfile
md5sum -c testfile.md5sum

# TODO: fcopy

rm testfile.md5sum linka linkb XXX
rm testfile.md5sum linka linkb newfile

0 comments on commit 88cc45f

Please sign in to comment.