Whamcloud - gitweb
Simplify adding manual test results to Tinderbox.
[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_dont_start_log() {
78   eval 'TBOX_LOG= '"$@"
79 }
80
81 # Start the log for a given tree.
82 tbox_start_log() {
83   TREE="$1"
84
85   # Send status messages to stdout, stderr.
86   exec 6>&1 7>&2
87
88   [ -n "$TBOX_LOG" ] || return 0
89
90   # Initialize the output log file.
91   : > $TBOX_LOG
92
93   # Send all our output to the log.
94   exec >>$TBOX_LOG 2>&1
95
96   # Monitor it on the old stdout.
97   tail -f $TBOX_LOG 1>&6 &
98
99   # Allow tail to print our last output before exiting.
100   trap "tbox_exit \"$TREE\" $! 1" 1 2 10 15
101   trap "tbox_exit \"$TREE\" $!" 0
102 }
103
104
105 # Begin writing to the log and send out the initial status.
106 # tbox_start TREE
107 tbox_start() {
108   TREE="$1"
109   tbox_start_log "$TREE"
110   tbox_status "$TREE" starting building "$TBOX_STARTTIME"
111 }