]> git.proxmox.com Git - mirror_zfs.git/blob - tests/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_004_pos.ksh
Add the ZFS Test Suite
[mirror_zfs.git] / tests / zfs-tests / tests / functional / cli_root / zfs_get / zfs_get_004_pos.ksh
1 #!/bin/ksh -p
2 #
3 # CDDL HEADER START
4 #
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.
8 #
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.
13 #
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]
19 #
20 # CDDL HEADER END
21 #
22
23 #
24 # Copyright 2007 Sun Microsystems, Inc. All rights reserved.
25 # Use is subject to license terms.
26 #
27
28 #
29 # Copyright (c) 2012 by Delphix. All rights reserved.
30 #
31
32 . $STF_SUITE/include/libtest.shlib
33
34 #
35 # DESCRIPTION:
36 # Verify 'zfs get all' can get all properties for all datasets in the system
37 #
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
42 #
43
44 verify_runnable "both"
45
46 function cleanup
47 {
48 [[ -e $propfile ]] && $RM -f $propfile
49
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
56
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
70 fi
71 }
72
73 log_assert "Verify the functions of 'zfs get all' work."
74 log_onexit cleanup
75
76 typeset globalzone=""
77
78 if is_global_zone ; then
79 globalzone="true"
80 fi
81
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"
87
88 fs=$TESTPOOL/$TESTFS
89 fssnap=$fs@$TESTSNAP
90 clone=$TESTPOOL/$TESTCLONE
91 volsnap=$TESTPOOL/$TESTVOL@$TESTSNAP
92
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
101
102 # collect datasets which can be set user defined properties
103 usrpropds="$clone $fs"
104
105 # collect all datasets which we are creating
106 allds="$fs $clone $fssnap $volsnap"
107
108 #create pool and datasets to guarantee testing under multiple pools and datasets.
109 file=$TESTDIR1/poolfile
110 typeset -i FILESIZE=104857600 #100M
111 (( DFILESIZE = FILESIZE * 2 )) # double of FILESIZE
112 typeset -i VOLSIZE=10485760 #10M
113 availspace=$(get_prop available $TESTPOOL)
114 typeset -i i=0
115
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 ))
121
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
129 fi
130
131 #set user defined properties for testing
132 for usrprop in ${usrprops[@]}; do
133 log_must $ZFS set $usrprop $pool
134 done
135
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
140
141 if [[ -n $globalzone ]] ; then
142 log_must $ZFS create -V $VOLSIZE $pool/$TESTVOL
143 else
144 log_must $ZFS create $pool/$TESTVOL
145 fi
146
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"
151
152 availspace=$(get_prop available $TESTPOOL)
153 done
154
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.$$
160
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"
167
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."
173
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 ))
181 ;;
182 snapshot )
183 (( propnum < snappropnum )) && \
184 (( failflag += 1 ))
185 ;;
186 volume )
187 (( propnum < volpropnum )) && \
188 (( failflag += 1 ))
189 ;;
190 esac
191
192 (( failflag != 0 )) && \
193 log_fail " 'zfs get all' fails to get out " \
194 "all properties for dataset $ds."
195
196 (( propnum = 0 ))
197 (( failflag = 0 ))
198 done
199
200 (( i += 1 ))
201 done
202
203 log_note "'zfs get' can get particular property for all datasets with that property."
204
205 function do_particular_prop_test #<property> <suitable datasets>
206 {
207 typeset props="$1"
208 typeset ds="$2"
209
210 for prop in ${commprops[*]}; do
211 ds=`$ZFS get -H -o name $prop`
212
213 [[ "$ds" != "$allds" ]] && \
214 log_fail "The result datasets are $ds, but all suitable" \
215 "datasets are $allds for the property $prop"
216 done
217 }
218
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"
223
224 do_particular_prop_test "$commprop" "$allds"
225 do_particular_prop_test "$usrprop" "$usrpropds"
226
227 log_pass "'zfs get all' works as expected."