7290 ZFS test suite needs to control what utilities it can run
[unleashed.git] / usr / src / test / zfs-tests / tests / functional / cli_root / zfs_get / zfs_get_004_pos.ksh
blobf57628c163f5bd61aac2e1d25b50ffcf0716f8de
1 #!/bin/ksh -p
3 # CDDL HEADER START
5 # The contents of this file are subject to the terms of the
6 # Common Development and Distribution License (the "License").
7 # You may not use this file except in compliance with the License.
9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 # or http://www.opensolaris.org/os/licensing.
11 # See the License for the specific language governing permissions
12 # and limitations under the License.
14 # When distributing Covered Code, include this CDDL HEADER in each
15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 # If applicable, add the following below this CDDL HEADER, with the
17 # fields enclosed by brackets "[]" replaced with your own identifying
18 # information: Portions Copyright [yyyy] [name of copyright owner]
20 # CDDL HEADER END
24 # Copyright 2007 Sun Microsystems, Inc. All rights reserved.
25 # Use is subject to license terms.
29 # Copyright (c) 2012, 2016 by Delphix. All rights reserved.
32 . $STF_SUITE/include/libtest.shlib
35 # DESCRIPTION:
36 # Verify 'zfs get all' can get all properties for all datasets in the system
38 # STRATEGY:
39 # 1. Create datasets for testing
40 # 2. Issue 'zfs get all' command
41 # 3. Verify the command gets all available properties of all datasets
44 verify_runnable "both"
46 function cleanup
48 [[ -e $propfile ]] && rm -f $propfile
50 datasetexists $clone && \
51 log_must zfs destroy $clone
52 for snap in $fssnap $volsnap ; do
53 snapexists $snap && \
54 log_must zfs destroy $snap
55 done
57 if [[ -n $globalzone ]] ; then
58 for pool in $TESTPOOL1 $TESTPOOL2 $TESTPOOL3; do
59 poolexists $pool && \
60 log_must zpool destroy -f $pool
61 done
62 for file in `ls $TESTDIR1/poolfile*`; do
63 rm -f $file
64 done
65 else
66 for fs in $TESTPOOL/$TESTFS1 $TESTPOOL/$TESTFS2 $TESTPOOL/$TESTFS3; do
67 datasetexists $fs && \
68 log_must zfs destroy -rf $fs
69 done
73 log_assert "Verify the functions of 'zfs get all' work."
74 log_onexit cleanup
76 typeset globalzone=""
78 if is_global_zone ; then
79 globalzone="true"
82 set -A opts "" "-r" "-H" "-p" "-rHp" "-o name" \
83 "-s local,default,temporary,inherited,none" \
84 "-o name -s local,default,temporary,inherited,none" \
85 "-rHp -o name -s local,default,temporary,inherited,none"
86 set -A usrprops "a:b=c" "d_1:1_e=0f" "123:456=789"
88 fs=$TESTPOOL/$TESTFS
89 fssnap=$fs@$TESTSNAP
90 clone=$TESTPOOL/$TESTCLONE
91 volsnap=$TESTPOOL/$TESTVOL@$TESTSNAP
93 #set user defined properties for $TESTPOOL
94 for usrprop in ${usrprops[@]}; do
95 log_must zfs set $usrprop $TESTPOOL
96 done
97 # create snapshot and clone in $TESTPOOL
98 log_must zfs snapshot $fssnap
99 log_must zfs clone $fssnap $clone
100 log_must zfs snapshot $volsnap
102 # collect datasets which can be set user defined properties
103 usrpropds="$clone $fs"
105 # collect all datasets which we are creating
106 allds="$fs $clone $fssnap $volsnap"
108 #create pool and datasets to guarantee testing under multiple pools and datasets.
109 file=$TESTDIR1/poolfile
110 typeset FILESIZE=$MINVDEVSIZE
111 (( DFILESIZE = $FILESIZE * 2 ))
112 typeset -i VOLSIZE=10485760
113 availspace=$(get_prop available $TESTPOOL)
114 typeset -i i=0
116 # make sure 'availspace' is larger then twice of FILESIZE to create a new pool.
117 # If any, we only totally create 3 pools for multple datasets testing to limit
118 # testing time
119 while (( availspace > DFILESIZE )) && (( i < 3 )) ; do
120 (( i += 1 ))
122 if [[ -n $globalzone ]] ; then
123 log_must mkfile $FILESIZE ${file}$i
124 eval pool=\$TESTPOOL$i
125 log_must zpool create $pool ${file}$i
126 else
127 eval pool=$TESTPOOL/\$TESTFS$i
128 log_must zfs create $pool
131 #set user defined properties for testing
132 for usrprop in ${usrprops[@]}; do
133 log_must zfs set $usrprop $pool
134 done
136 #create datasets in pool
137 log_must zfs create $pool/$TESTFS
138 log_must zfs snapshot $pool/$TESTFS@$TESTSNAP
139 log_must zfs clone $pool/$TESTFS@$TESTSNAP $pool/$TESTCLONE
141 if [[ -n $globalzone ]] ; then
142 log_must zfs create -V $VOLSIZE $pool/$TESTVOL
143 else
144 log_must zfs create $pool/$TESTVOL
147 ds=`zfs list -H -r -o name -t filesystem,volume $pool`
148 usrpropds="$usrpropds $pool/$TESTFS $pool/$TESTCLONE $pool/$TESTVOL"
149 allds="$allds $pool/$TESTFS $pool/$TESTCLONE $pool/$TESTVOL \
150 $pool/$TESTFS@$TESTSNAP"
152 availspace=$(get_prop available $TESTPOOL)
153 done
155 #the expected number of property for each type of dataset in this testing
156 typeset -i fspropnum=27
157 typeset -i snappropnum=8
158 typeset -i volpropnum=15
159 propfile=/var/tmp/allpropfile.$$
161 typeset -i i=0
162 typeset -i propnum=0
163 typeset -i failflag=0
164 while (( i < ${#opts[*]} )); do
165 [[ -e $propfile ]] && rm -f $propfile
166 log_must eval "zfs get ${opts[i]} all >$propfile"
168 for ds in $allds; do
169 grep $ds $propfile >/dev/null 2>&1
170 (( $? != 0 )) && \
171 log_fail "There is no property for" \
172 "dataset $ds in 'get all' output."
174 propnum=`cat $propfile | awk '{print $1}' | \
175 grep "${ds}$" | wc -l`
176 ds_type=`zfs get -H -o value type $ds`
177 case $ds_type in
178 filesystem )
179 (( propnum < fspropnum )) && \
180 (( failflag += 1 ))
182 snapshot )
183 (( propnum < snappropnum )) && \
184 (( failflag += 1 ))
186 volume )
187 (( propnum < volpropnum )) && \
188 (( failflag += 1 ))
190 esac
192 (( failflag != 0 )) && \
193 log_fail " 'zfs get all' fails to get out " \
194 "all properties for dataset $ds."
196 (( propnum = 0 ))
197 (( failflag = 0 ))
198 done
200 (( i += 1 ))
201 done
203 log_note "'zfs get' can get particular property for all datasets with that property."
205 function do_particular_prop_test #<property> <suitable datasets>
207 typeset props="$1"
208 typeset ds="$2"
210 for prop in ${commprops[*]}; do
211 ds=`zfs get -H -o name $prop`
213 [[ "$ds" != "$allds" ]] && \
214 log_fail "The result datasets are $ds, but all suitable" \
215 "datasets are $allds for the property $prop"
216 done
219 # Here, we do a testing for user defined properties and the most common properties
220 # for all datasets.
221 commprop="type creation used referenced compressratio"
222 usrprop="a:b d_1:1_e 123:456"
224 do_particular_prop_test "$commprop" "$allds"
225 do_particular_prop_test "$usrprop" "$usrpropds"
227 log_pass "'zfs get all' works as expected."