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