Home | History | Annotate | Download | only in test_scripts
      1 #!/bin/bash
      2 
      3 # Repeatedly copy files to NFS server.
      4 
      5 # Copyright (C) 2003-2006 IBM
      6 #
      7 # This program is free software; you can redistribute it and/or
      8 # modify it under the terms of the GNU General Public License as
      9 # published by the Free Software Foundation; either version 2 of the
     10 # License, or (at your option) any later version.
     11 #
     12 # This program is distributed in the hope that it will be useful, but
     13 # WITHOUT ANY WARRANTY; without even the implied warranty of
     14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     15 # General Public License for more details.
     16 #
     17 # You should have received a copy of the GNU General Public License
     18 # along with this program; if not, write to the Free Software
     19 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
     20 # 02111-1307, USA.
     21 
     22 if [ -z "$NFS_SERVER" -o "$NFS_SERVER" == "0" ]; then
     23 	echo "NFS server not configured."
     24 	exit 255
     25 fi
     26 
     27 SHORTHOST=`echo "$HOSTNAME" | sed -e 's/\..*//g'`
     28 
     29 # set up to delete nfs data and unmount nfs when we die
     30 NFSMOUNT=/pounder
     31 NFSLOCAL="$POUNDER_TMPDIR/nfs-$$"
     32 trap 'echo Cleaning up...; mv $NFSLOCAL/$SHORTHOST/testnet $NFSLOCAL/$SHORTHOST/testnet.del; rm -rf $NFSLOCAL/$SHORTHOST/testnet.del; umount $NFSLOCAL; rm -rf $NFSLOCAL; echo Clean.; exit 0' 1 2 15
     33 
     34 [ ! -x $NFSLOCAL ] && mkdir $NFSLOCAL
     35 echo "Mounting remote storage via NFS..."
     36 
     37 echo Mounting $NFS_SERVER:$NFSMOUNT on $NFSLOCAL...
     38 
     39 # Did we see any failures?
     40 LOGFILE=/proc/$$/fd/1
     41 OLD_ERRORS=`egrep -ic "(err|fail|cannot|invalid|denied)" $LOGFILE`
     42 
     43 if (mount "$NFS_SERVER:$NFSMOUNT" $NFSLOCAL -t nfs -o tcp); then
     44 	# Create a dir for this machine and sleep to give our mkdir a
     45 	# better chance of making it.
     46 	[ ! -x $NFSLOCAL/$SHORTHOST ] && mkdir $NFSLOCAL/$SHORTHOST
     47 	sleep 5
     48 
     49 	# If we've already stuff here, move it and delete it.
     50 	# Meanwhile, create ourselves a new directory for the copy
     51 	[ -x $NFSLOCAL/$SHORTHOST/testnet ] && \
     52 		mv $NFSLOCAL/$SHORTHOST/testnet $NFSLOCAL/$SHORTHOST/testnet.del
     53 	[ -x $NFSLOCAL/$SHORTHOST/testnet.del ] && \
     54 		rm -rf $NFSLOCAL/$SHORTHOST/testnet.del &
     55 
     56 	# Actually copy data...
     57 	echo "Remote NFS copy in progress..."
     58 	cp -pr /usr $NFSLOCAL/$SHORTHOST/testnet
     59 
     60 	# Now diff it...
     61 	diff -Naur /usr $NFSLOCAL/$SHORTHOST/testnet > $POUNDER_TMPDIR/nfs.diff
     62 
     63 	# Now remove it
     64 	rm -rf $NFSLOCAL/$SHORTHOST/testnet
     65 
     66 	# and unmount
     67 	umount $NFSLOCAL
     68 	rm -rf $NFSLOCAL
     69 else
     70 	echo Unable to connect to the NFS server $NFS_SERVER.
     71 	echo Please check network configuration and update the script.
     72 	exit -1
     73 fi
     74 
     75 # Anything in the diff?
     76 DIFF_ERRORS=`wc -l < $POUNDER_TMPDIR/nfs.diff`
     77 if [ $DIFF_ERRORS -gt 0 ]; then
     78 	exit $DIFF_ERRORS
     79 fi
     80 
     81 # Did we see any failures?
     82 NEW_ERRORS=`egrep -ic "(err|fail|cannot|invalid|denied)" $LOGFILE`
     83 ERRORS=$((NEW_ERRORS - OLD_ERRORS))
     84 if [ $ERRORS -eq 255 ]; then
     85         ERRORS=254
     86 fi
     87 exit $ERRORS
     88 
     89