setup.ksh revision f38cb554a534c6df738be3f4d23327e69888e634
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#!/usr/bin/ksh -p
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# CDDL HEADER START
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# The contents of this file are subject to the terms of the
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# Common Development and Distribution License (the "License").
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# You may not use this file except in compliance with the License.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# or http://www.opensolaris.org/os/licensing.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# See the License for the specific language governing permissions
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# and limitations under the License.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# When distributing Covered Code, include this CDDL HEADER in each
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# If applicable, add the following below this CDDL HEADER, with the
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# fields enclosed by brackets "[]" replaced with your own identifying
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# information: Portions Copyright [yyyy] [name of copyright owner]
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# CDDL HEADER END
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# Copyright 2008 Sun Microsystems, Inc. All rights reserved.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# Use is subject to license terms.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# Copyright (c) 2013 by Delphix. All rights reserved.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy. $STF_SUITE/tests/functional/cli_user/misc/misc.cfg
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy. $STF_SUITE/include/libtest.shlib
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# This setup script is moderately complex, as it creates scenarios for all
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# of the tests included in this directory. Usually we'd want each test case
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# to setup/teardown it's own configuration, but this would be time consuming
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# given the nature of these tests. However, as a side-effect, one test
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# leaving the system in an unknown state could impact other test cases.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren KennedyDISK=${DISKS%% *}
f38cb554a534c6df738be3f4d23327e69888e634John Wren KennedyVOLSIZE=150m
f38cb554a534c6df738be3f4d23327e69888e634John Wren KennedyTESTVOL=testvol
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# Create a default setup that includes a volume
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedydefault_setup_noexit "$DISK" "" "volume"
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# The rest of this setup script creates a ZFS filesystem configuration
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# that is used to test the rest of the zfs subcommands in this directory.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# create a snapshot and a clone to test clone promote
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedylog_must $ZFS snapshot $TESTPOOL/$TESTFS@snap
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedylog_must $ZFS clone $TESTPOOL/$TESTFS@snap $TESTPOOL/$TESTFS/clone
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# create a file in the filesystem that isn't in the above snapshot
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy$TOUCH /$TESTDIR/file.txt
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# create a non-default property and a child we can use to test inherit
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedylog_must $ZFS create $TESTPOOL/$TESTFS/$TESTFS2
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedylog_must $ZFS set snapdir=hidden $TESTPOOL/$TESTFS
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# create an unmounted filesystem to test unmount
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedylog_must $ZFS create $TESTPOOL/$TESTFS/$TESTFS2.unmounted
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedylog_must $ZFS unmount $TESTPOOL/$TESTFS/$TESTFS2.unmounted
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# send our snapshot to a known file in /tmp
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy$ZFS send $TESTPOOL/$TESTFS@snap > /tmp/zfstest_datastream.dat
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedyif [ ! -s /tmp/zfstest_datastream.dat ]
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedythen
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy log_fail "ZFS send datafile was not created!"
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedyfi
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedylog_must $CHMOD 644 /tmp/zfstest_datastream.dat
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# create a filesystem that has particular properties to test set/get
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedylog_must $ZFS create -o version=1 $TESTPOOL/$TESTFS/prop
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedyset -A props $PROP_NAMES
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedyset -A prop_vals $PROP_VALS
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedytypeset -i i=0
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedywhile [[ $i -lt ${#props[*]} ]]
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedydo
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy prop_name=${props[$i]}
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy prop_val=${prop_vals[$i]}
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy log_must $ZFS set $prop_name=$prop_val $TESTPOOL/$TESTFS/prop
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy i=$(( $i + 1 ))
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedydone
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# create a filesystem we don't mind renaming
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedylog_must $ZFS create $TESTPOOL/$TESTFS/renameme
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedyif is_global_zone
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedythen
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy # create a filesystem we can share
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy log_must $ZFS create $TESTPOOL/$TESTFS/unshared
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy log_must $ZFS set sharenfs=off $TESTPOOL/$TESTFS/unshared
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy # create a filesystem that we can unshare
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy log_must $ZFS create $TESTPOOL/$TESTFS/shared
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy log_must $ZFS set sharenfs=on $TESTPOOL/$TESTFS/shared
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedyfi
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedylog_must $ZFS create -o version=1 $TESTPOOL/$TESTFS/version1
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedylog_must $ZFS create -o version=1 $TESTPOOL/$TESTFS/allowed
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedylog_must $ZFS allow everyone create $TESTPOOL/$TESTFS/allowed
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedyif is_global_zone
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedythen
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy # Now create several virtual disks to test zpool with
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy $MKFILE 100m /$TESTDIR/disk1.dat
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy $MKFILE 100m /$TESTDIR/disk2.dat
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy $MKFILE 100m /$TESTDIR/disk3.dat
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy $MKFILE 100m /$TESTDIR/disk-additional.dat
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy $MKFILE 100m /$TESTDIR/disk-export.dat
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy $MKFILE 100m /$TESTDIR/disk-offline.dat
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy $MKFILE 100m /$TESTDIR/disk-spare1.dat
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy $MKFILE 100m /$TESTDIR/disk-spare2.dat
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy # and create a pool we can perform attach remove replace,
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy # etc. operations with
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy log_must $ZPOOL create $TESTPOOL.virt mirror /$TESTDIR/disk1.dat \
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy /$TESTDIR/disk2.dat /$TESTDIR/disk3.dat /$TESTDIR/disk-offline.dat \
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy spare /$TESTDIR/disk-spare1.dat
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy # Offline one of the disks to test online
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy log_must $ZPOOL offline $TESTPOOL.virt /$TESTDIR/disk-offline.dat
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy # create an exported pool to test import
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy log_must $ZPOOL create $TESTPOOL.exported /$TESTDIR/disk-export.dat
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy log_must $ZPOOL export $TESTPOOL.exported
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy set -A props $POOL_PROPS
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy set -A prop_vals $POOL_VALS
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy typeset -i i=0
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy while [[ $i -lt ${#props[*]} ]]
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy do
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy prop_name=${props[$i]}
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy prop_val=${prop_vals[$i]}
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy log_must $ZPOOL set $prop_name=$prop_val $TESTPOOL
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy i=$(( $i + 1 ))
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy done
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy # copy a v1 pool from cli_root
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy $CP $STF_SUITE/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v1.dat.bz2 \
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy /$TESTDIR
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy log_must $BUNZIP2 /$TESTDIR/zfs-pool-v1.dat.bz2
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy log_must $ZPOOL import -d /$TESTDIR v1-pool
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedyfi
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedylog_pass