1 #! /usr/bin/ksh -p
2 #
3 # Copyright 2009 Sun Microsystems, Inc. All rights reserved.
4 # Use is subject to license terms.
5 #
6
7 #
8 # BSD 3 Clause License
9 #
10 # Redistribution and use in source and binary forms, with or without
11 # modification, are permitted provided that the following conditions
12 # are met:
13 # - Redistributions of source code must retain the above copyright
14 # notice, this list of conditions and the following disclaimer.
15 #
16 # - Redistributions in binary form must reproduce the above copyright
17 # notice, this list of conditions and the following disclaimer in
18 # the documentation and/or other materials provided with the
19 # distribution.
20 #
21 # - Neither the name of Sun Microsystems, Inc. nor the
22 # names of its contributors may be used to endorse or promote products
23 # derived from this software without specific prior written permission.
24 #
25 # THIS SOFTWARE IS PROVIDED BY SUN MICROSYSTEMS, INC. "AS IS" AND ANY
26 # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
27 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
28 # DISCLAIMED. IN NO EVENT SHALL SUN MICROSYSTEMS, INC. BE LIABLE FOR ANY
29 # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
30 # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES
31 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
32 # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
34 # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 #
36
37 #
38 # Create the configuration file based on passed in variables
39 # or those set in the tetexec.cfg file.
40 #
41 #
42 # Copyright 2015 Nexenta Systems, Inc. All rights reserved.
43 #
44
45 tet_startup="startup"
46 tet_cleanup=""
47
48 iclist="ic1 ic2"
49 ic1="createconfig"
50 ic2="unconfigure"
51
52 #
53 # In order to complete the creation of the config file
54 # - create directory if needed
55 # - confirm ability to create file
56 # - parse the share_disk variable and create the appropriate entries.
57 # - Add the comment
58 # - Add device entries to the config file
59 #
60 createconfig()
61 {
62 #
63 # Check to see if the configure file variable is not set,
64 # and if not the set to the default value
65 #
66 if [[ -z $configfile ]]
67 then
68 configfile=${CTI_SUITE}/config/test_config
69 fi
70
71 #
72 # set the config file template variable to the test_config
73 # template file.
74 #
75 configfile_tmpl=${CTI_SUITE}/config/test_config.tmpl
76
77 #
78 # Commented code will be used if required in future
79 #
80 :'if [ -f $configfile ]
81 then
82 tet_infoline "Test Suite already configured."
83 tet_infoline "to unconfigure the test suite use :"
84 tet_infoline " run_test ndmp unconfigure"
85 tet_infoline " or supply an alternate config file name by using :"
86 tet_infoline " run_test -v config file=<filename> ndmp configure"
87 return
88 else
89 touch ${configfile}
90 if [ $? -ne 0 ]
91 then
92 tet_infoline "Could not create the configuration file"
93 return
94 fi
95 rm -f ${configfile}
96 fi
97 '
98 touch ${configfile}
99
100 if [ ! -f $configfile_tmpl ]
101 then
102 tet_infoline "There is no template config file to create config from."
103 tet_result FAIL
104 return
105 fi
106
107 exec 3<$configfile_tmpl
108 while :
109 do
110 read -u3 line
111 if [[ $? = 1 ]]
112 then
113 break
114 fi
115 if [[ "$line" = *([ ]) || "$line" = *([ ])#* ]]
116 then
117 echo $line
118 continue
119 fi
120
121 variable_name=`echo $line | awk -F= '{print $1}'`
122 eval variable_value=\${$variable_name}
123 if [[ -z $variable_value ]]
124 then
125 echo "$line"
126 else
127 echo $variable_name=$variable_value
128 fi
129 done > $configfile
130
131 tet_infoline "Created $configfile"
132 tet_result PASS
133 }
134
135 #
136 # NAME
137 # unconfig_test_suite
138 #
139 # DESCRIPTION
140 # The test purpose the test suite calls to un-initialize and
141 # configure the test suite.
142 #
143 unconfigure() {
144 #
145 # Check to see if the configure file variable is not set,
146 # and if not the set to the default value
147 #
148 if [[ -z $configfile ]]
149 then
150 configfile=${CTI_SUITE}/config/test_config
151 fi
152
153 #
154 # Remove the configuration file provided, and verify the results
155 # of the file removal.
156 #
157 rm -f $configfile
158 if [ $? -eq 0 ]
159 then
160 tet_infoline "PASS - $configfile removed."
161 tet_result PASS
162 else
163 tet_infoline "FAIL - unable to remove $configfile"
164 tet_result FAIL
165 fi
166 }
167
168 startup()
169 {
170 tet_infoline "Create config file $configfile"
171 }
172
173 #. ${TET_SUITE_ROOT}/share/lib/share_common
174
175 . ${TET_ROOT}/common/lib/ctiutils.ksh
176 . ${TET_ROOT}/lib/ksh/tcm.ksh