Whamcloud - gitweb
b=13698 support for remote mds and oss in lfscktest.sh
[fs/lustre-release.git] / lustre / tests / functions.sh
1 #!/bin/bash
2
3 # Simple function used by run_*.sh scripts
4
5 assert_env() {
6     local failed=""
7     for name in $@; do
8         if [ -z "${!name}" ]; then
9             echo "$0: $name must be set"
10             failed=1
11         fi
12     done
13     [ $failed ] && exit 1 || true
14 }
15
16 echoerr () { echo "$@" 1>&2 ; }
17
18 signaled() {
19     echoerr "$(date +'%F %H:%M:%S'): client load was signaled to terminate"
20
21     local PGID=$(ps -eo "%c %p %r" | awk "/ $PPID / {print \$3}")
22     kill -TERM -$PGID
23     sleep 5
24     kill -KILL -$PGID
25 }
26
27 mpi_run () {
28     local mpirun="$MPIRUN $MPIRUN_OPTIONS"
29     local command="$mpirun $@"
30     local mpilog=$TMP/mpi.log
31     local rc
32
33     if [ "$MPI_USER" != root -a $mpirun ]; then
34         echo "+ chmod 0777 $MOUNT"
35         chmod 0777 $MOUNT
36         command="su $MPI_USER sh -c \"$command \""
37     fi
38
39     ls -ald $MOUNT
40     echo "+ $command"
41     eval $command 2>&1 | tee $mpilog || true
42
43     rc=${PIPESTATUS[0]}
44     if [ $rc -eq 0 ] && grep -q "p4_error:" $mpilog ; then
45        rc=1
46     fi
47     return $rc
48 }
49
50 nids_list () {
51    local list
52    for i in ${1//,/ }; do
53        list="$list $i@$NETTYPE"
54    done
55    echo $list
56 }
57
58 # FIXME: all setup/cleanup can be done without rpc.sh
59 lst_end_session () {
60     local verbose=false
61     [ x$1 = x--verbose ] && verbose=true
62
63     export LST_SESSION=`$LST show_session 2>/dev/null | awk -F " " '{print $5}'`
64     [ "$LST_SESSION" == "" ] && return
65
66     if $verbose; then 
67         $LST show_error c s
68     fi
69     $LST stop b
70     $LST end_session
71 }
72
73 lst_session_cleanup_all () {
74     local list=$(comma_list $(nodes_list))
75     do_rpc_nodes $list lst_end_session
76 }
77
78 lst_cleanup () {
79     lsmod | grep -q lnet_selftest && rmmod lnet_selftest > /dev/null 2>&1 || true
80 }
81
82 lst_cleanup_all () {
83    local list=$(comma_list $(nodes_list))
84
85    # lst end_session needs to be executed only locally
86    # i.e. on node where lst new_session was called
87    lst_end_session --verbose 
88    do_rpc_nodes $list lst_cleanup
89 }
90
91 lst_setup () {
92     load_module lnet_selftest
93 }
94
95 lst_setup_all () {
96     local list=$(comma_list $(nodes_list))
97     do_rpc_nodes $list lst_setup 
98 }
99