PageRenderTime 46ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/sys/cddl/zfs/tests/cli_root/zfs_clone/zfs_clone_001_neg.ksh

https://github.com/freebsd/freebsd
Korn Shell | 143 lines | 60 code | 21 blank | 62 comment | 8 complexity | 60c13ec24b4f7a29b5817ea4bfd07989 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_clone_001_neg.ksh 1.4 09/01/13 SMI"
  28. #
  29. . $STF_SUITE/include/libtest.kshlib
  30. ################################################################################
  31. #
  32. # __stc_assertion_start
  33. #
  34. # ID: zfs_clone_001_neg
  35. #
  36. # DESCRIPTION:
  37. # 'zfs clone' should fail with inapplicable scenarios, including:
  38. # * Null arguments
  39. # * non-existant snapshots.
  40. # * invalid characters in ZFS namesapec
  41. # * Leading slash in the target clone name
  42. # * The argument contains an empty component.
  43. # * The pool specified in the target doesn't exist.
  44. # * The parent dataset of the target doesn't exist.
  45. # * The argument refer to a pool, not dataset.
  46. # * The target clone already exists.
  47. # * Null target clone argument.
  48. # * Too many arguments.
  49. #
  50. # STRATEGY:
  51. # 1. Create an array of parameters
  52. # 2. For each parameter in the array, execute the sub-command
  53. # 3. Verify an error is returned.
  54. #
  55. # TESTABILITY: explicit
  56. #
  57. # TEST_AUTOMATION_LEVEL: automated
  58. #
  59. # CODING_STATUS: COMPLETED (2005-07-25)
  60. #
  61. # __stc_assertion_end
  62. #
  63. ################################################################################
  64. verify_runnable "both"
  65. typeset target1=$TESTPOOL/$TESTFS1
  66. typeset target2=$TESTPOOL/$TESTCTR1/$TESTFS1
  67. typeset targets="$target1 $target2 $NONEXISTPOOLNAME/$TESTFS"
  68. set -A args "" \
  69. "$TESTPOOL/$TESTFS@blah $target1" "$TESTPOOL/$TESTVOL@blah $target1" \
  70. "$TESTPOOL/$TESTFS@blah* $target1" "$TESTPOOL/$TESTVOL@blah* $target1" \
  71. "$SNAPFS $target1*" "$SNAPFS1 $target1*" \
  72. "$SNAPFS /$target1" "$SNAPFS1 /$target1" \
  73. "$SNAPFS $TESTPOOL//$TESTFS1" "$SNAPFS1 $TESTPOOL//$TESTFS1" \
  74. "$SNAPFS $NONEXISTPOOLNAME/$TESTFS" "$SNAPFS1 $NONEXISTPOOLNAME/$TESTFS" \
  75. "$SNAPFS" "$SNAPFS1" \
  76. "$SNAPFS $target1 $target2" "$SNAPFS1 $target1 $target2"
  77. typeset -i argsnum=${#args[*]}
  78. typeset -i j=0
  79. while (( j < argsnum )); do
  80. args[((argsnum+j))]="-p ${args[j]}"
  81. ((j = j + 1))
  82. done
  83. set -A moreargs "$SNAPFS $target2" "$SNAPFS1 $target2" \
  84. "$SNAPFS $TESTPOOL" "$SNAPFS1 $TESTPOOL" \
  85. "$SNAPFS $TESTPOOL/$TESTCTR" "$SNAPFS $TESTPOOL/$TESTFS" \
  86. "$SNAPFS1 $TESTPOOL/$TESTCTR" "$SNAPFS1 $TESTPOOL/$TESTFS"
  87. set -A args ${args[*]} ${moreargs[*]}
  88. function setup_all
  89. {
  90. log_note "Create snapshots and mount them..."
  91. for snap in $SNAPFS $SNAPFS1 ; do
  92. if ! snapexists $snap ; then
  93. log_must $ZFS snapshot $snap
  94. fi
  95. done
  96. return 0
  97. }
  98. function cleanup_all
  99. {
  100. typeset -i i=0
  101. for fs in $targets; do
  102. datasetexists $fs && \
  103. log_must $ZFS destroy -f $fs
  104. (( i = i + 1 ))
  105. done
  106. for snap in $SNAPFS $SNAPFS1 ; do
  107. snapexists $snap && \
  108. log_must $ZFS destroy -Rf $snap
  109. done
  110. return 0
  111. }
  112. log_assert "Badly-formed 'zfs clone' with inapplicable scenarios" \
  113. "should return an error."
  114. log_onexit cleanup_all
  115. setup_all
  116. typeset -i i=0
  117. while (( i < ${#args[*]} )); do
  118. log_mustnot $ZFS clone ${args[i]}
  119. ((i = i + 1))
  120. done
  121. log_pass "Badly formed 'zfs clone' with inapplicable scenarios" \
  122. "fail as expected."