summaryrefslogtreecommitdiffstats
path: root/sanity/dev_sanity/sanity_test.sh
blob: 38a391d20f2ae9b968dd0ea9bbd339de5faea936 (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
#!/bin/bash
set -x

#Note : This script will be invoked from inotify.c program as soon as any new files created under /sanity/test/incoming directory.
#also note , incoming tar file will be in format  <translatorName_glusterUsername_developerHostname.tar> For ex:afr_lakshmipathi_entropy.tar 

# This script will pick up file from /sanity/test/incoming directory and performs following tasks
# a) Check whether no process is running,if so then move the tar file from queue to build directory ,extract it and build.
#   If process already running or build directory is not empty or mount point already in use,sleep 60 seconds & and check again.
# b) then start  gluster and mount it on client mount point.
# c) finally perform QA test on mount point.
# d) mail the results 





#directories
BASENAME=/sanity/test	
INCOMING_DIR=$BASENAME/incoming #where new tar will be scp'ed from remote machines.
BUILD_DIR=$BASENAME/build	#where glusterfs build is done. 
RESULTS_DIR=$BASENAME/results   # final QA test results will be available.
QUEUE_DIR=$BASENAME/queue	#tar files will be queued here first,before moving to build dir.
MOUNT_PT=/export/sanity		#sanity test mount point
#RESULTS_DIR=$MOUNT_PT/results


#Standard volume files will be available under VOL_DIR
VOL_DIR=$BASENAME/spec
# for afr
AFR_CLIENT_VOL=$VOL_DIR/afr_client.vol
AFR_SERVER_VOL=$VOL_DIR/afr_server.vol
#for stripe
STRIPE_CLIENT_VOL=$VOL_DIR/stripe_client.vol
STRIPE_SERVER_VOL=$VOL_DIR/stripe_server.vol
#for dht
DHT_CLIENT_VOL=$VOL_DIR/dht_client.vol
DHT_SERVER_VOL=$VOL_DIR/dht_server.vol

#glusterfs installation path
INSTALL_DIR=$BASENAME/install
TRASH_DIR=$BASENAME/trash

#sanity script logfile
LOG_FILE=$BASENAME/sanity.log

#qa tools path
QA_DIR=/opt/qa/tools/system_light
QA_TOOLS=/opt/qa/tools/system_light/run.sh


########################################### functions########################################### 



#move the tar file from INCOMING_DIR to QUEUE_DIR.
function mv_incoming_queue(){
echo "mv_incoming_queue:==>start" >> $LOG_FILE 2>&1

tarball=`ls -tr $INCOMING_DIR | head -1`
echo "mv_incoming_queue:Moving tar file from $INCOMING_DIR/$tarball to $QUEUE_DIR" >> $LOG_FILE 2>&1
if [ -f $tarball ]
then
    echo " $tarball file exist" >> $LOG_FILE 2>&1
else
    echo "file not found " >> $LOG_FILE 2>&1
fi

#cut tar part from transltor - so that it could be used for vol.name,log file and mount point.
translator_name=`echo $tarball | awk '{split($0,array,"_")} END{print array[1]}'`

#before moving to tar to queue , check whether any file with same name exists - if so ,then add inode that file.
if [ -f $QUEUE_DIR/$tarball ]
then
    echo " $tarball file exist.move it queue after renaming it." >> $LOG_FILE 2>&1
	mv $INCOMING_DIR/$tarball $QUEUE_DIR/`echo $tarball | awk '{split($0,array,".")} END{print array[1]}'`.`ls -i $INCOMING_DIR/$tarball | cut -d' ' -f1`.tgz
else
mv $INCOMING_DIR/$tarball $QUEUE_DIR
fi

echo "mv_incoming_queue:==> exit " >> $LOG_FILE 2>&1
}




			
#move file from QUEUE_DIR to BUILD_DIR
function mv_queue_build(){
echo "mv_queue_build:==>start" >> $LOG_FILE 2>&1
echo "mv_queue_build:Moving tar file from  $QUEUE_DIR to build " >> $LOG_FILE 2>&1

tarball=`ls -tr $QUEUE_DIR | head -1`
if [ -f $1 ]
then
    echo " $tarball file exist" >> $LOG_FILE 2>&1
else
    echo "file not found " >> $LOG_FILE 2>&1
fi

echo "moving $QUEUE_DIR/$tarball to $BUILD_DIR/$translator_name" >> $LOG_FILE 2>&1
mv -v $QUEUE_DIR/$tarball  $BUILD_DIR/$translator_name >> $LOG_FILE 2>&1
echo "mv_queue_build:==> exit " >> $LOG_FILE 2>&1
}






#check whether tar can be moved from Queue to build - to start build process.
#So a) check mount point is free or not.b)glusterfs/d already running or not.c)Verify build directory ,ensure no other process started building.
function is_ready(){
echo "is_ready:==>start" >> $LOG_FILE 2>&1

#is glusterfs client already mounted,for specific translator?
echo "checking for $translator_name_client.vol"
cat /etc/mtab | grep $translator_name"_client.vol"
if [ $? -eq 0 ]
then
    echo " `date` : $translator_name Already  mounted" >> $LOG_FILE 2>&1
    echo " `date` : No free slot avail. for $translator_name" 
	sleep 60
	is_ready
else
    echo "not  mounted.proceed. " >> $LOG_FILE 2>&1 
    rm -rf $BASENAME/$translator_name"_mail.txt"
    touch $BASENAME/$translator_name"_mail.txt"

fi


#is glusterfs and glusterfsd aready running for the given translator?
for file in `pgrep glusterfs`
do
grep $translator_name"_client.vol" /proc/$file/cmdline 
if [ $? -eq 0 ]
	then 
	echo "$translator_name client runnning with pid $file"
	sleep 60
	is_ready
	fi
grep $translator_name"_server.vol" /proc/$file/cmdline 
if [ $? -eq 0 ]
	then 
	echo "$translator_name server runnning with pid $file"
	sleep 60
	is_ready
	fi
done

#glusterfs not running and not mounted but it's building.
if [ "$(ls -A $BUILD_DIR/$translator_name)" ]; then
     echo "$BUILD_DIR/$translator_name is not Empty - Some other process is building glusterfs" >> $LOG_FILE 2>&1
	sleep 60
	is_ready
else
    echo "$BUILD_DIR/$translator_name is Empty. Proceed." >> $LOG_FILE 2>&1
fi
echo "is_ready:==> exit " >> $LOG_FILE 2>&1
}




#Build glusterfs from src
function build_glusterfs(){
echo " build_glusterfs:==>start" >> $LOG_FILE 2>&1
echo " moving to $BUILD_DIR/$translator_name and extract $tarball" >> $LOG_FILE 2>&1
cd $BUILD_DIR/$translator_name && tar -xvf $tarball 
#buildflag - status of build
buildflag='y'
#run autogen.sh
./autogen.sh
echo "perform cmm" >> $LOG_FILE 2>&1
./configure --prefix $INSTALL_DIR/$translator_name
make && make install
if [ $? -eq 0 ]
then
    echo "build successful." >> $LOG_FILE 2>&1
else
    echo "build not successful. " >> $LOG_FILE 2>&1
     buildflag='n'
fi
echo " build_glusterfs:==> exit " >> $LOG_FILE 2>&1
}





#make sure standard volume files already present on the system.-check for missing volume files.
function check_vol_files(){
MISSING_FILES='n'
 [ ! -f   $AFR_CLIENT_VOL ] && 	echo "$AFR_CLIENT_VOL not found " && MISSING_FILES='y'
 [ ! -f $AFR_SERVER_VOL ] &&  echo "$AFR_SERVER_VOL not found" && MISSING_FILES='y'
 [ ! -f $STRIPE_CLIENT_VOL  ] &&  echo "$STRIPE_CLIENT_VOL not found" && MISSING_FILES='y'
 [ ! -f $STRIPE_SERVER_VOL  ] &&   echo "$STRIPE_SERVER_VOL not found" && MISSING_FILES='y'
 [ ! -f $DHT_CLIENT_VOL  ] &&   echo "$DHT_CLIENT_VOL not found" && MISSING_FILES='y'
 [ ! -f $DHT_SERVER_VOL  ] &&  echo "$DHT_SERVER_VOL not found" && MISSING_FILES='y'

if [ $MISSING_FILES == 'n' ]
	then 
		echo "volumes files found" >> $LOG_FILE 2>&1
	else
		echo "Missing Volume files" >> $LOG_FILE 2>&1
fi

}



#start glusterfs server.
function start_glusterfsd(){
echo " start_glusterfsd:==>start" >> $LOG_FILE 2>&1
#Log and volume files  named after specified translator like stripe_client.vol or afr_client.vol
server_vol=$translator_name"_server.vol"
server_log=$translator_name"_server.log"
start_server='y'

echo "Starting glusterfs server" >> $LOG_FILE 2>&1
echo "Running command:$INSTALL_DIR/$translator_name/sbin/glusterfsd -f $VOL_DIR/$server_vol -l $RESULTS_DIR/$server_log -L DEBUG" >> $LOG_FILE 2>&1
$INSTALL_DIR/$translator_name/sbin/glusterfsd -f $VOL_DIR/$server_vol -l $RESULTS_DIR/$server_log -L DEBUG &

if [ $? -eq 0 ]; then
echo "server started successfully." >> $BASENAME/$translator_name"_mail.txt"
else
echo "Unable to start glusterfsd.See log file  $RESULTS_DIR/$server_log for more details" >> $BASENAME/$translator_name"_mail.txt"
start_server='n'
fi
echo " start_glusterfsd:==> exit " >> $LOG_FILE 2>&1
}
#creat and start glusterfsd 
function creat_start_glusterfsd(){
pgrep glusterd
if [ $? -eq 1 ];then
$INSTALL_DIR/$translator_name/sbin/glusterd
fi

#re-create backend newly
rm -rf /export/sanity/afr_export*

mkdir -p /export/sanity/afr_export
mkdir -p /export/sanity/afr_export1

#creat volume
$INSTALL_DIR/$translator_name/sbin/gluster volume create $translator_name replica 2 `hostname`:/export/sanity/afr_export `hostname`:/export/sanity/afr_export1
#start volume
$INSTALL_DIR/$translator_name/sbin/gluster volume start $translator_name
if [ $? -eq 0 ]; then
echo "Following gluster volume started successfully." >> $BASENAME/$translator_name"_mail.txt"
$INSTALL_DIR/$translator_name/sbin/gluster volume info >> $BASENAME/$translator_name"_mail.txt"
echo "----------------------------------------------";
fi
}


#start glusterfs client.
function start_glusterfs(){
echo " start_glusterfs:==>start" >> $LOG_FILE 2>&1
echo "Trying to mount glusterfs on $MOUNT_PT/$translator_name " >> $LOG_FILE 2>&1

#client volume file name and log file name
client_vol=$translator_name"_client.vol"
client_log=$translator_name"_client.log"
start_client='y'

echo "Running command:$INSTALL_DIR/$translator_name/sbin/glusterfs -f $VOL_DIR/$client_vol $MOUNT_PT/$translator_name -l $RESULTS_DIR/$client_log -L DEBUG" >> $LOG_FILE 2>&1
$INSTALL_DIR/$translator_name/sbin/glusterfs -f $VOL_DIR/$client_vol $MOUNT_PT/$translator_name -l $RESULTS_DIR/$client_log -L DEBUG 

if [ $? -eq 0 ]; then
echo "glusterfs client started" >> $BASENAME/$translator_name"_mail.txt"
else
echo "Unable to mount glusterfs.See log file  for more details" >> $BASENAME/$translator_name"_mail.txt"
start_client='n'
fi
echo " start_glusterfs:==> exit " >> $LOG_FILE 2>&1
}
#mount gluster volume
function mount_glusterfs(){
mount -t glusterfs `hostname`:$translator_name $MOUNT_PT/$translator_name
if [ $? -eq 0 ];then
echo "gluster volume mounted successfully." >> $BASENAME/$translator_name"_mail.txt"
df >> $BASENAME/$translator_name"_mail.txt"
echo "-----------------------------------";
fi
}

function umount_glusterfs(){
umount -l $MOUNT_PT/$translator_name
}

function stop_glusterd(){
$INSTALL_DIR/$translator_name/sbin/gluster --mode=script volume  stop $translator_name
$INSTALL_DIR/$translator_name/sbin/gluster --mode=script volume  delete $translator_name
/etc/init.d/glusterd stop

#cleanup build dirs
rm -f $BUILD_DIR/$translator_name/.gitignore 
mv -vf $BUILD_DIR/$translator_name/*  $TRASH_DIR # >> $LOG_FILE 2>&1
rm -rf $TRASH_DIR/*
}



#perform QA test.
function start_tests() {
echo " start_tests:==>start" >> $LOG_FILE 2>&1

    echo "starting QA test"  >> $LOG_FILE 2>&1
    cd $QA_DIR
    $QA_TOOLS -w $MOUNT_PT/$translator_name  -l $RESULTS_DIR/$translator_name"QA.log"
    echo "QA test: completed" >> $BASENAME/$translator_name"_mail.txt"

echo " start_tests:==> exit " >> $LOG_FILE 2>&1
}



#save logs and sent a mail.
function cleanup(){
echo "cleanup ==> start " >> $LOG_FILE 2>&1
#stop glusterfs and glusterfsd 
for file in `pgrep glusterfs`
do
grep $translator_name"_client.vol" /proc/$file/cmdline 
if [ $? -eq 0 ]
	then 
	kill $file
	fi
grep $translator_name"_server.vol" /proc/$file/cmdline 
if [ $? -eq 0 ]
	then 
	kill $file
	fi
done

#save results
echo "Moving glusterfs log files " >> $LOG_FILE 2>&1
trans_user_sys=`echo $tarball | awk '{split($0,array,".")} END{print array[1]}'`

#logs=$RESULTS_DIR/$translator_name/$trans_user_sys/`date +%m_%d_%y_%T`
mkdir -p $RESULTS_DIR/$translator_name/$trans_user_sys
cd $RESULTS_DIR/$translator_name/$trans_user_sys
logs=`date +%m_%d_%y_%T`
mkdir -vp $logs >> $LOG_FILE 2>&1

mv  -v $RESULTS_DIR/$server_log   $logs/ >> $LOG_FILE 2>&1
mv  -v $RESULTS_DIR/$client_log  $logs/ >> $LOG_FILE 2>&1

echo "Moving QA test log file "  >> $LOG_FILE 2>&1
mv  -v $RESULTS_DIR/$translator_name"QA.log"  $logs >> $LOG_FILE 2>&1

#create tar file of logs
echo "creating tar file tar cfz $trans_user_sys".tgz" $logs " >> $LOG_FILE 2>&1 
tar cfz $trans_user_sys".tgz" $logs

#attach the log files and sent to developer.
#get from address
usr=`echo $trans_user_sys | cut -d'_' -f2`
sys=`echo $trans_user_sys | cut -d'_' -f3`
echo "See attached log files for more details " >> $BASENAME/$translator_name"_mail.txt"
#mutt -s "Developer Sanity Test" -a $trans_user_sys".tgz" "$usr@gluster.com" < $BASENAME/$translator_name"_mail.txt"
mail -s "dev sanity test results"  -a $trans_user_sys".tgz" "$usr@gluster.com" < $BASENAME/$translator_name"_mail.txt"
rm -f $BUILD_DIR/$translator_name/.gitignore 
mv -vf $BUILD_DIR/$translator_name/*  $TRASH_DIR >> $LOG_FILE 2>&1

echo "Cleanup installed binaries" >> $LOG_FILE 2>&1
mv  -v $INSTALL_DIR/$translator_name/* $TRASH_DIR >> $LOG_FILE 2>&1
mv $BASENAME/$translator_name"_mail.txt" $TRASH_DIR
rm  -r $TRASH_DIR/* >> $LOG_FILE 2>&1

echo "cleanup ==> exit " >> $LOG_FILE 2>&1
}

function mail_status(){
#mail -s "dev sanity test results"  -a $trans_user_sys".tgz" "$usr@gluster.com" < $BASENAME/$translator_name"_mail.txt"
#save results
echo "Moving glusterfs log files " >> $LOG_FILE 2>&1
trans_user_sys=`echo $tarball | awk '{split($0,array,".")} END{print array[1]}'`

#logs=$RESULTS_DIR/$translator_name/$trans_user_sys/`date +%m_%d_%y_%T`
mkdir -p $RESULTS_DIR/$translator_name/$trans_user_sys
cd $RESULTS_DIR/$translator_name/$trans_user_sys
logs=`date +%m_%d_%y_%T`
mkdir -vp $logs >> $LOG_FILE 2>&1

#mv  -v $RESULTS_DIR/$server_log   $logs/ >> $LOG_FILE 2>&1
#mv  -v $RESULTS_DIR/$client_log  $logs/ >> $LOG_FILE 2>&1

echo "Moving QA test log file "  >> $LOG_FILE 2>&1
mv  -v $RESULTS_DIR/$translator_name"QA.log"  $logs >> $LOG_FILE 2>&1

#create tar file of logs
echo "creating tar file tar cfz $trans_user_sys".tgz" $logs " >> $LOG_FILE 2>&1 
tar cfz $trans_user_sys".tgz" $logs

#attach the log files and sent to developer.
#get from address
usr=`echo $trans_user_sys | cut -d'_' -f2`
sys=`echo $trans_user_sys | cut -d'_' -f3`
echo "See attached log files for more details " >> $BASENAME/$translator_name"_mail.txt"
#mutt -s "Developer Sanity Test" -a $trans_user_sys".tgz" "$usr@gluster.com" < $BASENAME/$translator_name"_mail.txt"
cat  /sanity/test/results/tests_failed >> $BASENAME/$translator_name"_mail.txt"
rm -rf /sanity/test/results/tests_failed
mail -s "dev sanity test results"  -a $trans_user_sys".tgz"  "$usr@gluster.com" < $BASENAME/$translator_name"_mail.txt"
}

########################################### MAIN part###########################################

echo "###########sanity_test.sh log################################" >> $LOG_FILE 2>&1

date>>$LOG_FILE
echo "############" >> $LOG_FILE 2>&1


#move the tar file
#echo "checking volume files" >> $LOG_FILE 2>&1
#check_vol_files
#echo "done." >> $LOG_FILE 2>&1


#move $INCOMING tar file to $QUEUE directory.
echo "moving tar file to $QUEUE_DIR directory" >> $LOG_FILE 2>&1
mv_incoming_queue	
echo "done." >> $LOG_FILE 2>&1

#check for status
is_ready


#move from $QUEUE to $BUILD if it is free.
echo "Moving to build.." >> $LOG_FILE 2>&1
mv_queue_build

echo "Start building.." >> $LOG_FILE 2>&1
build_glusterfs
echo "done." >> $LOG_FILE 2>&1
if [ $buildflag == 'n' ]
	then
	echo "build process  : FAILED" >> $BASENAME/$translator_name"_mail.txt"
	else
	echo  "build process : PASSED" >> $BASENAME/$translator_name"_mail.txt"
	#start_glusterfsd # starting server
	creat_start_glusterfsd
#	if [ $start_server == 'y' ]
#	then
#	start_glusterfs  # starting client
#	fi
	#qa testing
	mount_glusterfs;sleep 10;
#	if [ $start_client == 'y' ]
#	then
	start_tests  # start testing 
#	fi

fi
#clean up build dir
#cleanup
umount_glusterfs
stop_glusterd
mail_status
###########################################EOF###########################################