Home | History | Annotate | Download | only in rdist
      1 #!/bin/sh
      2 #
      3 #
      4 #   Copyright (c) International Business Machines  Corp., 2000
      5 #
      6 #   This program is free software;  you can redistribute it and/or modify
      7 #   it under the terms of the GNU General Public License as published by
      8 #   the Free Software Foundation; either version 2 of the License, or
      9 #   (at your option) any later version.
     10 #
     11 #   This program is distributed in the hope that it will be useful,
     12 #   but WITHOUT ANY WARRANTY;  without even the implied warranty of
     13 #   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
     14 #   the GNU General Public License for more details.
     15 #
     16 #   You should have received a copy of the GNU General Public License
     17 #   along with this program;  if not, write to the Free Software
     18 #   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
     19 #
     20 #
     21 #
     22 #  FILE   : rdist
     23 #
     24 #  PURPOSE: To test the basic functionality of the `rdist` command.
     25 #
     26 #  SETUP: The home directory of root on the machine exported as "RHOST"
     27 #         MUST have a ".rhosts" file with the hostname of the machine
     28 #         where the test is executed.
     29 #
     30 #  HISTORY:
     31 #    06/06/03 Manoj Iyer manjo (at] mail.utexas.edu
     32 #    - Modified testcases to use test harness APIs and fixed defects
     33 #    03/01 Robbie Williamson (robbiew (at] us.ibm.com)
     34 #      -Ported
     35 #
     36 #
     37 #***********************************************************************
     38 
     39 #-----------------------------------------------------------------------
     40 #
     41 # FUNCTION:  do_setup
     42 #
     43 #-----------------------------------------------------------------------
     44 
     45 do_setup()
     46 {
     47 
     48     USER_LIST=${USER_LIST:-'root'}
     49     TCdat=${TCdat:-$LTPROOT/testcases/bin/datafiles}
     50     TCtmp=${TCtmp:-$LTPROOT/testcases/bin/$TC${EXEC_SUFFIX}$$}
     51     FILES=${FILES:-'bin.sm bin.med bin.lg bin.jmb file.dir/bin.sm file.dir/bin.med file.dir/bin.jmb'}
     52     SLEEPTIME=${SLEEPTIME:-10}
     53 
     54     tst_setup
     55 
     56     exists awk hostname rdist
     57 
     58     RHOST=${RHOST:-`hostname`}
     59 
     60     # start with a clean LHOST
     61     for i in $FILES; do
     62         rm -rf $i
     63     done
     64 
     65     for i in $FILES; do
     66         BASE=$(basename "$i")
     67         DIR=$(dirname "$i")
     68         test -d "$DIR" || mkdir -p "$DIR"
     69         if [ $? -ne 0 ] ; then
     70             end_testcase "failed to create $DIR"
     71         fi
     72         if ! cp $TCdat/$BASE $DIR; then
     73             end_testcase "failed to copy $TCdat/$BASE to $DIR"
     74         fi
     75         chmod 764 $i
     76     done
     77 
     78     # get the sum of all the files to rdist on the local machine
     79     LSUM=0
     80     SUM=`sum -s $FILES | awk '{ print $1 }'`
     81     for i in $SUM; do
     82         LSUM=$(( $LSUM + $i ))
     83     done
     84 }
     85 
     86 #-----------------------------------------------------------------------
     87 #
     88 # FUNCTION:  create_distfile
     89 # create file $TCtmp/distfile
     90 #
     91 #-----------------------------------------------------------------------
     92 
     93 create_distfile()
     94 {
     95     T_FILES="FILES = ( "
     96     for i in $FILES; do
     97         if [ $(dirname "$i") == "." ]; then
     98             T_FILES="$T_FILES $i"
     99         else
    100             T_FILES="$T_FILES $DIR"
    101         fi
    102     done
    103     T_FILES="$T_FILES )"
    104 
    105     T_HOST="HOSTS = ("
    106     for c_ruser in $RUSERS; do
    107         for c_rhost in $HOSTS; do
    108          T_HOST=$T_HOST" $c_ruser@$c_rhost"
    109         done
    110     done
    111 
    112     T_HOST="$T_HOST)"
    113     cat <<EOF > "$TCtmp/distfile"
    114 $T_HOST
    115 $T_FILES
    116 \${FILES} -> \${HOSTS}
    117 EOF
    118 }
    119 
    120 #-----------------------------------------------------------------------
    121 #
    122 # FUNCTION:  check_result
    123 #
    124 # check the sum of all files rdisted from local machine to remote machine
    125 #
    126 #-----------------------------------------------------------------------
    127 
    128 check_result()
    129 {
    130     cd $TCtmp
    131     for c_rhost in $HOSTS; do
    132         for c_ruser in $RUSERS; do
    133             TOTAL_SUM=0
    134             for i in $(rsh -n -l $c_ruser $c_rhost sum -s $FILES | awk '{ print $1 }'); do
    135                 TOTAL_SUM=$(( $TOTAL_SUM + $i ))
    136             done
    137             if [ $TOTAL_SUM -eq $LSUM ]; then
    138                 tst_resm TINFO "Success rdist in $c_ruser@$c_rhost "
    139                 rsh -n -l $c_ruser $c_rhost "rm -rf $FILES"
    140             else
    141                 end_testcase "Wrong sum doing rdist in $curr_ruser@$curr_rhost"
    142             fi
    143        done
    144    done
    145 }
    146 
    147 #----------------------------------------------------------------------
    148 # FUNCTION: do_test
    149 # PURPOSE:  Perform the necessary steps to complete the test.
    150 # INPUT:    None.
    151 # OUPUT:    Error messages are logged if any of the tests fail.
    152 # EXIT VAR: 0 Success
    153 #----------------------------------------------------------------------
    154 
    155 do_test()
    156 {
    157     HOSTS=""
    158     RUSERS=""
    159 
    160     for cur_host in $RHOST; do
    161         HOSTS=$HOSTS" $cur_host"
    162         for cur_user in $USER_LIST; do
    163             RUSERS=$RUSERS" $cur_user"
    164             create_distfile
    165             if ! rdist -f $TCtmp/distfile; then
    166                 end_testcase "error doing rdist -f $TCtmp/distfile"
    167             fi
    168             check_result
    169             sleep $SLEEPTIME
    170         done
    171     done
    172 }
    173 
    174 #----------------------------------------------------------------------
    175 # FUNCTION: MAIN
    176 # PURPOSE:  To invoke the functions to perform the tasks described in
    177 #           the prologue.
    178 # INPUT:    None.
    179 # OUTPUT:   A testcase run log with the results of the execution of this
    180 #           test.
    181 #----------------------------------------------------------------------
    182 . net_cmdlib.sh
    183 
    184 read_opts $*
    185 do_setup
    186 do_test
    187 end_testcase
    188