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 2008 Sun Microsystems, Inc. All rights reserved. 27# Use is subject to license terms. 28# 29# ident "@(#)zfs_receive_008_pos.ksh 1.3 08/02/27 SMI" 30# 31 32. $STF_SUITE/tests/cli_root/cli_common.kshlib 33 34################################################################################# 35# 36# __stc_assertion_start 37# 38# ID: zfs_receive_008_pos 39# 40# DESCRIPTION: 41# Verifying 'zfs receive -vn [<filesystem|snapshot>] 42# and zfs receive -vn -d <filesystem>' 43# 44# STRATEGY: 45# 1. Fill in fs with some data 46# 2. Create full and incremental send stream 47# 3. run zfs receive with -v option 48# 3. Dryrun zfs receive with -vn option 49# 3. Dryrun zfs receive with -vn -d option 50# 4. Verify receive output and result 51# 52# TESTABILITY: explicit 53# 54# TEST_AUTOMATION_LEVEL: automated 55# 56# CODING_STATUS: COMPLETED (2007-06-14) 57# 58# __stc_assertion_end 59# 60################################################################################ 61function cleanup 62{ 63 for dset in $rst_snap $rst_fs $orig_snap; do 64 if datasetexists $dset; then 65 log_must $ZFS destroy -fr $dset 66 fi 67 done 68 69 for file in $fbackup $mnt_file $tmp_out; do 70 if [[ -f $file ]]; then 71 log_must $RM -f $file 72 fi 73 done 74 75 if datasetexists $TESTPOOL/$TESTFS; then 76 log_must $ZFS destroy -Rf $TESTPOOL/$TESTFS 77 log_must $ZFS create $TESTPOOL/$TESTFS 78 log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS 79 fi 80} 81 82verify_runnable "both" 83log_assert "Verifying 'zfs receive -vn [<filesystem|snapshot>] " \ 84 "and zfs receive -vn -d <filesystem>'" 85 86log_onexit cleanup 87 88typeset datasets="$TESTPOOL/$TESTFS $TESTPOOL" 89typeset rst_fs=$TESTPOOL/$TESTFS/$TESTFS 90typeset fbackup=$TMPDIR/fbackup.${TESTCASE_ID} 91typeset tmp_out=$TMPDIR/tmpout.${TESTCASE_ID} 92 93for orig_fs in $datasets ; do 94 typeset rst_snap=$rst_fs@snap 95 typeset orig_snap=$orig_fs@snap 96 typeset verb_msg="receiving full stream of ${orig_snap} into ${rst_snap}" 97 typeset dryrun_msg="would receive full stream of ${orig_snap} into ${rst_snap}" 98 99 if ! datasetexists $orig_fs; then 100 log_must $ZFS create $orig_fs 101 fi 102 103 typeset mntpnt 104 mntpnt=$(get_prop mountpoint $orig_fs) 105 if [[ $? -ne 0 ]] ; then 106 log_fail "get_prop mountpoint $orig_fs failed" 107 fi 108 109 typeset mnt_file=$mntpnt/file1 110 111 log_must $MKFILE 100m $mnt_file 112 log_must $ZFS snapshot $orig_snap 113 log_must eval "$ZFS send $orig_snap > $fbackup" 114 115 for opt in "-v" "-vn"; do 116 if datasetexists $rst_fs; then 117 log_must $ZFS destroy -fr $rst_fs 118 fi 119 log_note "Check ZFS receive $opt [<filesystem|snapshot>]" 120 log_must eval "$ZFS receive $opt $rst_fs < $fbackup > $tmp_out 2>&1" 121 if [[ $opt == "-v" ]]; then 122 log_must eval "$GREP \"$verb_msg\" $tmp_out >/dev/null 2>&1" 123 if ! datasetexists $rst_snap; then 124 log_fail "dataset was not received, even though the"\ 125 " -v flag was used." 126 fi 127 else 128 log_must eval "$GREP \"$dryrun_msg\" $tmp_out >/dev/null 2>&1" 129 if datasetexists $rst_snap; then 130 log_fail "dataset was received, even though the -nv"\ 131 " flag was used." 132 fi 133 fi 134 done 135 136 log_note "Check ZFS receive -vn -d <filesystem>" 137 if ! datasetexists $rst_fs; then 138 log_must $ZFS create $rst_fs 139 fi 140 log_must eval "$ZFS receive -vn -d -F $rst_fs <$fbackup >$tmp_out 2>&1" 141 typeset relative_path="" 142 if [[ ${orig_fs} == *"/"* ]]; then 143 relative_path=${orig_fs#*/} 144 fi 145 146 typeset leaf_fs=${rst_fs}/${relative_path} 147 leaf_fs=${leaf_fs%/} 148 rst_snap=${leaf_fs}@snap 149 dryrun_msg="would receive full stream of ${orig_snap} into ${rst_snap}" 150 151 log_must eval "$GREP \"$dryrun_msg\" $tmp_out > /dev/null 2>&1" 152 153 if datasetexists $rst_snap; then 154 log_fail "dataset $rst_snap should not existed." 155 fi 156 log_must $ZFS destroy -Rf $rst_fs 157 158 cleanup 159done 160 161log_pass "zfs receive -vn [<filesystem|snapshot>] and " \ 162 "zfs receive -vn -d <filesystem>' succeed." 163