summaryrefslogtreecommitdiffstats
path: root/sanity/nightly_valgrind/nightly_valgrind.sh
blob: b76f6c56cfb3740fac711209290545ad519b3935 (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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
#!/bin/bash

ulimit -c unlimited
set -x

#set -u
export PATH=$PATH:/opt/qa/tools:/usr/local/bin:/usr/local/sbin

WORKSPACE_DIR="/opt/users/nightly_sanity_valgrind/glusterfs"
WORKDIR="/mnt/nightly_valgrind"
translator=$1
VOLNAME=$translator
SPECDIR="/etc/glusterd/vols/$VOLNAME"
BUILDDIR="$WORKSPACE_DIR/build"

LOGDIR="$WORKDIR/logs_$translator/`date +%F`"
EXPORTDIR=$WORKDIR/data
MOUNTDIR=$WORKDIR/mount/$translator
RESULTDIR=/tmp/nightly_valgrind-results
SYSCALLDIR="$WORKDIR/syscall"
COREDIR="$WORKDIR/$translator"
CORE_REPOSITORY="/opt/cores"

echo "$COREDIR/core" > /proc/sys/kernel/core_pattern

#EMAIL="dl-qa@gluster.com"
EMAIL="lakshmipathi@shell.gluster.com:/home/lakshmipathi/nightly_valgrind/"
RFILE="lakshmipathi@shell.gluster.com:/home/lakshmipathi/resultfile/"
BINDIR="/opt/glusterfs/nightly_valgrind"
TOOLDIR="/opt/qa/tools/tools.git/syscallbench"
#WORKSPACE_DIR="/home/gluster/laks/new/glusterfs/"
#WORKDIR="/mnt/nightly"
#SPECDIR="/opt/users/vijay/nightly"
#BUILDDIR="$WORKSPACE_DIR/build"

#LOGDIR="$WORKDIR/logs/`date +%F`" 
#EXPORTDIR=$WORKDIR/data
#MOUNTDIR=$WORKDIR/mount
#RESULTDIR=/tmp/nightly-results

#EMAIL="lakshmipathi@gluster.com"
#BINDIR="/home/gluster/laks/new/glusterfs/build/build"

VALGRIND="valgrind   --error-limit=no --leak-check=full  --show-reachable=yes --log-file="

function update_git ()
{
        cd $WORKSPACE_DIR
	echo "$WORKSPACE_DIR in there"
        git pull
}

function prepare_dirs()
{
        if [ ! -d $EXPORTDIR ]
        then
                mkdir -p $EXPORTDIR;
        fi

        if [ ! -d $MOUNTDIR ]
        then
                mkdir -p $MOUNTDIR
        fi

    
	j=0;
        #Create individual export_dirs
	#cd $SPECDIR
        #for i in `ls server*.vol`
        #do
         #       let "j += 1"
          #      mkdir -p $EXPORTDIR/export$j
        #done

        #j=0
        #for i in `ls client*.vol`
        #do
         #       let "j += 1"
          #      mkdir -p $MOUNTDIR/client$j
        #done

        if [ ! -d $LOGDIR ]
        then
                mkdir -p $LOGDIR
        fi
	
	if [ ! -d $SYSCALLDIR ]
	then
	        mkdir -p $SYSCALLDIR
	fi

	if [ ! -d $COREDIR ]
	then
	        mkdir -p $COREDIR
        fi
}

function install_glusterfs()
{
    
        cd $WORKSPACE_DIR
        ./autogen.sh;
#	make distclean
        if [ ! -d $BUILDDIR ]
        then
                mkdir $BUILDDIR;
        fi
        #cd $BUILDDIR;	
#	make clean -j 32;
        export CFLAGS="-g -O0"
        ./configure --enable-libglusterfsclient  --enable-fusermount --prefix=$BINDIR>/dev/null;
#        ../configure --prefix=$BINDIR>/dev/null;
        make -j 32>/dev/null;
	echo "Post make"
        make install -j 32>/dev/null;

}

function start_glusterfs ()
{
	cd $SPECDIR;
	HOSTNAME=`hostname`
        j=0;
        for i in `ls $VOLNAME.$HOSTNAME*.vol`
        do
                let "j += 1"
                #bname=`basename $i .vol`
		RUN_VALGRIND="$VALGRIND$LOGDIR/$i.val.log"
		( $RUN_VALGRIND $BINDIR/sbin/glusterfsd -f $SPECDIR/$i -l $LOGDIR/$i.log -p $LOGDIR/$i.pid "-N" ) &
		sleep 30
                #$BINDIR/sbin/glusterfsd -f $SPECDIR/$i -l $LOGDIR/$bname$j.log -p $LOGDIR/$bname$j.pid
        done

        j=0
        for i in `ls $VOLNAME-fuse.vol`
        do
                #let "j += 1"
                #bname=`basename $i .vol`
                #$BINDIR/sbin/glusterfs -f $SPECDIR/$i  -l $LOGDIR/$bname$j.log -p $LOGDIR/$bname$j.pid $MOUNTDIR/client$j 
		RUN_VALGRIND="$VALGRIND$LOGDIR/$i.val.log"
		#( $RUN_VALGRIND $BINDIR/sbin/glusterfs -f $SPECDIR/$i  -l $LOGDIR/$i.log -p $LOGDIR/client.pid $MOUNTDIR/client$j "-N" )&
		( $RUN_VALGRIND $BINDIR/sbin/glusterfs -f /etc/glusterd/vols/$translator/$VOLNAME-fuse.vol -l $LOGDIR/$i.log  $MOUNTDIR/client0 "-N" )&
		sleep 40
        done
        
}


function run_tests ()
{
        cd $MOUNTDIR/client0;
	#set +e;
	/opt/qa/tools/system_light/run.sh -w $MOUNTDIR/client0 -l /tmp/runlog.$translator
 	#/opt/qa/tools/iozone -a  -s 1024
        x=$?;
        if [ !x ] 
        then
                echo "Sanity Passed!";
        else
                echo "Sanity Failed. Please check your changes!";
        fi
}

function stop_glusterfs()
{
        cd $LOGDIR
        j=0

        #for i in `ls client*.pid`
        #do
         #       let "j += 1"
                umount $MOUNTDIR/client0
		if [ $? -ne 0 ]; then
		    echo "client unmounting failed"
		fi
        #done
        for i in `ls $VOLNAME*.pid`
        do
                cat $i | xargs kill
        done

}

function cleanup()
{

        j=0;
        for i in `ls $SPECDIR | grep server*.vol`
        do
                let "j += 1";
                rm -rfv $EXPORTDIR/export$j
        done

        j=0
        for i in `ls $SPECDIR | grep client*.vol`
        do
                let "j += 1"
                rm -rfv $MOUNTDIR/client$j;
        done
}

function pre_run()
{
        update_git;
        prepare_dirs;
        #set -e;
        install_glusterfs;
}

function send_results()
{
	if [ ! -d $LOGDIR ]
	then
		mkdir $LOGDIR
	fi
        cd $LOGDIR;

	if [ ! -d $RESULTDIR ]
	then
		mkdir $RESULTDIR
	else
		rm -rf $RESULTDIR/*
	fi
	cp $LOGDIR/* $RESULTDIR
	#cp /tmp/runlog.$translator $RESULTDIR
	rm -rf /tmp/runlog.$translator
	mv /tmp/tests_failed $LOGDIR/tests_failed_$translator
	echo $translator >> $LOGDIR/tests_failed_$translator
	
	cnt=`ls -l $COREDIR/core* | wc -l`
	if [ $cnt -gt 2 ]; then
	    echo "core generated for $translator" >> $LOGDIR/tests_failed_$translator
	    mv $COREDIR/core* $CORE_REPOSITORY/core*_$translator_`date +%F`
	fi
	
        tar cfz results_$translator.tgz $RESULTDIR;
#        mutt -a results_$translator.tgz -s "Sanity Results for `date +%F`" -i $LOGDIR/tests_failed $EMAIL <.;

	scp results_$translator.tgz $RFILE
	scp $LOGDIR/tests_failed_$translator $EMAIL
}

function clean_results()
{
    directory=`date +%F`
    mkdir /tmp/old/$directory -p;
    mv $RESULTDIR/* /tmp/old/$directory
}

function syscallbench_plot()
{
    cp /tmp/`date +%F` $SYSCALLDIR
    cd $SYSCALLDIR 
    mv today yesterday
    ln -s `date +%F` today
    $TOOLDIR/syscallbench-plot today yesterday > $LOGDIR/plot.ps
}
    
    
function post_run()
{
        #set +e;
        stop_glusterfs;
        cleanup;
	#syscallbench_plot;
        send_results;
	clean_results;
}
function start_glusterd()
{
    $BINDIR/sbin/glusterd
    if [ $? -ne 0 ]; then
        echo "glusterd could not be started. Returning"
        return 11;
    else
        echo "glusterd started"
        return 0;
    fi
}
function create_volume ()
{
    vol_type=$1;
    VOLNAME=$1;
    #delete all
    $BINDIR/sbin/gluster --mode=script volume delete afr
    $BINDIR/sbin/gluster --mode=script volume delete dht
    $BINDIR/sbin/gluster --mode=script volume delete stripe
    rm -rf $EXPORTDIR/export[1-4]
    mkdir -p  $EXPORTDIR/export[1-4]
    if [ $vol_type == "dht" ]; then

        echo "Creating the distribute volume";
        $BINDIR/sbin/gluster volume create $VOLNAME $(hostname):$EXPORTDIR/export1 $(hostname):$EXPORTDIR/export2 $(hostname):$EXPORTDIR/export3 $(hostname):$EXPORTDIR/export4;
        if [ $? -ne 0 ]; then
            echo "gluster volume create failed. Check glusterd log file";
            return 11;
        else
            return 0;
        fi
    fi

    if [ $vol_type == "afr" ]; then
        echo "Creating the replicate volume"
        $BINDIR/sbin/gluster volume create $VOLNAME replica 2 $(hostname):$EXPORTDIR/export1 $(hostname):$EXPORTDIR/export2;
        if [ $? -ne 0 ]; then
            echo "gluster volume create failed. Check glusterd log file";
            return 11;
        else
            return 0;
        fi
    fi

    if [ $vol_type == "stripe" ]; then
        echo "Creating the stripe volume";
        $BINDIR/sbin/gluster volume create $VOLNAME stripe 4 $(hostname):$EXPORTDIR/export1 $(hostname):$EXPORTDIR/export2 $(hostname):$EXPORTDIR/export3 $(hostname):$EXPORTDIR/export4;
        if [ $? -ne 0 ]; then
            echo "gluster volume create failed. Check glusterd log file";
            return 11;
        else
            return 0;
        fi
    fi    
	$BINDIR/sbin/gluster volume start $VOLNAME
	killall glusterfs glusterfsd

}
function stop_glusterd()
{
killall glusterd
}
function edit_client_volfile()
{
translator=$1
awk -v port=8000 '{print} /option remote-host dev-sanity-test/ {printf("option remote-port %d\n", port++)}' /etc/glusterd/vols/$translator/$translator-fuse.vol > /tmp/$translator-fuse.vol
cp /tmp/$translator-fuse.vol /etc/glusterd/vols/$translator/
}

function edit_server_volfile()
{
translator=$1
HOSTNAME=`hostname`
FNAME="/etc/glusterd/vols/$translator/$translator.$HOSTNAME.mnt-nightly_valgrind"
#.dev-sanity-test.mnt-nightly_valgrind-data-export1.vol
if [ $translator == afr ];
then
awk -v port=8000 '{print} /option transport-type tcp/ {printf("option transport.socket.listen-port %d\n", port++)}' $FNAME"-data-export1.vol" > /tmp/$translator.`hostname`-mnt-nightly_valgrind-data-export1.vol
rm -rf $FNAME"-data-export1.vol"
cp /tmp/$translator.`hostname`-mnt-nightly_valgrind-data-export1.vol /etc/glusterd/vols/$translator/

awk -v port=8001 '{print} /option transport-type tcp/ {printf("option transport.socket.listen-port %d\n", port++)}' $FNAME"-data-export2.vol" > /tmp/$translator.`hostname`-mnt-nightly_valgrind-data-export2.vol
rm -rf $FNAME"-data-export2.vol"
cp /tmp/$translator.`hostname`-mnt-nightly_valgrind-data-export2.vol /etc/glusterd/vols/$translator/
else #for dht or stripe
awk -v port=8000 '{print} /option transport-type tcp/ {printf("option transport.socket.listen-port %d\n", port++)}' $FNAME"-data-export1.vol" > /tmp/$translator.`hostname`-mnt-nightly_valgrind-data-export1.vol
rm -rf $FNAME"-data-export1.vol"
cp /tmp/$translator.`hostname`-mnt-nightly_valgrind-data-export1.vol /etc/glusterd/vols/$translator/

awk -v port=8001 '{print} /option transport-type tcp/ {printf("option transport.socket.listen-port %d\n", port++)}' $FNAME"-data-export2.vol" > /tmp/$translator.`hostname`-mnt-nightly_valgrind-data-export2.vol
rm -rf $FNAME"-data-export2.vol"
cp /tmp/$translator.`hostname`-mnt-nightly_valgrind-data-export2.vol /etc/glusterd/vols/$translator/

awk -v port=8002 '{print} /option transport-type tcp/ {printf("option transport.socket.listen-port %d\n", port++)}' $FNAME"-data-export3.vol" > /tmp/$translator.`hostname`-mnt-nightly_valgrind-data-export3.vol
rm -rf $FNAME"-data-export3.vol"
cp /tmp/$translator.`hostname`-mnt-nightly_valgrind-data-export3.vol /etc/glusterd/vols/$translator/

awk -v port=8003 '{print} /option transport-type tcp/ {printf("option transport.socket.listen-port %d\n", port++)}' $FNAME"-data-export4.vol" > /tmp/$translator.`hostname`-mnt-nightly_valgrind-data-export4.vol
rm -rf $FNAME"-data-export4.vol"
cp /tmp/$translator.`hostname`-mnt-nightly_valgrind-data-export4.vol /etc/glusterd/vols/$translator/
fi
}
function main()
{
        echo "In main";
	translator=$1
        #trap "post_run" INT TERM EXIT;
        pre_run;
	start_glusterd;
	create_volume $translator;

	edit_client_volfile $translator;
	edit_server_volfile $translator;
	stop_glusterd
        start_glusterfs;
	df
        run_tests; 
        #trap - INT TERM EXIT
        post_run;
}


#check for command line arg.
if [ ! $# -eq 1 ]
then
echo "Usage: nightly_valgrind.sh afr/dht/stripe";
exit;
fi

main "$@"