7290 ZFS test suite needs to control what utilities it can run
[unleashed.git] / usr / src / test / zfs-tests / tests / functional / cli_root / zfs_snapshot / zfs_snapshot_002_neg.ksh
blob2efcf1cceb7ebf7af733bcb77215e1d1d56c37b2
1 #!/bin/ksh -p
3 # CDDL HEADER START
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.
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.
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]
20 # CDDL HEADER END
24 # Copyright 2007 Sun Microsystems, Inc. All rights reserved.
25 # Use is subject to license terms.
29 # Copyright (c) 2016 by Delphix. All rights reserved.
32 . $STF_SUITE/include/libtest.shlib
35 # DESCRIPTION:
36 # "zfs snapshot -r" fails with invalid arguments or scenarios.
37 # The invalid scenarios may include:
38 # (1) The child filesystem already has snapshot with the same name
39 # (2) The child volume already has snapshot with the same name
41 # STRATEGY:
42 # 1. Create an array of invalid arguments
43 # 2. Execute 'zfs snapshot -r' with each argument in the array,
44 # 3. Verify an error is returned.
47 verify_runnable "both"
49 function cleanup
51 typeset snap
53 for snap in $TESTPOOL/$TESTCTR/$TESTFS1@$TESTSNAP \
54 $TESTPOOL/$TESTCTR/$TESTVOL@$TESTSNAP;
56 snapexists $snap && \
57 log_must zfs destroy $snap
58 done
60 datasetexists $TESTPOOL/$TESTCTR/$TESTVOL && \
61 log_must zfs destroy -rf $TESTPOOL/$TESTCTR/$TESTVOL
65 log_assert "'zfs snapshot -r' fails with invalid arguments or scenarios. "
66 log_onexit cleanup
68 set -A args "" \
69 "$TESTPOOL/$TESTCTR@$TESTSNAP" "$TESTPOOL/$TESTCTR@blah?" \
70 "$TESTPOOL/$TESTCTR@blah*" "@$TESTSNAP" "$TESTPOOL/$TESTCTR@" \
71 "$TESTPOOL/$TESTFS/$TESTSNAP" "blah/blah@$TESTSNAP" \
72 "$TESTPOOL/$TESTCTR@$TESTSNAP@$TESTSNAP"
74 # setup preparations
75 log_must zfs snapshot $TESTPOOL/$TESTCTR/$TESTFS1@$TESTSNAP
77 # testing
78 typeset -i i=0
79 while (( i < ${#args[*]} )); do
80 log_mustnot zfs snapshot -r ${args[i]}
82 ((i = i + 1))
83 done
85 # Testing the invalid senario: the child volume already has an
86 # identical name snapshot, zfs snapshot -r should fail when
87 # creating snapshot with -r for the parent
88 log_must zfs destroy $TESTPOOL/$TESTCTR/$TESTFS1@$TESTSNAP
89 if is_global_zone; then
90 log_must zfs create -V $VOLSIZE $TESTPOOL/$TESTCTR/$TESTVOL
91 else
92 log_must zfs create $TESTPOOL/$TESTCTR/$TESTVOL
94 log_must zfs snapshot $TESTPOOL/$TESTCTR/$TESTVOL@$TESTSNAP
96 log_mustnot zfs snapshot -r $TESTPOOL/$TESTCTR@$TESTSNAP
98 log_pass "'zfs snapshot -r' fails with invalid arguments or scenarios as expected."