12fae26bdSAlan Somers#!/usr/local/bin/ksh93 -p
22fae26bdSAlan Somers#
32fae26bdSAlan Somers# CDDL HEADER START
42fae26bdSAlan Somers#
52fae26bdSAlan Somers# The contents of this file are subject to the terms of the
62fae26bdSAlan Somers# Common Development and Distribution License (the "License").
72fae26bdSAlan Somers# You may not use this file except in compliance with the License.
82fae26bdSAlan Somers#
92fae26bdSAlan Somers# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
102fae26bdSAlan Somers# or http://www.opensolaris.org/os/licensing.
112fae26bdSAlan Somers# See the License for the specific language governing permissions
122fae26bdSAlan Somers# and limitations under the License.
132fae26bdSAlan Somers#
142fae26bdSAlan Somers# When distributing Covered Code, include this CDDL HEADER in each
152fae26bdSAlan Somers# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
162fae26bdSAlan Somers# If applicable, add the following below this CDDL HEADER, with the
172fae26bdSAlan Somers# fields enclosed by brackets "[]" replaced with your own identifying
182fae26bdSAlan Somers# information: Portions Copyright [yyyy] [name of copyright owner]
192fae26bdSAlan Somers#
202fae26bdSAlan Somers# CDDL HEADER END
212fae26bdSAlan Somers#
222fae26bdSAlan Somers
232fae26bdSAlan Somers#
242fae26bdSAlan Somers# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
252fae26bdSAlan Somers# Use is subject to license terms.
262fae26bdSAlan Somers. $STF_SUITE/include/libtest.kshlib
272fae26bdSAlan Somers
282fae26bdSAlan Somers################################################################################
292fae26bdSAlan Somers#
302fae26bdSAlan Somers# __stc_assertion_start
312fae26bdSAlan Somers#
322fae26bdSAlan Somers# ID: zfs_promote_002_pos
332fae26bdSAlan Somers#
342fae26bdSAlan Somers# DESCRIPTION:
352fae26bdSAlan Somers#	'zfs promote' can deal with multiple snapshots in the origin filesystem.
362fae26bdSAlan Somers#
372fae26bdSAlan Somers# STRATEGY:
382fae26bdSAlan Somers#	1. Create multiple snapshots and a clone of the last snapshot
392fae26bdSAlan Somers#	2. Promote the clone filesystem
402fae26bdSAlan Somers#	3. Verify the promoted filesystem included all snapshots
412fae26bdSAlan Somers#
422fae26bdSAlan Somers# TESTABILITY: explicit
432fae26bdSAlan Somers#
442fae26bdSAlan Somers# TEST_AUTOMATION_LEVEL: automated
452fae26bdSAlan Somers#
462fae26bdSAlan Somers# CODING_STATUS: COMPLETED (2006-05-16)
472fae26bdSAlan Somers#
482fae26bdSAlan Somers# __stc_assertion_end
492fae26bdSAlan Somers#
502fae26bdSAlan Somers################################################################################
512fae26bdSAlan Somers
522fae26bdSAlan Somersverify_runnable "both"
532fae26bdSAlan Somers
542fae26bdSAlan Somersfunction cleanup
552fae26bdSAlan Somers{
562fae26bdSAlan Somers	if snapexists $csnap1; then
572fae26bdSAlan Somers		log_must $ZFS promote $fs
582fae26bdSAlan Somers	fi
592fae26bdSAlan Somers
602fae26bdSAlan Somers	typeset ds
612fae26bdSAlan Somers	typeset data
622fae26bdSAlan Somers	for ds in $snap $snap1; do
632fae26bdSAlan Somers		log_must $ZFS destroy -rR $ds
642fae26bdSAlan Somers	done
652fae26bdSAlan Somers	for file in $TESTDIR/$TESTFILE0 $TESTDIR/$TESTFILE1; do
662fae26bdSAlan Somers		[[ -e $file ]] && $RM -f $file
672fae26bdSAlan Somers	done
682fae26bdSAlan Somers}
692fae26bdSAlan Somers
702fae26bdSAlan Somerslog_assert "'zfs promote' can deal with multiple snapshots in a filesystem."
712fae26bdSAlan Somerslog_onexit cleanup
722fae26bdSAlan Somers
732fae26bdSAlan Somersfs=$TESTPOOL/$TESTFS
742fae26bdSAlan Somerssnap=$fs@$TESTSNAP
752fae26bdSAlan Somerssnap1=$fs@$TESTSNAP1
762fae26bdSAlan Somersclone=$TESTPOOL/$TESTCLONE
772fae26bdSAlan Somerscsnap=$clone@$TESTSNAP
782fae26bdSAlan Somerscsnap1=$clone@$TESTSNAP1
792fae26bdSAlan Somers
802fae26bdSAlan Somers# setup for promote testing
812fae26bdSAlan Somerslog_must $MKFILE $FILESIZE $TESTDIR/$TESTFILE0
822fae26bdSAlan Somerslog_must $ZFS snapshot $snap
832fae26bdSAlan Somerslog_must $MKFILE $FILESIZE $TESTDIR/$TESTFILE1
842fae26bdSAlan Somerslog_must $RM -f $testdir/$TESTFILE0
852fae26bdSAlan Somerslog_must $ZFS snapshot $snap1
862fae26bdSAlan Somerslog_must $ZFS clone $snap1 $clone
872fae26bdSAlan Somerslog_must $MKFILE $FILESIZE /$clone/$CLONEFILE
882fae26bdSAlan Somers
892fae26bdSAlan Somerslog_must $ZFS promote $clone
902fae26bdSAlan Somers
912fae26bdSAlan Somers# verify the 'promote' operation
922fae26bdSAlan Somersfor ds in $csnap $csnap1; do
932fae26bdSAlan Somers	! snapexists $ds && \
942fae26bdSAlan Somers		log_fail "Snapshot $ds doesn't exist after zfs promote."
952fae26bdSAlan Somersdone
962fae26bdSAlan Somersfor ds in $snap $snap1; do
972fae26bdSAlan Somers	snapexists $ds && \
982fae26bdSAlan Somers		log_fail "Snapshot $ds is still there after zfs promote."
992fae26bdSAlan Somersdone
1002fae26bdSAlan Somers
1012fae26bdSAlan Somersorigin_prop=$(get_prop origin $fs)
1022fae26bdSAlan Somers[[ "$origin_prop" != "$csnap1" ]] && \
1032fae26bdSAlan Somers	log_fail "The dependency of $fs is not correct."
1042fae26bdSAlan Somersorigin_prop=$(get_prop origin $clone)
1052fae26bdSAlan Somers[[ "$origin_prop" != "-" ]] && \
1062fae26bdSAlan Somers	 log_fail "The dependency of $clone is not correct."
1072fae26bdSAlan Somers
1082fae26bdSAlan Somerslog_pass "'zfs promote' deal with multiple snapshots as expected."
1092fae26bdSAlan Somers
110