PageRenderTime 44ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/zfs-tests/tests/functional/cli_root/zfs_snapshot/zfs_snapshot_001_neg.ksh

http://github.com/zfsonlinux/zfs
Korn Shell | 117 lines | 49 code | 19 blank | 49 comment | 8 complexity | 3c62d58a37ef03c810cdcf914d4e4935 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. . $STF_SUITE/tests/functional/cli_root/zfs_snapshot/zfs_snapshot.cfg
  31. #
  32. # DESCRIPTION:
  33. # Try each 'zfs snapshot' with inapplicable scenarios to make sure
  34. # it returns an error. include:
  35. # * No arguments given.
  36. # * The argument contains invalid characters for the ZFS namesapec
  37. # * Leading slash in snapshot name
  38. # * The argument contains an empty component.
  39. # * Missing '@' delimiter.
  40. # * Multiple '@' delimiters in snapshot name.
  41. # * The snapshot already exist.
  42. # * Create snapshot upon the pool.
  43. # (Be removed since pool is treated as filesystem as well)
  44. # * Create snapshot upon a non-existent filesystem.
  45. # * Too many arguments.
  46. #
  47. # STRATEGY:
  48. # 1. Create an array of parameters
  49. # 2. For each parameter in the array, execute the sub-command
  50. # 3. Verify an error is returned.
  51. #
  52. verify_runnable "both"
  53. set -A args "" \
  54. "$TESTPOOL/$TESTFS@blah*" "$TESTPOOL/$TESTFS@blah?" \
  55. "$TESTPOOL/$TESTVOL@blah*" "$TESTPOOL/$TESTVOL@blah?" \
  56. "/$TESTPOOL/$TESTFS@$TESTSNAP" "/$TESTPOOL/$TESTVOL@$TESTSNAP" \
  57. "@$TESTSNAP" "$TESTPOOL/$TESTFS@" "$TESTPOOL/$TESTVOL@" \
  58. "$TESTPOOL//$TESTFS@$TESTSNAP" "$TESTPOOL//$TESTVOL@$TESTSNAP" \
  59. "$TESTPOOL/$TESTFS/$TESTSNAP" "$TESTPOOL/$TESTVOL/$TESTSNAP" \
  60. "$TESTPOOL/$TESTFS@$TESTSNAP@$TESTSNAP1" \
  61. "$TESTPOOL/$TESTVOL@$TESTSNAP@$TESTSNAP1" \
  62. "$SNAPFS" "$SNAPFS1" \
  63. "blah/blah@$TESTSNAP"
  64. function setup_all
  65. {
  66. log_note "Create snapshots and mount them..."
  67. for snap in $SNAPFS $SNAPFS1; do
  68. if ! snapexists $snap; then
  69. log_must zfs snapshot $snap
  70. fi
  71. done
  72. return 0
  73. }
  74. function cleanup_all
  75. {
  76. typeset -i i=0
  77. while (( i < ${#args[*]} )); do
  78. for snap in ${args[i]}; do
  79. snapexists $snap && log_must zfs destroy -f $snap
  80. done
  81. (( i = i + 1 ))
  82. done
  83. for mtpt in $SNAPDIR $SNAPDIR1; do
  84. [[ -d $mtpt ]] && log_must rm -rf $mtpt
  85. done
  86. return 0
  87. }
  88. log_assert "Badly-formed 'zfs snapshot' with inapplicable scenarios " \
  89. "should return an error."
  90. log_onexit cleanup_all
  91. setup_all
  92. typeset -i i=0
  93. while (( i < ${#args[*]} )); do
  94. log_mustnot zfs snapshot ${args[i]}
  95. ((i = i + 1))
  96. done
  97. log_pass "Badly formed 'zfs snapshot' with inapplicable scenarios " \
  98. "fail as expected."