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