]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - tests/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_005_neg.ksh
Vendor import of openzfs master @ 184df27eef0abdc7ab2105b21257f753834b936b
[FreeBSD/FreeBSD.git] / tests / zfs-tests / tests / functional / cli_root / zfs_receive / zfs_receive_005_neg.ksh
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 2007 Sun Microsystems, Inc.  All rights reserved.
25 # Use is subject to license terms.
26 #
27
28 #
29 # Copyright (c) 2016 by Delphix. All rights reserved.
30 #
31
32 . $STF_SUITE/tests/functional/cli_root/cli_common.kshlib
33
34 #
35 # DESCRIPTION:
36 #       Verify 'zfs receive' fails with unsupported scenarios.
37 #       including:
38 #       (1) Invalid send streams;
39 #       (2) The received incremental send doesn't match the filesystem
40 #           latest status.
41 #
42 # STRATEGY:
43 #       1. Preparation for unsupported scenarios
44 #       2. Execute 'zfs receive'
45 #       3. Verify the results are failed
46 #
47
48 verify_runnable "both"
49
50 function cleanup
51 {
52         typeset snap
53         typeset bkup
54
55         for snap in $init_snap $inc_snap; do
56                 snapexists $snap && \
57                         log_must zfs destroy -f $snap
58         done
59
60         datasetexists $rst_root && \
61                 log_must zfs destroy -Rf $rst_root
62
63         for bkup in $full_bkup $inc_bkup; do
64                 [[ -e $bkup ]] && \
65                         log_must rm -f $bkup
66         done
67 }
68
69 log_assert "Verify 'zfs receive' fails with unsupported scenarios."
70 log_onexit cleanup
71
72 init_snap=$TESTPOOL/$TESTFS@initsnap
73 inc_snap=$TESTPOOL/$TESTFS@incsnap
74 rst_root=$TESTPOOL/rst_ctr
75 rst_init_snap=$rst_root/$TESTFS@init_snap
76 rst_inc_snap=$rst_root/$TESTFS@inc_snap
77 full_bkup=$TEST_BASE_DIR/full_bkup.$$
78 inc_bkup=$TEST_BASE_DIR/inc_bkup.$$
79
80 log_must zfs create $rst_root
81 log_must zfs snapshot $init_snap
82 log_must eval "zfs send $init_snap > $full_bkup"
83
84 log_note "'zfs receive' fails with invalid send streams."
85 log_mustnot eval "zfs receive $rst_init_snap < /dev/zero"
86 log_mustnot eval "zfs receive -d $rst_root </dev/zero"
87
88 log_must eval "zfs receive $rst_init_snap < $full_bkup"
89
90 log_note "Unmatched send stream with restoring filesystem" \
91         " cannot be received."
92 log_must zfs snapshot $inc_snap
93 log_must eval "zfs send -i $init_snap $inc_snap > $inc_bkup"
94 #make changes on the restoring filesystem
95 log_must touch $ZFSROOT/$rst_root/$TESTFS/tmpfile
96 log_mustnot eval "zfs receive $rst_inc_snap < $inc_bkup"
97 log_mustnot eval "zfs receive -d $rst_root < $inc_bkup"
98
99 log_pass "Unsupported scenarios to 'zfs receive' fail as expected."