]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - tests/zfs-tests/tests/functional/cli_root/zfs_promote/zfs_promote_002_pos.ksh
Vendor import of openzfs master @ 184df27eef0abdc7ab2105b21257f753834b936b
[FreeBSD/FreeBSD.git] / tests / zfs-tests / tests / functional / cli_root / zfs_promote / zfs_promote_002_pos.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) 2012, 2016 by Delphix. All rights reserved.
30 #
31
32 . $STF_SUITE/tests/functional/cli_root/zfs_promote/zfs_promote.cfg
33 . $STF_SUITE/include/libtest.shlib
34
35 #
36 # DESCRIPTION:
37 #       'zfs promote' can deal with multiple snapshots in the origin filesystem.
38 #
39 # STRATEGY:
40 #       1. Create multiple snapshots and a clone of the last snapshot
41 #       2. Promote the clone filesystem
42 #       3. Verify the promoted filesystem included all snapshots
43 #
44
45 verify_runnable "both"
46
47 function cleanup
48 {
49         if snapexists $csnap1; then
50                 log_must zfs promote $fs
51         fi
52
53         typeset ds
54         typeset data
55         for ds in $snap $snap1; do
56                 log_must zfs destroy -rR $ds
57         done
58         for file in $TESTDIR/$TESTFILE0 $TESTDIR/$TESTFILE1; do
59                 [[ -e $file ]] && rm -f $file
60         done
61 }
62
63 log_assert "'zfs promote' can deal with multiple snapshots in a filesystem."
64 log_onexit cleanup
65
66 fs=$TESTPOOL/$TESTFS
67 snap=$fs@$TESTSNAP
68 snap1=$fs@$TESTSNAP1
69 clone=$TESTPOOL/$TESTCLONE
70 csnap=$clone@$TESTSNAP
71 csnap1=$clone@$TESTSNAP1
72
73 # setup for promote testing
74 log_must mkfile $FILESIZE $TESTDIR/$TESTFILE0
75 log_must zfs snapshot $snap
76 log_must mkfile $FILESIZE $TESTDIR/$TESTFILE1
77 log_must rm -f $testdir/$TESTFILE0
78 log_must zfs snapshot $snap1
79 log_must zfs clone $snap1 $clone
80 log_must mkfile $FILESIZE /$clone/$CLONEFILE
81
82 log_must zfs promote $clone
83
84 # verify the 'promote' operation
85 for ds in $csnap $csnap1; do
86         ! snapexists $ds && \
87                 log_fail "Snapshot $ds doesn't exist after zfs promote."
88 done
89 for ds in $snap $snap1; do
90         snapexists $ds && \
91                 log_fail "Snapshot $ds is still there after zfs promote."
92 done
93
94 origin_prop=$(get_prop origin $fs)
95 [[ "$origin_prop" != "$csnap1" ]] && \
96         log_fail "The dependency of $fs is not correct."
97 origin_prop=$(get_prop origin $clone)
98 [[ "$origin_prop" != "-" ]] && \
99          log_fail "The dependency of $clone is not correct."
100
101 log_pass "'zfs promote' deal with multiple snapshots as expected."
102