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