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