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. $STF_SUITE/tests/cli_root/zfs_mount/zfs_mount.kshlib
282fae26bdSAlan Somers
292fae26bdSAlan Somers################################################################################
302fae26bdSAlan Somers#
312fae26bdSAlan Somers# __stc_assertion_start
322fae26bdSAlan Somers#
332fae26bdSAlan Somers# ID: zpool_import_rename_001_pos
342fae26bdSAlan Somers#
352fae26bdSAlan Somers# DESCRIPTION:
362fae26bdSAlan Somers# An exported pool can be imported under a different name. Hence
372fae26bdSAlan Somers# we test that a previously exported pool can be renamed.
382fae26bdSAlan Somers#
392fae26bdSAlan Somers# STRATEGY:
402fae26bdSAlan Somers#	1. Copy a file into the default test directory.
412fae26bdSAlan Somers#	2. Umount the default directory.
422fae26bdSAlan Somers#	3. Export the pool.
432fae26bdSAlan Somers#	4. Import the pool using the name ${TESTPOOL}-new,
442fae26bdSAlan Somers#	   and using the various combinations.
452fae26bdSAlan Somers#               - Regular import
462fae26bdSAlan Somers#               - Alternate Root Specified
472fae26bdSAlan Somers#	5. Verify it exists in the 'zpool list' output.
482fae26bdSAlan Somers#	6. Verify the default file system is mounted and that the file
492fae26bdSAlan Somers#	   from step (1) is present.
502fae26bdSAlan Somers#
512fae26bdSAlan Somers# TESTABILITY: explicit
522fae26bdSAlan Somers#
532fae26bdSAlan Somers# TEST_AUTOMATION_LEVEL: automated
542fae26bdSAlan Somers#
552fae26bdSAlan Somers# CODING_STATUS: COMPLETED (2005-07-04)
562fae26bdSAlan Somers#
572fae26bdSAlan Somers# __stc_assertion_end
582fae26bdSAlan Somers#
592fae26bdSAlan Somers################################################################################
602fae26bdSAlan Somers
612fae26bdSAlan Somersverify_runnable "global"
622fae26bdSAlan Somers
632fae26bdSAlan Somersset -A pools "$TESTPOOL" "$TESTPOOL1"
642fae26bdSAlan Somersset -A devs "" "-d $DEVICE_DIR"
652fae26bdSAlan Somersset -A options "" "-R $ALTER_ROOT"
662fae26bdSAlan Somersset -A mtpts "$TESTDIR" "$TESTDIR1"
672fae26bdSAlan Somers
682fae26bdSAlan Somers
692fae26bdSAlan Somersfunction cleanup
702fae26bdSAlan Somers{
712fae26bdSAlan Somers	typeset -i i=0
722fae26bdSAlan Somers	while (( i < ${#pools[*]} )); do
732fae26bdSAlan Somers		if poolexists "${pools[i]}-new" ; then
742fae26bdSAlan Somers			log_must $ZPOOL export "${pools[i]}-new"
752fae26bdSAlan Somers
762fae26bdSAlan Somers			[[ -d /${pools[i]}-new ]] && \
772fae26bdSAlan Somers				log_must $RM -rf /${pools[i]}-new
782fae26bdSAlan Somers
792fae26bdSAlan Somers			log_must $ZPOOL import ${devs[i]} \
802fae26bdSAlan Somers				"${pools[i]}-new" ${pools[i]}
812fae26bdSAlan Somers		fi
822fae26bdSAlan Somers
832fae26bdSAlan Somers		datasetexists "${pools[i]}" || \
842fae26bdSAlan Somers			log_must $ZPOOL import ${devs[i]} ${pools[i]}
852fae26bdSAlan Somers
862fae26bdSAlan Somers		ismounted "${pools[i]}/$TESTFS" || \
872fae26bdSAlan Somers			log_must $ZFS mount ${pools[i]}/$TESTFS
882fae26bdSAlan Somers
892fae26bdSAlan Somers		[[ -e ${mtpts[i]}/$TESTFILE0 ]] && \
902fae26bdSAlan Somers			log_must $RM -rf ${mtpts[i]}/$TESTFILE0
912fae26bdSAlan Somers
922fae26bdSAlan Somers		((i = i + 1))
932fae26bdSAlan Somers
942fae26bdSAlan Somers	done
952fae26bdSAlan Somers
962fae26bdSAlan Somers	cleanup_filesystem $TESTPOOL1 $TESTFS $TESTDIR1
972fae26bdSAlan Somers
982fae26bdSAlan Somers	destroy_pool $TESTPOOL1
992fae26bdSAlan Somers
1002fae26bdSAlan Somers	[[ -d $ALTER_ROOT ]] && \
1012fae26bdSAlan Somers		log_must $RM -rf $ALTER_ROOT
1022fae26bdSAlan Somers}
1032fae26bdSAlan Somers
1042fae26bdSAlan Somersfunction perform_inner_test
1052fae26bdSAlan Somers{
1062fae26bdSAlan Somers	target=$1
1072fae26bdSAlan Somers
1082fae26bdSAlan Somers	log_must $ZPOOL import ${devs[i]} ${options[j]} \
1092fae26bdSAlan Somers		$target ${pools[i]}-new
1102fae26bdSAlan Somers
1112fae26bdSAlan Somers	log_must poolexists "${pools[i]}-new"
1122fae26bdSAlan Somers
1132fae26bdSAlan Somers	log_must ismounted ${pools[i]}-new/$TESTFS
1142fae26bdSAlan Somers
1152fae26bdSAlan Somers	basedir=${mtpts[i]}
1162fae26bdSAlan Somers	[[ -n ${options[j]} ]] && \
1172fae26bdSAlan Somers		basedir=$ALTER_ROOT/${mtpts[i]}
1182fae26bdSAlan Somers
1192fae26bdSAlan Somers	[[ ! -e $basedir/$TESTFILE0 ]] && \
1202fae26bdSAlan Somers		log_fail "$basedir/$TESTFILE0 missing after import."
1212fae26bdSAlan Somers
1222fae26bdSAlan Somers	checksum2=$($SUM $basedir/$TESTFILE0 | $AWK '{print $1}')
1232fae26bdSAlan Somers	[[ "$checksum1" != "$checksum2" ]] && \
1242fae26bdSAlan Somers		log_fail "Checksums differ ($checksum1 != $checksum2)"
1252fae26bdSAlan Somers
1262fae26bdSAlan Somers	log_must $ZPOOL export "${pools[i]}-new"
1272fae26bdSAlan Somers
1282fae26bdSAlan Somers	[[ -d /${pools[i]}-new ]] && \
1292fae26bdSAlan Somers		log_must $RM -rf /${pools[i]}-new
1302fae26bdSAlan Somers
1312fae26bdSAlan Somers	target=${pools[i]}-new
1322fae26bdSAlan Somers	if (( RANDOM % 2 == 0 )) ; then
1332fae26bdSAlan Somers		target=$guid
1342fae26bdSAlan Somers	fi
1352fae26bdSAlan Somers	log_must $ZPOOL import ${devs[i]} $target ${pools[i]}
1362fae26bdSAlan Somers}
1372fae26bdSAlan Somers
1382fae26bdSAlan Somerslog_onexit cleanup
1392fae26bdSAlan Somers
1402fae26bdSAlan Somerslog_assert "Verify that an imported pool can be renamed."
1412fae26bdSAlan Somers
1422fae26bdSAlan Somerssetup_filesystem "$DEVICE_FILES" $TESTPOOL1 $TESTFS $TESTDIR1
1432fae26bdSAlan Somerschecksum1=$($SUM $MYTESTFILE | $AWK '{print $1}')
1442fae26bdSAlan Somers
1452fae26bdSAlan Somerstypeset -i i=0
1462fae26bdSAlan Somerstypeset -i j=0
1472fae26bdSAlan Somerstypeset basedir
1482fae26bdSAlan Somers
1492fae26bdSAlan Somerswhile (( i < ${#pools[*]} )); do
1502fae26bdSAlan Somers	guid=$(get_config ${pools[i]} pool_guid)
1512fae26bdSAlan Somers	log_must $CP $MYTESTFILE ${mtpts[i]}/$TESTFILE0
1522fae26bdSAlan Somers
1532fae26bdSAlan Somers	log_must $ZFS umount ${mtpts[i]}
1542fae26bdSAlan Somers
1552fae26bdSAlan Somers	j=0
1562fae26bdSAlan Somers	while (( j <  ${#options[*]} )); do
1572fae26bdSAlan Somers		log_must $ZPOOL export ${pools[i]}
1582fae26bdSAlan Somers
1592fae26bdSAlan Somers		[[ -d /${pools[i]} ]] && \
1602fae26bdSAlan Somers			log_must $RM -rf /${pools[i]}
1612fae26bdSAlan Somers
1622fae26bdSAlan Somers		log_note "Testing import by name."
1632fae26bdSAlan Somers		perform_inner_test ${pools[i]}
1642fae26bdSAlan Somers
1652fae26bdSAlan Somers		log_must $ZPOOL export ${pools[i]}
1662fae26bdSAlan Somers
1672fae26bdSAlan Somers		log_note "Testing import by GUID."
1682fae26bdSAlan Somers		perform_inner_test $guid
1692fae26bdSAlan Somers
1702fae26bdSAlan Somers		((j = j + 1))
1712fae26bdSAlan Somers	done
1722fae26bdSAlan Somers
1732fae26bdSAlan Somers	((i = i + 1))
1742fae26bdSAlan Somersdone
1752fae26bdSAlan Somers
1762fae26bdSAlan Somerslog_pass "Successfully imported and renamed a ZPOOL"
177