Whamcloud - gitweb
- added test_3b which emulates recursive mount. Does not pass yet.
[fs/lustre-release.git] / lustre / tests / tbox.sh
1 # tbox.sh - Shell functions to manage tinderbox build reporting
2 # Copyright (C) 2002  Cluster File Systems, Inc.
3 # Gord Eagle <gord@clusterfs.com>, 2002-08-22
4
5 HOSTNAME=`hostname`
6 PROGNAME=`echo "$0" | sed -e 's%^.*/%%'`
7 MAILPROG="${MAILPROG-mail}"
8
9 TBOX_PHASE=build # or test
10 TBOX_STARTTIME=`date +%s`
11 TBOX_LOG="${TBOX_LOG-/tmp/tbox.$$.$TBOX_STARTTIME.log}"
12 TBOX_BUILDMAIL=tinderbox_builds@lustre.org
13 TBOX_BUILDNAME="${TBOX_BUILDNAME-$PROGNAME-$HOSTNAME}"
14
15 # Send a status message to the list.
16 tbox_status() {
17   [ -n "$TBOX_BUILDNAME" -a -n "$TBOX_BUILDMAIL" ] || return 0
18   [ "$#" -ge 4 ] || return 1
19   if [ "$#" -gt 4 ]; then
20     log="$5"
21     echo >> $log
22   else
23     log=
24   fi
25
26   TREE="$1"
27   SUBJECT="$2"
28   STATUS="$3"
29   TIMENOW="$4"
30
31   echo "sending tinderbox mail to $TBOX_BUILDMAIL: $TREE $SUBJECT $STATUS"
32
33   TMPFILE="/tmp/tinderbox.boilerplate.$$.$TIMENOW"
34
35   cat > $TMPFILE <<-EOF
36   tinderbox: tree: $TREE
37   tinderbox: starttime: $TBOX_STARTTIME
38   tinderbox: timenow: $TIMENOW
39   tinderbox: builddate: $TBOX_STARTTIME
40   tinderbox: status: $STATUS
41   tinderbox: buildname: $TBOX_BUILDNAME
42   tinderbox: errorparser: unix
43   tinderbox: END
44
45 EOF
46
47   cat $TMPFILE $log | $MAILPROG -s "build $SUBJECT ($TBOX_BUILDNAME)" $TBOX_BUILDMAIL
48   rm -f $TMPFILE
49 }
50
51 # Send out the failure or success message based on exit status.
52 tbox_exit() {
53   TREE="$1"
54   TAILPID="$2"
55   CODE=${3-$?}
56   if [ $CODE -eq 0 ]; then
57     SUBJECT=successful
58     STATUS=success
59   else
60     SUBJECT=failed
61     STATUS="${TBOX_PHASE}_failed"
62   fi
63
64   # Send off the status message.
65   trap 0
66   tbox_status "$TREE" "$SUBJECT" "$STATUS"
67   rm -f $TBOX_LOG
68
69   # Wait for tail to display all output, then finish it.
70   sleep 1
71   kill $TAILPID
72   exit $CODE
73 }
74
75 # Run a subprogram, but stop it from sending its own tinderbox
76 # messages.
77 tbox_absorb_log() {
78   # This probably doesn't do what you think it does... it only prepends
79   # TBOX_LOG= to our arguments.
80   set TBOX_LOG= "$@"
81
82   # Now evaluate the command.
83   eval "$@"
84 }
85
86 # Start the log for a given tree.
87 tbox_start_log() {
88   TREE="$1"
89
90   # Send status messages to stdout, stderr.
91   exec 6>&1 7>&2
92
93   [ -n "$TBOX_LOG" ] || return 0
94
95   # Initialize the output log file.
96   : > $TBOX_LOG
97
98   # Send all our output to the log.
99   exec >>$TBOX_LOG 2>&1
100
101   # Monitor it on the old stdout.
102   tail -f $TBOX_LOG 1>&6 &
103
104   # Allow tail to print our last output before exiting.
105   trap "tbox_exit \"$TREE\" $! 1" 1 2 10 15
106   trap "tbox_exit \"$TREE\" $!" 0
107 }
108
109
110 # Begin writing to the log and send out the initial status.
111 # tbox_start TREE
112 tbox_start() {
113   TREE="$1"
114   tbox_start_log "$TREE"
115   tbox_status "$TREE" starting building "$TBOX_STARTTIME"
116 }