PageRenderTime 68ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/tests/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_004_pos.ksh

http://github.com/zfsonlinux/zfs
Korn Shell | 227 lines | 139 code | 38 blank | 50 comment | 33 complexity | 57dca41c0d7102554998666fa6006fc1 MD5 | raw file
Possible License(s): Apache-2.0, MPL-2.0-no-copyleft-exception
  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. # Copyright 2007 Sun Microsystems, Inc. All rights reserved.
  24. # Use is subject to license terms.
  25. #
  26. #
  27. # Copyright (c) 2012, 2016 by Delphix. All rights reserved.
  28. #
  29. . $STF_SUITE/include/libtest.shlib
  30. #
  31. # DESCRIPTION:
  32. # Verify 'zfs get all' can get all properties for all datasets in the system
  33. #
  34. # STRATEGY:
  35. # 1. Create datasets for testing
  36. # 2. Issue 'zfs get all' command
  37. # 3. Verify the command gets all available properties of all datasets
  38. #
  39. verify_runnable "both"
  40. function cleanup
  41. {
  42. [[ -e $propfile ]] && rm -f $propfile
  43. datasetexists $clone && \
  44. log_must zfs destroy $clone
  45. for snap in $fssnap $volsnap ; do
  46. snapexists $snap && \
  47. log_must zfs destroy $snap
  48. done
  49. if [[ -n $globalzone ]] ; then
  50. for pool in $TESTPOOL1 $TESTPOOL2 $TESTPOOL3; do
  51. poolexists $pool && \
  52. log_must zpool destroy -f $pool
  53. done
  54. for file in `ls $TESTDIR1/poolfile*`; do
  55. rm -f $file
  56. done
  57. else
  58. for fs in $TESTPOOL/$TESTFS1 $TESTPOOL/$TESTFS2 $TESTPOOL/$TESTFS3; do
  59. datasetexists $fs && \
  60. log_must zfs destroy -rf $fs
  61. done
  62. fi
  63. }
  64. log_assert "Verify the functions of 'zfs get all' work."
  65. log_onexit cleanup
  66. typeset globalzone=""
  67. if is_global_zone ; then
  68. globalzone="true"
  69. fi
  70. set -A opts "" "-r" "-H" "-p" "-rHp" "-o name" \
  71. "-s local,default,temporary,inherited,none" \
  72. "-o name -s local,default,temporary,inherited,none" \
  73. "-rHp -o name -s local,default,temporary,inherited,none"
  74. set -A usrprops "a:b=c" "d_1:1_e=0f" "123:456=789"
  75. fs=$TESTPOOL/$TESTFS
  76. fssnap=$fs@$TESTSNAP
  77. clone=$TESTPOOL/$TESTCLONE
  78. volsnap=$TESTPOOL/$TESTVOL@$TESTSNAP
  79. #set user defined properties for $TESTPOOL
  80. for usrprop in ${usrprops[@]}; do
  81. log_must zfs set $usrprop $TESTPOOL
  82. done
  83. # create snapshot and clone in $TESTPOOL
  84. log_must zfs snapshot $fssnap
  85. log_must zfs clone $fssnap $clone
  86. log_must zfs snapshot $volsnap
  87. # collect datasets which can be set user defined properties
  88. usrpropds="$clone $fs"
  89. # collect all datasets which we are creating
  90. allds="$fs $clone $fssnap $volsnap"
  91. #create pool and datasets to guarantee testing under multiple pools and datasets.
  92. file=$TESTDIR1/poolfile
  93. typeset FILESIZE=$MINVDEVSIZE
  94. (( DFILESIZE = $FILESIZE * 2 ))
  95. typeset -i VOLSIZE=10485760
  96. availspace=$(get_prop available $TESTPOOL)
  97. typeset -i i=0
  98. # make sure 'availspace' is larger then twice of FILESIZE to create a new pool.
  99. # If any, we only totally create 3 pools for multiple datasets testing to limit
  100. # testing time
  101. while (( availspace > DFILESIZE )) && (( i < 3 )) ; do
  102. (( i += 1 ))
  103. if [[ -n $globalzone ]] ; then
  104. log_must mkfile $FILESIZE ${file}$i
  105. eval pool=\$TESTPOOL$i
  106. log_must zpool create $pool ${file}$i
  107. else
  108. eval pool=$TESTPOOL/\$TESTFS$i
  109. log_must zfs create $pool
  110. fi
  111. #set user defined properties for testing
  112. for usrprop in ${usrprops[@]}; do
  113. log_must zfs set $usrprop $pool
  114. done
  115. #create datasets in pool
  116. log_must zfs create $pool/$TESTFS
  117. log_must zfs snapshot $pool/$TESTFS@$TESTSNAP
  118. log_must zfs clone $pool/$TESTFS@$TESTSNAP $pool/$TESTCLONE
  119. if [[ -n $globalzone ]] ; then
  120. log_must zfs create -V $VOLSIZE $pool/$TESTVOL
  121. else
  122. log_must zfs create $pool/$TESTVOL
  123. fi
  124. ds=`zfs list -H -r -o name -t filesystem,volume $pool`
  125. usrpropds="$usrpropds $pool/$TESTFS $pool/$TESTCLONE $pool/$TESTVOL"
  126. allds="$allds $pool/$TESTFS $pool/$TESTCLONE $pool/$TESTVOL \
  127. $pool/$TESTFS@$TESTSNAP"
  128. availspace=$(get_prop available $TESTPOOL)
  129. done
  130. #the expected number of property for each type of dataset in this testing
  131. typeset -i fspropnum=27
  132. typeset -i snappropnum=8
  133. typeset -i volpropnum=15
  134. propfile=$TEST_BASE_DIR/allpropfile.$$
  135. typeset -i i=0
  136. typeset -i propnum=0
  137. typeset -i failflag=0
  138. while (( i < ${#opts[*]} )); do
  139. [[ -e $propfile ]] && rm -f $propfile
  140. log_must eval "zfs get ${opts[i]} all >$propfile"
  141. for ds in $allds; do
  142. grep $ds $propfile >/dev/null 2>&1
  143. (( $? != 0 )) && \
  144. log_fail "There is no property for" \
  145. "dataset $ds in 'get all' output."
  146. propnum=`cat $propfile | awk '{print $1}' | \
  147. grep "${ds}$" | wc -l`
  148. ds_type=`zfs get -H -o value type $ds`
  149. case $ds_type in
  150. filesystem )
  151. (( propnum < fspropnum )) && \
  152. (( failflag += 1 ))
  153. ;;
  154. snapshot )
  155. (( propnum < snappropnum )) && \
  156. (( failflag += 1 ))
  157. ;;
  158. volume )
  159. (( propnum < volpropnum )) && \
  160. (( failflag += 1 ))
  161. ;;
  162. esac
  163. (( failflag != 0 )) && \
  164. log_fail " 'zfs get all' fails to get out " \
  165. "all properties for dataset $ds."
  166. (( propnum = 0 ))
  167. (( failflag = 0 ))
  168. done
  169. (( i += 1 ))
  170. done
  171. log_note "'zfs get' can get particular property for all datasets with that property."
  172. function do_particular_prop_test #<property> <suitable datasets>
  173. {
  174. typeset props="$1"
  175. typeset ds="$2"
  176. for prop in ${commprops[*]}; do
  177. ds=`zfs get -H -o name $prop`
  178. [[ "$ds" != "$allds" ]] && \
  179. log_fail "The result datasets are $ds, but all suitable" \
  180. "datasets are $allds for the property $prop"
  181. done
  182. }
  183. # Here, we do a testing for user defined properties and the most common properties
  184. # for all datasets.
  185. commprop="type creation used referenced compressratio"
  186. usrprop="a:b d_1:1_e 123:456"
  187. do_particular_prop_test "$commprop" "$allds"
  188. do_particular_prop_test "$usrprop" "$usrpropds"
  189. log_pass "'zfs get all' works as expected."