comparison usr/src/test/zfs-tests/tests/functional/cli_root/zfs_unshare/zfs_unshare_001_pos.ksh @ 13899:0bcf78798346

3311 Want a test framework for arbitrary OS unit tests 3312 Add a testrunner package for OS unit tests 3313 Add a testrunner package to convert ZFS tests from STF Reviewed by: Matt Ahrens <matthew.ahrens@delphix.com> Reviewed by: Will Guyette <will.guyette@delphix.com> Reviewed by: Dan Kimmel <dan.kimmel@delphix.com> Reviewed by: Adam Leventhal <ahl@delphix.com> Reviewed by: Henrik Mattson <henrik.mattson@delphix.com> Reviewed by: Sonu Pillai <sonu.pillai@delphix.com> Reviewed by: Christopher Siden <chris.siden@delphix.com> Reviewed by: George Wilson <george.wilson@delphix.com> Reviewed by: Richard Lowe <richlowe@richlowe.net> Approved by: Richard Lowe <richlowe@richlowe.net>
author John Wren Kennedy <john.kennedy@delphix.com>
date Wed, 05 Dec 2012 22:04:50 -0500
parents
children
comparison
equal deleted inserted replaced
13898:7f822b09519b 13899:0bcf78798346
1 #!/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 2007 Sun Microsystems, Inc. All rights reserved.
25 # Use is subject to license terms.
26 #
27
28 . $STF_SUITE/include/libtest.shlib
29
30 #
31 # DESCRIPTION:
32 # Verify that 'zfs unshare <filesystem|mountpoint>' unshares a given shared
33 # filesystem.
34 #
35 # STRATEGY:
36 # 1. Share filesystems
37 # 2. Invoke 'zfs unshare <filesystem|mountpoint>' to unshare zfs file system
38 # 3. Verify that the file system is unshared
39 # 4. Verify that unsharing an unshared file system fails
40 # 5. Verify that "zfs unshare -a" succeeds to unshare all zfs file systems.
41 #
42
43 verify_runnable "global"
44
45 function cleanup
46 {
47 typeset -i i=0
48 while (( i < ${#mntp_fs[*]} )); do
49 log_must $ZFS set sharenfs=off ${mntp_fs[((i+1))]}
50
51 ((i = i + 2))
52 done
53
54 if mounted $TESTPOOL/$TESTCLONE; then
55 log_must $ZFS unmount $TESTDIR2
56 fi
57
58 [[ -d $TESTDIR2 ]] && \
59 log_must $RM -rf $TESTDIR2
60
61 if datasetexists "$TESTPOOL/$TESTCLONE"; then
62 log_must $ZFS destroy -f $TESTPOOL/$TESTCLONE
63 fi
64
65 if snapexists "$TESTPOOL/$TESTFS2@snapshot"; then
66 log_must $ZFS destroy -f $TESTPOOL/$TESTFS2@snapshot
67 fi
68
69 if datasetexists "$TESTPOOL/$TESTFS2"; then
70 log_must $ZFS destroy -f $TESTPOOL/$TESTFS2
71 fi
72 }
73
74 #
75 # Main test routine.
76 #
77 # Given a mountpoint and file system this routine will attempt
78 # unshare the filesystem via <filesystem|mountpoint> argument
79 # and then verify it has been unshared.
80 #
81 function test_unshare # <mntp> <filesystem>
82 {
83 typeset mntp=$1
84 typeset filesystem=$2
85 typeset prop_value
86
87 prop_value=$(get_prop "sharenfs" $filesystem)
88
89 if [[ $prop_value == "off" ]]; then
90 not_shared $mntp ||
91 log_must $UNSHARE -F nfs $mntp
92 log_must $ZFS set sharenfs=on $filesystem
93 is_shared $mntp || \
94 log_fail "'$ZFS set sharenfs=on' fails to make" \
95 "file system $filesystem shared."
96 fi
97
98 is_shared $mntp || log_must $ZFS share $filesystem
99
100 #
101 # Verify 'zfs unshare <filesystem>' works as well.
102 #
103 log_must $ZFS unshare $filesystem
104 not_shared $mntp || log_fail "'zfs unshare <filesystem>' fails"
105
106 log_must $ZFS share $filesystem
107
108 log_must $ZFS unshare $mntp
109 not_shared $mntp || log_fail "'zfs unshare <mountpoint>' fails"
110
111 log_note "Unsharing an unshared file system fails."
112 log_mustnot $ZFS unshare $filesystem
113 log_mustnot $ZFS unshare $mntp
114 }
115
116 set -A mntp_fs \
117 "$TESTDIR" "$TESTPOOL/$TESTFS" \
118 "$TESTDIR1" "$TESTPOOL/$TESTCTR/$TESTFS1" \
119 "$TESTDIR2" "$TESTPOOL/$TESTCLONE"
120
121 log_assert "Verify that 'zfs unshare [-a] <filesystem|mountpoint>' succeeds as root."
122 log_onexit cleanup
123
124 log_must $ZFS create $TESTPOOL/$TESTFS2
125 log_must $ZFS snapshot $TESTPOOL/$TESTFS2@snapshot
126 log_must $ZFS clone $TESTPOOL/$TESTFS2@snapshot $TESTPOOL/$TESTCLONE
127 log_must $ZFS set mountpoint=$TESTDIR2 $TESTPOOL/$TESTCLONE
128
129 #
130 # Invoke 'test_unshare' routine to test 'zfs unshare <filesystem|mountpoint>'.
131 #
132 typeset -i i=0
133 while (( i < ${#mntp_fs[*]} )); do
134 test_unshare ${mntp_fs[i]} ${mntp_fs[((i + 1 ))]}
135
136 ((i = i + 2))
137 done
138
139 log_note "Verify '$ZFS unshare -a' succeds as root."
140
141 i=0
142 typeset sharenfs_val
143 while (( i < ${#mntp_fs[*]} )); do
144 sharenfs_val=$(get_prop "sharenfs" ${mntp_fs[((i+1))]})
145 if [[ $sharenfs_val == "on" ]]; then
146 not_shared ${mntp_fs[i]} && \
147 log_must $ZFS share ${mntp_fs[((i+1))]}
148 else
149 log_must $ZFS set sharenfs=on ${mntp_fs[((i+1))]}
150 is_shared ${mntp_fs[i]} || \
151 log_fail "'$ZFS set sharenfs=on' fails to share filesystem."
152 fi
153
154 ((i = i + 2))
155 done
156
157 #
158 # test 'zfs unshare -a '
159 #
160 log_must $ZFS unshare -a
161
162 #
163 # verify all shared filesystems become unshared
164 #
165 i=0
166 while (( i < ${#mntp_fs[*]} )); do
167 not_shared ${mntp_fs[i]} || \
168 log_fail "'$ZFS unshare -a' fails to unshare all shared zfs filesystems."
169
170 ((i = i + 2))
171 done
172
173 log_pass "'$ZFS unshare [-a] <filesystem|mountpoint>' succeeds as root."