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 NAME=$(basename $0)
  29 
  30 . $STF_SUITE/include/sharemnt.kshlib
  31 . $STC_GENUTILS/include/nfs-smf.kshlib
  32 . $STC_GENUTILS/include/libsmf.shlib
  33 EXIT_CODE=$STF_PASS
  34 
  35 # Turn on debug info, if requested
  36 export STC_GENUTILS_DEBUG=$STC_GENUTILS_DEBUG:$SHAREMNT_DEBUG
  37 [[ :$SHAREMNT_DEBUG: == *:${NAME}:* \
  38         || :${SHAREMNT_DEBUG}: == *:all:* ]] && set -x
  39 
  40 function cleanup {              # cleanup and exit
  41         [[ :$SHAREMNT_DEBUG: == *:${NAME}:* \
  42                 || :${SHAREMNT_DEBUG}: == *:all:* ]] && set -x
  43 
  44         rm -fr $STF_TMPDIR
  45 
  46         exit ${1}
  47 }
  48 
  49 # umount $MNTDIR if it is still mounted
  50 nfsstat -m $MNTDIR | grep "$MNTDIR" > /dev/null 2>&1
  51 if (( $? == 0 )); then
  52         umount -f $MNTDIR > $STF_TMPDIR/umnt.out.$$ 2>&1
  53         if (( $? != 0 )); then
  54                 echo "$NAME: Warning - umount MNTDIR=[$MNTDIR] failed -"
  55                 cat $STF_TMPDIR/umnt.out.$$
  56                 echo "\t... please clean it up manually."
  57                 EXIT_CODE=$STF_FAIL
  58         else
  59                 rm -fr $ZONE_PATH$NFSMNTDIR
  60         fi
  61 else
  62         rm -fr $ZONE_PATH$NFSMNTDIR
  63 fi
  64 
  65 # Also cleanup the test automount maps
  66 if [[ ! -f $STF_CONFIG/auto_master.shmnt.orig ]]; then
  67         echo "$NAME: Warning - can't find the original auto_master"
  68         echo "\t... please reset the auto_master map manaully"
  69 else
  70         grep -v "direct\.shmnt" $STF_CONFIG/auto_master.shmnt.orig \
  71                 > /etc/auto_master 2> $STF_TMPDIR/map.out.$$
  72         if (( $? != 0 )); then
  73                 echo "$NAME: Failed to restore the original auto_master"
  74                 echo "\t... please recreate the auto_master map manaully"
  75                 cat $STF_TMPDIR/map.out.$$ /etc/auto_master
  76                 EXIT_CODE=$STF_FAIL
  77         fi
  78 fi
  79 
  80 smf_fmri_transition_state "do" "$AUTO_FMRI" "restart" 60 \
  81         > $STF_TMPDIR/smf.out.$$ 2>&1
  82 if (( $? != 0 )); then
  83         echo "$NAME: client<$(hostname)> failed to restart autofs service"
  84         cat $STF_TMPDIR/smf.out.$$
  85 fi
  86 print_debug $STF_TMPDIR/smf.out.$$
  87 
  88 #
  89 # Restore the auto_enable property of the NFS services back to original value
  90 # Note svc:/network/nfs/client does not have an auto_enable property.
  91 #
  92 restore_fmri_svcprop $STF_CONFIG/svc_prop.orig $SERVICES
  93 if (( $? != 0 )); then
  94         echo "$NAME: failed to restore auto_enable property for <$SERVICES>"
  95         cat $STF_CONFIG/svc_prop.orig
  96         EXIT_CODE=$STF_FAIL
  97 fi
  98 
  99 # Make sure automountd is started before exit
 100 MyZone=$(zonename)
 101 condition="pgrep -z $MyZone automountd > /dev/null 2>&1"
 102 wait_now 20 "$condition"
 103 rc=$?
 104 if (( $rc != 0 )); then
 105         echo "$NAME: client<$(hostname)> automountd is still not running"
 106         echo "\tafter $rc seconds with <$AUTO_FMRI> is online."
 107         pgrep -l -z $MyZone automountd
 108         svcs -lp $AUTO_FMRI
 109         EXIT_CODE=$STF_FAIL
 110 fi
 111 # still need time to allow automounter to process after the restart
 112 sleep 30
 113 rm -fr $AUTOIND > /dev/null 2>&1
 114 
 115 # restore mapid domain
 116 restore_nfs_property nfsmapid_domain $STF_CONFIG/bin/stf_config.suite \
 117     >$STF_TMPDIR/mapid.out.$$ 2>&1
 118 if (( $? != 0 )); then
 119         echo "$NAME: failed to restore nfsmapid_domain"
 120         cat $STF_TMPDIR/mapid.out.$$
 121         EXIT_CODE=$STF_FAIL
 122 fi
 123 print_debug $STF_TMPDIR/mapid.out.$$
 124 
 125 # delete test user(s)
 126 del_users $TUSER_UTAG > $STF_TMPDIR/userdel.out.$$ 2>&1
 127 if (( $? != 0 )); then
 128         echo "$NAME: failed to delete test users whose tag: $TUSER_UTAG"
 129         cat $STF_TMPDIR/userdel.out.$$
 130         EXIT_CODE=$STF_FAIL
 131 fi
 132 
 133 # Now cleanup the server..
 134 SRVDEBUG=$STC_GENUTILS_DEBUG:$SHAREMNT_DEBUG
 135 [[ :$SRVDEBUG: == *:RSH:* ]] && SRVDEBUG=all
 136 RSH root $SERVER \
 137         "export SHAREMNT_DEBUG=$SRVDEBUG; \
 138         F=$SRV_TMPDIR/srv_setup; \
 139         if [[ -f \$F ]]; then \$F -c; else echo NeedlessToDo; fi" \
 140         > $STF_TMPDIR/rsh.out.$$ 2>&1
 141 rc=$?
 142 print_debug $STF_TMPDIR/rsh.out.$$
 143 
 144 egrep "^NeedlessToDo$" $STF_TMPDIR/rsh.out.$$ > /dev/null 2>&1
 145 if (( $? == 0 && $rc == 0 )); then
 146         echo "$NAME: script<$SRV_TMPDIR/srv_setup> does not exist"
 147         echo "\t it seems we don't need to cleanup on SERVER<$SERVER>"
 148         cleanup $EXIT_CODE
 149 fi
 150 
 151 grep "Done" $STF_TMPDIR/rsh.out.$$ > /dev/null 2>&1
 152 if (( $? != 0 || $rc != 0 )); then
 153         echo "$NAME: run cleanup script on SERVER<$SERVER> failed :"
 154         cat $STF_TMPDIR/rsh.out.$$
 155         echo "\t please cleanup the SERVER manually"
 156         EXIT_CODE=$STF_FAIL
 157 else
 158         # Now remove STF_TMPDIR on server
 159         RSH root $SERVER "/bin/rm -rf $SRV_TMPDIR" \
 160                 > $STF_TMPDIR/rsh.out.$$ 2>&1
 161         if (( $? != 0 )); then
 162                 echo "$NAME: remove $SRV_TMPDIR on SERVER<$SERVER> failed:"
 163                 cat $STF_TMPDIR/rsh.out.$$
 164                 echo "\t please remove it on SERVER<$SERVER> manually"
 165                 EXIT_CODE=$STF_FAIL
 166         fi
 167 fi
 168 
 169 cleanup $EXIT_CODE