]> git.proxmox.com Git - mirror_zfs-debian.git/blob - tests/zfs-tests/tests/functional/cli_root/zfs_clone/zfs_clone_001_neg.ksh
New upstream version 0.7.2
[mirror_zfs-debian.git] / tests / zfs-tests / tests / functional / cli_root / zfs_clone / zfs_clone_001_neg.ksh
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 #
24 # Copyright 2009 Sun Microsystems, Inc. All rights reserved.
25 # Use is subject to license terms.
26 #
27
28 #
29 # Copyright (c) 2012, 2016 by Delphix. All rights reserved.
30 #
31
32 . $STF_SUITE/include/libtest.shlib
33
34 #
35 # DESCRIPTION:
36 # 'zfs clone' should fail with inapplicable scenarios, including:
37 # * Null arguments
38 # * non-existent snapshots.
39 # * invalid characters in ZFS namesapec
40 # * Leading slash in the target clone name
41 # * The argument contains an empty component.
42 # * The pool specified in the target doesn't exist.
43 # * The parent dataset of the target doesn't exist.
44 # * The argument refer to a pool, not dataset.
45 # * The target clone already exists.
46 # * Null target clone argument.
47 # * Too many arguments.
48 # * Invalid record sizes.
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
56 verify_runnable "both"
57
58 typeset target1=$TESTPOOL/$TESTFS1
59 typeset target2=$TESTPOOL/$TESTCTR1/$TESTFS1
60 typeset targets="$target1 $target2 $NONEXISTPOOLNAME/$TESTFS"
61
62 set -A args "" \
63 "$TESTPOOL/$TESTFS@blah $target1" "$TESTPOOL/$TESTVOL@blah $target1" \
64 "$TESTPOOL/$TESTFS@blah* $target1" "$TESTPOOL/$TESTVOL@blah* $target1" \
65 "$SNAPFS $target1*" "$SNAPFS1 $target1*" \
66 "$SNAPFS /$target1" "$SNAPFS1 /$target1" \
67 "$SNAPFS $TESTPOOL//$TESTFS1" "$SNAPFS1 $TESTPOOL//$TESTFS1" \
68 "$SNAPFS $NONEXISTPOOLNAME/$TESTFS" "$SNAPFS1 $NONEXISTPOOLNAME/$TESTFS" \
69 "$SNAPFS" "$SNAPFS1" \
70 "$SNAPFS $target1 $target2" "$SNAPFS1 $target1 $target2" \
71 "-o recordsize=2M $SNAPFS1 $target1" \
72 "-o recordsize=128B $SNAPFS1 $target1"
73 typeset -i argsnum=${#args[*]}
74 typeset -i j=0
75 while (( j < argsnum )); do
76 args[((argsnum+j))]="-p ${args[j]}"
77 ((j = j + 1))
78 done
79
80 set -A moreargs "$SNAPFS $target2" "$SNAPFS1 $target2" \
81 "$SNAPFS $TESTPOOL" "$SNAPFS1 $TESTPOOL" \
82 "$SNAPFS $TESTPOOL/$TESTCTR" "$SNAPFS $TESTPOOL/$TESTFS" \
83 "$SNAPFS1 $TESTPOOL/$TESTCTR" "$SNAPFS1 $TESTPOOL/$TESTFS"
84
85 set -A args ${args[*]} ${moreargs[*]}
86
87 function setup_all
88 {
89 log_note "Create snapshots and mount them..."
90
91 for snap in $SNAPFS $SNAPFS1 ; do
92 if ! snapexists $snap ; then
93 log_must zfs snapshot $snap
94 fi
95 done
96
97 return 0
98 }
99
100 function cleanup_all
101 {
102 for fs in $targets; do
103 datasetexists $fs && log_must zfs destroy -f $fs
104 done
105
106 for snap in $SNAPFS $SNAPFS1 ; do
107 snapexists $snap && log_must zfs destroy -Rf $snap
108 done
109
110 return 0
111 }
112
113 log_assert "Badly-formed 'zfs clone' with inapplicable scenarios" \
114 "should return an error."
115 log_onexit cleanup_all
116
117 setup_all
118
119 typeset -i i=0
120 while (( i < ${#args[*]} )); do
121 log_mustnot zfs clone ${args[i]}
122 ((i = i + 1))
123 done
124
125 log_pass "Badly formed 'zfs clone' with inapplicable scenarios" \
126 "fail as expected."