1#!/bin/ksh -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 28# 29# Copyright (c) 2012 by Delphix. All rights reserved. 30# 31 32. $STF_SUITE/include/libtest.shlib 33 34# 35# DESCRIPTION: 36# 'zfs clone' should fail with inapplicable scenarios, including: 37# * Null arguments 38# * non-existant snapshots. 39# * invalid characters in ZFS namesapec 40# * Leading slash in the target clone name 41# * The argument contains an empty component. 42# * The pool specified in the target doesn't exist. 43# * The parent dataset of the target doesn't exist. 44# * The argument refer to a pool, not dataset. 45# * The target clone already exists. 46# * Null target clone argument. 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 55verify_runnable "both" 56 57typeset target1=$TESTPOOL/$TESTFS1 58typeset target2=$TESTPOOL/$TESTCTR1/$TESTFS1 59typeset targets="$target1 $target2 $NONEXISTPOOLNAME/$TESTFS" 60 61set -A args "" \ 62 "$TESTPOOL/$TESTFS@blah $target1" "$TESTPOOL/$TESTVOL@blah $target1" \ 63 "$TESTPOOL/$TESTFS@blah* $target1" "$TESTPOOL/$TESTVOL@blah* $target1" \ 64 "$SNAPFS $target1*" "$SNAPFS1 $target1*" \ 65 "$SNAPFS /$target1" "$SNAPFS1 /$target1" \ 66 "$SNAPFS $TESTPOOL//$TESTFS1" "$SNAPFS1 $TESTPOOL//$TESTFS1" \ 67 "$SNAPFS $NONEXISTPOOLNAME/$TESTFS" "$SNAPFS1 $NONEXISTPOOLNAME/$TESTFS" \ 68 "$SNAPFS" "$SNAPFS1" \ 69 "$SNAPFS $target1 $target2" "$SNAPFS1 $target1 $target2" 70typeset -i argsnum=${#args[*]} 71typeset -i j=0 72while (( j < argsnum )); do 73 args[((argsnum+j))]="-p ${args[j]}" 74 ((j = j + 1)) 75done 76 77set -A moreargs "$SNAPFS $target2" "$SNAPFS1 $target2" \ 78 "$SNAPFS $TESTPOOL" "$SNAPFS1 $TESTPOOL" \ 79 "$SNAPFS $TESTPOOL/$TESTCTR" "$SNAPFS $TESTPOOL/$TESTFS" \ 80 "$SNAPFS1 $TESTPOOL/$TESTCTR" "$SNAPFS1 $TESTPOOL/$TESTFS" 81 82set -A args ${args[*]} ${moreargs[*]} 83 84function setup_all 85{ 86 log_note "Create snapshots and mount them..." 87 88 for snap in $SNAPFS $SNAPFS1 ; do 89 if ! snapexists $snap ; then 90 log_must $ZFS snapshot $snap 91 fi 92 done 93 94 return 0 95} 96 97function cleanup_all 98{ 99 for fs in $targets; do 100 datasetexists $fs && log_must $ZFS destroy -f $fs 101 done 102 103 for snap in $SNAPFS $SNAPFS1 ; do 104 snapexists $snap && log_must $ZFS destroy -Rf $snap 105 done 106 107 return 0 108} 109 110log_assert "Badly-formed 'zfs clone' with inapplicable scenarios" \ 111 "should return an error." 112log_onexit cleanup_all 113 114setup_all 115 116typeset -i i=0 117while (( i < ${#args[*]} )); do 118 log_mustnot $ZFS clone ${args[i]} 119 ((i = i + 1)) 120done 121 122log_pass "Badly formed 'zfs clone' with inapplicable scenarios" \ 123 "fail as expected." 124