7290 ZFS test suite needs to control what utilities it can run
[unleashed.git] / usr / src / test / zfs-tests / tests / functional / cli_root / zfs_promote / zfs_promote_001_pos.ksh
blob0bf7c5b6a1765d571d311b60945041122b6abd19
1 #!/bin/ksh -p
3 # CDDL HEADER START
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.
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.
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]
20 # CDDL HEADER END
24 # Copyright 2007 Sun Microsystems, Inc. All rights reserved.
25 # Use is subject to license terms.
29 # Copyright (c) 2012, 2016 by Delphix. All rights reserved.
32 . $STF_SUITE/tests/functional/cli_root/zfs_promote/zfs_promote.cfg
33 . $STF_SUITE/include/libtest.shlib
36 # DESCRIPTION:
37 # 'zfs promote' can promote a clone filesystem to no longer be dependent
38 # on its "origin" snapshot.
40 # STRATEGY:
41 # 1. Create a snapshot and a clone of the snapshot
42 # 2. Promote the clone filesystem
43 # 3. Verify the promoted filesystem become independent
46 verify_runnable "both"
48 function cleanup
50 if snapexists $csnap; then
51 log_must zfs promote $fs
53 snapexists $snap && \
54 log_must zfs destroy -rR $snap
56 typeset data
57 for data in $file0 $file1; do
58 [[ -e $data ]] && rm -f $data
59 done
62 function testing_verify
64 typeset ds=$1
65 typeset ds_file=$2
66 typeset snap_file=$3
67 typeset c_ds=$4
68 typeset c_file=$5
69 typeset csnap_file=$6
70 typeset origin_prop=""
73 snapexists $ds@$TESTSNAP && \
74 log_fail "zfs promote cannot promote $ds@$TESTSNAP."
75 ! snapexists $c_ds@$TESTSNAP && \
76 log_fail "The $c_ds@$TESTSNAP after zfs promote doesn't exist."
78 origin_prop=$(get_prop origin $ds)
79 [[ "$origin_prop" != "$c_ds@$TESTSNAP" ]] && \
80 log_fail "The dependency of $ds is not correct."
81 origin_prop=$(get_prop origin $c_ds)
82 [[ "$origin_prop" != "-" ]] && \
83 log_fail "The dependency of $c_ds is not correct."
85 if [[ -e $snap_file ]] || [[ ! -e $csnap_file ]]; then
86 log_fail "Data file $snap_file cannot be correctly promoted."
88 if [[ ! -e $ds_file ]] || [[ ! -e $c_file ]]; then
89 log_fail "There exists data file losing after zfs promote."
92 log_mustnot zfs destroy -r $c_ds
95 log_assert "'zfs promote' can promote a clone filesystem."
96 log_onexit cleanup
98 fs=$TESTPOOL/$TESTFS
99 file0=$TESTDIR/$TESTFILE0
100 file1=$TESTDIR/$TESTFILE1
101 snap=$fs@$TESTSNAP
102 snapfile=$TESTDIR/.zfs/snapshot/$TESTSNAP/$TESTFILE0
103 clone=$TESTPOOL/$TESTCLONE
104 cfile=/$clone/$CLONEFILE
105 csnap=$clone@$TESTSNAP
106 csnapfile=/$clone/.zfs/snapshot/$TESTSNAP/$TESTFILE0
108 # setup for promte testing
109 log_must mkfile $FILESIZE $file0
110 log_must zfs snapshot $snap
111 log_must mkfile $FILESIZE $file1
112 log_must rm -f $file0
113 log_must zfs clone $snap $clone
114 log_must mkfile $FILESIZE $cfile
116 log_must zfs promote $clone
117 # verify the 'promote' operation
118 testing_verify $fs $file1 $snapfile $clone $cfile $csnapfile
120 log_note "Verify 'zfs promote' can change back the dependency relationship."
121 log_must zfs promote $fs
122 #verify the result
123 testing_verify $clone $cfile $csnapfile $fs $file1 $snapfile
125 log_pass "'zfs promote' reverses the clone parent-child dependency relationship"\
126 "as expected."