aboutsummaryrefslogtreecommitdiff
path: root/tests/zfs-tests/tests/functional/cli_user/misc/setup.ksh
blob: fc0ebde10025b29c65eb2d860db5499d279c40b8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#!/bin/ksh -p
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# or http://www.opensolaris.org/os/licensing.
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#

#
# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.
#

#
# Copyright (c) 2013, 2016 by Delphix. All rights reserved.
#

. $STF_SUITE/include/libtest.shlib
. $STF_SUITE/tests/functional/cli_user/misc/misc.cfg

# This setup script is moderately complex, as it creates scenarios for all
# of the tests included in this directory. Usually we'd want each test case
# to setup/teardown its own configuration, but this would be time consuming
# given the nature of these tests. However, as a side-effect, one test
# leaving the system in an unknown state could impact other test cases.


DISK=${DISKS%% *}
VOLSIZE=150m
TESTVOL=testvol

# Create a default setup that includes a volume
default_setup_noexit "$DISK" "" "volume"

#
# The rest of this setup script creates a ZFS filesystem configuration
# that is used to test the rest of the zfs subcommands in this directory.
#

# create a snapshot and a clone to test clone promote
log_must zfs snapshot $TESTPOOL/$TESTFS@snap
log_must zfs clone $TESTPOOL/$TESTFS@snap $TESTPOOL/$TESTFS/clone
# create a file in the filesystem that isn't in the above snapshot
touch $TESTDIR/file.txt


# create a non-default property and a child we can use to test inherit
log_must zfs create $TESTPOOL/$TESTFS/$TESTFS2
log_must zfs set snapdir=hidden $TESTPOOL/$TESTFS


# create an unmounted filesystem to test unmount
log_must zfs create $TESTPOOL/$TESTFS/$TESTFS2.unmounted
log_must zfs unmount $TESTPOOL/$TESTFS/$TESTFS2.unmounted


# send our snapshot to a known file in /tmp
zfs send $TESTPOOL/$TESTFS@snap > $TEST_BASE_DIR/zfstest_datastream.dat
if [ ! -s $TEST_BASE_DIR/zfstest_datastream.dat ]
then
	log_fail "ZFS send datafile was not created!"
fi
log_must chmod 644 $TEST_BASE_DIR/zfstest_datastream.dat


# create a filesystem that has particular properties to test set/get
log_must zfs create -o version=1 $TESTPOOL/$TESTFS/prop
set -A props $PROP_NAMES
set -A prop_vals $PROP_VALS
typeset -i i=0

while [[ $i -lt ${#props[*]} ]]
do
	prop_name=${props[$i]}
	prop_val=${prop_vals[$i]}
	log_must zfs set $prop_name=$prop_val $TESTPOOL/$TESTFS/prop
	i=$(( $i + 1 ))
done

# create a filesystem we don't mind renaming
log_must zfs create $TESTPOOL/$TESTFS/renameme


if is_global_zone && ! is_linux
then
	# create a filesystem we can share
	log_must zfs create $TESTPOOL/$TESTFS/unshared
	log_must zfs set sharenfs=off $TESTPOOL/$TESTFS/unshared

	# create a filesystem that we can unshare
	log_must zfs create $TESTPOOL/$TESTFS/shared
	log_must zfs set sharenfs=on $TESTPOOL/$TESTFS/shared
fi


log_must zfs create -o version=1 $TESTPOOL/$TESTFS/version1
log_must zfs create -o version=1 $TESTPOOL/$TESTFS/allowed
log_must zfs allow everyone create $TESTPOOL/$TESTFS/allowed

if is_global_zone
then

	# Now create several virtual disks to test zpool with

	mkfile $MINVDEVSIZE $TEST_BASE_DIR/disk1.dat
	mkfile $MINVDEVSIZE $TEST_BASE_DIR/disk2.dat
	mkfile $MINVDEVSIZE $TEST_BASE_DIR/disk3.dat
	mkfile $MINVDEVSIZE $TEST_BASE_DIR/disk-additional.dat
	mkfile $MINVDEVSIZE $TEST_BASE_DIR/disk-export.dat
	mkfile $MINVDEVSIZE $TEST_BASE_DIR/disk-offline.dat
	mkfile $MINVDEVSIZE $TEST_BASE_DIR/disk-spare1.dat
	mkfile $MINVDEVSIZE $TEST_BASE_DIR/disk-spare2.dat

	# and create a pool we can perform attach remove replace,
	# etc. operations with
	log_must zpool create $TESTPOOL.virt mirror $TEST_BASE_DIR/disk1.dat \
	$TEST_BASE_DIR/disk2.dat $TEST_BASE_DIR/disk3.dat \
	$TEST_BASE_DIR/disk-offline.dat spare $TEST_BASE_DIR/disk-spare1.dat


	# Offline one of the disks to test online
	log_must zpool offline $TESTPOOL.virt $TEST_BASE_DIR/disk-offline.dat


	# create an exported pool to test import
	log_must zpool create $TESTPOOL.exported $TEST_BASE_DIR/disk-export.dat
	log_must zpool export $TESTPOOL.exported

	set -A props $POOL_PROPS
	set -A prop_vals $POOL_VALS
	typeset -i i=0

	while [[ $i -lt ${#props[*]} ]]
	do
		prop_name=${props[$i]}
		prop_val=${prop_vals[$i]}
		log_must zpool set $prop_name=$prop_val $TESTPOOL
		i=$(( $i + 1 ))
	done

	# copy a v1 pool from cli_root
	cp $STF_SUITE/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v1.dat.bz2 \
	    $TEST_BASE_DIR/
	log_must bunzip2 $TEST_BASE_DIR/zfs-pool-v1.dat.bz2
	log_must zpool import -d $TEST_BASE_DIR/ v1-pool
fi
log_pass