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 
  28 #
  29 # For recovery testing purposes, cleanup server filesystem from
  30 # previous nfs4_gen test suite being run. Setup server with 
  31 # reboot capability.
  32 #
  33 
  34 . ${STF_SUITE}/include/nfsgen.kshlib
  35 
  36 NAME=$(basename $0)
  37 
  38 [[ :$NFSGEN_DEBUG: = *:${NAME}:* || :${NFSGEN_DEBUG}: = *:all:* ]] \
  39        && set -x
  40 
  41 [[ $SETUP == "none" ]] && exit $STF_UNSUPPORTED
  42 
  43 DIR=$(dirname $0)
  44 
  45 function internalCleanup 
  46 {
  47         fileList="$STF_TMPDIR/recov_setserver \
  48                 $STF_TMPDIR/nfs4red \
  49                 $STF_TMPDIR/S99nfs4red \
  50                 $STF_TMPDIR/rsh.out.$$ \
  51                 $STF_TMPDIR/recov_setclient2 \
  52                 $STF_TMPDIR/rcp.out.$$"
  53 
  54         cleanup $1 "" $fileList
  55 }
  56         
  57 
  58 function prepareRemoteEnv 
  59 {
  60         rm -f $STF_TMPDIR/$SERVER.recov_env
  61         echo "PATH=/opt/SUNWstc-genutils/bin:/usr/bin:/usr/sbin:/usr/lib/nfs:\$PATH; export PATH" \
  62                  > $STF_TMPDIR/$SERVER.recov_env
  63         echo "NFSGEN_DEBUG=$NFSGEN_DEBUG; export NFSGEN_DEBUG" >> $STF_TMPDIR/$SERVER.recov_env
  64         echo "CLIENT=$CLIENT; export CLIENT" >> $STF_TMPDIR/$SERVER.recov_env
  65         echo "SERVER=$SERVER; export SERVER" >> $STF_TMPDIR/$SERVER.recov_env
  66         echo "SHRDIR=$SHRDIR; export SHRDIR" >> $STF_TMPDIR/$SERVER.recov_env
  67         echo "MNTOPT=$MNTOPT; export MNTOPT" >> $STF_TMPDIR/$SERVER.recov_env
  68         echo "LC_ALL=C; export LC_ALL" >> $STF_TMPDIR/$SERVER.recov_env
  69         echo "NOTICEDIR=$NOTICEDIR; export NOTICEDIR" >> $STF_TMPDIR/$SERVER.recov_env
  70 }
  71 
  72 
  73 # add environment variables to srv_setup script:
  74 rm -f $STF_TMPDIR/recov_setserver $STF_TMPDIR/srv_checkDir.ksh
  75 cd $DIR
  76 prepareRemoteEnv
  77 
  78 # check STF_TMPDIR
  79 cat > $STF_TMPDIR/srv_checkDir.ksh << EOF
  80 [[ :$NFSGEN_DEBUG: = *:${NAME}:* || :${NFSGEN_DEBUG}: = *:all:* ]] && set -x
  81 checkdir=\$1
  82 swapList="\`mount | grep swap | awk '{print \$1}'\`"
  83 for i in \$swapList
  84 do
  85         echo \$checkdir | grep \^\$i
  86         if [[ \$? == 0 ]]; then
  87                 echo "\$checkdir is in a swap partition, temp files will lost after reboot"
  88                 return 1
  89         fi
  90 done
  91 EOF
  92 
  93 #check STF_TMPDIR is not located in a swap partition
  94 RUN_CHECK RSH root $SERVER "mkdir -p $SRV_TMPDIR" || exit $STF_UNINITIATED
  95 RUN_CHECK scp $STF_TMPDIR/srv_checkDir.ksh root@$SERVER:$SRV_TMPDIR || exit $STF_UNINITIATED
  96 RSH root $SERVER "/usr/bin/ksh $SRV_TMPDIR/srv_checkDir.ksh $SRV_TMPDIR" > $STF_TMPDIR/rsh.out.$$ 2>&1
  97 if (( $? != 0 )); then
  98         echo "check $SRV_TMPDIR is in a swap partition on $SERVER failed"
  99         cat $STF_TMPDIR/rsh.out.$$
 100         exit $STF_UNINITIATED
 101 fi
 102 
 103 SETD="NFSGEN_DEBUG=0; export NFSGEN_DEBUG"
 104 [[ :${NFSGEN_DEBUG}: == *:${NAME}:* || :${NFSGEN_DEBUG}: == *:all:* ]] \
 105         && SETD="NFSGEN_DEBUG=$NFSGEN_DEBUG; export NFSGEN_DEBUG"
 106 
 107 sed -e "s%Tmpdir_from_client%$SRV_TMPDIR%" -e "s%SetDebugMode%$SETD%"\
 108         -e "s%ENV_from_client%$SERVER.recov_env%" -e "s%NFS_UTIL%nfs-util.kshlib%"\
 109         -e "s%TEST_ZFS%$TestZFS%" -e "s%SHR_DIR%$SHRDIR%"\
 110         -e "s%SHR_OPT%$SHROPT%" -e "s%SHR_GRP%$SHRGRP%" srv_setup > $STF_TMPDIR/recov_setserver
 111 if (( $? != 0 )); then
 112         echo "$NAME: can't setup [recov_setserver] file."
 113         internalCleanup $STF_UNINITIATED
 114 fi
 115 
 116 # and the reboot scripts
 117 sed -e "s%Tmpdir_from_client%$SRV_TMPDIR%" \
 118         -e "s%SetDebugMode%$SETD%"\
 119         -e "s%ENV_from_client%$SERVER.recov_env%" nfs4red > $STF_TMPDIR/nfs4red
 120 if [ $? -ne 0 ]; then
 121         echo "$NAME: can't setup [nfs4red] file."
 122         internalCleanup $STF_UNINITIATED
 123 fi
 124 
 125 sed -e "s%Tmpdir_from_client%$SRV_TMPDIR%" \
 126         -e "s%ENV_from_client%$SERVER.recov_env%" \
 127         -e "s%SetDebugMode%$SETD%" S99nfs4red > $STF_TMPDIR/S99nfs4red
 128 if (( $? != 0 )); then
 129         echo "$NAME: can't setup [S99nfs4red] file."
 130         internalCleanup $STF_UNINITIATED
 131 fi
 132 
 133 
 134 # ... now setup the $SERVER
 135 RSH root $SERVER "mkdir -p $SRV_TMPDIR" > $STF_TMPDIR/rsh.out.$$ 2>&1
 136 if (( $? != 0 )); then
 137         echo "$NAME: create temp direcotry on $SERVER failed:"
 138         cat $STF_TMPDIR/rsh.out.$$
 139         internalCleanup $STF_OTHER
 140 fi
 141 
 142 # copy server programs over to $SERVER for setup
 143 scp $STF_TMPDIR/recov_setserver $STF_TMPDIR/$SERVER.recov_env $STF_TMPDIR/nfs4red \
 144         $STF_SUITE/include/nfs-util.kshlib root@$SERVER:${SRV_TMPDIR} \
 145         > $STF_TMPDIR/rcp.out.$$ 2>&1
 146 if (( $? != 0 )); then
 147         echo "$NAME: copying setup files to $SERVER failed:"
 148         cat $STF_TMPDIR/rcp.out.$$
 149         internalCleanup $STF_OTHER
 150 fi
 151 
 152 scp $STF_TMPDIR/S99nfs4red root@$SERVER:/etc/rc3.d > $STF_TMPDIR/rcp.out.$$ 2>&1
 153 if (( $? != 0 )); then
 154         echo "$NAME: copying S99nfs4red file to $SERVER failed:"
 155         cat $STF_TMPDIR/rcp.out.$$
 156         internalCleanup $STF_OTHER
 157 fi
 158 
 159 RSH root $SERVER "/usr/bin/ksh ${SRV_TMPDIR}/recov_setserver -s" \
 160         > $STF_TMPDIR/rsh.out.$$ 2>&1
 161 ret=$?
 162 grep "OKAY" $STF_TMPDIR/rsh.out.$$ | grep -v echo > /dev/null 2>&1
 163 if (( $? == 0 && $ret == 0 )); then
 164         # If server returned some warning, print it out
 165         grep "STF_WARNING" $STF_TMPDIR/rsh.out.$$ | grep -v echo > /dev/null 2>&1
 166         if (( $? == 0 )); then
 167                 echo "$NAME: setup $SERVER have warnings:"
 168                 grep STF_WARNING $STF_TMPDIR/rsh.out.$$
 169         fi
 170 else
 171         grep "ERROR" $STF_TMPDIR/rsh.out.$$ | grep -v echo > /dev/null 2>&1
 172         if (( $? == 0 )); then
 173                 echo "$NAME: setup $SERVER had errors:"
 174         else
 175                 echo "$NAME: setup $SERVER failed:"
 176         fi
 177         cat $STF_TMPDIR/rsh.out.$$
 178         internalCleanup $STF_OTHER
 179 fi
 180 [[ :${NFSGEN_DEBUG}: == *:${NAME}:* || :${NFSGEN_DEBUG}: == *:all:* ]] \
 181         && cat $STF_TMPDIR/rsh.out.$$
 182 
 183 echo "  SERVER=$SERVER recovery setup OK!! "
 184 
 185 internalCleanup $STF_PASS