Home | History | Annotate | Download | only in nicdrv
      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 2009 Sun Microsystems, Inc.  All rights reserved.
     25 # Use is subject to license terms.
     26 #
     27 # ident	"@(#)configure.ksh	1.8	09/06/24 SMI"
     28 #
     29 
     30 . ${STF_TOOLS}/include/stf.kshlib
     31 . ${STF_SUITE}/include/common.kshlib
     32 
     33 
     34 
     35 #
     36 # failed to configure the test suite
     37 #
     38 fail()
     39 {
     40 	echo $1
     41 	recover_env
     42 	exit $STF_FAIL
     43 }
     44 
     45 #
     46 # enable smf service, and save them to a file($g_service_bak)
     47 # for unconfigure and recovery
     48 # $1 service name
     49 #
     50 enable_service()
     51 {
     52 	typeset service_name=$1
     53 	if [[ "$(svcs -Ho STA $service_name)" != "ON" ]]; then
     54 		echo "local $service_name" >> $g_service_bak	
     55 		exec_cmd "svcadm enable -r -s $service_name"
     56 	else
     57 		return 0	
     58 	fi
     59 }
     60 #
     61 # enable smf service on remote host
     62 #
     63 enable_remote_service()
     64 {
     65 	typeset host_name=$1
     66 	typeset service_name=$2
     67 	if [[ "$(rsh -n $host_name svcs -Ho STA $service_name)" != "ON" ]]; then
     68 		echo "remote $host_name $service_name" >> $g_service_bak	
     69 		exec_rshcmd $host_name "svcadm enable -r -s $service_name"
     70 	else
     71 		return 0	
     72 	fi
     73 }
     74 
     75 #
     76 # disable services in $g_service_bak file
     77 # In this file, each line is a service. 
     78 # The first column is either "local" or "remote"
     79 #
     80 restore_service()
     81 {
     82 	typeset service_name
     83 	for service_name in $(cat $g_service_bak | grep ^local |awk '{print $2}'); do
     84 		exec_cmd "svcadm disable $service_name"
     85 	done
     86 	cat $g_service_bak | grep ^remote |  while read line; do
     87 		typeset hostname=$(echo $line | awk '{print $2}')
     88 		service_name=$(echo $line | awk '{print $3}')
     89 		echo remote $hostname $service_name
     90 		exec_rshcmd $hostname "svcadm disable $service_name"
     91 	done
     92 	
     93 }
     94 
     95 #
     96 # Recover the system, if configuring is interrupted
     97 #
     98 recover_env() {
     99 	
    100 	if [ -f /etc/nsswitch.nicdrv ]; then
    101 		cp /etc/nsswitch.nicdrv /etc/nsswitch.conf
    102 		rm -f /etc/nsswitch.nicdrv
    103 	fi
    104 
    105 	if exec_rshcmd $RMT_HST "test -f /etc/nsswitch.nicdrv" >/dev/null ; then
    106 		exec_rshcmd $RMT_HST "cp /etc/nsswitch.nicdrv /etc/nsswitch.conf"
    107 		exec_rshcmd $RMT_HST "rm /etc/nsswitch.nicdrv" 
    108 	fi
    109 
    110 
    111 	if [ -f /etc/ftpd/ftpusers.nicdrv ]; then
    112 		cp /etc/ftpd/ftpusers.nicdrv /etc/ftpd/ftpusers
    113 		rm -f /etc/ftpd/ftpusers.nicdrv
    114 	fi
    115 
    116 	if exec_rshcmd $RMT_HST "test -f /etc/ftpd/ftpusers.nicdrv" > /dev/null ; then
    117 		exec_rshcmd $RMT_HST "cp /etc/ftpd/ftpusers.nicdrv /etc/ftpd/ftpusers"
    118 		exec_rshcmd $RMT_HST "rm -f /etc/ftpd/ftpusers.nicdrv"
    119 	fi
    120 
    121 	if [ -f $g_service_bak ]; then
    122 		restore_service && rm -f $g_service_bak
    123 	fi
    124 }
    125 
    126 check_netperf() {
    127 	bin_dir=`isainfo -n`
    128 	if [ -z $NETPERF_HOME ]; then
    129 		echo "not set NETPERF_HOME path,use default path"
    130 		NETPERF_HOME=${STF_TOOLS}/../SUNWstc-netperf2/bin/
    131 		echo "NETPERF_HOME=$NETPERF_HOME"
    132 	fi
    133 	if [ ! -f $NETPERF_HOME/$bin_dir/netperf ]; then
    134 		echo "Couldn't not find netperf tools, \
    135 			please verify it is installed in proper location."
    136 		exit ${STF_FAIL}
    137 	fi
    138 }
    139 
    140 #
    141 # Change root role for OpenSolaris release
    142 #
    143 change_role_mode() {
    144 	typeset ret1 ret2
    145 	grep OpenSolaris /etc/release > /dev/null
    146         ret1=$?
    147 	grep root::::type=role /etc/user_attr > /dev/null
    148         ret2=$?
    149 	if (( $ret1 == 0 && $ret2 == 0 )); then
    150 		exec_cmd "pfexec cp /etc/user_attr /etc/user_attr.nicdrv"
    151 		exec_cmd "pfexec rolemod -K type=normal root"
    152 	fi
    153 }
    154 
    155 change_role_mode
    156 
    157 #
    158 # Before configure system service, checking the host availability
    159 
    160 #
    161 
    162 check_host_alive $LOCAL_HST $RMT_HST
    163 if [ $? -ne 0 ]; then
    164         echo "The client isn't alive, Test FAIL!"
    165         exit ${STF_FAIL}
    166 else
    167         echo "The client is alive!"
    168 fi
    169 
    170 #
    171 # Check netperf tools on host computer
    172 #
    173 check_netperf
    174 
    175 #
    176 #capture Ctrl-C or kill signals
    177 #
    178 trap "recover_env; exit" 1 2 3 9 15
    179 
    180 #
    181 # Enable network services on local host and remote host
    182 #
    183 g_service_bak=$LOGDIR/svc.nicdrv
    184 
    185 if [[ ! -f $g_service_bak ]]; then
    186 	enable_service svc:/network/shell:default || fail
    187 	enable_service svc:/network/ftp:default || fail
    188 	enable_service svc:/network/nfs/client:default || fail
    189 
    190 	enable_remote_service $RMT_HST svc:/network/ftp:default || fail
    191 	enable_remote_service $RMT_HST svc:/network/nfs/client:default || fail
    192 fi
    193 
    194 
    195 #
    196 # Make sure the first name service should be hosts file
    197 #
    198 if [[ ! -f /etc/nsswitch.nicdrv ]]; then
    199 	exec_cmd "cp /etc/nsswitch.conf /etc/nsswitch.nicdrv"
    200 	exec_cmd "cp /etc/nsswitch.files /etc/nsswitch.conf"
    201 fi
    202 
    203 if exec_rshcmd $RMT_HST "test ! -f /etc/nsswitch.nicdrv" >/dev/null; then
    204 	exec_rshcmd $RMT_HST "cp /etc/nsswitch.conf /etc/nsswitch.nicdrv"
    205 	exec_rshcmd $RMT_HST "cp /etc/nsswitch.files /etc/nsswitch.conf"
    206 fi
    207 
    208 #
    209 # Make sure the root user can login ftp server
    210 #
    211 if [[ ! -f /etc/ftpd/ftpusers.nicdrv ]] ; then
    212 	exec_cmd "cp /etc/ftpd/ftpusers /etc/ftpd/ftpusers.nicdrv"
    213 	exec_cmd "sed '/^root/d' /etc/ftpd/ftpusers.nicdrv > /etc/ftpd/ftpusers"
    214 fi
    215 
    216 if exec_rshcmd $RMT_HST "test ! -f /etc/ftpd/ftpusers.nicdrv" > /dev/null; then
    217 	exec_rshcmd $RMT_HST "cp /etc/ftpd/ftpusers /etc/ftpd/ftpusers.nicdrv"
    218 	exec_rshcmd $RMT_HST "sed '/^root/d' /etc/ftpd/ftpusers.nicdrv \
    219 		> /etc/ftpd/ftpusers"
    220 fi
    221 
    222 #
    223 # Get all of the driver functions
    224 #
    225 if [ -f "$DRV_ALL_FUNC_LOG" ]; then
    226 	rm $DRV_ALL_FUNC_LOG
    227 fi
    228 dtrace -l -n ${TST_INT}::entry | awk '{print $4}' > $DRV_ALL_FUNC_LOG
    229 
    230 #
    231 # The ratio of the total run time of NICDRV
    232 # RUN_TIME = TIME / RUN_TIME_MULTIPLIER
    233 #
    234 RUN_TIME_MULTIPLIER=${RUN_TIME_MULTIPLIER:-1}
    235 case "$RUN_MODE" in
    236 	"WiFi")	RUN_TIME_MULTIPLIER=2;;
    237 	"LOW-END")	RUN_TIME_MULTIPLIER=2;;
    238 	"ONPIT")	RUN_TIME_MULTIPLIER=1;;
    239 esac
    240 echo "NICDRV is working on $RUN_MODE run mode."
    241 export RUN_TIME_MULTIPLIER
    242 
    243 
    244 exit ${STF_PASS}
    245