summaryrefslogtreecommitdiff
path: root/ndb/test/run-test/ndb-autotest.sh
blob: 397df97d52f37049ff02e8baedcf58463dadff1d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
#!/bin/sh

save_args=$*
VERSION="ndb-autotest.sh version 1.0"

DATE=`date '+%Y-%m-%d'`
export DATE

set -e
ulimit -Sc unlimited

echo "`date` starting: $*"

RSYNC_RSH=ssh
export RSYNC_RSH

do_clone=yes
build=yes
deploy=yes

clone=5.0-ndb
RUN="daily-basic daily-devel"
conf=autotest.conf

while [ "$1" ]
do
        case "$1" in
                --no-clone) do_clone="";;
                --no-build) build="";;
                --no-deploy) deploy="";;
		--clone=*) clone=`echo $1 | sed s/--clone=//`;;
                --conf=*) conf=`echo $1 | sed s/--conf=//`;;
                --version) echo $VERSION; exit;;
                *) RUN=$*;;
        esac
        shift
done

if [ -f $conf ]
then
	. $conf
else
	echo "Can't find config file: $conf"
	exit
fi

env

LOCK=$HOME/.autotest-lock
src_clone=$src_clone_base-$clone

if [ -f $LOCK ]
then
	echo "Lock file exists: $LOCK"
	exit 1
fi

echo "$DATE $RUN" > $LOCK
trap "rm -f $LOCK" ERR

dst_place=${build_dir}/clone-mysql-$clone-$DATE

if [ "$do_clone" ]
then
	rm -rf $dst_place
	bk clone  $src_clone $dst_place
fi

if [ "$build" ]
then
	cd $dst_place
        rm -rf $run_dir/*
        aclocal; autoheader; autoconf; automake
        (cd innobase; aclocal; autoheader; autoconf; automake)
        (cd bdb/dist; sh s_all)
	eval $configure --prefix=$run_dir
	make
	make install
fi

###
# check script version
#
script=$run_dir/mysql-test/ndb/ndb-autotest.sh
if [ -x $script ]
then
	$script --version > /tmp/version.$$
else
	echo $VERSION > /tmp/version.$$
fi	
match=`grep -c "$VERSION" /tmp/version.$$`
rm -f /tmp/version.$$
if [ $match -eq 0 ]
then
	echo "Incorrect script version...restarting"
	cp $run_dir/mysql-test/ndb/ndb-autotest.sh /tmp/at.$$.sh
	rm -rf $run_dir $dst_place
	sh /tmp/at.$$.sh $save_args
	exit
fi

# Check that all interesting files are present
test_dir=$run_dir/mysql-test/ndb
atrt=$test_dir/atrt
html=$test_dir/make-html-reports.sh
PATH=$test_dir:$PATH
export PATH

filter(){
	neg=$1
	shift
	while [ $# -gt 0 ]
	do
		if [ `grep -c $1 $neg` -eq 0 ] ; then echo $1; fi
		shift
	done
}

###
# check ndb_cpcc fail hosts
#
ndb_cpcc $hosts | awk '{ if($1=="Failed"){ print;}}' > /tmp/failed.$DATE
filter /tmp/failed.$DATE $hosts > /tmp/hosts.$DATE
hosts=`cat /tmp/hosts.$DATE` 

if [ "$deploy" ]
then
	(cd / && tar cfz /tmp/build.$DATE.tgz $run_dir )
	for i in $hosts
	do
		ok=0
		scp /tmp/build.$DATE.tgz $i:/tmp/build.$DATE.$$.tgz && \
		ssh $i "rm -rf /space/autotest/*" && \
		ssh $i "cd / && tar xfz /tmp/build.$DATE.$$.tgz" && \
		ssh $i "rm /tmp/build.$DATE.$$.tgz" && ok=1
		if [ $ok -eq 0 ]
		then
			echo "$i failed during scp/ssh, excluding"
			echo $i >> /tmp/failed.$DATE
		fi
	done
fi
rm -f /tmp/build.$DATE.tgz

###
# handle scp failed hosts
#
filter /tmp/failed.$DATE $hosts > /tmp/hosts.$DATE
hosts=`cat /tmp/hosts.$DATE` 
cat /tmp/failed.$DATE > /tmp/filter_hosts.$$

###
# functions for running atrt 
#
choose(){
        SRC=$1
        TMP1=/tmp/choose.$$
        TMP2=/tmp/choose.$$.$$
        shift

        cp $SRC $TMP1
        i=1
        while [ $# -gt 0 ]
        do
                sed -e s,"CHOOSE_host$i",$1,g < $TMP1 > $TMP2
                mv $TMP2 $TMP1
                shift
                i=`expr $i + 1`
        done
        cat $TMP1
        rm -f $TMP1
}
start(){
	rm -rf report.txt result* log.txt
	$atrt -v -v -r -R --log-file=log.txt --testcase-file=$test_dir/$2-tests.txt &
	pid=$!
	echo $pid > run.pid
	wait $pid
	rm run.pid
	[ -f log.txt ] && mv log.txt $3
	[ -f report.txt ] && mv report.txt $3
	[ "`find . -name 'result*'`" ] && mv result* $3
	cd $3
	sh $html . $1 $DATE
	cd ..
	p2=`pwd`
	cd ..
	tar cfz /tmp/res.$$.tgz `basename $p2`/$DATE
	scp /tmp/res.$$.tgz $result_host:$result_path
	ssh $result_host "cd $result_path && tar xfz res.$$.tgz && rm -f res.$$.tgz"
	rm -f /tmp/res.$$.tgz
}

p=`pwd`
for dir in $RUN
do
	echo "Fixing hosts for $dir"

	run_dir=$base_dir/run-$dir-mysql-$clone-$target
	res_dir=$base_dir/result-$dir-mysql-$clone-$target/$DATE

	mkdir -p $res_dir
	rm -rf $res_dir/*
	
	count=`grep -c "COMPUTER" $run_dir/1.ndb_mgmd/initconfig.template`
	avail_hosts=`filter /tmp/filter_hosts.$$ $hosts`
	avail=`echo $avail_hosts | wc -w`
	if  [ $count -gt $avail ]
	then
		echo "Not enough hosts"
		echo "Needs: $count available: $avail ($avail_hosts)"
		break;
	fi

	run_hosts=`echo $avail_hosts| awk '{for(i=1;i<='$count';i++)print $i;}'`
	choose $run_dir/d.template $run_hosts > $run_dir/d.txt
	choose $run_dir/1.ndb_mgmd/initconfig.template $run_hosts > $run_dir/1.ndb_mgmd/config.ini
	echo $run_hosts >> /tmp/filter_hosts.$$	

	cd $run_dir
	start $dir-mysql-$clone-$target $dir $res_dir &
done
cd $p
rm /tmp/filter_hosts.$$

wait

rm -f $LOCK