PageRenderTime 26ms CodeModel.GetById 2ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/sys/cddl/zfs/tests/cli_root/zfs_destroy/zfs_destroy_005_neg.ksh

https://bitbucket.org/freebsd/freebsd-base
Korn Shell | 227 lines | 87 code | 26 blank | 114 comment | 20 complexity | d570771f8807a177126b47dd2e687af0 MD5 | raw file
  1. #!/usr/local/bin/ksh93 -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. # $FreeBSD$
  23. #
  24. # Copyright 2009 Sun Microsystems, Inc. All rights reserved.
  25. # Use is subject to license terms.
  26. #
  27. # ident "@(#)zfs_destroy_005_neg.ksh 1.3 09/08/06 SMI"
  28. #
  29. . $STF_SUITE/include/libtest.kshlib
  30. . $STF_SUITE/tests/cli_root/zfs_destroy/zfs_destroy_common.kshlib
  31. #################################################################################
  32. #
  33. # __stc_assertion_start
  34. #
  35. # ID: zfs_destroy_005_neg
  36. #
  37. # DESCRIPTION:
  38. # Separately verify 'zfs destroy -f|-r|-rf|-R|-rR <dataset>' will fail in
  39. # different conditions.
  40. #
  41. # STRATEGY:
  42. # 1. Create pool, fs & vol.
  43. # 2. Create snapshot for fs & vol.
  44. # 3. Invoke 'zfs destroy ''|-f <dataset>', it should fail.
  45. # 4. Create clone for fs & vol.
  46. # 5. Invoke 'zfs destroy -r|-rf <dataset>', it should fail.
  47. # 6. Write file to filesystem or enter snapshot mountpoint.
  48. # 7. Invoke 'zfs destroy -R|-rR <dataset>', it should fail.
  49. #
  50. # TESTABILITY: explicit
  51. #
  52. # TEST_AUTOMATION_LEVEL: automated
  53. #
  54. # CODING_STATUS: COMPLETED (2005-08-03)
  55. #
  56. # __stc_assertion_end
  57. #
  58. ################################################################################
  59. verify_runnable "both"
  60. log_assert "Separately verify 'zfs destroy -f|-r|-rf|-R|-rR <dataset>' will " \
  61. "fail in different conditions."
  62. log_onexit cleanup_testenv
  63. #
  64. # Run 'zfs destroy [-rRf] <dataset>', make sure it fail.
  65. #
  66. # $1 the collection of options
  67. # $2 the collection of datasets
  68. #
  69. function negative_test
  70. {
  71. typeset options=$1
  72. typeset datasets=$2
  73. for dtst in $datasets; do
  74. if ! is_global_zone; then
  75. if [[ $dtst == $VOL || $dtst == $VOLSNAP || \
  76. $dtst == $VOLCLONE ]]
  77. then
  78. log_note "UNSUPPORTED: " \
  79. "Volume is unavailable in LZ."
  80. continue
  81. fi
  82. fi
  83. for opt in $options; do
  84. log_mustnot $ZFS destroy $opt $dtst
  85. done
  86. done
  87. }
  88. # This filesystem is created by setup.ksh, and conflicts with the filesystems
  89. # created from within this file
  90. $ZFS destroy -f $TESTPOOL/$TESTFS
  91. #
  92. # Create snapshots for filesystem and volume,
  93. # and verify 'zfs destroy' failed without '-r' or '-R'.
  94. #
  95. setup_testenv snap
  96. negative_test "-f" "$CTR $FS $VOL"
  97. #
  98. # Create clones for filesystem and volume,
  99. # and verify 'zfs destroy' failed without '-R'.
  100. #
  101. setup_testenv clone
  102. negative_test "-r -rf" "$CTR $FS $VOL"
  103. #
  104. # Get $FS mountpoint and make it busy, then verify 'zfs destroy $CTR'
  105. # failed without '-f'.
  106. #
  107. # Then verify the datasets are expected existed or non-existed.
  108. #
  109. typeset mtpt_dir=$(get_prop mountpoint $FS)
  110. make_dir_busy $mtpt_dir
  111. negative_test "-R -rR" $CTR
  112. #
  113. # Checking the outcome of the test above is tricky, because the order in
  114. # which datasets are destroyed is not deterministic. Both $FS and $VOL are
  115. # busy, and the remaining datasets will be different depending on whether we
  116. # tried (and failed) to delete $FS or $VOL first.
  117. # The following datasets will exist independent of the order
  118. check_dataset datasetexists $CTR $FS $VOL
  119. if datasetexists $VOLSNAP && datasetnonexists $FSSNAP; then
  120. # The recursive destroy failed on $FS
  121. check_dataset datasetnonexists $FSSNAP $FSCLONE
  122. check_dataset datasetexists $VOLSNAP $VOLCLONE
  123. elif datasetexists $FSSNAP && datasetnonexists $VOLSNAP; then
  124. # The recursive destroy failed on $VOL
  125. check_dataset datasetnonexists $VOLSNAP $VOLCLONE
  126. check_dataset datasetexists $FSSNAP $FSCLONE
  127. else
  128. log_must zfs list -rtall
  129. log_fail "Unexpected datasets remaining"
  130. fi
  131. #
  132. # Create the clones for test environment, then verify 'zfs destroy $FS'
  133. # failed without '-f'.
  134. #
  135. # Then verify the datasets are expected existed or non-existed.
  136. #
  137. setup_testenv clone
  138. negative_test "-R -rR" $FS
  139. check_dataset datasetexists $CTR $FS $VOL $VOLSNAP $VOLCLONE
  140. log_must datasetnonexists $FSSNAP $FSCLONE
  141. make_dir_unbusy $mtpt_dir
  142. if is_global_zone; then
  143. #
  144. # Create the clones for test environment and make the volume busy.
  145. # Then verify 'zfs destroy $CTR' failed without '-f'.
  146. #
  147. # Then verify the datasets are expected existed or non-existed.
  148. #
  149. setup_testenv clone
  150. make_dir_busy $TESTDIR1
  151. negative_test "-R -rR" $CTR
  152. log_must datasetexists $CTR $VOL
  153. log_must datasetnonexists $VOLSNAP $VOLCLONE
  154. # Here again, the non-determinism of destroy order is a factor. $FS,
  155. # $FSSNAP and $FSCLONE will still exist here iff we attempted to destroy
  156. # $VOL (and failed) first. So check that either all of the datasets are
  157. # present, or they're all gone.
  158. if datasetexists $FS; then
  159. check_dataset datasetexists $FS $FSSNAP $FSCLONE
  160. else
  161. check_dataset datasetnonexists $FS $FSSNAP $FSCLONE
  162. fi
  163. #
  164. # Create the clones for test environment and make the volume busy.
  165. # Then verify 'zfs destroy $VOL' failed without '-f'.
  166. #
  167. # Then verify the datasets are expected existed or non-existed.
  168. #
  169. setup_testenv clone
  170. negative_test "-R -rR" $VOL
  171. log_must datasetexists $CTR $VOL $FS $FSSNAP $FSCLONE
  172. log_must datasetnonexists $VOLSNAP $VOLCLONE
  173. make_dir_unbusy $TESTDIR1
  174. fi
  175. #
  176. # Create the clones for test environment and make the snapshot busy.
  177. # Then verify 'zfs destroy $snap' failed without '-f'.
  178. #
  179. # Then verify the datasets are expected existed or non-existed.
  180. #
  181. snaplist="$FSSNAP"
  182. setup_testenv clone
  183. for snap in $snaplist; do
  184. for option in -R -rR ; do
  185. mtpt_dir=$(snapshot_mountpoint $snap)
  186. (( $? != 0 )) && \
  187. log_fail "get mountpoint $snap failed."
  188. init_dir=$PWD
  189. log_must cd $mtpt_dir
  190. log_must $ZFS destroy $option $snap
  191. check_dataset datasetexists $CTR $FS $VOL
  192. if [[ $snap == $FSSNAP ]]; then
  193. log_must datasetnonexists $snap $FSCLONE
  194. else
  195. log_must datasetnonexists $snap $VOLCLONE
  196. fi
  197. setup_testenv clone
  198. done
  199. done
  200. cmds="zfs destroy -f|-r|-rf|-R|-rR <dataset>"
  201. log_pass "'$cmds' must fail in certain conditions."