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_001_neg
33#
34# DESCRIPTION:
35#	Try each 'zfs snapshot' with inapplicable scenarios to make sure
36#	it returns an error. include:
37#		* No arguments given.
38#		* The argument contains invalid characters for the ZFS namesapec
39#		* Leading slash in snapshot name
40#		* The argument contains an empty component.
41#		* Missing '@' delimiter.
42#		* Multiple '@' delimiters in snapshot name.
43#		* The snapshot already exist.
44#		* Create snapshot upon the pool.
45#			(Be removed since pool is treated as filesystem as well)
46#		* Create snapshot upon a non-existent filesystem.
47#		* Too many arguments.
48#
49# STRATEGY:
50#	1. Create an array of parameters
51#	2. For each parameter in the array, execute the sub-command
52#	3. Verify an error is returned.
53#
54# TESTABILITY: explicit
55#
56# TEST_AUTOMATION_LEVEL: automated
57#
58# CODING_STATUS: COMPLETED (2005-07-26)
59#
60# __stc_assertion_end
61#
62################################################################################
63
64verify_runnable "both"
65
66set -A args "" \
67	"$TESTPOOL/$TESTFS@blah*" "$TESTPOOL/$TESTFS@blah?" \
68	"$TESTPOOL/$TESTVOL@blah*" "$TESTPOOL/$TESTVOL@blah?" \
69	"/$TESTPOOL/$TESTFS@$TESTSNAP" "/$TESTPOOL/$TESTVOL@$TESTSNAP" \
70	"@$TESTSNAP" "$TESTPOOL/$TESTFS@" "$TESTPOOL/$TESTVOL@" \
71	"$TESTPOOL//$TESTFS@$TESTSNAP" "$TESTPOOL//$TESTVOL@$TESTSNAP" \
72	"$TESTPOOL/$TESTFS/$TESTSNAP" "$TESTPOOL/$TESTVOL/$TESTSNAP" \
73	"$TESTPOOL/$TESTFS@$TESTSNAP@$TESTSNAP1" \
74	"$TESTPOOL/$TESTVOL@$TESTSNAP@$TESTSNAP1" \
75	"$SNAPFS" "$SNAPFS1" \
76	"blah/blah@$TESTSNAP"
77
78function setup_all
79{
80	log_note "Create snapshots and mount them..."
81
82	for snap in $SNAPFS $SNAPFS1 ; do
83		if ! snapexists $snap ; then
84			log_must $ZFS snapshot $snap
85		fi
86	done
87
88	return 0
89}
90
91function cleanup_all
92{
93	typeset -i i=0
94
95	while (( i < ${#args[*]} )); do
96
97		for snap in ${args[i]}; do
98        		snapexists $snap && \
99				log_must $ZFS destroy -f $snap
100
101		done
102
103		(( i = i + 1 ))
104	done
105
106	for mtpt in $SNAPDIR $SNAPDIR1 ; do
107		[[ -d $mtpt ]] && \
108			log_must $RM -rf $mtpt
109	done
110
111	return 0
112}
113
114log_assert "Badly-formed 'zfs snapshot' with inapplicable scenarios " \
115	"should return an error."
116log_onexit cleanup_all
117
118setup_all
119
120typeset -i i=0
121while (( i < ${#args[*]} )); do
122	log_mustnot $ZFS snapshot ${args[i]}
123	((i = i + 1))
124done
125
126log_pass "Badly formed 'zfs snapshot' with inapplicable scenarios " \
127	"fail as expected."
128