summaryrefslogtreecommitdiffstats
path: root/legacy/performance/nightly_performance.sh
blob: 5ec6f09d408110bf8f387eb834a2551ecc4312a2 (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
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
#!/bin/bash

ulimit -c unlimited
set -x
set -u
export PATH=$PATH:/opt/qa/tools:/usr/local/bin:/usr/local/sbin:/usr/sbin:/sbin
echo $PATH;

function _init()
{
    echo "inited";
        arch=$(uname);
    num_clients=1;
    if [ "$arch" == "SunOs" ]; then
        mount_type="nfs";
    else
        mount_type="fuse";
    fi
#    translator="dht";

    while getopts 't:c:m:' option
    do
        case $option in
            t)
                translator="$OPTARG"
                ;;
            c)
                num_clients="$OPTARG"
                ;;
            m)
                mount_type="$OPTARG"
                ;;
            esac
    done

    if [ "$arch" == "SunOs" ]; then
        mount_type="nfs";
    fi

    echo "translator: $translator" && echo "mount type: $mount_type";
    sleep 1;
    DEFAULT_LOGDIR="/usr/local/var/log/glusterfs";
#     if [ $mount_type == "fuse" ]; then
# 	WORKSPACE_DIR="/opt/users/nightly_performance/glusterfs.git";
#     else
# 	if [ $mount_type == "nfs" ]; then
# 	    WORKSPACE_DIR="/opt/users/nfs_performance/glusterfs.git";
# 	else
# 	    echo "Unknown mount type $mount_type. Exiting";
# 	    exit 22;
# 	fi
#     fi

    WORKSPACE_DIR="/root/sanity/glusterfs.git";
	
    WORKDIR="/export/nightly";
    SPECDIR="/opt/users/nightly_sanity/$translator";
    BUILDDIR="$WORKSPACE_DIR/build";
    
    LOGDIR="$WORKDIR/logs_$translator/`date +%F`";
    EXPORTDIR=$WORKDIR/data;
    MOUNTDIR=$WORKDIR/mount;
    RESULTDIR=/export/nightly-results;
    SYSCALLDIR="$WORKDIR/syscall";
    COREDIR="$WORKDIR/$translator";
    CORE_REPOSITORY="/opt/cores_$mount_type/$translator";

    if [ "$arch" == "Linux" ]; then
        echo "$COREDIR/core" > /proc/sys/kernel/core_pattern;
	echo "1" > /proc/sys/kernel/core_uses_pid;
    fi

    #EMAIL="dl-qa@gluster.com"
    EMAIL="raghavendrabhat@shell.gluster.com:/home/raghavendrabhat/nightly_sanity/";
#    EMAIL="raghavendrabhat@gluster.com";
    BINDIR="/opt/glusterfs/nightly";
    TOOLDIR="/opt/qa/tools/tools.git/syscallbench";
    echo "inited all the variables";

}

#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"


# 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 [ "$mount_type" == "both" ]; then
        j=0;
        for i in $(seq 1 $num_clients); do
            let "j+=1";
            mkdir -p $MOUNTDIR/client$j;
        done
        j=0;
        for i in $(seq 1 $num_clients); do
            let "j+=1";
            mkdir -p $MOUNTDIR/nfs_client$j;
        done
    else if [ "$mount_type" == "fuse" ];then
        j=0;
        for i in $(seq 1 $num_clients); do
            let "j+=1";
            mkdir -p $MOUNTDIR/client$j;
        done
    else if [ "$mount_type" == "nfs" ]; then
        j=0;
        for i in $(seq 1 $num_clients); do
            let "j+=1";
            mkdir -p $MOUNTDIR/nfs_client$j;
        done
    else
	echo "Unknown mount type; Please specify one of fuse , nfs or both";
    fi
    fi
    fi

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

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

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

function start_glusterd ()
{
    glusterd -LDEBUG
    if [ $? -ne 0 ]; then
        echo "glusterd could not be started. Returning"
        return 11;
    else
        echo "glusterd started"
        return 0;
    fi
}

