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

/tests/zfs-tests/tests/functional/cli_root/zfs_clone/zfs_clone_001_neg.ksh

http://github.com/zfsonlinux/zfs
Korn Shell | 126 lines | 58 code | 19 blank | 49 comment | 8 complexity | ccf4afb1dee5a33d1bab423713b24609 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) 2012, 2016 by Delphix. All rights reserved.
  28. #
  29. . $STF_SUITE/include/libtest.shlib
  30. #
  31. # DESCRIPTION:
  32. # 'zfs clone' should fail with inapplicable scenarios, including:
  33. # * Null arguments
  34. # * non-existent snapshots.
  35. # * invalid characters in ZFS namesapec
  36. # * Leading slash in the target clone name
  37. # * The argument contains an empty component.
  38. # * The pool specified in the target doesn't exist.
  39. # * The parent dataset of the target doesn't exist.
  40. # * The argument refer to a pool, not dataset.
  41. # * The target clone already exists.
  42. # * Null target clone argument.
  43. # * Too many arguments.
  44. # * Invalid record sizes.
  45. #
  46. # STRATEGY:
  47. # 1. Create an array of parameters
  48. # 2. For each parameter in the array, execute the sub-command
  49. # 3. Verify an error is returned.
  50. #
  51. verify_runnable "both"
  52. typeset target1=$TESTPOOL/$TESTFS1
  53. typeset target2=$TESTPOOL/$TESTCTR1/$TESTFS1
  54. typeset targets="$target1 $target2 $NONEXISTPOOLNAME/$TESTFS"
  55. set -A args "" \
  56. "$TESTPOOL/$TESTFS@blah $target1" "$TESTPOOL/$TESTVOL@blah $target1" \
  57. "$TESTPOOL/$TESTFS@blah* $target1" "$TESTPOOL/$TESTVOL@blah* $target1" \
  58. "$SNAPFS $target1*" "$SNAPFS1 $target1*" \
  59. "$SNAPFS /$target1" "$SNAPFS1 /$target1" \
  60. "$SNAPFS $TESTPOOL//$TESTFS1" "$SNAPFS1 $TESTPOOL//$TESTFS1" \
  61. "$SNAPFS $NONEXISTPOOLNAME/$TESTFS" "$SNAPFS1 $NONEXISTPOOLNAME/$TESTFS" \
  62. "$SNAPFS" "$SNAPFS1" \
  63. "$SNAPFS $target1 $target2" "$SNAPFS1 $target1 $target2" \
  64. "-o recordsize=2M $SNAPFS1 $target1" \
  65. "-o recordsize=128B $SNAPFS1 $target1"
  66. typeset -i argsnum=${#args[*]}
  67. typeset -i j=0
  68. while (( j < argsnum )); do
  69. args[((argsnum+j))]="-p ${args[j]}"
  70. ((j = j + 1))
  71. done
  72. set -A moreargs "$SNAPFS $target2" "$SNAPFS1 $target2" \
  73. "$SNAPFS $TESTPOOL" "$SNAPFS1 $TESTPOOL" \
  74. "$SNAPFS $TESTPOOL/$TESTCTR" "$SNAPFS $TESTPOOL/$TESTFS" \
  75. "$SNAPFS1 $TESTPOOL/$TESTCTR" "$SNAPFS1 $TESTPOOL/$TESTFS"
  76. set -A args ${args[*]} ${moreargs[*]}
  77. function setup_all
  78. {
  79. log_note "Create snapshots and mount them..."
  80. for snap in $SNAPFS $SNAPFS1 ; do
  81. if ! snapexists $snap ; then
  82. log_must zfs snapshot $snap
  83. fi
  84. done
  85. return 0
  86. }
  87. function cleanup_all
  88. {
  89. for fs in $targets; do
  90. datasetexists $fs && log_must zfs destroy -f $fs
  91. done
  92. for snap in $SNAPFS $SNAPFS1 ; do
  93. snapexists $snap && log_must zfs destroy -Rf $snap
  94. done
  95. return 0
  96. }
  97. log_assert "Badly-formed 'zfs clone' with inapplicable scenarios" \
  98. "should return an error."
  99. log_onexit cleanup_all
  100. setup_all
  101. typeset -i i=0
  102. while (( i < ${#args[*]} )); do
  103. log_mustnot zfs clone ${args[i]}
  104. ((i = i + 1))
  105. done
  106. log_pass "Badly formed 'zfs clone' with inapplicable scenarios" \
  107. "fail as expected."