Skip to content

Commit

Permalink
Run a full integration test with a ZFS filesystem during build
Browse files Browse the repository at this point in the history
  • Loading branch information
decoyjoe committed Dec 13, 2024
1 parent 376ccd3 commit f7e93b4
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 4 deletions.
12 changes: 10 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ jobs:
sudo apt install -y binfmt-support
sudo update-binfmts --install APE /bin/sh --magic MZqFpD
./test.sh
./test-smoke.sh
- name: Test in FreeBSD
uses: vmactions/freebsd-vm@v1
Expand All @@ -77,4 +77,12 @@ jobs:
prepare: |
pkg install -y jq
run: |
./test.sh
echo 'Begin smoke tests...'
./test-smoke.sh
echo 'Completed smoke tests.'
echo ''
echo 'Begin integration tests...'
./test-integration.sh
echo 'Completed integration tests.'
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,6 @@ echo ''
echo 'Testing...'
echo ''

"${repo_root}/test.sh"
"${repo_root}/test-smoke.sh"

popd > /dev/null
90 changes: 90 additions & 0 deletions test-integration.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#!/usr/bin/env sh

set -eu

output_dir=$(pwd)
prod_disk="${output_dir}/disk-production.raw"
backup_disk="${output_dir}/disk-backup.raw"

echo 'Create sparse files to use as disks for ZFS...'
for disk_file in $prod_disk $backup_disk; do
truncate -s 10M $disk_file
ls -l $disk_file
done

prod_pool='production-pool'
backup_pool='backup-pool'

echo 'Create ZFS pools...'
zpool create $prod_pool $prod_disk
zpool create $backup_pool $backup_disk

zpool status

prod_dataset="${prod_pool}\test"
backup_dataset="${backup_pool}\test"
echo "Create dataset \"${prod_dataset}\"..." # backup dataset created from syncoid replication
zfs create $prod_pool
zfs list -rt all $prod_pool

echo 'Create sanoid config...'
mkdir /etc/sanoid
wget -O /etc/sanoid/sanoid.defaults.conf https://github.com/jimsalterjrs/sanoid/raw/refs/tags/v2.2.0/sanoid.defaults.conf

cat < EOF > /etc/sanoid/sanoid.conf
[${prod_dataset}]
use_template = default
frequently = 60
frequent_period = 1
EOF

test_file_path="/${prod_dataset}/date.txt"

echo 'Create an initial test file with data...'
echo date > $test_file_path

echo 'Run sanoid to take snapshots...'
./sanoid --take-snapshots --verbose

echo 'Update test file with new data...'
echo date > $test_file_path

echo 'Wait 1 minute to take another snapshot...'
sleep 1m

echo 'Taking new snapshot with sanoid...'
./sanoid --take-snapshots --verbose

echo 'List all snapshots...'
zfs list -rt $prod_pool

echo 'Execute findoid to test locating snapshots containing a given file...'
./findoid $test_file_path

echo 'Execute syncoid to replicate snapshots to backup pool...'
./syncoid $prod_dataset $backup_pool

echo 'List all snapshots on backup pool...'
zfs list -rt all $backup_pool

echo 'Adjust sanoid config to prune minute-ly snapshots...'
cat < EOF > /etc/sanoid/sanoid.conf
[${prod_dataset}]
use_template = default
frequently = 0
EOF

echo 'Execute sanoid to prune snapshots...'
./sanoid --prune-snapshots --verbose

echo 'List all snapshots...'
zfs list -rt $prod_pool

echo ''
echo 'sanoid, findoid, and syncoid tested successfully!'
echo ''

echo 'Destroying test pools...'
for pool in $prod_pool $backup_pool; do
zfs destroy $pool
done
2 changes: 1 addition & 1 deletion test.sh → test-smoke.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ set -eu
output_dir=$(pwd)

# Optionally pass in the output directory
# Usage: test.sh [output-directory]
# Usage: test-smoke.sh [output-directory]
if [ $# -gt 0 ] && [ -n "${1}" ]; then
output_dir=$(realpath "${1}")
fi
Expand Down

0 comments on commit f7e93b4

Please sign in to comment.