mirror of
https://github.com/markusressel/zfs-inplace-rebalancing
synced 2026-02-05 05:24:07 +00:00
Test mac os (#53)
* add: test on MacOS Add test for MacOS in Github action Maybe see this to add test for FreeBSD : https://github.com/marketplace/actions/freebsd-vm * add: log to test adding log to the test for better understanding * fix: shellcheck remove the yellow color that is unused in the test * fix: fail on lower-casting the `"${variable,,}"` seam to not work on macOS so y remove it for the `skip_hardlink_flag` because it's always lowercase * fix: macOS remove all the lower-case casting * fix(perf): going to `stat` remove `lsattr` macOS The command `lsattr` is not supported on macOS so I have remove it switch to `stat` instead of `ls` for better performance and no subshell use of parameter expansion with `%` in place of `awk` for performance and no subshell * fix: forgot to remove variable
This commit is contained in:
parent
922531829e
commit
bd8d447150
13
.github/workflows/test.yml
vendored
13
.github/workflows/test.yml
vendored
@ -9,11 +9,20 @@ on:
|
|||||||
branches: [ master ]
|
branches: [ master ]
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
shellcheck:
|
linuxTest:
|
||||||
name: Test
|
name: Test on Linux
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Run testing script
|
- name: Run testing script
|
||||||
run: ./testing.sh
|
run: ./testing.sh
|
||||||
|
|
||||||
|
macOsTest:
|
||||||
|
name: Test on macOS
|
||||||
|
runs-on: macos-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Run testing script on macOS
|
||||||
|
run: ./testing.sh
|
||||||
35
testing.sh
35
testing.sh
@ -10,6 +10,25 @@ log_error_file=./error.log
|
|||||||
test_data_src=./test/pool
|
test_data_src=./test/pool
|
||||||
test_pool_data_path=./testing_data
|
test_pool_data_path=./testing_data
|
||||||
|
|
||||||
|
## Color Constants
|
||||||
|
|
||||||
|
# Reset
|
||||||
|
Color_Off='\033[0m' # Text Reset
|
||||||
|
|
||||||
|
# Regular Colors
|
||||||
|
Red='\033[0;31m' # Red
|
||||||
|
Green='\033[0;32m' # Green
|
||||||
|
Cyan='\033[0;36m' # Cyan
|
||||||
|
|
||||||
|
## Functions
|
||||||
|
|
||||||
|
# print a given text entirely in a given color
|
||||||
|
function color_echo () {
|
||||||
|
color=$1
|
||||||
|
text=$2
|
||||||
|
echo -e "${color}${text}${Color_Off}"
|
||||||
|
}
|
||||||
|
|
||||||
function prepare() {
|
function prepare() {
|
||||||
# cleanup
|
# cleanup
|
||||||
rm -f $log_std_file
|
rm -f $log_std_file
|
||||||
@ -24,7 +43,7 @@ function prepare() {
|
|||||||
function assertions() {
|
function assertions() {
|
||||||
# check error log is empty
|
# check error log is empty
|
||||||
if grep -q '[^[:space:]]' $log_error_file; then
|
if grep -q '[^[:space:]]' $log_error_file; then
|
||||||
echo "error log is not empty!"
|
color_echo "$Red" "error log is not empty!"
|
||||||
cat $log_error_file
|
cat $log_error_file
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
@ -44,21 +63,30 @@ function assert_matching_file_not_copied() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
color_echo "$Cyan" "Running tests..."
|
||||||
|
|
||||||
|
color_echo "$Cyan" "Running tests with default options..."
|
||||||
prepare
|
prepare
|
||||||
./zfs-inplace-rebalancing.sh $test_pool_data_path >> $log_std_file 2>> $log_error_file
|
./zfs-inplace-rebalancing.sh $test_pool_data_path >> $log_std_file 2>> $log_error_file
|
||||||
cat $log_std_file
|
cat $log_std_file
|
||||||
assertions
|
assertions
|
||||||
|
color_echo "$Green" "Tests passed!"
|
||||||
|
|
||||||
|
color_echo "$Cyan" "Running tests with checksum true and 1 pass..."
|
||||||
prepare
|
prepare
|
||||||
./zfs-inplace-rebalancing.sh --checksum true --passes 1 $test_pool_data_path >> $log_std_file 2>> $log_error_file
|
./zfs-inplace-rebalancing.sh --checksum true --passes 1 $test_pool_data_path >> $log_std_file 2>> $log_error_file
|
||||||
cat $log_std_file
|
cat $log_std_file
|
||||||
assertions
|
assertions
|
||||||
|
color_echo "$Green" "Tests passed!"
|
||||||
|
|
||||||
|
color_echo "$Cyan" "Running tests with checksum false..."
|
||||||
prepare
|
prepare
|
||||||
./zfs-inplace-rebalancing.sh --checksum false $test_pool_data_path >> $log_std_file 2>> $log_error_file
|
./zfs-inplace-rebalancing.sh --checksum false $test_pool_data_path >> $log_std_file 2>> $log_error_file
|
||||||
cat $log_std_file
|
cat $log_std_file
|
||||||
assertions
|
assertions
|
||||||
|
color_echo "$Green" "Tests passed!"
|
||||||
|
|
||||||
|
color_echo "$Cyan" "Running tests with skip-hardlinks false..."
|
||||||
prepare
|
prepare
|
||||||
ln "$test_pool_data_path/projects/[2020] some project/mp4.txt" "$test_pool_data_path/projects/[2020] some project/mp4.txt.link"
|
ln "$test_pool_data_path/projects/[2020] some project/mp4.txt" "$test_pool_data_path/projects/[2020] some project/mp4.txt.link"
|
||||||
./zfs-inplace-rebalancing.sh --skip-hardlinks false $test_pool_data_path >> $log_std_file 2>> $log_error_file
|
./zfs-inplace-rebalancing.sh --skip-hardlinks false $test_pool_data_path >> $log_std_file 2>> $log_error_file
|
||||||
@ -67,7 +95,9 @@ cat $log_std_file
|
|||||||
assert_matching_file_copied "mp4.txt"
|
assert_matching_file_copied "mp4.txt"
|
||||||
assert_matching_file_copied "mp4.txt.link"
|
assert_matching_file_copied "mp4.txt.link"
|
||||||
assertions
|
assertions
|
||||||
|
color_echo "$Green" "Tests passed!"
|
||||||
|
|
||||||
|
color_echo "$Cyan" "Running tests with skip-hardlinks true..."
|
||||||
prepare
|
prepare
|
||||||
ln "$test_pool_data_path/projects/[2020] some project/mp4.txt" "$test_pool_data_path/projects/[2020] some project/mp4.txt.link"
|
ln "$test_pool_data_path/projects/[2020] some project/mp4.txt" "$test_pool_data_path/projects/[2020] some project/mp4.txt.link"
|
||||||
./zfs-inplace-rebalancing.sh --skip-hardlinks true $test_pool_data_path >> $log_std_file 2>> $log_error_file
|
./zfs-inplace-rebalancing.sh --skip-hardlinks true $test_pool_data_path >> $log_std_file 2>> $log_error_file
|
||||||
@ -76,3 +106,6 @@ cat $log_std_file
|
|||||||
assert_matching_file_not_copied "mp4.txt.link"
|
assert_matching_file_not_copied "mp4.txt.link"
|
||||||
assert_matching_file_not_copied "mp4.txt"
|
assert_matching_file_not_copied "mp4.txt"
|
||||||
assertions
|
assertions
|
||||||
|
color_echo "$Green" "Tests passed!"
|
||||||
|
|
||||||
|
color_echo "$Green" "All tests passed!"
|
||||||
@ -58,8 +58,8 @@ function rebalance() {
|
|||||||
# check if file has >=2 links in the case of --skip-hardlinks
|
# check if file has >=2 links in the case of --skip-hardlinks
|
||||||
# this shouldn't be needed in the typical case of `find` only finding files with links == 1
|
# this shouldn't be needed in the typical case of `find` only finding files with links == 1
|
||||||
# but this can run for a long time, so it's good to double check if something changed
|
# but this can run for a long time, so it's good to double check if something changed
|
||||||
if [[ "${skip_hardlinks_flag,,}" == "true"* ]]; then
|
if [[ "${skip_hardlinks_flag}" == "true"* ]]; then
|
||||||
if [[ "${OSTYPE,,}" == "linux-gnu"* ]]; then
|
if [[ "${OSTYPE}" == "linux-gnu"* ]]; then
|
||||||
# Linux
|
# Linux
|
||||||
#
|
#
|
||||||
# -c --format=FORMAT
|
# -c --format=FORMAT
|
||||||
@ -68,7 +68,7 @@ function rebalance() {
|
|||||||
# %h number of hard links
|
# %h number of hard links
|
||||||
|
|
||||||
hardlink_count=$(stat -c "%h" "${file_path}")
|
hardlink_count=$(stat -c "%h" "${file_path}")
|
||||||
elif [[ "${OSTYPE,,}" == "darwin"* ]] || [[ "${OSTYPE,,}" == "freebsd"* ]]; then
|
elif [[ "${OSTYPE}" == "darwin"* ]] || [[ "${OSTYPE}" == "freebsd"* ]]; then
|
||||||
# Mac OS
|
# Mac OS
|
||||||
# FreeBSD
|
# FreeBSD
|
||||||
# -f format
|
# -f format
|
||||||
@ -108,7 +108,7 @@ function rebalance() {
|
|||||||
tmp_file_path="${file_path}${tmp_extension}"
|
tmp_file_path="${file_path}${tmp_extension}"
|
||||||
|
|
||||||
echo "Copying '${file_path}' to '${tmp_file_path}'..."
|
echo "Copying '${file_path}' to '${tmp_file_path}'..."
|
||||||
if [[ "${OSTYPE,,}" == "linux-gnu"* ]]; then
|
if [[ "${OSTYPE}" == "linux-gnu"* ]]; then
|
||||||
# Linux
|
# Linux
|
||||||
|
|
||||||
# --reflink=never -- force standard copy (see ZFS Block Cloning)
|
# --reflink=never -- force standard copy (see ZFS Block Cloning)
|
||||||
@ -116,7 +116,7 @@ function rebalance() {
|
|||||||
# -p -- preserve ACLs to
|
# -p -- preserve ACLs to
|
||||||
# -x -- stay on one system
|
# -x -- stay on one system
|
||||||
cp --reflink=never -ax "${file_path}" "${tmp_file_path}"
|
cp --reflink=never -ax "${file_path}" "${tmp_file_path}"
|
||||||
elif [[ "${OSTYPE,,}" == "darwin"* ]] || [[ "${OSTYPE,,}" == "freebsd"* ]]; then
|
elif [[ "${OSTYPE}" == "darwin"* ]] || [[ "${OSTYPE}" == "freebsd"* ]]; then
|
||||||
# Mac OS
|
# Mac OS
|
||||||
# FreeBSD
|
# FreeBSD
|
||||||
|
|
||||||
@ -131,45 +131,48 @@ function rebalance() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# compare copy against original to make sure nothing went wrong
|
# compare copy against original to make sure nothing went wrong
|
||||||
if [[ "${checksum_flag,,}" == "true"* ]]; then
|
if [[ "${checksum_flag}" == "true"* ]]; then
|
||||||
echo "Comparing copy against original..."
|
echo "Comparing copy against original..."
|
||||||
if [[ "${OSTYPE,,}" == "linux-gnu"* ]]; then
|
if [[ "${OSTYPE}" == "linux-gnu"* ]]; then
|
||||||
# Linux
|
# Linux
|
||||||
|
|
||||||
# file attributes
|
# file attributes
|
||||||
original_md5=$(lsattr "${file_path}" | awk '{print $1}')
|
original_md5=$(lsattr "${file_path}")
|
||||||
# file permissions, owner, group
|
# remove anything after the last space
|
||||||
# shellcheck disable=SC2012
|
original_md5=${original_md5% *}
|
||||||
original_md5="${original_md5} $(ls -lha "${file_path}" | awk '{print $1 " " $3 " " $4}')"
|
# file permissions, owner, group, size, modification time
|
||||||
|
original_md5="${original_md5} $(stat -c "%A %U %G %s %Y" "${file_path}")"
|
||||||
# file content
|
# file content
|
||||||
original_md5="${original_md5} $(md5sum -b "${file_path}" | awk '{print $1}')"
|
original_md5="${original_md5} $(md5sum -b "${file_path}")"
|
||||||
|
|
||||||
|
|
||||||
# file attributes
|
# file attributes
|
||||||
copy_md5=$(lsattr "${tmp_file_path}" | awk '{print $1}')
|
copy_md5=$(lsattr "${tmp_file_path}")
|
||||||
# file permissions, owner, group
|
# remove anything after the last space
|
||||||
# shellcheck disable=SC2012
|
copy_md5=${copy_md5% *}
|
||||||
copy_md5="${copy_md5} $(ls -lha "${tmp_file_path}" | awk '{print $1 " " $3 " " $4}')"
|
# file permissions, owner, group, size, modification time
|
||||||
|
copy_md5="${copy_md5} $(stat -c "%A %U %G %s %Y" "${tmp_file_path}")"
|
||||||
# file content
|
# file content
|
||||||
copy_md5="${copy_md5} $(md5sum -b "${tmp_file_path}" | awk '{print $1}')"
|
copy_md5="${copy_md5} $(md5sum -b "${tmp_file_path}")"
|
||||||
elif [[ "${OSTYPE,,}" == "darwin"* ]] || [[ "${OSTYPE,,}" == "freebsd"* ]]; then
|
# remove the temporary extension
|
||||||
|
copy_md5=${copy_md5%"${tmp_extension}"}
|
||||||
|
elif [[ "${OSTYPE}" == "darwin"* ]] || [[ "${OSTYPE}" == "freebsd"* ]]; then
|
||||||
# Mac OS
|
# Mac OS
|
||||||
# FreeBSD
|
# FreeBSD
|
||||||
|
|
||||||
# file attributes
|
# note: no lsattr on Mac OS or FreeBSD
|
||||||
original_md5=$(lsattr "${file_path}" | awk '{print $1}')
|
|
||||||
# file permissions, owner, group
|
# file permissions, owner, group size, modification time
|
||||||
# shellcheck disable=SC2012
|
original_md5="$(stat -f "%Sp %Su %Sg %z %m" "${file_path}")"
|
||||||
original_md5="${original_md5} $(ls -lha "${file_path}" | awk '{print $1 " " $3 " " $4}')"
|
|
||||||
# file content
|
# file content
|
||||||
original_md5="${original_md5} $(md5 -q "${file_path}")"
|
original_md5="${original_md5} $(md5 -q "${file_path}")"
|
||||||
|
|
||||||
# file attributes
|
# file permissions, owner, group size, modification time
|
||||||
copy_md5=$(lsattr "${tmp_file_path}" | awk '{print $1}')
|
copy_md5="$(stat -f "%Sp %Su %Sg %z %m" "${tmp_file_path}")"
|
||||||
# file permissions, owner, group
|
|
||||||
# shellcheck disable=SC2012
|
|
||||||
copy_md5="${copy_md5} $(ls -lha "${tmp_file_path}" | awk '{print $1 " " $3 " " $4}')"
|
|
||||||
# file content
|
# file content
|
||||||
copy_md5="${copy_md5} $(md5 -q "${tmp_file_path}")"
|
copy_md5="${copy_md5} $(md5 -q "${tmp_file_path}")"
|
||||||
|
# remove the temporary extension
|
||||||
|
copy_md5=${copy_md5%"${tmp_extension}"}
|
||||||
else
|
else
|
||||||
echo "Unsupported OS type: $OSTYPE"
|
echo "Unsupported OS type: $OSTYPE"
|
||||||
exit 1
|
exit 1
|
||||||
@ -254,7 +257,7 @@ color_echo "$Cyan" " Use Checksum: ${checksum_flag}"
|
|||||||
color_echo "$Cyan" " Skip Hardlinks: ${skip_hardlinks_flag}"
|
color_echo "$Cyan" " Skip Hardlinks: ${skip_hardlinks_flag}"
|
||||||
|
|
||||||
# count files
|
# count files
|
||||||
if [[ "${skip_hardlinks_flag,,}" == "true"* ]]; then
|
if [[ "${skip_hardlinks_flag}" == "true"* ]]; then
|
||||||
file_count=$(find "${root_path}" -type f -links 1 | wc -l)
|
file_count=$(find "${root_path}" -type f -links 1 | wc -l)
|
||||||
else
|
else
|
||||||
file_count=$(find "${root_path}" -type f | wc -l)
|
file_count=$(find "${root_path}" -type f | wc -l)
|
||||||
@ -269,7 +272,7 @@ fi
|
|||||||
|
|
||||||
# recursively scan through files and execute "rebalance" procedure
|
# recursively scan through files and execute "rebalance" procedure
|
||||||
# in the case of --skip-hardlinks, only find files with links == 1
|
# in the case of --skip-hardlinks, only find files with links == 1
|
||||||
if [[ "${skip_hardlinks_flag,,}" == "true"* ]]; then
|
if [[ "${skip_hardlinks_flag}" == "true"* ]]; then
|
||||||
find "$root_path" -type f -links 1 -print0 | while IFS= read -r -d '' file; do rebalance "$file"; done
|
find "$root_path" -type f -links 1 -print0 | while IFS= read -r -d '' file; do rebalance "$file"; done
|
||||||
else
|
else
|
||||||
find "$root_path" -type f -print0 | while IFS= read -r -d '' file; do rebalance "$file"; done
|
find "$root_path" -type f -print0 | while IFS= read -r -d '' file; do rebalance "$file"; done
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user