xref: /illumos-gate/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_snapshot/zfs_snapshot_002_neg.ksh (revision b6805bf78d2bbbeeaea8909a05623587b42d58b3)
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. $STF_SUITE/include/libtest.shlib
28
29#
30# DESCRIPTION:
31#	"zfs snapshot -r" fails with invalid arguments or scenarios.
32#	The invalid scenarios may include:
33#	(1) The child filesystem already has snapshot with the same name
34#	(2) The child volume already has snapshot with the same name
35#
36# STRATEGY:
37#	1. Create an array of invalid arguments
38#	2. Execute 'zfs snapshot -r' with each argument in the array,
39#	3. Verify an error is returned.
40#
41
42verify_runnable "both"
43
44function cleanup
45{
46	typeset snap
47
48	for snap in $TESTPOOL/$TESTCTR/$TESTFS1@$TESTSNAP \
49		$TESTPOOL/$TESTCTR/$TESTVOL@$TESTSNAP;
50	do
51		snapexists $snap && \
52			log_must $ZFS destroy $snap
53	done
54
55	datasetexists $TESTPOOL/$TESTCTR/$TESTVOL && \
56		log_must $ZFS destroy -rf $TESTPOOL/$TESTCTR/$TESTVOL
57
58}
59
60log_assert "'zfs snapshot -r' fails with invalid arguments or scenarios. "
61log_onexit cleanup
62
63set -A args "" \
64    "$TESTPOOL/$TESTCTR@$TESTSNAP" "$TESTPOOL/$TESTCTR@blah?" \
65    "$TESTPOOL/$TESTCTR@blah*" "@$TESTSNAP" "$TESTPOOL/$TESTCTR@" \
66    "$TESTPOOL/$TESTFS/$TESTSNAP" "blah/blah@$TESTSNAP" \
67    "$TESTPOOL/$TESTCTR@$TESTSNAP@$TESTSNAP"
68
69# setup preparations
70log_must $ZFS snapshot $TESTPOOL/$TESTCTR/$TESTFS1@$TESTSNAP
71
72# testing
73typeset -i i=0
74while (( i < ${#args[*]} )); do
75	log_mustnot $ZFS snapshot -r ${args[i]}
76
77	((i = i + 1))
78done
79
80# Testing the invalid senario: the child volume already has an
81# identical name snapshot, zfs snapshot -r should fail when
82# creating snapshot with -r for the parent
83log_must $ZFS destroy $TESTPOOL/$TESTCTR/$TESTFS1@$TESTSNAP
84if is_global_zone; then
85	log_must $ZFS create -V $VOLSIZE $TESTPOOL/$TESTCTR/$TESTVOL
86else
87	log_must $ZFS create $TESTPOOL/$TESTCTR/$TESTVOL
88fi
89log_must $ZFS snapshot $TESTPOOL/$TESTCTR/$TESTVOL@$TESTSNAP
90
91log_mustnot $ZFS snapshot -r $TESTPOOL/$TESTCTR@$TESTSNAP
92
93log_pass "'zfs snapshot -r' fails with invalid arguments or scenarios as expected."
94