Changeset View
Changeset View
Standalone View
Standalone View
head/sbin/bectl/tests/bectl_test.sh
Show All 20 Lines | |||||
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||||
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||||
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||||
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||||
# SUCH DAMAGE. | # SUCH DAMAGE. | ||||
# | # | ||||
# $FreeBSD$ | # $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 | # Establishes a bectl_create zpool that can be used for some light testing; contains | ||||
# a 'default' BE and not much else. | # a 'default' BE and not much else. | ||||
bectl_create_setup() | bectl_create_setup() | ||||
{ | { | ||||
zpool=$1 | zpool=$1 | ||||
disk=$2 | disk=$2 | ||||
mnt=$3 | mnt=$3 | ||||
# Sanity check to make sure `make_zpool_name` succeeded | |||||
atf_check test -n "$zpool" | |||||
kldload -n -q zfs || atf_skip "ZFS module not loaded on the current system" | kldload -n -q zfs || atf_skip "ZFS module not loaded on the current system" | ||||
atf_check mkdir -p ${mnt} | atf_check mkdir -p ${mnt} | ||||
atf_check truncate -s 1G ${disk} | atf_check truncate -s 1G ${disk} | ||||
atf_check zpool create -o altroot=${mnt} ${zpool} ${disk} | atf_check zpool create -o altroot=${mnt} ${zpool} ${disk} | ||||
atf_check zfs create -o mountpoint=none ${zpool}/ROOT | atf_check zfs create -o mountpoint=none ${zpool}/ROOT | ||||
atf_check zfs create -o mountpoint=/ -o canmount=noauto \ | atf_check zfs create -o mountpoint=/ -o canmount=noauto \ | ||||
${zpool}/ROOT/default | ${zpool}/ROOT/default | ||||
} | } | ||||
bectl_create_deep_setup() | bectl_create_deep_setup() | ||||
{ | { | ||||
zpool=$1 | zpool=$1 | ||||
disk=$2 | disk=$2 | ||||
mnt=$3 | mnt=$3 | ||||
# Sanity check to make sure `make_zpool_name` succeeded | |||||
atf_check test -n "$zpool" | |||||
bectl_create_setup ${zpool} ${disk} ${mnt} | bectl_create_setup ${zpool} ${disk} ${mnt} | ||||
atf_check mkdir -p ${root} | atf_check mkdir -p ${root} | ||||
atf_check -o ignore bectl -r ${zpool}/ROOT mount default ${root} | atf_check -o ignore bectl -r ${zpool}/ROOT mount default ${root} | ||||
atf_check mkdir -p ${root}/usr | atf_check mkdir -p ${root}/usr | ||||
atf_check zfs create -o mountpoint=/usr -o canmount=noauto \ | atf_check zfs create -o mountpoint=/usr -o canmount=noauto \ | ||||
${zpool}/ROOT/default/usr | ${zpool}/ROOT/default/usr | ||||
atf_check -o ignore bectl -r ${zpool}/ROOT umount default | atf_check -o ignore bectl -r ${zpool}/ROOT umount default | ||||
} | } | ||||
bectl_cleanup() | bectl_cleanup() | ||||
{ | { | ||||
zpool=$1 | zpool=$1 | ||||
if [ -z "$zpool" ]; then | |||||
if zpool get health ${zpool} >/dev/null 2>&1; then | echo "Skipping cleanup; zpool not set up" | ||||
elif zpool get health ${zpool} >/dev/null 2>&1; then | |||||
zpool destroy -f ${zpool} | zpool destroy -f ${zpool} | ||||
fi | fi | ||||
} | } | ||||
atf_test_case bectl_create cleanup | atf_test_case bectl_create cleanup | ||||
bectl_create_head() | bectl_create_head() | ||||
{ | { | ||||
atf_set "descr" "Check the various forms of bectl create" | atf_set "descr" "Check the various forms of bectl create" | ||||
atf_set "require.user" root | atf_set "require.user" root | ||||
} | } | ||||
bectl_create_body() | bectl_create_body() | ||||
{ | { | ||||
cwd=$(realpath .) | cwd=$(realpath .) | ||||
zpool=bectl_test | zpool=$(make_zpool_name) | ||||
disk=${cwd}/disk.img | disk=${cwd}/disk.img | ||||
mount=${cwd}/mnt | mount=${cwd}/mnt | ||||
bectl_create_setup ${zpool} ${disk} ${mount} | bectl_create_setup ${zpool} ${disk} ${mount} | ||||
# Test standard creation, creation of a snapshot, and creation from a | # Test standard creation, creation of a snapshot, and creation from a | ||||
# snapshot. | # snapshot. | ||||
atf_check bectl -r ${zpool}/ROOT create -e default default2 | atf_check bectl -r ${zpool}/ROOT create -e default default2 | ||||
atf_check bectl -r ${zpool}/ROOT create default2@test_snap | atf_check bectl -r ${zpool}/ROOT create default2@test_snap | ||||
atf_check bectl -r ${zpool}/ROOT create -e default2@test_snap default3 | atf_check bectl -r ${zpool}/ROOT create -e default2@test_snap default3 | ||||
} | } | ||||
bectl_create_cleanup() | bectl_create_cleanup() | ||||
{ | { | ||||
bectl_cleanup $(get_zpool_name) | |||||
bectl_cleanup bectl_test | |||||
} | } | ||||
atf_test_case bectl_destroy cleanup | atf_test_case bectl_destroy cleanup | ||||
bectl_destroy_head() | bectl_destroy_head() | ||||
{ | { | ||||
atf_set "descr" "Check bectl destroy" | atf_set "descr" "Check bectl destroy" | ||||
atf_set "require.user" root | atf_set "require.user" root | ||||
} | } | ||||
bectl_destroy_body() | bectl_destroy_body() | ||||
{ | { | ||||
cwd=$(realpath .) | cwd=$(realpath .) | ||||
zpool=bectl_test | zpool=$(make_zpool_name) | ||||
disk=${cwd}/disk.img | disk=${cwd}/disk.img | ||||
mount=${cwd}/mnt | mount=${cwd}/mnt | ||||
bectl_create_setup ${zpool} ${disk} ${mount} | bectl_create_setup ${zpool} ${disk} ${mount} | ||||
atf_check bectl -r ${zpool}/ROOT create -e default default2 | atf_check bectl -r ${zpool}/ROOT create -e default default2 | ||||
atf_check -o not-empty zfs get mountpoint ${zpool}/ROOT/default2 | atf_check -o not-empty zfs get mountpoint ${zpool}/ROOT/default2 | ||||
atf_check -e ignore bectl -r ${zpool}/ROOT destroy default2 | atf_check -e ignore bectl -r ${zpool}/ROOT destroy default2 | ||||
atf_check -e not-empty -s not-exit:0 zfs get mountpoint ${zpool}/ROOT/default2 | atf_check -e not-empty -s not-exit:0 zfs get mountpoint ${zpool}/ROOT/default2 | ||||
} | } | ||||
bectl_destroy_cleanup() | bectl_destroy_cleanup() | ||||
{ | { | ||||
bectl_cleanup bectl_test | bectl_cleanup $(get_zpool_name) | ||||
} | } | ||||
atf_test_case bectl_export_import cleanup | atf_test_case bectl_export_import cleanup | ||||
bectl_export_import_head() | bectl_export_import_head() | ||||
{ | { | ||||
atf_set "descr" "Check bectl export and import" | atf_set "descr" "Check bectl export and import" | ||||
atf_set "require.user" root | atf_set "require.user" root | ||||
} | } | ||||
bectl_export_import_body() | bectl_export_import_body() | ||||
{ | { | ||||
cwd=$(realpath .) | cwd=$(realpath .) | ||||
zpool=bectl_test | zpool=$(make_zpool_name) | ||||
disk=${cwd}/disk.img | disk=${cwd}/disk.img | ||||
mount=${cwd}/mnt | mount=${cwd}/mnt | ||||
bectl_create_setup ${zpool} ${disk} ${mount} | bectl_create_setup ${zpool} ${disk} ${mount} | ||||
atf_check -o save:exported bectl -r ${zpool}/ROOT export default | atf_check -o save:exported bectl -r ${zpool}/ROOT export default | ||||
atf_check -x "bectl -r ${zpool}/ROOT import default2 < exported" | atf_check -x "bectl -r ${zpool}/ROOT import default2 < exported" | ||||
atf_check -o not-empty zfs get mountpoint ${zpool}/ROOT/default2 | atf_check -o not-empty zfs get mountpoint ${zpool}/ROOT/default2 | ||||
atf_check -e ignore bectl -r ${zpool}/ROOT destroy default2 | atf_check -e ignore bectl -r ${zpool}/ROOT destroy default2 | ||||
atf_check -e not-empty -s not-exit:0 zfs get mountpoint \ | atf_check -e not-empty -s not-exit:0 zfs get mountpoint \ | ||||
${zpool}/ROOT/default2 | ${zpool}/ROOT/default2 | ||||
} | } | ||||
bectl_export_import_cleanup() | bectl_export_import_cleanup() | ||||
{ | { | ||||
bectl_cleanup bectl_test | bectl_cleanup $(get_zpool_name) | ||||
} | } | ||||
atf_test_case bectl_list cleanup | atf_test_case bectl_list cleanup | ||||
bectl_list_head() | bectl_list_head() | ||||
{ | { | ||||
atf_set "descr" "Check bectl list" | atf_set "descr" "Check bectl list" | ||||
atf_set "require.user" root | atf_set "require.user" root | ||||
} | } | ||||
bectl_list_body() | bectl_list_body() | ||||
{ | { | ||||
cwd=$(realpath .) | cwd=$(realpath .) | ||||
zpool=bectl_test | zpool=$(make_zpool_name) | ||||
disk=${cwd}/disk.img | disk=${cwd}/disk.img | ||||
mount=${cwd}/mnt | mount=${cwd}/mnt | ||||
bectl_create_setup ${zpool} ${disk} ${mount} | bectl_create_setup ${zpool} ${disk} ${mount} | ||||
# Test the list functionality, including that BEs come and go away | # Test the list functionality, including that BEs come and go away | ||||
# as they're created and destroyed. Creation and destruction tests | # as they're created and destroyed. Creation and destruction tests | ||||
# use the 'zfs' utility to verify that they're actually created, so | # use the 'zfs' utility to verify that they're actually created, so | ||||
# these are just light tests that 'list' is picking them up. | # these are just light tests that 'list' is picking them up. | ||||
atf_check -o save:list.out bectl -r ${zpool}/ROOT list | atf_check -o save:list.out bectl -r ${zpool}/ROOT list | ||||
atf_check -o not-empty grep 'default' list.out | atf_check -o not-empty grep 'default' list.out | ||||
atf_check bectl -r ${zpool}/ROOT create -e default default2 | atf_check bectl -r ${zpool}/ROOT create -e default default2 | ||||
atf_check -o save:list.out bectl -r ${zpool}/ROOT list | atf_check -o save:list.out bectl -r ${zpool}/ROOT list | ||||
atf_check -o not-empty grep 'default2' list.out | atf_check -o not-empty grep 'default2' list.out | ||||
atf_check -e ignore bectl -r ${zpool}/ROOT destroy default2 | atf_check -e ignore bectl -r ${zpool}/ROOT destroy default2 | ||||
atf_check -o save:list.out bectl -r ${zpool}/ROOT list | atf_check -o save:list.out bectl -r ${zpool}/ROOT list | ||||
atf_check -s not-exit:0 grep 'default2' list.out | atf_check -s not-exit:0 grep 'default2' list.out | ||||
# XXX TODO: Formatting checks | # XXX TODO: Formatting checks | ||||
} | } | ||||
bectl_list_cleanup() | bectl_list_cleanup() | ||||
{ | { | ||||
bectl_cleanup bectl_test | bectl_cleanup $(get_zpool_name) | ||||
} | } | ||||
atf_test_case bectl_mount cleanup | atf_test_case bectl_mount cleanup | ||||
bectl_mount_head() | bectl_mount_head() | ||||
{ | { | ||||
atf_set "descr" "Check bectl mount/unmount" | atf_set "descr" "Check bectl mount/unmount" | ||||
atf_set "require.user" root | atf_set "require.user" root | ||||
} | } | ||||
bectl_mount_body() | bectl_mount_body() | ||||
{ | { | ||||
cwd=$(realpath .) | cwd=$(realpath .) | ||||
zpool=bectl_test | zpool=$(make_zpool_name) | ||||
disk=${cwd}/disk.img | disk=${cwd}/disk.img | ||||
mount=${cwd}/mnt | mount=${cwd}/mnt | ||||
root=${mount}/root | root=${mount}/root | ||||
bectl_create_deep_setup ${zpool} ${disk} ${mount} | bectl_create_deep_setup ${zpool} ${disk} ${mount} | ||||
atf_check mkdir -p ${root} | atf_check mkdir -p ${root} | ||||
# Test unmount first... | # Test unmount first... | ||||
atf_check -o not-empty bectl -r ${zpool}/ROOT mount default ${root} | atf_check -o not-empty bectl -r ${zpool}/ROOT mount default ${root} | ||||
atf_check -o not-empty -x "mount | grep '^${zpool}/ROOT/default'" | atf_check -o not-empty -x "mount | grep '^${zpool}/ROOT/default'" | ||||
atf_check bectl -r ${zpool}/ROOT unmount default | atf_check bectl -r ${zpool}/ROOT unmount default | ||||
atf_check -s not-exit:0 -x "mount | grep '^${zpool}/ROOT/default'" | atf_check -s not-exit:0 -x "mount | grep '^${zpool}/ROOT/default'" | ||||
# Then umount! | # Then umount! | ||||
atf_check -o not-empty bectl -r ${zpool}/ROOT mount default ${root} | atf_check -o not-empty bectl -r ${zpool}/ROOT mount default ${root} | ||||
atf_check -o not-empty -x "mount | grep '^${zpool}/ROOT/default'" | atf_check -o not-empty -x "mount | grep '^${zpool}/ROOT/default'" | ||||
atf_check bectl -r ${zpool}/ROOT umount default | atf_check bectl -r ${zpool}/ROOT umount default | ||||
atf_check -s not-exit:0 -x "mount | grep '^${zpool}/ROOT/default'" | atf_check -s not-exit:0 -x "mount | grep '^${zpool}/ROOT/default'" | ||||
} | } | ||||
bectl_mount_cleanup() | bectl_mount_cleanup() | ||||
{ | { | ||||
bectl_cleanup bectl_test | bectl_cleanup $(get_zpool_name) | ||||
} | } | ||||
atf_test_case bectl_rename cleanup | atf_test_case bectl_rename cleanup | ||||
bectl_rename_head() | bectl_rename_head() | ||||
{ | { | ||||
atf_set "descr" "Check bectl rename" | atf_set "descr" "Check bectl rename" | ||||
atf_set "require.user" root | atf_set "require.user" root | ||||
} | } | ||||
bectl_rename_body() | bectl_rename_body() | ||||
{ | { | ||||
cwd=$(realpath .) | cwd=$(realpath .) | ||||
zpool=bectl_test | zpool=$(make_zpool_name) | ||||
disk=${cwd}/disk.img | disk=${cwd}/disk.img | ||||
mount=${cwd}/mnt | mount=${cwd}/mnt | ||||
bectl_create_setup ${zpool} ${disk} ${mount} | bectl_create_setup ${zpool} ${disk} ${mount} | ||||
atf_check bectl -r ${zpool}/ROOT rename default default2 | atf_check bectl -r ${zpool}/ROOT rename default default2 | ||||
atf_check -o not-empty zfs get mountpoint ${zpool}/ROOT/default2 | atf_check -o not-empty zfs get mountpoint ${zpool}/ROOT/default2 | ||||
atf_check -e not-empty -s not-exit:0 zfs get mountpoint \ | atf_check -e not-empty -s not-exit:0 zfs get mountpoint \ | ||||
${zpool}/ROOT/default | ${zpool}/ROOT/default | ||||
} | } | ||||
bectl_rename_cleanup() | bectl_rename_cleanup() | ||||
{ | { | ||||
bectl_cleanup bectl_test | bectl_cleanup $(get_zpool_name) | ||||
} | } | ||||
atf_test_case bectl_jail cleanup | atf_test_case bectl_jail cleanup | ||||
bectl_jail_head() | bectl_jail_head() | ||||
{ | { | ||||
atf_set "descr" "Check bectl rename" | atf_set "descr" "Check bectl rename" | ||||
atf_set "require.user" root | atf_set "require.user" root | ||||
} | } | ||||
bectl_jail_body() | bectl_jail_body() | ||||
{ | { | ||||
cwd=$(realpath .) | cwd=$(realpath .) | ||||
zpool=bectl_test | zpool=$(make_zpool_name) | ||||
disk=${cwd}/disk.img | disk=${cwd}/disk.img | ||||
mount=${cwd}/mnt | mount=${cwd}/mnt | ||||
root=${mount}/root | root=${mount}/root | ||||
if [ ! -f /rescue/rescue ]; then | if [ ! -f /rescue/rescue ]; then | ||||
atf_skip "This test requires a rescue binary" | atf_skip "This test requires a rescue binary" | ||||
fi | fi | ||||
bectl_create_deep_setup ${zpool} ${disk} ${mount} | bectl_create_deep_setup ${zpool} ${disk} ${mount} | ||||
▲ Show 20 Lines • Show All 58 Lines • ▼ Show 20 Lines | for bootenv in "default" "target"; do | ||||
jailid="$(jls | grep ${mountpoint} | awk '{print $1}')" | jailid="$(jls | grep ${mountpoint} | awk '{print $1}')" | ||||
if [ -z "$jailid" ]; then | if [ -z "$jailid" ]; then | ||||
continue; | continue; | ||||
fi | fi | ||||
jail -r ${jailid} | jail -r ${jailid} | ||||
done; | done; | ||||
bectl_cleanup bectl_test | bectl_cleanup $(get_zpool_name) | ||||
} | } | ||||
atf_init_test_cases() | atf_init_test_cases() | ||||
{ | { | ||||
atf_add_test_case bectl_create | atf_add_test_case bectl_create | ||||
atf_add_test_case bectl_destroy | atf_add_test_case bectl_destroy | ||||
atf_add_test_case bectl_export_import | atf_add_test_case bectl_export_import | ||||
atf_add_test_case bectl_list | atf_add_test_case bectl_list | ||||
atf_add_test_case bectl_mount | atf_add_test_case bectl_mount | ||||
atf_add_test_case bectl_rename | atf_add_test_case bectl_rename | ||||
atf_add_test_case bectl_jail | atf_add_test_case bectl_jail | ||||
} | } |