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 # runtests.ksh - control program for domain tests. This script sets up a
28 # basic environment where the other test scripts run. Below is the
29 # configuration of the environment("Yes" means it is set; otherwise
30 # "No"):
31 #
32 # NFSMAPID_DOMAIN DNS TXT RR DNS domain NIS domain
33 # =============== ============== ========== ==========
34 # Yes Yes Yes Yes
35 #
36
37 [[ -n "$DEBUG" ]] && [[ $DEBUG != 0 ]] && set -x
38
39 # set up script execution environment
40 . ./dom_env
41
42 function cleanup
43 {
44 # restore nfscfg_domain_tmout in /usr/lib/nfs/nfsmapid
45 [[ $is_tmout_changed == 1 ]] && echo "nfscfg_domain_tmout?W 0t300" \
46 | mdb -w /usr/lib/nfs/nfsmapid > /dev/null
47
48 # restore system files and services
49 restore_state -c STATE_INITIAL
50 }
51
52 trap "cleanup" EXIT
53 trap "exit 1" HUP INT QUIT PIPE TERM
54
55 # should run as root
56 EXEC=""
57 id | grep "0(root)" > /dev/null 2>&1
58 if [[ $? != 0 ]]; then
59 EXEC="/suexec"
60 fi
61
62 # save current system state
63 save_state STATE_INITIAL >$LOGFILE 2>&1
64 ckreturn $? "$NAME{setup}: failed to save system state" $LOGFILE "UNINITIATED" \
65 || exit $UNINITIATED
66
67 # get a list of kornshell scripts
68 TESTLIST=${TESTLIST:-$(egrep -v "^#|^ *$" domain.flist)}
69
70 # check for cipso support
71 HOST=$(uname -n | cut -d. -f1)
72 is_cipso "vers=4" $HOST
73 if [[ $? == $CIPSO_NFSV4 ]]; then
74 for t in $TESTLIST
75 do
76 echo "$t{all_tests}: DNS UNSUPPORTED under CIPSO Trusted Extensions"
77 echo "\tTest UNSUPPORTED"
78 done
79 exit 0
80 fi
81
82 # setup DNS server on client
83 ./dnscfg >$LOGFILE 2>&1
84 ckreturn $? "$NAME{setup}: failed to set up dns server" $LOGFILE "UNINITIATED" \
85 || exit $UNINITIATED
86
87 dns_domain=$(get_domain_resolv 2>$LOGFILE)
88 ckreturn $? "NAME{setup}: failed to get DNS domain" $LOGFILE "UNINITIATED" \
89 || exit $UNINITIATED
90
91 txt_rr=$(get_domain_txt_record $dns_domain 2>$LOGFILE)
92 ckreturn $? "NAME{setup}: failed to get text RR from local DNS server" $LOGFILE\
93 "UNINITIATED" || exit $UNINITIATED
94
95 dns_server=$(uname -n | cut -d. -f1)
96
97 # If IPv6 is being used, force the server name name to be its IPv4 address.
98 # As DNS accesses used here are not going OTW, so there is no loss of coverage.
99 # See 5044318 and 5050132
100 getent ipnodes $dns_server 2>/dev/null | grep $dns_server \
101 | grep ':' >/dev/null 2>&1
102 [[ $? == 0 ]] && dns_server=$(getent hosts $dns_server | awk '{print $1}')
103
104 echo "\nSet up DNS server on $dns_server for domain $dns_domain," \
105 "the value for _nfsv4idmapdomain is $txt_rr."
106
107 # second DNS server
108 second_dns_server_info=$(get_second_dns_server)
109 [[ $? == 0 ]] && second_dns_server_available=1
110 if [[ $second_dns_server_available == 1 ]]; then
111 second_dns_server=$(echo $second_dns_server_info | cut -d' ' -f1)
112 second_dns_domain=$(echo $second_dns_server_info | cut -d' ' -f2)
113 second_txt_rr=$(echo $second_dns_server_info | cut -d' ' -f3)
114
115 echo "\nUse the second DNS server on $second_dns_server," \
116 "its domain is $second_dns_domain," \
117 "the value for _nfsv4idmapdomain is $second_txt_rr."
118 fi
119
120 # modify /etc/default/nfs to set NFSMAPID_DOMAIN
121 nfsfile_domain=domain.from.nfsfile
122 chg_domain_default_nfs $nfsfile_domain
123 mapid_service restart $TIMEOUT "failed to restart mapid service" \
124 "UNINITIATED" || exit $UNINITIATED
125
126 # get NIS domain
127 nis_domain=$(get_domain_domainname)
128
129 # change nfscfg_domain_tmout value to reduce assertion execution time
130 DOMAIN_TMOUT=${DOMAIN_TMOUT:-10}
131 echo "nfscfg_domain_tmout?W 0t$DOMAIN_TMOUT" | mdb -w /usr/lib/nfs/nfsmapid \
132 > $LOGFILE 2>&1
133 mapid_service restart $TIMEOUT "failed to restart mapid service" \
134 "WARNING"
135 curval=$(echo "nfscfg_domain_tmout/D" | \
136 mdb -p $(pgrep -z `zonename` -x nfsmapid) | \
137 tail -1 | nawk '{print $2}')
138 if [[ $curval == $DOMAIN_TMOUT ]]; then
139 is_tmout_changed=1
140 echo "\nnfscfg_domain_tmout is $DOMAIN_TMOUT seconds."
141 else
142 is_tmout_changed=0
143 echo "\nWARNING: failed to change nfscfg_domain_tmout," \
144 "you are probably in sparse root zone."
145 [[ "$DEUBG" == 1 ]] && cat $LOGFILE
146 echo "\nCurrent zone: $(zonename), nfscfg_domain_tmout: $curval seconds"
147 fi
148 rm $LOGFILE
149
150 # export variables to test cases
151 export dns_server dns_domain txt_rr second_dns_server second_dns_domain \
152 second_txt_rr nfsfile_domain nis_domain
153
154 export LD_LIBRARY_PATH=/usr/lib/nfs
155
156 # Start the tests with some information
157 echo " "
158 echo "Testing at CLIENT=[$CLIENT] with dns server setup at [$dns_server]"
159 echo "Started DOMAIN tests at [`date`] ..."
160 echo " "
161
162 save_state STATE_DOMAIN_TEST
163
164 for t in $TESTLIST
165 do
166 ${EXEC} ./$t
167 st=$?
168 if [[ $st != $PASS ]] && [[ $st != $FAIL ]]; then
169 echo "\n$t{remaining_tests}: unexpected tests termination"
170 echo "\tTest $(rc2str $st): $t terminated with status $st\n"
171 fi
172 restore_state STATE_DOMAIN_TEST
173 done
174
175 clear_state STATE_DOMAIN_TEST
176
177 echo " "
178 echo "Testing ends at [`date`]."
179 echo " "
180
181 exit 0