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 14, 2024
1 parent 75090b7 commit 00df69c
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 10 deletions.
28 changes: 20 additions & 8 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ jobs:
run: |
# Build on Ubuntu
set -e
# Add a new binfmt entry that matches APE's (Actually Portable Executable)'s
# magic number to avoid execution by Ubuntu's built-in "MZ" binfmt
# interpreter which "helpfully" tries to run the binary with Wine.
Expand Down Expand Up @@ -62,19 +64,29 @@ jobs:
run: |
# Test on Ubuntu
# Add a new binfmt entry that matches APE's (Actually Portable Executable)'s
# magic number to avoid execution by Ubuntu's built-in "MZ" binfmt
# interpreter which "helpfully" tries to run the binary with Wine.
sudo apt install -y binfmt-support
sudo update-binfmts --install APE /bin/sh --magic MZqFpD
set -e
# Test the assimiate workaround here
sudo chmod +x sanoid-portable
sh ./sanoid-portable --assimilate
./test.sh
./test-smoke.sh
- name: Test in FreeBSD
uses: vmactions/freebsd-vm@v1
with:
usesh: true
prepare: |
pkg install -y jq
pkg install -y bash jq wget
run: |
./test.sh
set -e
echo 'Begin smoke tests...'
./test-smoke.sh
echo 'Completed smoke tests.'
echo ''
echo 'Begin integration tests...'
./test-integration.sh
echo 'Completed integration tests.'
1 change: 1 addition & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ jobs:
sudo update-binfmts --install APE /bin/sh --magic MZqFpD
sudo chmod +x sanoid-portable
sanoid_version=$(./sanoid-portable --version)
release_version="${{ github.event.release.tag_name }}"
Expand Down
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
92 changes: 92 additions & 0 deletions test-integration.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#!/usr/bin/env bash

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 64M $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_dataset
zfs list -rt all

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

echo 'Create /etc/sanoid/sanoid.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 in the dataset...'
date > $test_file_path

echo 'Run sanoid to take snapshots of the dataset...'
./sanoid --take-snapshots --verbose

echo 'Update test file with new data...'
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 all

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

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

echo 'List all snapshots on both pools...'
zfs list -rt all

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

echo "Execute sanoid to prune snapshots on ${prod_dataset}..."
./sanoid --prune-snapshots --verbose

echo "List all snapshots on ${prod_dataset}..."
zfs list -rt all $prod_dataset

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

echo 'Destroying test pools...'
for pool in $prod_pool $backup_pool; do
zpool destroy -f $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 00df69c

Please sign in to comment.