]> git.proxmox.com Git - mirror_zfs.git/blob - tests/zfs-tests/tests/functional/cli_root/zfs_snapshot/zfs_snapshot_001_neg.ksh
Add the ZFS Test Suite
[mirror_zfs.git] / tests / zfs-tests / tests / functional / cli_root / zfs_snapshot / zfs_snapshot_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 2007 Sun Microsystems, Inc. All rights reserved.
25 # Use is subject to license terms.
26 #
27
28 #
29 # Copyright (c) 2012 by Delphix. All rights reserved.
30 #
31
32 . $STF_SUITE/include/libtest.shlib
33 . $STF_SUITE/tests/functional/cli_root/zfs_snapshot/zfs_snapshot.cfg
34
35 #
36 # DESCRIPTION:
37 # Try each 'zfs snapshot' with inapplicable scenarios to make sure
38 # it returns an error. include:
39 # * No arguments given.
40 # * The argument contains invalid characters for the ZFS namesapec
41 # * Leading slash in snapshot name
42 # * The argument contains an empty component.
43 # * Missing '@' delimiter.
44 # * Multiple '@' delimiters in snapshot name.
45 # * The snapshot already exist.
46 # * Create snapshot upon the pool.
47 # (Be removed since pool is treated as filesystem as well)
48 # * Create snapshot upon a non-existent filesystem.
49 # * Too many arguments.
50 #
51 # STRATEGY:
52 # 1. Create an array of parameters
53 # 2. For each parameter in the array, execute the sub-command
54 # 3. Verify an error is returned.
55 #
56
57 verify_runnable "both"
58
59 set -A args "" \
60 "$TESTPOOL/$TESTFS@blah*" "$TESTPOOL/$TESTFS@blah?" \
61 "$TESTPOOL/$TESTVOL@blah*" "$TESTPOOL/$TESTVOL@blah?" \
62 "/$TESTPOOL/$TESTFS@$TESTSNAP" "/$TESTPOOL/$TESTVOL@$TESTSNAP" \
63 "@$TESTSNAP" "$TESTPOOL/$TESTFS@" "$TESTPOOL/$TESTVOL@" \
64 "$TESTPOOL//$TESTFS@$TESTSNAP" "$TESTPOOL//$TESTVOL@$TESTSNAP" \
65 "$TESTPOOL/$TESTFS/$TESTSNAP" "$TESTPOOL/$TESTVOL/$TESTSNAP" \
66 "$TESTPOOL/$TESTFS@$TESTSNAP@$TESTSNAP1" \
67 "$TESTPOOL/$TESTVOL@$TESTSNAP@$TESTSNAP1" \
68 "$SNAPFS" "$SNAPFS1" \
69 "blah/blah@$TESTSNAP"
70
71
72
73 function setup_all
74 {
75 log_note "Create snapshots and mount them..."
76
77 for snap in $SNAPFS $SNAPFS1; do
78 if ! snapexists $snap; then
79 log_must $ZFS snapshot $snap
80 fi
81 done
82
83 return 0
84 }
85
86 function cleanup_all
87 {
88 typeset -i i=0
89
90 while (( i < ${#args[*]} )); do
91 for snap in ${args[i]}; do
92 snapexists $snap && log_must $ZFS destroy -f $snap
93 done
94 (( i = i + 1 ))
95 done
96
97 for mtpt in $SNAPDIR $SNAPDIR1; do
98 [[ -d $mtpt ]] && log_must $RM -rf $mtpt
99 done
100
101 return 0
102 }
103
104 log_assert "Badly-formed 'zfs snapshot' with inapplicable scenarios " \
105 "should return an error."
106 log_onexit cleanup_all
107
108 setup_all
109
110 typeset -i i=0
111 while (( i < ${#args[*]} )); do
112 log_mustnot $ZFS snapshot ${args[i]}
113 ((i = i + 1))
114 done
115
116 log_pass "Badly formed 'zfs snapshot' with inapplicable scenarios " \
117 "fail as expected."