diff options
Diffstat (limited to 'tests/zfs-tests/tests/functional/cli_root/zfs_get')
15 files changed, 1398 insertions, 0 deletions
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_get/Makefile.am b/tests/zfs-tests/tests/functional/cli_root/zfs_get/Makefile.am new file mode 100644 index 000000000000..22e95907675d --- /dev/null +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_get/Makefile.am @@ -0,0 +1,18 @@ +pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/cli_root/zfs_get +dist_pkgdata_SCRIPTS = \ + setup.ksh \ + cleanup.ksh \ + zfs_get_001_pos.ksh \ + zfs_get_002_pos.ksh \ + zfs_get_003_pos.ksh \ + zfs_get_004_pos.ksh \ + zfs_get_005_neg.ksh \ + zfs_get_006_neg.ksh \ + zfs_get_007_neg.ksh \ + zfs_get_008_pos.ksh \ + zfs_get_009_pos.ksh \ + zfs_get_010_neg.ksh + +dist_pkgdata_DATA = \ + zfs_get_common.kshlib \ + zfs_get_list_d.kshlib diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_get/cleanup.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_get/cleanup.ksh new file mode 100755 index 000000000000..79cd6e9f908e --- /dev/null +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_get/cleanup.ksh @@ -0,0 +1,30 @@ +#!/bin/ksh -p +# +# CDDL HEADER START +# +# The contents of this file are subject to the terms of the +# Common Development and Distribution License (the "License"). +# You may not use this file except in compliance with the License. +# +# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE +# or http://www.opensolaris.org/os/licensing. +# See the License for the specific language governing permissions +# and limitations under the License. +# +# When distributing Covered Code, include this CDDL HEADER in each +# file and include the License file at usr/src/OPENSOLARIS.LICENSE. +# If applicable, add the following below this CDDL HEADER, with the +# fields enclosed by brackets "[]" replaced with your own identifying +# information: Portions Copyright [yyyy] [name of copyright owner] +# +# CDDL HEADER END +# + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# + +. $STF_SUITE/include/libtest.shlib + +default_cleanup diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_get/setup.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_get/setup.ksh new file mode 100755 index 000000000000..9692385996d1 --- /dev/null +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_get/setup.ksh @@ -0,0 +1,32 @@ +#!/bin/ksh -p +# +# CDDL HEADER START +# +# The contents of this file are subject to the terms of the +# Common Development and Distribution License (the "License"). +# You may not use this file except in compliance with the License. +# +# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE +# or http://www.opensolaris.org/os/licensing. +# See the License for the specific language governing permissions +# and limitations under the License. +# +# When distributing Covered Code, include this CDDL HEADER in each +# file and include the License file at usr/src/OPENSOLARIS.LICENSE. +# If applicable, add the following below this CDDL HEADER, with the +# fields enclosed by brackets "[]" replaced with your own identifying +# information: Portions Copyright [yyyy] [name of copyright owner] +# +# CDDL HEADER END +# + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# + +. $STF_SUITE/include/libtest.shlib + +DISK=${DISKS%% *} + +default_container_volume_setup $DISK diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_001_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_001_pos.ksh new file mode 100755 index 000000000000..eeae5390f088 --- /dev/null +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_001_pos.ksh @@ -0,0 +1,163 @@ +#!/bin/ksh -p +# +# CDDL HEADER START +# +# The contents of this file are subject to the terms of the +# Common Development and Distribution License (the "License"). +# You may not use this file except in compliance with the License. +# +# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE +# or http://www.opensolaris.org/os/licensing. +# See the License for the specific language governing permissions +# and limitations under the License. +# +# When distributing Covered Code, include this CDDL HEADER in each +# file and include the License file at usr/src/OPENSOLARIS.LICENSE. +# If applicable, add the following below this CDDL HEADER, with the +# fields enclosed by brackets "[]" replaced with your own identifying +# information: Portions Copyright [yyyy] [name of copyright owner] +# +# CDDL HEADER END +# + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# + +# +# Copyright (c) 2016 by Delphix. All rights reserved. +# + +. $STF_SUITE/tests/functional/cli_root/zfs_get/zfs_get_common.kshlib +. $STF_SUITE/tests/functional/cli_root/zfs_get/zfs_get_list_d.kshlib + +# +# DESCRIPTION: +# Setting the valid option and properties, 'zfs get' should return the +# correct property value. +# +# STRATEGY: +# 1. Create pool, filesystem, volume, snapshot, and bookmark. +# 2. Setting valid parameter, 'zfs get' should succeed. +# 3. Compare the output property name with the original input property. +# + +verify_runnable "both" + +typeset options=("" "-p" "-r" "-H") + +typeset -i i=${#options[*]} +typeset -i j=0 +while ((j<${#depth_options[*]})); +do + options[$i]=-"${depth_options[$j]}" + ((j+=1)) + ((i+=1)) +done + +typeset zfs_props=("type" used available creation volsize referenced \ + compressratio mounted origin recordsize quota reservation mountpoint \ + sharenfs checksum compression atime devices exec readonly setuid \ + snapdir aclinherit canmount primarycache secondarycache version \ + usedbychildren usedbydataset usedbyrefreservation usedbysnapshots) +if is_freebsd; then + typeset zfs_props_os=(jailed aclmode) +else + typeset zfs_props_os=(zoned acltype) +fi +typeset userquota_props=(userquota@root groupquota@root userused@root \ + groupused@root) +typeset all_props=("${zfs_props[@]}" \ + "${zfs_props_os[@]}" \ + "${userquota_props[@]}") +typeset dataset=($TESTPOOL/$TESTCTR $TESTPOOL/$TESTFS $TESTPOOL/$TESTVOL \ + $TESTPOOL/$TESTFS@$TESTSNAP $TESTPOOL/$TESTVOL@$TESTSNAP) + +typeset bookmark_props=(creation) +typeset bookmark=($TESTPOOL/$TESTFS#$TESTBKMARK $TESTPOOL/$TESTVOL#$TESTBKMARK) + +# +# According to dataset and option, checking if 'zfs get' return correct +# property information. +# +# $1 dataset +# $2 properties which are expected to output into $TESTDIR/$TESTFILE0 +# $3 option +# +function check_return_value +{ + typeset dst=$1 + typeset props=$2 + typeset opt=$3 + typeset -i found=0 + typeset p + + for p in $props; do + found=0 + + while read line; do + typeset item + item=$(echo $line | awk '{print $2}' 2>&1) + + if [[ $item == $p ]]; then + ((found += 1)) + break + fi + done < $TESTDIR/$TESTFILE0 + + if ((found == 0)); then + log_fail "'zfs get $opt $props $dst' return " \ + "error message.'$p' haven't been found." + fi + done + + log_note "SUCCESS: 'zfs get $opt $prop $dst'." +} + +log_assert "Setting the valid options and properties 'zfs get' should return " \ + "the correct property value." +log_onexit cleanup + +# Create filesystem and volume's snapshot +create_snapshot $TESTPOOL/$TESTFS $TESTSNAP +create_snapshot $TESTPOOL/$TESTVOL $TESTSNAP + +# Create filesystem and volume's bookmark +create_bookmark $TESTPOOL/$TESTFS $TESTSNAP $TESTBKMARK +create_bookmark $TESTPOOL/$TESTVOL $TESTSNAP $TESTBKMARK + +typeset -i i=0 +while ((i < ${#dataset[@]})); do + for opt in "${options[@]}"; do + for prop in ${all_props[@]}; do + eval "zfs get $opt $prop ${dataset[i]} > \ + $TESTDIR/$TESTFILE0" + ret=$? + if [[ $ret != 0 ]]; then + log_fail "zfs get returned: $ret" + fi + check_return_value ${dataset[i]} "$prop" "$opt" + done + done + ((i += 1)) +done + +i=0 +while ((i < ${#bookmark[@]})); do + for opt in "${options[@]}"; do + for prop in ${bookmark_props[@]}; do + eval "zfs get $opt $prop ${bookmark[i]} > \ + $TESTDIR/$TESTFILE0" + ret=$? + if [[ $ret != 0 ]]; then + log_fail "zfs get returned: $ret" + fi + check_return_value ${bookmark[i]} "$prop" "$opt" + done + done + ((i += 1)) +done + +log_pass "Setting the valid options to dataset, it should succeed and return " \ + "valid value. 'zfs get' pass." diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_002_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_002_pos.ksh new file mode 100755 index 000000000000..c3746514eae0 --- /dev/null +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_002_pos.ksh @@ -0,0 +1,97 @@ +#!/bin/ksh -p +# +# CDDL HEADER START +# +# The contents of this file are subject to the terms of the +# Common Development and Distribution License (the "License"). +# You may not use this file except in compliance with the License. +# +# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE +# or http://www.opensolaris.org/os/licensing. +# See the License for the specific language governing permissions +# and limitations under the License. +# +# When distributing Covered Code, include this CDDL HEADER in each +# file and include the License file at usr/src/OPENSOLARIS.LICENSE. +# If applicable, add the following below this CDDL HEADER, with the +# fields enclosed by brackets "[]" replaced with your own identifying +# information: Portions Copyright [yyyy] [name of copyright owner] +# +# CDDL HEADER END +# + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# + +# +# Copyright (c) 2016 by Delphix. All rights reserved. +# + +. $STF_SUITE/tests/functional/cli_root/zfs_get/zfs_get_common.kshlib + +# +# DESCRIPTION: +# Setting the valid option and properties 'zfs get' return correct value. +# It should be successful. +# +# STRATEGY: +# 1. Create pool, filesystem, dataset, volume and snapshot. +# 2. Getting the options and properties random combination. +# 3. Using the combination as the parameters of 'zfs get' to check the +# command line return value. +# + +verify_runnable "both" + +typeset options=(" " p r H) + +typeset zfs_props=("type" used available creation volsize referenced \ + compressratio mounted origin recordsize quota reservation mountpoint \ + sharenfs checksum compression atime devices exec readonly setuid \ + snapdir aclinherit canmount primarycache secondarycache version \ + usedbychildren usedbydataset usedbyrefreservation usedbysnapshots) +if is_freebsd; then + typeset zfs_props_os=(jailed aclmode) +else + typeset zfs_props_os=(zoned acltype) +fi +typeset userquota_props=(userquota@root groupquota@root userused@root \ + groupused@root) +typeset props=("${zfs_props[@]}" \ + "${zfs_props_os[@]}" \ + "${userquota_props[@]}") +typeset dataset=($TESTPOOL/$TESTCTR $TESTPOOL/$TESTFS $TESTPOOL/$TESTVOL \ + $TESTPOOL/$TESTFS@$TESTSNAP $TESTPOOL/$TESTVOL@$TESTSNAP) + +log_assert "Setting the valid options and properties 'zfs get' return " \ + "correct value. It should be successful." +log_onexit cleanup + +# Create volume and filesystem's snapshot +create_snapshot $TESTPOOL/$TESTFS $TESTSNAP +create_snapshot $TESTPOOL/$TESTVOL $TESTSNAP + +# +# Begin to test 'get [-prH] <property[,property]...> +# <filesystem|dataset|volume|snapshot>' +# 'get [-prH] <-a|-d> <filesystem|dataset|volume|snapshot>" +# +typeset -i opt_numb=8 +typeset -i prop_numb=20 +for dst in ${dataset[@]}; do + # option can be empty, so "" is necessary. + for opt in "" $(gen_option_str "${options[*]}" "-" "" $opt_numb); do + for prop in $(gen_option_str "${props[*]}" "" "," $prop_numb) + do + zfs get $opt $prop $dst > /dev/null 2>&1 + ret=$? + if [[ $ret != 0 ]]; then + log_fail "zfs get $opt $prop $dst (Code: $ret)" + fi + done + done +done + +log_pass "Setting the valid options to dataset, 'zfs get' pass." diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_003_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_003_pos.ksh new file mode 100755 index 000000000000..2ea5aa0cb4cf --- /dev/null +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_003_pos.ksh @@ -0,0 +1,65 @@ +#!/bin/ksh -p +# +# CDDL HEADER START +# +# The contents of this file are subject to the terms of the +# Common Development and Distribution License (the "License"). +# You may not use this file except in compliance with the License. +# +# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE +# or http://www.opensolaris.org/os/licensing. +# See the License for the specific language governing permissions +# and limitations under the License. +# +# When distributing Covered Code, include this CDDL HEADER in each +# file and include the License file at usr/src/OPENSOLARIS.LICENSE. +# If applicable, add the following below this CDDL HEADER, with the +# fields enclosed by brackets "[]" replaced with your own identifying +# information: Portions Copyright [yyyy] [name of copyright owner] +# +# CDDL HEADER END +# + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# + +# +# Copyright (c) 2016 by Delphix. All rights reserved. +# + +. $STF_SUITE/include/libtest.shlib + +# +# DESCRIPTION: +# 'zfs get' should get consistent report with different options. +# +# STRATEGY: +# 1. Create pool and filesystem. +# 2. 'zfs mount -o remount,noatime <fs>.' +# 3. Verify the value of 'zfs get atime' and 'zfs get all | grep atime' +# are identical. +# + +verify_runnable "both" + +function cleanup +{ + log_must zfs mount -o remount,atime $TESTPOOL/$TESTFS +} + +log_assert "'zfs get' should get consistent report with different option." +log_onexit cleanup + +log_must zfs set atime=on $TESTPOOL/$TESTFS +log_must zfs mount -o remount,noatime $TESTPOOL/$TESTFS + +value1=$(zfs get -H atime $TESTPOOL/$TESTFS | awk '{print $3}') +value2=$(zfs get -H all $TESTPOOL/$TESTFS | awk '{print $2 " " $3}' | \ + grep ^atime | awk '{print $2}') +if [[ $value1 != $value2 ]]; then + log_fail "value1($value1) != value2($value2)" +fi + +log_pass "'zfs get' get consistent report with different option passed." diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_004_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_004_pos.ksh new file mode 100755 index 000000000000..4bd61137c7be --- /dev/null +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_004_pos.ksh @@ -0,0 +1,227 @@ +#!/bin/ksh -p +# +# CDDL HEADER START +# +# The contents of this file are subject to the terms of the +# Common Development and Distribution License (the "License"). +# You may not use this file except in compliance with the License. +# +# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE +# or http://www.opensolaris.org/os/licensing. +# See the License for the specific language governing permissions +# and limitations under the License. +# +# When distributing Covered Code, include this CDDL HEADER in each +# file and include the License file at usr/src/OPENSOLARIS.LICENSE. +# If applicable, add the following below this CDDL HEADER, with the +# fields enclosed by brackets "[]" replaced with your own identifying +# information: Portions Copyright [yyyy] [name of copyright owner] +# +# CDDL HEADER END +# + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# + +# +# Copyright (c) 2012, 2016 by Delphix. All rights reserved. +# + +. $STF_SUITE/include/libtest.shlib + +# +# DESCRIPTION: +# Verify 'zfs get all' can get all properties for all datasets in the system +# +# STRATEGY: +# 1. Create datasets for testing +# 2. Issue 'zfs get all' command +# 3. Verify the command gets all available properties of all datasets +# + +verify_runnable "both" + +function cleanup +{ + [[ -e $propfile ]] && rm -f $propfile + + datasetexists $clone && \ + log_must zfs destroy $clone + for snap in $fssnap $volsnap ; do + snapexists $snap && \ + log_must zfs destroy $snap + done + + if [[ -n $globalzone ]] ; then + for pool in $TESTPOOL1 $TESTPOOL2 $TESTPOOL3; do + poolexists $pool && \ + log_must zpool destroy -f $pool + done + for file in `ls $TESTDIR1/poolfile*`; do + rm -f $file + done + else + for fs in $TESTPOOL/$TESTFS1 $TESTPOOL/$TESTFS2 $TESTPOOL/$TESTFS3; do + datasetexists $fs && \ + log_must zfs destroy -rf $fs + done + fi +} + +log_assert "Verify the functions of 'zfs get all' work." +log_onexit cleanup + +typeset globalzone="" + +if is_global_zone ; then + globalzone="true" +fi + +set -A opts "" "-r" "-H" "-p" "-rHp" "-o name" \ + "-s local,default,temporary,inherited,none" \ + "-o name -s local,default,temporary,inherited,none" \ + "-rHp -o name -s local,default,temporary,inherited,none" +set -A usrprops "a:b=c" "d_1:1_e=0f" "123:456=789" + +fs=$TESTPOOL/$TESTFS +fssnap=$fs@$TESTSNAP +clone=$TESTPOOL/$TESTCLONE +volsnap=$TESTPOOL/$TESTVOL@$TESTSNAP + +#set user defined properties for $TESTPOOL +for usrprop in ${usrprops[@]}; do + log_must zfs set $usrprop $TESTPOOL +done +# create snapshot and clone in $TESTPOOL +log_must zfs snapshot $fssnap +log_must zfs clone $fssnap $clone +log_must zfs snapshot $volsnap + +# collect datasets which can be set user defined properties +usrpropds="$clone $fs" + +# collect all datasets which we are creating +allds="$fs $clone $fssnap $volsnap" + +#create pool and datasets to guarantee testing under multiple pools and datasets. +file=$TESTDIR1/poolfile +typeset FILESIZE=$MINVDEVSIZE +(( DFILESIZE = $FILESIZE * 2 )) +typeset -i VOLSIZE=10485760 +availspace=$(get_prop available $TESTPOOL) +typeset -i i=0 + +# make sure 'availspace' is larger then twice of FILESIZE to create a new pool. +# If any, we only totally create 3 pools for multiple datasets testing to limit +# testing time +while (( availspace > DFILESIZE )) && (( i < 3 )) ; do + (( i += 1 )) + + if [[ -n $globalzone ]] ; then + log_must mkfile $FILESIZE ${file}$i + eval pool=\$TESTPOOL$i + log_must zpool create $pool ${file}$i + else + eval pool=$TESTPOOL/\$TESTFS$i + log_must zfs create $pool + fi + + #set user defined properties for testing + for usrprop in ${usrprops[@]}; do + log_must zfs set $usrprop $pool + done + + #create datasets in pool + log_must zfs create $pool/$TESTFS + log_must zfs snapshot $pool/$TESTFS@$TESTSNAP + log_must zfs clone $pool/$TESTFS@$TESTSNAP $pool/$TESTCLONE + + if [[ -n $globalzone ]] ; then + log_must zfs create -V $VOLSIZE $pool/$TESTVOL + else + log_must zfs create $pool/$TESTVOL + fi + + ds=`zfs list -H -r -o name -t filesystem,volume $pool` + usrpropds="$usrpropds $pool/$TESTFS $pool/$TESTCLONE $pool/$TESTVOL" + allds="$allds $pool/$TESTFS $pool/$TESTCLONE $pool/$TESTVOL \ + $pool/$TESTFS@$TESTSNAP" + + availspace=$(get_prop available $TESTPOOL) +done + +#the expected number of property for each type of dataset in this testing +typeset -i fspropnum=27 +typeset -i snappropnum=8 +typeset -i volpropnum=15 +propfile=$TEST_BASE_DIR/allpropfile.$$ + +typeset -i i=0 +typeset -i propnum=0 +typeset -i failflag=0 +while (( i < ${#opts[*]} )); do + [[ -e $propfile ]] && rm -f $propfile + log_must eval "zfs get ${opts[i]} all >$propfile" + + for ds in $allds; do + grep $ds $propfile >/dev/null 2>&1 + (( $? != 0 )) && \ + log_fail "There is no property for" \ + "dataset $ds in 'get all' output." + + propnum=`cat $propfile | awk '{print $1}' | \ + grep "${ds}$" | wc -l` + ds_type=`zfs get -H -o value type $ds` + case $ds_type in + filesystem ) + (( propnum < fspropnum )) && \ + (( failflag += 1 )) + ;; + snapshot ) + (( propnum < snappropnum )) && \ + (( failflag += 1 )) + ;; + volume ) + (( propnum < volpropnum )) && \ + (( failflag += 1 )) + ;; + esac + + (( failflag != 0 )) && \ + log_fail " 'zfs get all' fails to get out " \ + "all properties for dataset $ds." + + (( propnum = 0 )) + (( failflag = 0 )) + done + + (( i += 1 )) +done + +log_note "'zfs get' can get particular property for all datasets with that property." + +function do_particular_prop_test #<property> <suitable datasets> +{ + typeset props="$1" + typeset ds="$2" + + for prop in ${commprops[*]}; do + ds=`zfs get -H -o name $prop` + + [[ "$ds" != "$allds" ]] && \ + log_fail "The result datasets are $ds, but all suitable" \ + "datasets are $allds for the property $prop" + done +} + +# Here, we do a testing for user defined properties and the most common properties +# for all datasets. +commprop="type creation used referenced compressratio" +usrprop="a:b d_1:1_e 123:456" + +do_particular_prop_test "$commprop" "$allds" +do_particular_prop_test "$usrprop" "$usrpropds" + +log_pass "'zfs get all' works as expected." diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_005_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_005_neg.ksh new file mode 100755 index 000000000000..510c54506d0f --- /dev/null +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_005_neg.ksh @@ -0,0 +1,156 @@ +#!/bin/ksh -p +# +# CDDL HEADER START +# +# The contents of this file are subject to the terms of the +# Common Development and Distribution License (the "License"). +# You may not use this file except in compliance with the License. +# +# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE +# or http://www.opensolaris.org/os/licensing. +# See the License for the specific language governing permissions +# and limitations under the License. +# +# When distributing Covered Code, include this CDDL HEADER in each +# file and include the License file at usr/src/OPENSOLARIS.LICENSE. +# If applicable, add the following below this CDDL HEADER, with the +# fields enclosed by brackets "[]" replaced with your own identifying +# information: Portions Copyright [yyyy] [name of copyright owner] +# +# CDDL HEADER END +# + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# + +# +# Copyright (c) 2016 by Delphix. All rights reserved. +# + +. $STF_SUITE/tests/functional/cli_root/zfs_get/zfs_get_common.kshlib + +# +# DESCRIPTION: +# Setting the invalid option and properties, 'zfs get' should failed. +# +# STRATEGY: +# 1. Create pool, filesystem, volume and snapshot. +# 2. Getting incorrect combination by invalid parameters +# 3. Using the combination as the parameters of 'zfs get' to check the +# command line return value. +# + +verify_runnable "both" + +typeset val_opts=(p r H) +typeset v_props=(type used available creation volsize referenced compressratio \ + mounted origin recordsize quota reservation mountpoint sharenfs checksum \ + compression atime devices exec readonly setuid snapdir version \ + aclinherit canmount primarycache secondarycache \ + usedbychildren usedbydataset usedbyrefreservation usedbysnapshots) +if is_freebsd; then + typeset v_props_os=(jailed aclmode) +else + typeset v_props_os=(zoned acltype) +fi +typeset userquota_props=(userquota@root groupquota@root userused@root \ + groupused@root) +typeset val_props=("${v_props[@]}" \ + "${v_props_os[@]}" \ + "${userquota_props[@]}") +set -f # Force shell does not parse '?' and '*' as the wildcard +typeset inval_opts=(P R h ? *) +typeset inval_props=(Type 0 ? * -on --on readonl time USED RATIO MOUNTED) + +typeset dataset=($TESTPOOL/$TESTFS $TESTPOOL/$TESTCTR $TESTPOOL/$TESTVOL \ + $TESTPOOL/$TESTFS@$TESTSNAP $TESTPOOL/$TESTVOL@$TESTSNAP) + +typeset -i opt_numb=6 +typeset -i prop_numb=12 + +val_opts_str=$(gen_option_str "${val_opts[*]}" "-" "" $opt_numb) +val_props_str=$(gen_option_str "${val_props[*]}" "" "," $prop_numb) + +inval_opts_str=$(gen_option_str "${inval_opts[*]}" "-" "" $opt_numb) +inval_props_str=$(gen_option_str "${inval_props[*]}" "" "," $prop_numb) + +typeset val_bookmark_props=(creation) +typeset bookmark=($TESTPOOL/$TESTFS#$TESTBKMARK $TESTPOOL/$TESTVOL#$TESTBKMARK) + +# +# Test different options and properties combination. +# +# $1 options +# $2 properties +# +function test_options +{ + typeset opts=$1 + typeset props=$2 + + for dst in ${dataset[@]}; do + for opt in $opts; do + for prop in $props; do + zfs get $opt -- $prop $dst > /dev/null 2>&1 + ret=$? + if [[ $ret == 0 ]]; then + log_fail "zfs get $opt -- $prop " \ + "$dst unexpectedly succeeded." + fi + done + done + done +} + +# +# Test different options and properties combination for bookmarks. +# +# $1 options +# $2 properties +# +function test_options_bookmarks +{ + typeset opts=$1 + typeset props=$2 + + for dst in ${bookmark[@]}; do + for opt in $opts; do + for prop in $props; do + zfs get $opt -- $prop $dst > /dev/null 2>&1 + ret=$? + if [[ $ret == 0 ]]; then + log_fail "zfs get $opt -- $prop " \ + "$dst unexpectedly succeeded." + fi + done + done + done +} + +log_assert "Setting the invalid option and properties, 'zfs get' should be \ + failed." +log_onexit cleanup + +# Create filesystem and volume's snapshot +create_snapshot $TESTPOOL/$TESTFS $TESTSNAP +create_snapshot $TESTPOOL/$TESTVOL $TESTSNAP + +# Create filesystem and volume's bookmark +create_bookmark $TESTPOOL/$TESTFS $TESTSNAP $TESTBKMARK +create_bookmark $TESTPOOL/$TESTVOL $TESTSNAP $TESTBKMARK + +log_note "Valid options + invalid properties, 'zfs get' should fail." +test_options "$val_opts_str" "$inval_props_str" +test_options_bookmarks "$val_opts_str" "$inval_props_str" + +log_note "Invalid options + valid properties, 'zfs get' should fail." +test_options "$inval_opts_str" "$val_props_str" +test_options_bookmarks "$inval_opts_str" "$val_bookmark_props" + +log_note "Invalid options + invalid properties, 'zfs get' should fail." +test_options "$inval_opts_str" "$inval_props_str" +test_options_bookmarks "$inval_opts_str" "$inval_props_str" + +log_pass "Setting the invalid options to dataset, 'zfs get' pass." diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_006_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_006_neg.ksh new file mode 100755 index 000000000000..a91685849069 --- /dev/null +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_006_neg.ksh @@ -0,0 +1,68 @@ +#!/bin/ksh -p +# +# CDDL HEADER START +# +# The contents of this file are subject to the terms of the +# Common Development and Distribution License (the "License"). +# You may not use this file except in compliance with the License. +# +# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE +# or http://www.opensolaris.org/os/licensing. +# See the License for the specific language governing permissions +# and limitations under the License. +# +# When distributing Covered Code, include this CDDL HEADER in each +# file and include the License file at usr/src/OPENSOLARIS.LICENSE. +# If applicable, add the following below this CDDL HEADER, with the +# fields enclosed by brackets "[]" replaced with your own identifying +# information: Portions Copyright [yyyy] [name of copyright owner] +# +# CDDL HEADER END +# + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# + +# +# Copyright (c) 2016 by Delphix. All rights reserved. +# + +. $STF_SUITE/tests/functional/cli_root/zfs_get/zfs_get_common.kshlib + +# +# DESCRIPTION: +# Verify 'zfs get all' can deal with invalid scenarios +# +# STRATEGY: +# 1. Define invalid scenarios for 'zfs get all' +# 2. Run zfs get with those invalid scenarios +# 3. Verify that zfs get fails with invalid scenarios +# + +verify_runnable "both" + +log_assert "Verify 'zfs get all' fails with invalid combination scenarios." + +set -f # Force ksh ignore '?' and '*' +set -A bad_combine "ALL" "\-R all" "-P all" "-h all" "-rph all" "-RpH all" "-PrH all" \ + "-o all" "-s all" "-? all" "-* all" "-?* all" "all -r" "all -p" \ + "all -H" "all -rp" "all -rH" "all -ph" "all -rpH" "all -r $TESTPOOL" \ + "all -H $TESTPOOL" "all -p $TESTPOOL" "all -r -p -H $TESTPOOL" \ + "all -rph $TESTPOOL" "all,available,reservation $TESTPOOL" \ + "all $TESTPOOL?" "all $TESTPOOL*" "all nonexistpool" + +export POSIXLY_CORRECT=1 + +typeset -i i=0 +while (( i < ${#bad_combine[*]} )) +do + log_mustnot eval "zfs get ${bad_combine[i]} >/dev/null" + + (( i = i + 1 )) +done + +unset POSIXLY_CORRECT + +log_pass "'zfs get all' fails with invalid combinations scenarios as expected." diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_007_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_007_neg.ksh new file mode 100755 index 000000000000..9bb00807f1b0 --- /dev/null +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_007_neg.ksh @@ -0,0 +1,64 @@ +#!/bin/ksh -p +# +# CDDL HEADER START +# +# The contents of this file are subject to the terms of the +# Common Development and Distribution License (the "License"). +# You may not use this file except in compliance with the License. +# +# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE +# or http://www.opensolaris.org/os/licensing. +# See the License for the specific language governing permissions +# and limitations under the License. +# +# When distributing Covered Code, include this CDDL HEADER in each +# file and include the License file at usr/src/OPENSOLARIS.LICENSE. +# If applicable, add the following below this CDDL HEADER, with the +# fields enclosed by brackets "[]" replaced with your own identifying +# information: Portions Copyright [yyyy] [name of copyright owner] +# +# CDDL HEADER END +# + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# + +# +# Copyright (c) 2016 by Delphix. All rights reserved. +# + +. $STF_SUITE/tests/functional/cli_root/zfs_get/zfs_get_common.kshlib + +# +# DESCRIPTION: +# 'zfs get -o' should fail with invalid column names +# +# STRATEGY: +# 1. Run zfs get -o with invalid column name combinations +# 2. Verify that zfs get returns error +# + +verify_runnable "both" + +log_assert "'zfs get -o' fails with invalid options or column names" + +set -A badargs "o name,property,value,resource" "o name" \ + "-O name,property,value,source" "-oo name" "-o blah" \ + "-o name,property,blah,source" "-o name,name,name,name,name" \ + "-o name,property,value,," "-o *,*,*,*" "-o ?,?,?,?" \ + "-o" "-o ,,,,," "-o -o -o -o" "-o NAME,PROPERTY,VALUE,SOURCE" \ + "-o name,properTy,value,source" "-o name, property, value,source" \ + "-o name:property:value:source" "-o name,property:value,source" \ + "-o name;property;value;source" + +typeset -i i=0 +while (( i < ${#badargs[*]} )) +do + log_mustnot eval "zfs get \"${badargs[i]}\" >/dev/null 2>&1" + + (( i = i + 1 )) +done + +log_pass "'zfs get -o' fails with invalid options or column name as expected." diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_008_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_008_pos.ksh new file mode 100755 index 000000000000..296fe99968c8 --- /dev/null +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_008_pos.ksh @@ -0,0 +1,117 @@ +#!/bin/ksh -p +# +# CDDL HEADER START +# +# The contents of this file are subject to the terms of the +# Common Development and Distribution License (the "License"). +# You may not use this file except in compliance with the License. +# +# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE +# or http://www.opensolaris.org/os/licensing. +# See the License for the specific language governing permissions +# and limitations under the License. +# +# When distributing Covered Code, include this CDDL HEADER in each +# file and include the License file at usr/src/OPENSOLARIS.LICENSE. +# If applicable, add the following below this CDDL HEADER, with the +# fields enclosed by brackets "[]" replaced with your own identifying +# information: Portions Copyright [yyyy] [name of copyright owner] +# +# CDDL HEADER END +# + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# + +# +# Copyright (c) 2016 by Delphix. All rights reserved. +# + +. $STF_SUITE/tests/functional/cli_root/zfs_get/zfs_get_common.kshlib +. $STF_SUITE/tests/functional/cli_root/zfs_get/zfs_get_list_d.kshlib + +# +# DESCRIPTION: +# Verify "-d <n>" can work with other options +# +# STRATEGY: +# 1. Create pool, filesystem, dataset, volume, snapshot, and bookmark. +# 2. Getting an -d option, other options and properties random combination. +# 3. Using the combination as the parameters of 'zfs get' to check the +# command line return value. +# + +verify_runnable "both" + +set -A options " " "-r" "-H" "-p" "-rHp" "-o name" \ + "-s local,default,temporary,inherited,none" \ + "-o name -s local,default,temporary,inherited,none" \ + "-rHp -o name -s local,default,temporary,inherited,none" + +set -A props type used available creation volsize referenced compressratio \ + mounted origin recordsize quota reservation mountpoint sharenfs \ + checksum compression atime devices exec readonly setuid snapdir \ + aclinherit canmount primarycache secondarycache \ + usedbychildren usedbydataset usedbyrefreservation usedbysnapshots \ + userquota@root groupquota@root userused@root groupused@root +if is_freebsd; then + set -A props ${props[*]} jailed aclmode +else + set -A props ${props[*]} zoned acltype +fi + +zfs upgrade -v > /dev/null 2>&1 +if [[ $? -eq 0 ]]; then + set -A props ${props[*]} version +fi + +set -A dataset $TESTPOOL/$TESTCTR $TESTPOOL/$TESTFS $TESTPOOL/$TESTVOL \ + $TESTPOOL/$TESTFS@$TESTSNAP $TESTPOOL/$TESTVOL@$TESTSNAP + +set -A bookmark_props creation +set -A bookmark $TESTPOOL/$TESTFS#$TESTBKMARK $TESTPOOL/$TESTVOL#$TESTBKMARK + +log_assert "Verify '-d <n>' can work with other options" +log_onexit cleanup + +# Create volume and filesystem's snapshot +create_snapshot $TESTPOOL/$TESTFS $TESTSNAP +create_snapshot $TESTPOOL/$TESTVOL $TESTSNAP + +# Create filesystem and volume's bookmark +create_bookmark $TESTPOOL/$TESTFS $TESTSNAP $TESTBKMARK +create_bookmark $TESTPOOL/$TESTVOL $TESTSNAP $TESTBKMARK + +typeset -i opt_numb=16 +typeset -i prop_numb=16 +typeset -i i=0 +typeset -i item=0 +typeset -i depth_item=0 + +for dst in ${dataset[@]}; do + (( i=0 )) + while (( i < opt_numb )); do + (( item = $RANDOM % ${#options[@]} )) + (( depth_item = $RANDOM % ${#depth_options[@]} )) + for prop in $(gen_option_str "${props[*]}" "" "," $prop_numb) + do + log_must eval "zfs get -${depth_options[depth_item]} ${options[item]} $prop $dst > /dev/null 2>&1" + done + (( i += 1 )) + done +done + +for dst in ${bookmark[@]}; do + (( i=0 )) + while (( i < opt_numb )); do + (( item = $RANDOM % ${#options[@]} )) + (( depth_item = $RANDOM % ${#depth_options[@]} )) + log_must eval "zfs get -${depth_options[depth_item]} ${options[item]} $bookmark_props $dst > /dev/null 2>&1" + (( i += 1 )) + done +done + +log_pass "Verify '-d <n>' can work with other options" + diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_009_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_009_pos.ksh new file mode 100755 index 000000000000..7fd6918b43db --- /dev/null +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_009_pos.ksh @@ -0,0 +1,112 @@ +#!/bin/ksh -p +# +# CDDL HEADER START +# +# The contents of this file are subject to the terms of the +# Common Development and Distribution License (the "License"). +# You may not use this file except in compliance with the License. +# +# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE +# or http://www.opensolaris.org/os/licensing. +# See the License for the specific language governing permissions +# and limitations under the License. +# +# When distributing Covered Code, include this CDDL HEADER in each +# file and include the License file at usr/src/OPENSOLARIS.LICENSE. +# If applicable, add the following below this CDDL HEADER, with the +# fields enclosed by brackets "[]" replaced with your own identifying +# information: Portions Copyright [yyyy] [name of copyright owner] +# +# CDDL HEADER END +# + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# + +# +# Copyright (c) 2016 by Delphix. All rights reserved. +# + +. $STF_SUITE/tests/functional/cli_root/zfs_get/zfs_get_common.kshlib +. $STF_SUITE/tests/functional/cli_root/zfs_get/zfs_get_list_d.kshlib + +# +# DESCRIPTION: +# 'zfs get -d <n>' should get expected output. +# +# STRATEGY: +# 1. Create a multiple depth filesystem. +# 2. 'zfs get -d <n>' to get the output. +# 3. 'zfs get -r|egrep' to get the expected output. +# 4. Compare the two outputs, they should be same. +# + +verify_runnable "both" + +if is_kmemleak; then + log_unsupported "Test case runs slowly when kmemleak is enabled" +fi + +log_assert "'zfs get -d <n>' should get expected output." +log_onexit depth_fs_cleanup + +set -A all_props type used available creation volsize referenced \ + compressratio mounted origin recordsize quota reservation mountpoint \ + sharenfs checksum compression atime devices exec readonly setuid \ + snapdir aclinherit canmount primarycache secondarycache \ + usedbychildren usedbydataset usedbyrefreservation usedbysnapshots \ + userquota@root groupquota@root userused@root groupused@root +if is_freebsd; then + set -A all_props ${all_props[*]} jailed aclmode +else + set -A all_props ${all_props[*]} zoned acltype +fi + +zfs upgrade -v > /dev/null 2>&1 +if [[ $? -eq 0 ]]; then + set -A all_props ${all_props[*]} version +fi + +depth_fs_setup + +mntpnt=$(get_prop mountpoint $DEPTH_FS) +DEPTH_OUTPUT="$mntpnt/depth_output" +EXPECT_OUTPUT="$mntpnt/expect_output" +typeset -i prop_numb=16 +typeset -i old_val=0 +typeset -i j=0 +typeset eg_opt="$DEPTH_FS"$ +for dp in ${depth_array[@]}; do + (( j=old_val+1 )) + while (( j<=dp && j<=MAX_DEPTH )); do + eg_opt="$eg_opt""|depth""$j"$ + (( j+=1 )) + done + for prop in $(gen_option_str "${all_props[*]}" "" "," $prop_numb); do + log_must eval "zfs get -H -d $dp -o name $prop $DEPTH_FS > $DEPTH_OUTPUT" + log_must eval "zfs get -rH -o name $prop $DEPTH_FS | egrep -e '$eg_opt' > $EXPECT_OUTPUT" + log_must diff $DEPTH_OUTPUT $EXPECT_OUTPUT + done + (( old_val=dp )) +done + +# Ensure 'zfs get -t snapshot <dataset>' works as though -d 1 was specified +log_must eval "zfs get -H -t snapshot -o name creation $DEPTH_FS > $DEPTH_OUTPUT" +log_must eval "zfs get -H -t snapshot -d 1 -o name creation $DEPTH_FS > $EXPECT_OUTPUT" +log_must diff $DEPTH_OUTPUT $EXPECT_OUTPUT + +# Ensure 'zfs get -t snap' works as a shorthand for 'zfs get -t snapshot' +log_must eval "zfs get -H -t snap -d 1 -o name creation $DEPTH_FS > $DEPTH_OUTPUT" +log_must eval "zfs get -H -t snapshot -d 1 -o name creation $DEPTH_FS > $EXPECT_OUTPUT" +log_must diff $DEPTH_OUTPUT $EXPECT_OUTPUT + +# Ensure 'zfs get -t bookmark <dataset>' works as though -d 1 was specified +log_must eval "zfs get -H -t bookmark -o name creation $DEPTH_FS > $DEPTH_OUTPUT" +log_must eval "zfs get -H -t bookmark -d 1 -o name creation $DEPTH_FS > $EXPECT_OUTPUT" +log_must diff $DEPTH_OUTPUT $EXPECT_OUTPUT + + +log_pass "'zfs get -d <n>' should get expected output." + diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_010_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_010_neg.ksh new file mode 100755 index 000000000000..e1f53845fd9c --- /dev/null +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_010_neg.ksh @@ -0,0 +1,59 @@ +#!/bin/ksh -p +# +# CDDL HEADER START +# +# The contents of this file are subject to the terms of the +# Common Development and Distribution License (the "License"). +# You may not use this file except in compliance with the License. +# +# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE +# or http://www.opensolaris.org/os/licensing. +# See the License for the specific language governing permissions +# and limitations under the License. +# +# When distributing Covered Code, include this CDDL HEADER in each +# file and include the License file at usr/src/OPENSOLARIS.LICENSE. +# If applicable, add the following below this CDDL HEADER, with the +# fields enclosed by brackets "[]" replaced with your own identifying +# information: Portions Copyright [yyyy] [name of copyright owner] +# +# CDDL HEADER END +# + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# + +# +# Copyright (c) 2016 by Delphix. All rights reserved. +# + +. $STF_SUITE/tests/functional/cli_root/zfs_get/zfs_get_common.kshlib +. $STF_SUITE/tests/functional/cli_root/zfs_get/zfs_get_list_d.kshlib + +# +# DESCRIPTION: +# A negative depth or a non numeric depth should fail in 'zfs get -d <n>' +# +# STRATEGY: +# 1. Run zfs get -d with negative depth or non numeric depth +# 2. Verify that zfs get returns error +# + +verify_runnable "both" + +log_assert "A negative depth or a non numeric depth should fail in 'zfs get -d <n>'" + +set -A badargs "a" "AB" "aBc" "2A" "a2b" "aB2" "-1" "-32" "-999" + +typeset -i i=0 +while (( i < ${#badargs[*]} )) +do + log_mustnot eval "zfs get -d ${badargs[i]} $TESTPOOL/$TESTFS >/dev/null 2>&1" + (( i = i + 1 )) +done + +log_pass "A negative depth or a non numeric depth should fail in 'zfs get -d <n>'" + + diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_common.kshlib b/tests/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_common.kshlib new file mode 100644 index 000000000000..d8cb9af028e5 --- /dev/null +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_common.kshlib @@ -0,0 +1,106 @@ +# +# CDDL HEADER START +# +# The contents of this file are subject to the terms of the +# Common Development and Distribution License (the "License"). +# You may not use this file except in compliance with the License. +# +# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE +# or http://www.opensolaris.org/os/licensing. +# See the License for the specific language governing permissions +# and limitations under the License. +# +# When distributing Covered Code, include this CDDL HEADER in each +# file and include the License file at usr/src/OPENSOLARIS.LICENSE. +# If applicable, add the following below this CDDL HEADER, with the +# fields enclosed by brackets "[]" replaced with your own identifying +# information: Portions Copyright [yyyy] [name of copyright owner] +# +# CDDL HEADER END +# + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# + +# +# Copyright (c) 2016 by Delphix. All rights reserved. +# + +. $STF_SUITE/include/libtest.shlib + +# +# According to $elements, $prefix and $separator, the function random produce +# the number of $counter combination. +# +# $1 elements which is used to get the combination. +# $2 prefix is appended to the combination +# $3 separator between the combination, such as ' ' or ',' +# $4 counter is the number of combination which you want to get. +# +function gen_option_str # $elements $prefix $separator $counter +{ + typeset elements="" + typeset prefix=${2} + typeset separator=${3} + typeset -i counter=${4:-0} + typeset -i i=0 + typeset comb_str="" + + for e in $1; do + elements[i]="$e" + (( i += 1 )) + done + (( ${#elements[@]} == 0 )) && log_fail "The elements can't be empty." + + typeset -i item=0 + typeset -i j=0 + typeset -i numb_item=0 + + # Loop and get the specified number combination strings. + i=0 + while (( i < counter )); do + j=0 + numb_item=0 + comb_str="" + + # Get random number items for each combinations. + (( numb_item = ($RANDOM % ${#elements[@]}) + 1 )) + + while (( j < numb_item )); do + # Random select elements from the array + (( item = $RANDOM % ${#elements[@]} )) + + if (( ${#comb_str} == 0 )); then + comb_str=${elements[item]} + else + comb_str=$comb_str$separator${elements[item]} + fi + (( j += 1 )) + done + + echo "$prefix$comb_str" + + (( i += 1 )) + done +} + +# +# Cleanup the volume snapshot, filesystem snapshot, volume bookmark, and +# filesystem bookmark that were created for this test case. +# +function cleanup +{ + datasetexists $TESTPOOL/$TESTVOL@$TESTSNAP && \ + destroy_snapshot $TESTPOOL/$TESTVOL@$TESTSNAP + datasetexists $TESTPOOL/$TESTFS@$TESTSNAP && \ + destroy_snapshot $TESTPOOL/$TESTFS@$TESTSNAP + + bkmarkexists $TESTPOOL/$TESTVOL#$TESTBKMARK && \ + destroy_bookmark $TESTPOOL/$TESTVOL#$TESTBKMARK + bkmarkexists $TESTPOOL/$TESTFS#$TESTBKMARK && \ + destroy_bookmark $TESTPOOL/$TESTFS#$TESTBKMARK + + [[ -e $TESTFILE0 ]] && log_must rm $TESTFILE0 +} diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_list_d.kshlib b/tests/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_list_d.kshlib new file mode 100644 index 000000000000..48b3268f7813 --- /dev/null +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_list_d.kshlib @@ -0,0 +1,84 @@ +# +# CDDL HEADER START +# +# The contents of this file are subject to the terms of the +# Common Development and Distribution License (the "License"). +# You may not use this file except in compliance with the License. +# +# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE +# or http://www.opensolaris.org/os/licensing. +# See the License for the specific language governing permissions +# and limitations under the License. +# +# When distributing Covered Code, include this CDDL HEADER in each +# file and include the License file at usr/src/OPENSOLARIS.LICENSE. +# If applicable, add the following below this CDDL HEADER, with the +# fields enclosed by brackets "[]" replaced with your own identifying +# information: Portions Copyright [yyyy] [name of copyright owner] +# +# CDDL HEADER END +# + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# + +# +# Copyright (c) 2016 by Delphix. All rights reserved. +# + +. $STF_SUITE/include/libtest.shlib + +DEPTH_FS=$TESTPOOL/depth_fs +MAX_DEPTH=3 +DS_COUNT=3 +set -A depth_options "d 0" "d 1" "d 2" "d 4" "d 32" +set -A depth_array 0 1 2 4 32 + +# +# Setup multiple depths datasets, including fs, volumes, snapshots and bookmarks. +# +function depth_fs_setup +{ + typeset -i i j k + typeset fslist + + log_must zfs create $DEPTH_FS + + (( i=1 )) + while (( i<=MAX_DEPTH )); do + if (( i==1 )); then + fslist=$DEPTH_FS + else + (( k=i-1 )) + fslist=$(zfs list -rH -t filesystem -o name $DEPTH_FS|grep depth"$k"$) + if (( $? != 0 )); then + log_fail "No depth$k filesystem" + fi + fi + for fs in $fslist; do + (( j=1 )) + while (( j<=DS_COUNT )); do + log_must zfs create $fs/fs_"$j"_depth"$i" + if is_global_zone ; then + log_must zfs create -V 8M $fs/vol_"$j"_depth"$i" + fi + log_must zfs snapshot $fs@snap_"$j"_depth"$i" + log_must zfs bookmark $fs@snap_"$j"_depth"$i" '#bookmark'_"$j"_depth"$i" + (( j=j+1 )) + done + done + (( i=i+1 )) + done +} + +# +# Cleanup multiple depths filesystem. +# +function depth_fs_cleanup +{ + log_must zfs destroy -rR $DEPTH_FS +} + + |