PageRenderTime 35ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://github.com/zfsonlinux/zfs
Korn Shell | 163 lines | 98 code | 18 blank | 47 comment | 18 complexity | bde10a2cb7d403770e3dfa9a578ebbed 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 2009 Sun Microsystems, Inc. All rights reserved.
  24. # Use is subject to license terms.
  25. #
  26. #
  27. # Copyright (c) 2016 by Delphix. All rights reserved.
  28. #
  29. . $STF_SUITE/tests/functional/cli_root/zfs_get/zfs_get_common.kshlib
  30. . $STF_SUITE/tests/functional/cli_root/zfs_get/zfs_get_list_d.kshlib
  31. #
  32. # DESCRIPTION:
  33. # Setting the valid option and properties, 'zfs get' should return the
  34. # correct property value.
  35. #
  36. # STRATEGY:
  37. # 1. Create pool, filesystem, volume, snapshot, and bookmark.
  38. # 2. Setting valid parameter, 'zfs get' should succeed.
  39. # 3. Compare the output property name with the original input property.
  40. #
  41. verify_runnable "both"
  42. typeset options=("" "-p" "-r" "-H")
  43. typeset -i i=${#options[*]}
  44. typeset -i j=0
  45. while ((j<${#depth_options[*]}));
  46. do
  47. options[$i]=-"${depth_options[$j]}"
  48. ((j+=1))
  49. ((i+=1))
  50. done
  51. typeset zfs_props=("type" used available creation volsize referenced \
  52. compressratio mounted origin recordsize quota reservation mountpoint \
  53. sharenfs checksum compression atime devices exec readonly setuid \
  54. snapdir aclinherit canmount primarycache secondarycache version \
  55. usedbychildren usedbydataset usedbyrefreservation usedbysnapshots)
  56. if is_freebsd; then
  57. typeset zfs_props_os=(jailed aclmode)
  58. else
  59. typeset zfs_props_os=(zoned acltype)
  60. fi
  61. typeset userquota_props=(userquota@root groupquota@root userused@root \
  62. groupused@root)
  63. typeset all_props=("${zfs_props[@]}" \
  64. "${zfs_props_os[@]}" \
  65. "${userquota_props[@]}")
  66. typeset dataset=($TESTPOOL/$TESTCTR $TESTPOOL/$TESTFS $TESTPOOL/$TESTVOL \
  67. $TESTPOOL/$TESTFS@$TESTSNAP $TESTPOOL/$TESTVOL@$TESTSNAP)
  68. typeset bookmark_props=(creation)
  69. typeset bookmark=($TESTPOOL/$TESTFS#$TESTBKMARK $TESTPOOL/$TESTVOL#$TESTBKMARK)
  70. #
  71. # According to dataset and option, checking if 'zfs get' return correct
  72. # property information.
  73. #
  74. # $1 dataset
  75. # $2 properties which are expected to output into $TESTDIR/$TESTFILE0
  76. # $3 option
  77. #
  78. function check_return_value
  79. {
  80. typeset dst=$1
  81. typeset props=$2
  82. typeset opt=$3
  83. typeset -i found=0
  84. typeset p
  85. for p in $props; do
  86. found=0
  87. while read line; do
  88. typeset item
  89. item=$(echo $line | awk '{print $2}' 2>&1)
  90. if [[ $item == $p ]]; then
  91. ((found += 1))
  92. break
  93. fi
  94. done < $TESTDIR/$TESTFILE0
  95. if ((found == 0)); then
  96. log_fail "'zfs get $opt $props $dst' return " \
  97. "error message.'$p' haven't been found."
  98. fi
  99. done
  100. log_note "SUCCESS: 'zfs get $opt $prop $dst'."
  101. }
  102. log_assert "Setting the valid options and properties 'zfs get' should return " \
  103. "the correct property value."
  104. log_onexit cleanup
  105. # Create filesystem and volume's snapshot
  106. create_snapshot $TESTPOOL/$TESTFS $TESTSNAP
  107. create_snapshot $TESTPOOL/$TESTVOL $TESTSNAP
  108. # Create filesystem and volume's bookmark
  109. create_bookmark $TESTPOOL/$TESTFS $TESTSNAP $TESTBKMARK
  110. create_bookmark $TESTPOOL/$TESTVOL $TESTSNAP $TESTBKMARK
  111. typeset -i i=0
  112. while ((i < ${#dataset[@]})); do
  113. for opt in "${options[@]}"; do
  114. for prop in ${all_props[@]}; do
  115. eval "zfs get $opt $prop ${dataset[i]} > \
  116. $TESTDIR/$TESTFILE0"
  117. ret=$?
  118. if [[ $ret != 0 ]]; then
  119. log_fail "zfs get returned: $ret"
  120. fi
  121. check_return_value ${dataset[i]} "$prop" "$opt"
  122. done
  123. done
  124. ((i += 1))
  125. done
  126. i=0
  127. while ((i < ${#bookmark[@]})); do
  128. for opt in "${options[@]}"; do
  129. for prop in ${bookmark_props[@]}; do
  130. eval "zfs get $opt $prop ${bookmark[i]} > \
  131. $TESTDIR/$TESTFILE0"
  132. ret=$?
  133. if [[ $ret != 0 ]]; then
  134. log_fail "zfs get returned: $ret"
  135. fi
  136. check_return_value ${bookmark[i]} "$prop" "$opt"
  137. done
  138. done
  139. ((i += 1))
  140. done
  141. log_pass "Setting the valid options to dataset, it should succeed and return " \
  142. "valid value. 'zfs get' pass."