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 2006 Sun Microsystems, Inc. All rights reserved.
25 # Use is subject to license terms.
26 #
27 # nfsmapid03.sh - nfsmapid tests for the following configuration:
28 #
29 # NFSMAPID_DOMAIN DNS TXT RR DNS domain NIS domain
30 # =============== ============== ========== ==========
31 # No No Yes Yes
32 #
33 # Note that there are two ways to do the "DNS TXT RR not available" set up.
34 # One is to remove the TXT RR string in named configuration files, another way
35 # is to shutdown DNS server. Both of these two ways are used in test cases in
36 # this file.
37 #
38
39 [[ -n "$DEBUG" ]] && [[ $DEBUG != 0 ]] && set -x
40
41 # set up script execution environment
42 . ./dom_env
43
44 # should run as root
45 is_root "$NAME{setup}:" "All tests for domain affected"
46
47 # get timeout value nfsmapid uses for domain checking
48 nfsdomain_tmout=$(get_nfsmapid_domain_tout_wrapper)
49
50 # comment out NFSMAPID_DOMAIN string in /etc/default/nfs
51 comm_domain_default_nfs
52
53 # modify /var/named/dns.test.nfs.master to remove TXT RR
54 chg_txt_field_dns /var/named/dns.test.nfs.master dummy=none
55
56 # restart DNS server
57 dns_service restart $TIMEOUT "failed to restart dns service" \
58 "UNRESOLVED" || exit $UNRESOLVED
59
60 # refresh nfsmapid server
61 mapid_service refresh $TIMEOUT "failed to refresh mapid service" \
62 "UNRESOLVED" || exit $UNRESOLVED
63
64 # assertion list
65 ASSERTIONS=${ASSERTIONS:-"a b c d"}
66
67 # generate assertion descriptions
68 gen_assert_desc $NAME "as_"
69
70 #
71 # Assertion definition
72 #
73
74 # as_a: No domain in /etc/default/nfs, DNS up, no TXT RR, get domain from
75 # /etc/resolv.conf
76 function as_a {
77 [[ -n "$DEBUG" ]] && [[ $DEBUG != 0 ]] && set -x
78
79 exp=$dns_domain
80 assertion a "$(get_assert_desc a)" $exp
81
82 # Get mapid domain
83 act=$(get_nfsmapid_domain)
84
85 # Check Assertion
86 ckres2 "get_nfsmapid_domain" "$act" "$exp" "domains differ" \
87 || return $FAIL
88 }
89
90 # as_b1: Current domain is from /etc/default/nfs, change DNS domain to
91 # an invalid value, use the new DNS domain value after
92 # nfscfg_domain_tmout timer expires
93 # as_b2: DNS domain changes back to a valid value, read the new DNS domain
94 # value and connect to the server to get TXT RR after nfscfg_domain_tmout
95 # timer expires
96 #
97 # Nfsmapid has a daemon thread to check domain configuration changes on the
98 # system periodically(300 seconds by default). When it reads domain from
99 # /etc/default/nfs or /etc/resolv.conf files, it check those files' mtime
100 # first. If mtime wasn't changed, it just uses the cahced value; otherwise,
101 # it reads the new value from those files.
102 #
103 # If DNS domain changes(as happend in above case), nfsmapid will connect to
104 # the server to get the appropriate TXT RR, and use that as domain value.
105 #
106 # Test cases b1 and b2 tests the above behaviors.
107 function as_b {
108 [[ -n "$DEBUG" ]] && [[ $DEBUG != 0 ]] && set -x
109
110 #
111 # Assertion b1
112 #
113
114 new_dns_domain="new.domain.for.test"
115 exp=$new_dns_domain
116 assertion b1 "$(get_assert_desc b1)" $exp
117
118 # Setup: change DNS domain to an invalid value
119 chg_domain_dns $new_dns_domain
120
121 # Wait for timeout and get mapid domain
122 sleep $nfsdomain_tmout
123 act=$(get_nfsmapid_domain)
124
125 # Check Assertion
126 ckres2 "get_nfsmapid_domain" "$act" "$exp" \
127 "domains differ; $NAME{b2} skipped" || return $FAIL
128
129 #
130 # Assertion b2
131 #
132
133 exp=$txt_rr
134 assertion b2 "$(get_assert_desc b2)" $exp
135
136 # Setup: change DNS domain back to a valid value, and add TXT RR
137 chg_domain_dns $dns_domain
138 chg_txt_field_dns /var/named/dns.test.nfs.master $txt_rr
139 dns_service restart $TIMEOUT "failed to restart dns service" \
140 "UNRESOLVED" || return $UNRESOLVED
141
142 # Wait for timeout and get mapid domain
143 sleep $nfsdomain_tmout
144 act=$(get_nfsmapid_domain)
145
146 # Check Assertion
147 ckres2 "get_nfsmapid_domain" "$act" "$exp" "domains differ" \
148 || return $FAIL
149 }
150
151 # as_c1: No domain in /etc/default/nfs, DNS down, get domain from
152 # /etc/resolv.conf
153 # as_c2: Then DNS up, use TXT RR as domain after 35 seconds
154 #
155 # If DNS is configured but the DNS server doesn't respond, nfsmapid starts
156 # a thread to check that every 30 seconds. This test case is designed to
157 # test the polling behavior.
158 function as_c {
159 [[ -n "$DEBUG" ]] && [[ $DEBUG != 0 ]] && set -x
160
161 #
162 # Assertion c1
163 #
164
165 exp=$dns_domain
166 assertion c1 "$(get_assert_desc c1)" $exp
167
168 # Setup: disable DNS service
169 dns_service disable $TIMEOUT "failed to disable dns service" \
170 "UNRESOLVED" || return $UNRESOLVED
171
172 # Get mapid domain
173 mapid_service refresh $TIMEOUT "failed to refresh mapid service" \
174 "UNRESOLVED" || return $UNRESOLVED
175 act=$(get_nfsmapid_domain)
176
177 # Check Assertion
178 ckres2 "get_nfsmapid_domain" "$act" "$exp" \
179 "domains differ; $NAME{c2} skipped" || return $FAIL
180
181 #
182 # Assertion c2
183 #
184
185 exp=$txt_rr
186 assertion c2 "$(get_assert_desc c2)" $exp
187
188 # Setup: set TXT RR value and enable DNS service
189 chg_txt_field_dns /var/named/dns.test.nfs.master $txt_rr
190 dns_service enable $TIMEOUT "failed to enable dns service" \
191 "UNRESOLVED" || return $UNRESOLVED
192
193 # Get mapid domain
194 sleep 35
195 act=$(get_nfsmapid_domain)
196
197 # Check Assertion
198 ckres2 "get_nfsmapid_domain" "$act" "$exp" "domains differ" \
199 || return $FAIL
200 }
201
202 # as_d1: No domain in /etc/default/nfs, DNS up, no TXT RR, wait until
203 # nfscfg_domain_tmout timer expires, get domain from DNS domain,
204 # cache is off
205 # as_d2: Then add TXT RR and restart DNS server, wait until
206 # nfscfg_domain_tmout timer expires, get domain from TXT RR, cache is on
207 function as_d {
208 [[ -n "$DEBUG" ]] && [[ $DEBUG != 0 ]] && set -x
209
210 #
211 # Assertion d1
212 #
213
214 exp=0
215 assertion d1 "$(get_assert_desc d1)" $exp
216
217 # Get mapid domain
218 sleep $nfsdomain_tmout
219 act=$(get_dns_txt_cache_flag)
220 domain=$(get_nfsmapid_domain)
221
222 # First check cache
223 ckres2 -s "get_dns_txt_cache_flag" "$act" "$exp" \
224 "cache should be off; $NAME{d2} skipped" || return $FAIL
225
226 # Then check domain
227 ckres2 "get_nfsmapid_domain" "$domain" "$dns_domain" \
228 "domains differ; $NAME{d2} skipped" || return $FAIL
229
230 #
231 # Assertion d2
232 #
233
234 exp=1
235 assertion d2 "$(get_assert_desc d2)" $exp
236
237 # Setup: set TXT RR and restart DNS server
238 chg_txt_field_dns /var/named/dns.test.nfs.master $txt_rr
239 dns_service restart $TIMEOUT "failed to restart dns service" \
240 "UNRESOLVED" || return $UNRESOLVED
241
242 # Get mapid domain
243 sleep $nfsdomain_tmout
244 act=$(get_dns_txt_cache_flag)
245 domain=$(get_nfsmapid_domain)
246
247 # First check cache
248 ckres2 -s "get_dns_txt_cache_flag" "$act" "$exp" "cache should be off" \
249 || return $FAIL
250
251 # Then check domain
252 ckres2 "get_nfsmapid_domain" "$domain" "$txt_rr" "domains differ" \
253 || return $FAIL
254 }
255
256 # Run assertions
257 #
258
259 save_state STATE_NFSMAPID03
260
261 echo "\nNFSMAPID03 Starting Assertions\n"
262
263 for i in $ASSERTIONS
264 do
265 eval as_${i} || print_state
266 restore_state STATE_NFSMAPID03
267 done
268
269 clear_state STATE_NFSMAPID03
270
271 echo "\nNFSMAPID03 assertions finished!\n"