Index: sbin/bectl/tests/bectl_test.sh =================================================================== --- sbin/bectl/tests/bectl_test.sh +++ sbin/bectl/tests/bectl_test.sh @@ -26,6 +26,17 @@ # # $FreeBSD$ +ZPOOL_NAME_FILE=zpool_name +get_zpool_name() +{ + cat $ZPOOL_NAME_FILE +} +make_zpool_name() +{ + mktemp -u bectl_test_XXXXXX > $ZPOOL_NAME_FILE + get_zpool_name +} + # Establishes a bectl_create zpool that can be used for some light testing; contains # a 'default' BE and not much else. bectl_create_setup() @@ -34,6 +45,8 @@ disk=$2 mnt=$3 + atf_check test -n "$zpool" + kldload -n -q zfs || atf_skip "ZFS module not loaded on the current system" atf_check mkdir -p ${mnt} atf_check truncate -s 1G ${disk} @@ -60,8 +73,9 @@ bectl_cleanup() { zpool=$1 - - if zpool get health ${zpool} >/dev/null 2>&1; then + if [ -z "$zpool" ]; then + echo "Skipping cleanup; zpool not set up" + elif zpool get health ${zpool} >/dev/null 2>&1; then zpool destroy -f ${zpool} fi } @@ -76,7 +90,7 @@ bectl_create_body() { cwd=$(realpath .) - zpool=bectl_test + zpool=$(make_zpool_name) disk=${cwd}/disk.img mount=${cwd}/mnt @@ -89,8 +103,7 @@ } bectl_create_cleanup() { - - bectl_cleanup bectl_test + bectl_cleanup $(get_zpool_name) } atf_test_case bectl_destroy cleanup @@ -103,7 +116,7 @@ bectl_destroy_body() { cwd=$(realpath .) - zpool=bectl_test + zpool=$(make_zpool_name) disk=${cwd}/disk.img mount=${cwd}/mnt @@ -116,7 +129,7 @@ bectl_destroy_cleanup() { - bectl_cleanup bectl_test + bectl_cleanup $(get_zpool_name) } atf_test_case bectl_export_import cleanup @@ -129,7 +142,7 @@ bectl_export_import_body() { cwd=$(realpath .) - zpool=bectl_test + zpool=$(make_zpool_name) disk=${cwd}/disk.img mount=${cwd}/mnt @@ -144,7 +157,7 @@ bectl_export_import_cleanup() { - bectl_cleanup bectl_test + bectl_cleanup $(get_zpool_name) } atf_test_case bectl_list cleanup @@ -157,7 +170,7 @@ bectl_list_body() { cwd=$(realpath .) - zpool=bectl_test + zpool=$(make_zpool_name) disk=${cwd}/disk.img mount=${cwd}/mnt @@ -179,7 +192,7 @@ bectl_list_cleanup() { - bectl_cleanup bectl_test + bectl_cleanup $(get_zpool_name) } atf_test_case bectl_mount cleanup @@ -192,7 +205,7 @@ bectl_mount_body() { cwd=$(realpath .) - zpool=bectl_test + zpool=$(make_zpool_name) disk=${cwd}/disk.img mount=${cwd}/mnt root=${mount}/root @@ -213,7 +226,7 @@ bectl_mount_cleanup() { - bectl_cleanup bectl_test + bectl_cleanup $(get_zpool_name) } atf_test_case bectl_rename cleanup @@ -226,7 +239,7 @@ bectl_rename_body() { cwd=$(realpath .) - zpool=bectl_test + zpool=$(make_zpool_name) disk=${cwd}/disk.img mount=${cwd}/mnt @@ -239,7 +252,7 @@ bectl_rename_cleanup() { - bectl_cleanup bectl_test + bectl_cleanup $(get_zpool_name) } atf_test_case bectl_jail cleanup @@ -252,7 +265,7 @@ bectl_jail_body() { cwd=$(realpath .) - zpool=bectl_test + zpool=$(make_zpool_name) disk=${cwd}/disk.img mount=${cwd}/mnt root=${mount}/root @@ -327,7 +340,7 @@ jail -r ${jailid} done; - bectl_cleanup bectl_test + bectl_cleanup $(get_zpool_name) } atf_init_test_cases()