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 2009 Sun Microsystems, Inc.  All rights reserved.
27# Use is subject to license terms.
28#
29# ident	"@(#)zfs_clone_001_neg.ksh	1.4	09/01/13 SMI"
30#
31. $STF_SUITE/include/libtest.kshlib
32
33################################################################################
34#
35# __stc_assertion_start
36#
37# ID: zfs_clone_001_neg
38#
39# DESCRIPTION:
40#	'zfs clone' should fail with inapplicable scenarios, including:
41#		* Null arguments
42#		* non-existant snapshots.
43#		* invalid characters in ZFS namesapec
44#		* Leading slash in the target clone name
45#		* The argument contains an empty component.
46#		* The pool specified in the target doesn't exist.
47#		* The parent dataset of the target doesn't exist.
48#		* The argument refer to a pool, not dataset.
49#		* The target clone already exists.
50#		* Null target clone argument.
51#		* Too many arguments.
52#
53# STRATEGY:
54#	1. Create an array of parameters
55#	2. For each parameter in the array, execute the sub-command
56#	3. Verify an error is returned.
57#
58# TESTABILITY: explicit
59#
60# TEST_AUTOMATION_LEVEL: automated
61#
62# CODING_STATUS: COMPLETED (2005-07-25)
63#
64# __stc_assertion_end
65#
66################################################################################
67
68verify_runnable "both"
69
70typeset target1=$TESTPOOL/$TESTFS1
71typeset target2=$TESTPOOL/$TESTCTR1/$TESTFS1
72typeset targets="$target1 $target2 $NONEXISTPOOLNAME/$TESTFS"
73
74set -A args "" \
75	"$TESTPOOL/$TESTFS@blah $target1" "$TESTPOOL/$TESTVOL@blah $target1" \
76	"$TESTPOOL/$TESTFS@blah* $target1" "$TESTPOOL/$TESTVOL@blah* $target1" \
77	"$SNAPFS $target1*" "$SNAPFS1 $target1*" \
78	"$SNAPFS /$target1" "$SNAPFS1 /$target1" \
79	"$SNAPFS $TESTPOOL//$TESTFS1" "$SNAPFS1 $TESTPOOL//$TESTFS1" \
80	"$SNAPFS $NONEXISTPOOLNAME/$TESTFS" "$SNAPFS1 $NONEXISTPOOLNAME/$TESTFS" \
81	"$SNAPFS" "$SNAPFS1" \
82	"$SNAPFS $target1 $target2" "$SNAPFS1 $target1 $target2"
83typeset -i argsnum=${#args[*]}
84typeset -i j=0
85while (( j < argsnum )); do
86	args[((argsnum+j))]="-p ${args[j]}"
87	((j = j + 1))
88done
89
90set -A moreargs "$SNAPFS $target2" "$SNAPFS1 $target2" \
91	"$SNAPFS $TESTPOOL" "$SNAPFS1 $TESTPOOL" \
92	"$SNAPFS $TESTPOOL/$TESTCTR" "$SNAPFS $TESTPOOL/$TESTFS" \
93	"$SNAPFS1 $TESTPOOL/$TESTCTR" "$SNAPFS1 $TESTPOOL/$TESTFS"
94
95set -A args ${args[*]} ${moreargs[*]}
96
97function setup_all
98{
99	log_note "Create snapshots and mount them..."
100
101	for snap in $SNAPFS $SNAPFS1 ; do
102		if ! snapexists $snap ; then
103			log_must $ZFS snapshot $snap
104		fi
105	done
106
107	return 0
108}
109
110function cleanup_all
111{
112	typeset -i i=0
113
114	for fs in $targets; do
115
116        	datasetexists $fs && \
117			log_must $ZFS destroy -f $fs
118
119		(( i = i + 1 ))
120	done
121
122	for snap in $SNAPFS $SNAPFS1 ; do
123		snapexists $snap && \
124			log_must $ZFS destroy -Rf $snap
125	done
126
127	return 0
128}
129
130log_assert "Badly-formed 'zfs clone' with inapplicable scenarios" \
131	"should return an error."
132log_onexit cleanup_all
133
134setup_all
135
136typeset -i i=0
137while (( i < ${#args[*]} )); do
138	log_mustnot $ZFS clone ${args[i]}
139	((i = i + 1))
140done
141
142log_pass "Badly formed 'zfs clone' with inapplicable scenarios" \
143	"fail as expected."
144