Mercurial > illumos > illumos-gate
comparison usr/src/test/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_common.kshlib @ 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 # | |
2 # CDDL HEADER START | |
3 # | |
4 # The contents of this file are subject to the terms of the | |
5 # Common Development and Distribution License (the "License"). | |
6 # You may not use this file except in compliance with the License. | |
7 # | |
8 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE | |
9 # or http://www.opensolaris.org/os/licensing. | |
10 # See the License for the specific language governing permissions | |
11 # and limitations under the License. | |
12 # | |
13 # When distributing Covered Code, include this CDDL HEADER in each | |
14 # file and include the License file at usr/src/OPENSOLARIS.LICENSE. | |
15 # If applicable, add the following below this CDDL HEADER, with the | |
16 # fields enclosed by brackets "[]" replaced with your own identifying | |
17 # information: Portions Copyright [yyyy] [name of copyright owner] | |
18 # | |
19 # CDDL HEADER END | |
20 # | |
21 | |
22 # | |
23 # Copyright 2007 Sun Microsystems, Inc. All rights reserved. | |
24 # Use is subject to license terms. | |
25 # | |
26 | |
27 # | |
28 # Copyright (c) 2012 by Delphix. All rights reserved. | |
29 # | |
30 | |
31 . $STF_SUITE/include/libtest.shlib | |
32 . $STF_SUITE/tests/functional/cli_root/zfs_destroy/zfs_destroy.cfg | |
33 | |
34 # | |
35 # Create or recover a set of test environment which include ctr, vol, fs, | |
36 # snap & clone. It looks like the following. | |
37 # | |
38 # pool | |
39 # |ctr | |
40 # | |fs | |
41 # | | |fssnap | |
42 # | |vol | |
43 # | |volsnap | |
44 # |fsclone | |
45 # |volclone | |
46 # | |
47 # $1 indicate which dependent dataset need be created. Such as 'snap', 'clone'. | |
48 # | |
49 function setup_testenv #[dtst] | |
50 { | |
51 typeset dtst=$1 | |
52 | |
53 if ! datasetexists $CTR; then | |
54 log_must $ZFS create $CTR | |
55 fi | |
56 if ! datasetexists $FS; then | |
57 log_must $ZFS create $FS | |
58 fi | |
59 # Volume test is only availible on globle zone | |
60 if ! datasetexists $VOL && is_global_zone; then | |
61 log_must $ZFS create -V $VOLSIZE $VOL | |
62 | |
63 $ECHO "y" | $NEWFS /dev/zvol/dsk/$VOL > /dev/null 2>&1 | |
64 if (( $? == 0 )); then | |
65 log_note "SUCCESS: $NEWFS /dev/zvol/dsk/$VOL>/dev/null" | |
66 else | |
67 log_fail "$NEWFS /dev/zvol/dsk/$VOL > /dev/null" | |
68 fi | |
69 | |
70 if [[ ! -d $TESTDIR1 ]]; then | |
71 log_must $MKDIR $TESTDIR1 | |
72 fi | |
73 log_must $MOUNT /dev/zvol/dsk/$VOL $TESTDIR1 | |
74 fi | |
75 | |
76 if [[ $dtst == snap || $dtst == clone ]]; then | |
77 if ! datasetexists $FSSNAP; then | |
78 log_must $ZFS snapshot $FSSNAP | |
79 fi | |
80 if ! datasetexists $VOLSNAP && is_global_zone; then | |
81 log_must $ZFS snapshot $VOLSNAP | |
82 fi | |
83 fi | |
84 | |
85 if [[ $dtst == clone ]]; then | |
86 if ! datasetexists $FSCLONE; then | |
87 log_must $ZFS clone $FSSNAP $FSCLONE | |
88 fi | |
89 if ! datasetexists $VOLCLONE && is_global_zone; then | |
90 log_must $ZFS clone $VOLSNAP $VOLCLONE | |
91 fi | |
92 fi | |
93 } | |
94 | |
95 # Clean up the testing environment | |
96 # | |
97 function cleanup_testenv | |
98 { | |
99 if is_global_zone && ismounted "$TESTDIR1" "ufs" ; then | |
100 log_must $UMOUNT -f $TESTDIR1 | |
101 fi | |
102 if [[ -d $TESTDIR1 ]]; then | |
103 log_must $RM -rf $TESTDIR1 | |
104 fi | |
105 | |
106 $PKILL $MKBUSY | |
107 | |
108 if datasetexists $CTR; then | |
109 log_must $ZFS destroy -Rf $CTR | |
110 fi | |
111 } | |
112 | |
113 # | |
114 # Delete volume and related datasets from list, if the test cases was | |
115 # runing in local zone. Then check them are existed or non-exists. | |
116 # | |
117 # $1 function name | |
118 # $2-n datasets name | |
119 # | |
120 function check_dataset | |
121 { | |
122 typeset funname=$1 | |
123 typeset newlist="" | |
124 typeset dtst | |
125 shift | |
126 | |
127 for dtst in "$@"; do | |
128 # Volume and related stuff are unvailable in local zone | |
129 if ! is_global_zone; then | |
130 if [[ $dtst == $VOL || $dtst == $VOLSNAP || \ | |
131 $dtst == $VOLCLONE ]] | |
132 then | |
133 continue | |
134 fi | |
135 fi | |
136 newlist="$newlist $dtst" | |
137 done | |
138 | |
139 if (( ${#newlist} != 0 )); then | |
140 # Run each item in $newlist individually so on failure, the | |
141 # probelmatic dataset is listed in the logs. | |
142 for i in $newlist; do | |
143 log_must $funname $i | |
144 done | |
145 fi | |
146 } |