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 2007 Sun Microsystems, Inc. All rights reserved. 25# Use is subject to license terms. 26 27. $STF_SUITE/tests/cli_root/cli_common.kshlib 28 29################################################################################# 30# 31# __stc_assertion_start 32# 33# ID: zfs_receive_004_neg 34# 35# DESCRIPTION: 36# Verify 'zfs receive' fails with malformed parameters. 37# 38# STRATEGY: 39# 1. Denfine malformed parameters array 40# 2. Feed the malformed parameters to 'zfs receive' 41# 3. Verify the command should be failed 42# 43# TESTABILITY: explicit 44# 45# TEST_AUTOMATION_LEVEL: automated 46# 47# CODING_STATUS: COMPLETED (2005-09-06) 48# 49# __stc_assertion_end 50# 51################################################################################ 52 53verify_runnable "both" 54 55function cleanup 56{ 57 typeset snap 58 typeset bkup 59 60 for snap in $init_snap $inc_snap $init_topsnap $inc_topsnap ; do 61 snapexists $snap && \ 62 log_must $ZFS destroy -Rf $snap 63 done 64 65 for bkup in $full_bkup $inc_bkup $full_topbkup $inc_topbkup; do 66 [[ -e $bkup ]] && \ 67 log_must $RM -f $bkup 68 done 69} 70 71log_assert "Verify that invalid parameters to 'zfs receive' are caught." 72log_onexit cleanup 73 74init_snap=$TESTPOOL/$TESTFS@initsnap 75inc_snap=$TESTPOOL/$TESTFS@incsnap 76full_bkup=$TMPDIR/full_bkup.${TESTCASE_ID} 77inc_bkup=$TMPDIR/inc_bkup.${TESTCASE_ID} 78 79init_topsnap=$TESTPOOL@initsnap 80inc_topsnap=$TESTPOOL@incsnap 81full_topbkup=$TMPDIR/full_topbkup.${TESTCASE_ID} 82inc_topbkup=$TMPDIR/inc_topbkup.${TESTCASE_ID} 83 84log_must $ZFS snapshot $init_topsnap 85log_must eval "$ZFS send $init_topsnap > $full_topbkup" 86 87log_must $ZFS snapshot $inc_topsnap 88log_must eval "$ZFS send -i $init_topsnap $inc_topsnap > $inc_topbkup" 89 90log_must $ZFS snapshot $init_snap 91log_must eval "$ZFS send $init_snap > $full_bkup" 92 93log_must $ZFS snapshot $inc_snap 94log_must eval "$ZFS send -i $init_snap $inc_snap > $inc_bkup" 95 96set -A badargs \ 97 "" "nonexistent-snap" "blah@blah" "$snap1" "$snap1 $snap2" \ 98 "-d" "-d nonexistent-dataset" \ 99 "$TESTPOOL/fs@" "$TESTPOOL/fs@@mysnap" "$TESTPOOL/fs@@" \ 100 "$TESTPOOL/fs/@mysnap" "$TESTPOOL/fs@/mysnap" \ 101 "$TESTPOOL/nonexistent-fs/nonexistent-fs" \ 102 "-d $TESTPOOL/nonexistent-fs" "-d $TESTPOOL/$TESTFS/nonexistent-fs" 103 104typeset -i i=0 105while (( i < ${#badargs[*]} )) 106do 107 for bkup in $full_bkup $inc_bkup $full_topbkup $inc_topbkup ; do 108 log_mustnot eval "$ZFS receive ${badargs[i]} < $bkup" 109 done 110 111 (( i = i + 1 )) 112done 113 114log_pass "Invalid parameters to 'zfs receive' are caught as expected." 115