xref: /titanic_52/usr/src/test/zfs-tests/tests/functional/cli_user/misc/setup.ksh (revision f38cb554a534c6df738be3f4d23327e69888e634)
1#!/usr/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 2008 Sun Microsystems, Inc.  All rights reserved.
25# Use is subject to license terms.
26#
27
28#
29# Copyright (c) 2013 by Delphix. All rights reserved.
30#
31
32. $STF_SUITE/tests/functional/cli_user/misc/misc.cfg
33. $STF_SUITE/include/libtest.shlib
34
35# This setup script is moderately complex, as it creates scenarios for all
36# of the tests included in this directory. Usually we'd want each test case
37# to setup/teardown it's own configuration, but this would be time consuming
38# given the nature of these tests. However, as a side-effect, one test
39# leaving the system in an unknown state could impact other test cases.
40
41
42DISK=${DISKS%% *}
43VOLSIZE=150m
44TESTVOL=testvol
45
46# Create a default setup that includes a volume
47default_setup_noexit "$DISK" "" "volume"
48
49#
50# The rest of this setup script creates a ZFS filesystem configuration
51# that is used to test the rest of the zfs subcommands in this directory.
52#
53
54# create a snapshot and a clone to test clone promote
55log_must $ZFS snapshot $TESTPOOL/$TESTFS@snap
56log_must $ZFS clone $TESTPOOL/$TESTFS@snap $TESTPOOL/$TESTFS/clone
57# create a file in the filesystem that isn't in the above snapshot
58$TOUCH /$TESTDIR/file.txt
59
60
61# create a non-default property and a child we can use to test inherit
62log_must $ZFS create $TESTPOOL/$TESTFS/$TESTFS2
63log_must $ZFS set snapdir=hidden $TESTPOOL/$TESTFS
64
65
66# create an unmounted filesystem to test unmount
67log_must $ZFS create $TESTPOOL/$TESTFS/$TESTFS2.unmounted
68log_must $ZFS unmount $TESTPOOL/$TESTFS/$TESTFS2.unmounted
69
70
71# send our snapshot to a known file in /tmp
72$ZFS send $TESTPOOL/$TESTFS@snap > /tmp/zfstest_datastream.dat
73if [ ! -s /tmp/zfstest_datastream.dat ]
74then
75	log_fail "ZFS send datafile was not created!"
76fi
77log_must $CHMOD 644 /tmp/zfstest_datastream.dat
78
79
80# create a filesystem that has particular properties to test set/get
81log_must $ZFS create -o version=1 $TESTPOOL/$TESTFS/prop
82set -A props $PROP_NAMES
83set -A prop_vals $PROP_VALS
84typeset -i i=0
85
86while [[ $i -lt ${#props[*]} ]]
87do
88	prop_name=${props[$i]}
89	prop_val=${prop_vals[$i]}
90	log_must $ZFS set $prop_name=$prop_val $TESTPOOL/$TESTFS/prop
91	i=$(( $i + 1 ))
92done
93
94# create a filesystem we don't mind renaming
95log_must $ZFS create $TESTPOOL/$TESTFS/renameme
96
97
98if is_global_zone
99then
100	# create a filesystem we can share
101	log_must $ZFS create $TESTPOOL/$TESTFS/unshared
102	log_must $ZFS set sharenfs=off $TESTPOOL/$TESTFS/unshared
103
104	# create a filesystem that we can unshare
105	log_must $ZFS create $TESTPOOL/$TESTFS/shared
106	log_must $ZFS set sharenfs=on $TESTPOOL/$TESTFS/shared
107fi
108
109
110log_must $ZFS create -o version=1 $TESTPOOL/$TESTFS/version1
111log_must $ZFS create -o version=1 $TESTPOOL/$TESTFS/allowed
112log_must $ZFS allow everyone create $TESTPOOL/$TESTFS/allowed
113
114if is_global_zone
115then
116
117	# Now create several virtual disks to test zpool with
118
119	$MKFILE 100m /$TESTDIR/disk1.dat
120	$MKFILE 100m /$TESTDIR/disk2.dat
121	$MKFILE 100m /$TESTDIR/disk3.dat
122	$MKFILE 100m /$TESTDIR/disk-additional.dat
123	$MKFILE 100m /$TESTDIR/disk-export.dat
124	$MKFILE 100m /$TESTDIR/disk-offline.dat
125	$MKFILE 100m /$TESTDIR/disk-spare1.dat
126	$MKFILE 100m /$TESTDIR/disk-spare2.dat
127
128	# and create a pool we can perform attach remove replace,
129	# etc. operations with
130	log_must $ZPOOL create $TESTPOOL.virt mirror /$TESTDIR/disk1.dat \
131	/$TESTDIR/disk2.dat /$TESTDIR/disk3.dat /$TESTDIR/disk-offline.dat \
132	spare /$TESTDIR/disk-spare1.dat
133
134
135	# Offline one of the disks to test online
136	log_must $ZPOOL offline $TESTPOOL.virt /$TESTDIR/disk-offline.dat
137
138
139	# create an exported pool to test import
140	log_must $ZPOOL create $TESTPOOL.exported /$TESTDIR/disk-export.dat
141	log_must $ZPOOL export $TESTPOOL.exported
142
143	set -A props $POOL_PROPS
144	set -A prop_vals $POOL_VALS
145	typeset -i i=0
146
147	while [[ $i -lt ${#props[*]} ]]
148	do
149		prop_name=${props[$i]}
150		prop_val=${prop_vals[$i]}
151		log_must $ZPOOL set $prop_name=$prop_val $TESTPOOL
152		i=$(( $i + 1 ))
153	done
154
155	# copy a v1 pool from cli_root
156	$CP $STF_SUITE/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v1.dat.bz2 \
157	    /$TESTDIR
158	log_must $BUNZIP2 /$TESTDIR/zfs-pool-v1.dat.bz2
159	log_must $ZPOOL import -d /$TESTDIR v1-pool
160fi
161log_pass
162