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