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 # nfsmapid01.sh - nfsmapid tests for the following configuration:
  28 #
  29 #       NFSMAPID_DOMAIN   DNS TXT RR      DNS domain  NIS domain
  30 #       ===============   ==============  ==========  ==========
  31 #       Yes               Yes             Yes         Yes
  32 #
  33 
  34 [[ -n "$DEBUG" ]] && [[ $DEBUG != 0 ]] && set -x
  35 
  36 # set up script execution environment
  37 . ./dom_env
  38 
  39 # should run as root
  40 is_root "$NAME{setup}:" "All tests for domain affected"
  41 
  42 # get timeout value nfsmapid uses for domain checking
  43 nfsdomain_tmout=$(get_nfsmapid_domain_tout_wrapper)
  44 
  45 # assertion list
  46 ASSERTIONS=${ASSERTIONS:-"a b c d"}
  47 
  48 # generate assertion descriptions
  49 gen_assert_desc $NAME "as_"
  50 
  51 #
  52 # Assertion definition
  53 #
  54 
  55 # as_a: TXT RR present, get domain from /etc/default/nfs
  56 function as_a {
  57         [[ -n "$DEBUG" ]] && [[ $DEBUG != 0 ]] && set -x
  58 
  59         exp=$nfsfile_domain
  60         assertion a "$(get_assert_desc a)" $exp
  61 
  62         # Get mapid domain
  63         mapid_service refresh $TIMEOUT "failed to refresh mapid service" \
  64             "UNRESOLVED" || return $UNRESOLVED
  65         act=$(get_nfsmapid_domain)
  66 
  67         # check assertion
  68         ckres2 "get_nfsmapid_domain" "$act" "$exp" "domains differ" \
  69             || return $FAIL
  70 }
  71 
  72 # as_b: No TXT record, get domain from /etc/default/nfs
  73 function as_b {
  74         [[ -n "$DEBUG" ]] && [[ $DEBUG != 0 ]] && set -x
  75 
  76         exp=$nfsfile_domain
  77         assertion b "$(get_assert_desc b)" $exp
  78 
  79         # Setup: 
  80         #    - remove TXT RR in dns.nfs.test.mater file and restart dns server 
  81         chg_txt_field_dns /var/named/${dns_domain}.master dummy=none
  82         dns_service restart $TIMEOUT "failed to restart dns service"\
  83             "UNRESOLVED" || return $UNRESOLVED
  84 
  85         # Get mapid domain
  86         mapid_service refresh $TIMEOUT "failed to refresh mapid service" \
  87             "UNRESOLVED" || return $UNRESOLVED
  88         act=$(get_nfsmapid_domain)
  89 
  90         # Check assertion
  91         ckres2 "get_nfsmapid_domain" "$act" "$exp" "domains differ" \
  92             || return $FAIL
  93 }
  94 
  95 
  96 # as_c: DNS down, get domain from /etc/default/nfs
  97 function as_c {
  98         [[ -n "$DEBUG" ]] && [[ $DEBUG != 0 ]] && set -x
  99 
 100         exp=$(get_domain_default_nfs)
 101         assertion c "$(get_assert_desc c)" $exp
 102 
 103         # Setup:
 104         #    - shut down dns server(no access to txt record)
 105         dns_service disable $TIMEOUT "failed to disable dns service" \
 106             "UNRESOLVED" || return $UNRESOLVED
 107 
 108         # Get mapid domain
 109         mapid_service refresh $TIMEOUT "failed to refresh mapid service" \
 110             "UNRESOLVED" || return $UNRESOLVED
 111         act=$(get_nfsmapid_domain)
 112 
 113         # Check assertion
 114         ckres2 "get_nfsmapid_domain" "$act" "$exp" "domains differ" \
 115             || return $FAIL
 116 }
 117 
 118 # as_d1: Remove domain from /etc/default/nfs, get domain from TXT RR after
 119 #       nfscfg_domain_tmout timer expires
 120 # as_d2: Add domain in /etc/default/nfs, get domain from that file again
 121 #       after nfscfg_domain_tmout timer expires
 122 # 
 123 # nfsmapid has a daemon thread to handle SIGHUP and SIGTERM. This thread also
 124 # has a timer for checking system configuration changes. If no signals arrives 
 125 # when the timer expires, nfsmapid will call check_domain() to re-calculate
 126 # nfs domain.
 127 #
 128 # Testcase {d1} and {d2} test the above the above timeout behavior.
 129 function as_d {
 130         [[ -n "$DEBUG" ]] && [[ $DEBUG != 0 ]] && set -x
 131 
 132         #
 133         # Assertion {d1}
 134         #
 135         exp=$txt_rr
 136         assertion d1 "$(get_assert_desc d1)" $exp
 137 
 138         # Setup:
 139         #    - comment out MAPID_DOMAIN entry in /etc/default/nfs
 140         comm_domain_default_nfs
 141 
 142         # Wait for timeout and then get mapid domain
 143         sleep $nfsdomain_tmout
 144         act=$(get_nfsmapid_domain)
 145 
 146         # Check assertion
 147         ckres2 "get_nfsmapid_domain" "$act" "$exp" \
 148            "domains differ, $NAME{d2} skiped" /dev/null || return $FAIL
 149 
 150         #
 151         # Assertion {d2}
 152         #
 153 
 154         # restore /etc/default/nfs file
 155         uncomm_domain_default_nfs 
 156 
 157         exp=$nfsfile_domain
 158         assertion d2 "$(get_assert_desc d2)" $exp
 159 
 160         # Wait for timeout and then get mapid domain
 161         sleep $nfsdomain_tmout
 162         act=$(get_nfsmapid_domain)
 163 
 164         # Check assertion
 165         ckres2 "get_nfsmapid_domain" "$act" "$exp" "domains differ" \
 166             || return $FAIL
 167 }
 168 
 169 #
 170 # Run assertions
 171 #
 172 
 173 save_state STATE_NFSMAPID01
 174 
 175 echo "\nNFSMAPID01 Starting Assertions\n"
 176 
 177 for i in $ASSERTIONS
 178 do
 179         eval as_${i} || print_state
 180         restore_state STATE_NFSMAPID01
 181 done
 182 
 183 clear_state STATE_NFSMAPID01
 184 
 185 echo "\nNFSMAPID01 assertions finished!\n"