function volume_create ()
{
    vol_type=$1;
    if [ $vol_type == "dht" ]; then
        echo "Creating the distribute volume";
        gluster volume create vol $(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"
        gluster volume create vol 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 sttipe volume";
        gluster volume create vol 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    
}

function start_volume()
{
    echo "Starting the volume";
    gluster volume start vol;
    if [ $? -ne 0 ]; then
        echo "gluster volume start failed. Check glusterd log file"
        return 11;
    else
        return 0;
    fi
}

function mount_volume ()
{
    echo "Started the volume. Mounting it"
    if [ $mount_type == "fuse" ]; then	
	modprobe fuse;
        if [ $? -ne  0 ]; then
            echo "loading fuse module failed. Returning";
            return 11;
        fi

        for i in $(seq 1 $num_clients)
        do
            #mount -t glusterfs $(hostname):vol $MOUNTDIR/client$i
            glusterfs --volfile-server=$(hostname) --volfile-id=vol $MOUNTDIR/client$i;
	    df -h; #to be removed
        done
    fi
   
    if [ $mount_type == "nfs" ]; then
        sleep 2;
        gluster volume info;
        sleep 2;
        showmount -e | grep "vol";
        success=$?;
        if [ $success -ne 0 ]; then
            echo "NFS server has not been started. There may be some problem while starting the volume or kernel nfs server may be running.";
            return 11;
        fi
        for i in $(seq 1 $num_clients)
        do
            mount $(hostname):vol $MOUNTDIR/nfs_client$i
        done
    fi

    if [ $mount_type == "both" ]; then
	modprobe fuse;
        if [ $? -ne 0 ]; then
            ret=22;
            echo "loading fuse module failed. Continuing with nfs";
        else
            ret=0;
        fi
        for i in $(seq 1 $num_clients)
        do 
            #mount -t glusterfs $(hostname):vol $MOUNTDIR/client$i
            if [ $ret -eq 0 ]; then
                glusterfs --volfile-server=$(hostname) --volfile-id=vol $MOUNTDIR/client$i;
            fi

            sleep 2;
            gluster volume info;
            sleep 2;
            mount $(hostname):vol $MOUNTDIR/nfs_client$i
        done
    # else
#         echo "Unknown mount type"
#         stop_glusterfs;
#         return 11;
    fi   
}

function start_glusterfs ()
{
    volume_create $translator;
    if [ $? -ne 0 ]; then
        echo "Error while creating the volume exiting.";
        return 11;
    fi
    start_volume;
    if [ $? -ne 0 ]; then
        echo "Error while starting the volume exiting.";
        return 11;
    fi
    mount_volume;
    if [ $? -ne 0 ];then
        if [ $mount_type == "fuse" ] || [ $mount_type == "both" ]; then
            echo "Mounted the volume";
        else
            echo "Error while mounting the volume. Exiting.";
            return 11;
        fi
    else
        echo "Mounted the volume";
    fi
}


function run_tests ()
{
    if [ $mount_type == "fuse" ]; then
        cd $MOUNTDIR/client1;
    fi
    
    if [ $mount_type == "nfs" ]; then
	cd $MOUNTDIR/nfs_client1;
    fi
    
        set +e;
        if [ "$arch" == "SunOs" ] || [ "$mount_type" == "nfs" ]; then
	    /opt/qa/tools/performance/perf.sh $MOUNTDIR/nfs_client1 
        else
            /opt/qa/tools/performance/perf.sh $MOUNTDIR/client1
        fi
        x=$?;
        if [ !x ] 
        then
                echo "Sanity Passed!";
        else
                echo "Sanity Failed. Please check your changes!";
        fi
}

function stop_glusterfs()
{
    for i in $(seq 1 $num_clients)
    do
        let "j += 1";
        if [ $mount_type == "fuse" ]; then
            umount $MOUNTDIR/client$j;
            if [ $? -ne 0 ]; then
		echo "unmounting $MOUNTDIR/client$j failed.";
	    fi
            umount $MOUNTDIR/client$j -l;
        else if [ $mount_type == "nfs" ]; then
            umount $MOUNTDIR/nfs_client$j;
            if [ $? -ne 0 ]; then
		echo "unmounting $MOUNTDIR/nfs_client$j failed";
	    fi
            umount $MOUNTDIR/nfs_client$j -l;
        else if [ $mount_type == "both" ]; then
            umount $MOUNTDIR/client$j;
	    if [ $? -ne 0 ]; then
		echo "unmounting $MOUNTDIR/client$j failed";
	    fi
            umount MOUNTDIR/client$j -l;
            umount $MOUNTDIR/nfs_client$j;
            if [ $? -ne 0 ]; then
		echo "unmounting $MOUNTDIR/nfs_client$j failed";
	    fi
            umount $MOUNTDIR/nfs_client -l;
	fi
	fi
	fi
    done

    gluster --mode=script volume stop vol;
    if [ $? -ne 0 ]; then
        echo "Error while stopping glusterfs server processes.";
        return 11;
    fi

    gluster --mode=script volume delete vol;
    if [ $? -ne  0 ]; then 
	echo "Error while deleting the server processes. Going ahead with umount";
	return 11;
    fi
}

function stop_glusterd ()
{
    pkill glusterd;
}

function cleanup()
{
    rm -rfv $EXPORTDIR/*;
    rm -rfv $MOUNTDIR/client*;
    rm -rfv $MOUNTDIR/nfs_client*
    rm -rfv /etc/glusterd;
}

function pre_run_cleanup ()
{
    stop_glusterd;
    cleanup;
}

function pre_run()
{
   #     update_git;
    #set -e;
    echo "Entered pre_run";
        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 -r $DEFAULT_LOGDIR $LOGDIR;
	rm -rf $DEFAULT_LOGDIR/*.log;
	rm -rf $DEFAULT_LOGDIR/bricks/*;

	#cp $LOGDIR/* $RESULTDIR;
        cp /export/runlog.$translator $RESULTDIR;
#	mv /export/tests_failed $LOGDIR/tests_failed_$translator;
#	echo $translator >> $LOGDIR/tests_failed_$translator;
#	cat /tmp/posix >> $LOGDIR/tests_failed_$translator;
	cat /tmp/git_head* >> $LOGDIR/perf-numbers_$translator;
	cat /export/bonnie >> $LOGDIR/perf-numbers_$translator;
	cat /export/iozone >> $LOGDIR/perf-numbers_$translator;
	cp /export/bonnie $LOGDIR;
	cp /expot/iozone $LOGDIR;

	DATE=$(date +%F);
	ls $COREDIR/core* ;
	if [ $? -eq 0 ]; then
	    echo "core generated for $translator" >> $LOGDIR/perf-numbers_$translator;
	    #mv $COREDIR/core* $CORE_REPOSITORY/core*_$translator_`date +%F`
	    for i in $(ls $COREDIR); do
		echo $i;
		if [ ! -d $CORE_REPOSITORY/$DATE ]; then
		    mkdir -p $CORE_REPOSITORY/$DATE;
		fi
		mv $COREDIR/$i $CORE_REPOSITORY/$DATE;
	    done
	fi
	
	cp $LOGDIR/* $RESULTDIR;
        tar cfj results_$translator.bz2 $RESULTDIR;
	cp $LOGDIR/perf-numbers_$translator $LOGDIR/tests_failed_$translator;
        #mutt -a results_$translator.bz2 -s "Performance sanity Results for `date +%F`" -i $LOGDIR/perf-numbers_$translator $EMAIL <.;

	###############IMP##############################
	#This part is needed if the iozone and bonnie results are to be uploaded in the dev server
#         cp /tmp/bonnie /tmp/bonnie_$translator_`date +%F`;
#         cp /tmp/iozone /tmp/iozone_$translator_`date +%F`;
#         scp /tmp/bonnie_`date +%F` raghavendrabhat@dev.gluster.com:/home/raghavendrabhat/public_html/test;
#         scp /tmp/iozone_`date +%F` raghavendrabhat@dev.gluster.com:/home/raghavendrabhat/public_html/test;
	##############IMP################################

	cp $LOGDIR/results_$translator.bz2 /tmp/logs_$translator.bz2
	scp /tmp/logs_$translator.bz2 raghavendrabhat@shell.gluster.com:/home/raghavendrabhat/result/
	scp $LOGDIR/tests_failed_$translator $EMAIL
	if [ $? -ne 0 ]; then
	    echo "sendimg mail failed" >/tmp/mail_sent;
	else
	    echo "sendimg mail successful" >/tmp/mail_sent;
	fi

        rm /export/bonnie /export/iozone;
	rm /tmp/logs_$translator.bz2;
}

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

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  check_and_kill ()
{
    pgrep glusterfs;
    if [ $? -eq 0 ]; then
	pkill glusterfs;
    fi

    pgrep glusterfsd;
    if [ $? -eq 0 ]; then
	pkill glusterfsd;
    fi

    pgrep glusterd;
    if [ $? -eq 0 ]; then 
	pkill glusterd;
    fi
}

function post_run()
{
        set +e;
        stop_glusterfs;
	check_and_kill;
        cleanup;
	syscallbench_plot;
        send_results;
	clean_results;
}

function main()
{
        echo "In main";
	#translator=$1
        trap "post_run" INT TERM EXIT;
	pre_run_cleanup;
        pre_run;
	start_glusterd;
        start_glusterfs;
        run_tests; 
        trap - INT TERM EXIT
        post_run;
}


#check for command line arg.
# if [ ! $# -eq 3 ]
# then
# echo "Usage: nightly.sh afr/dht/stripe <number of clients> <mount type>";
# exit;
# fi

_init "$@" && main "$@"