summaryrefslogtreecommitdiffstats
path: root/For Weekly Test/12-09-2011/gsmselftest.py
blob: 9f8d0c25359b012da2c0ff37706694ccc608173c (plain) (blame)
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
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
#! /usr/bin/env python
import sys
import ControllerClass
import DbClass
import PingClass
from time import sleep

global resultsList
resultsList = list()

def ping(handler):
	
	global serverStatus
	
	if handler == 'landline':
		server = PingClass.Ping('sipgate.de')
		serverStatus = server.ping(1)

	elif handler == 'sip':
		server = PingClass.Ping('132.230.4.8')
		serverStatus = server.ping(1)

	elif handler == 'unisip':
		server = PingClass.Ping('132.230.252.228')
		serverStatus = server.ping(1)

	elif handler == 'GSMRZ3':
		server = PingClass.Ping('localhost')
		serverStatus = server.ping(1)

	elif handler == 'GSMRZ2':
		server = PingClass.Ping('10.4.58.241')
		serverStatus = server.ping(1)
	else:
		serverStatus = 1

def allPing():
	
	global sipGate
	global sipServer
	global unisip
	global gsmBox1
	global gsmBox2
		
	server = PingClass.Ping('sipgate.de')
	sipGate = server.ping(1)

	server = PingClass.Ping('132.230.4.8')
	sipServer = server.ping(1)

	server = PingClass.Ping('132.230.252.228')
	unisip = server.ping(1)

	server = PingClass.Ping('localhost')
	gsmBox1 = server.ping(1)

	server = PingClass.Ping('10.4.58.241')
	gsmBox2 = server.ping(1)

def initDB():
    global dbStatus
    global db
    
    db = DbClass.DBMySQLConnection('root', 'randompasswordSQL', 'localhost', 'gsmselftesting')
    db.connectDB()
    dbStatus = db.connectDB()

def initTest(callFrom,callTo):
    global dest
    global caller
    global callAdd
    global accCaller
    global recAdd
    global destNo
    global accDest
    global result
    global repeatTest
    
    initDB()
    
    if dbStatus != 0:
        
        dest = db.deviceAddress(str(callTo))
        
        caller = db.deviceAddress(str(callFrom))
        
        callAdd = caller[0]
        accCaller = caller[2]+':'+caller[3]+':'+caller[4]+':'
        
        destAdd = dest[0]
        destNo = dest[1]
        accDest = dest[2]+':'+dest[3]+':'+dest[4]+':'
        
        makeTest = ControllerClass.doTheTest(callFrom, callAdd, accCaller, callTo, destAdd, destNo, accDest)	
        makeTest.FuncTest()
        
        result = str(makeTest.testResult)
    
    else:
        print "No connection to Database"
    
    return result

def initTrueTable():
	nanoBTS1 = None
	nanoBTS2 = None
    	nanoBTS3 = None
    	o2Card = None
	eplusCard = None
	vodaCard = None
	tmobileCard = None
	outgoingLandline = None
	asteriskServer = None

    	for x in resultsList:

        	destination = x[1]
        	result = x[2]
		caller = x[0]

        	if destination == 'GSMRZ1': 
                	if result =='486':
		    		nanoBTS1 = False
                    		for y in resultsList:
                    			call = y[0]
					destination = y[1]
                    			result = y[2]
                    			if call == 'GSMRZ1':
						if result == '200':
							nanoBTS1 = True

					if destination == 'GSMRZ1':
						if result == '200':
							nanoBTS1 = True
                	elif result =='200':
				nanoBTS1 = True

        	elif destination == 'GSMRZ2': 
                	if result =='486':
		    		nanoBTS2 = False
                    		for y in resultsList:
                    			call = y[0]
					destination = y[1]
                    			result = y[2]
                    			if call == 'GSMRZ2':
						if result == '200':
							nanoBTS2 = True

					if destination == 'GSMRZ2':
						if result == '200':
							nanoBTS2 = True
                	elif result =='200':
				nanoBTS2 = True

        	elif destination == 'GSMRZ3': 
                	if result =='486':
		    		nanoBTS3 = False
                    		for y in resultsList:
                    			call = y[0]
					destination = y[1]
                    			result = y[2]
                    			if call == 'GSMRZ3':
						if result == '200':
							nanoBTS3 = True

					if destination == 'GSMRZ2':
						if result == '200':
							nanoBTS3 = True
                	elif result =='200':
				nanoBTS3 = True

       		elif destination == 'GSMExt.O2': 
                	if result =='486':
		    		o2Card = False
                    		for y in resultsList:
                    			call = y[0]
					destination = y[1]
                    			result = y[2]
                    			if call == 'GSMExt.O2':
						if result == '200':
							o2Card = True

					if destination == 'GSMExt.O2':
						if result == '200':
							o2Card = True
                	elif result =='200':
				o2Card = True

        	elif destination == 'GSMExt.Voda': 
                	if result =='486':
		    		vodaCard = False
                    		for y in resultsList:
                    			call = y[0]
					destination = y[1]
                    			result = y[2]
                    			if call == 'GSMExt.Voda':
						if result == '200':
							vodaCard = True

					if destination == 'GSMExt.Voda':
						if result == '200':
							vodaCard = True
                	elif result =='200':
				vodaCard = True

        	elif destination == 'GSMExt.Eplus': 
                	if result =='486':
		    		eplusCard = False
                    		for y in resultsList:
                    			call = y[0]
					destination = y[1]
                    			result = y[2]
                    			if call == 'GSMExt.Eplus':
						if result == '200':
							eplusCard = True

					if destination == 'GSMExt.Eplus':
						if result == '200':
							eplusCard = True
                	elif result =='200':
				eplusCard = True

        	elif destination == 'GSMExt.Tm': 
                	if result =='486':
		    		tmobileCard = False
                    		for y in resultsList:
                    			call = y[0]
					destination = y[1]
                    			result = y[2]
                    			if call == 'GSMExt.Tm':
						if result == '200':
							tmobileCard = True

					if destination == 'GSMExt.Tm':
						if result == '200':
							tmobileCard = True
                	elif result =='200':
				tmobileCard = True

        	elif destination == 'sip': 
                	if result =='486':
		    		asteriskServer = False
                    		for y in resultsList:
                    			call = y[0]
					destination = y[1]
                    			result = y[2]
                    			if call == 'sip':
						if result == '200':
							asteriskServer = True

					if destination == 'sip':
						if result == '200':
							asteriskServer = True
            
                	elif result =='200':
				asteriskServer = True

		if caller == 'GSMRZ1' or caller == 'GSMRZ2' or caller == 'GSMRZ3':

        		if destination == 'landline': 
                		if result =='486':
		    			outgoingLandline = False
                    			for y in resultsList:
                    				call = y[0]
						destination = y[1]
                    				result = y[2]
                    				if caller == 'GSMRZ1' or caller == 'GSMRZ2' or caller == 'GSMRZ3':
							if destination == 'landline':
								if result == '200':
									outgoingLandline = True

	print '\n'
    	if o2Card == False and eplusCard == False and vodaCard == False and tmobileCard == False:
		print 'GSM BOX Modem down'
    	else:
    		if o2Card == False:
			print "O2 card indicate having problem"
    		if eplusCard == False:
			print "eplus card indicate having problem"
    		if vodaCard == False:
			print "vodaphone card indicate having problem"
    		if tmobileCard == False:
			print "T-Mobile card indicate having problem"
		print '\n'

    	if nanoBTS1 == False and nanoBTS2 == False and nanoBTS3 == False:
		print 'openBSC down'
    	else:
    		if nanoBTS1 == False:
			print "nanoBTS 1 indicate having problem"
    		if nanoBTS2 == False:
			print "nanoBTS 2 indicate having problem"
    		if nanoBTS3 == False:
			print "nanoBTS 3 indicate having problem"

	if outgoingLandline == False:
		print 'outgoing from GSM RZ to landline having problem'
		print '\n'

    	if asteriskServer == False:
		print "Asterisk server indicate having problem"
    	elif asteriskServer == True:
		print 'Asterisk server working good'
	print '\n'


def doTest(callFrom,callTo):
	ping(callFrom)

	if serverStatus <> 0:

		ping(callTo)
		if serverStatus <> 0:
			print 'Call From	: ', callFrom
			print 'Call Destination	: ', callTo
            		initTest(callFrom,callTo)
			resultsList.append([callFrom, callTo, result])
			db.errorCode(result)
			print 'Result		: ' +result+ ' ' +db.errCode
			sleep(5)
		else:
			print '[failed] 500 '+callTo+ ' Server Internal Error'
	else:
		print '[failed] 500 '+callFrom+ ' Server Internal Error'

def doSipTest():
	
	print '--SIP Part Test--'
	destList = ['gsmr1','gsmr2', 'gsmr3', 'landline', 'unisip', 'GSMExt.O2', 'GSMExt.Voda', 'GSMExt.Eplus', 'GSMExt.Tm' ]
	#destList = ['landline']
	for callTo in destList:

		callFrom = 'sip'
		doTest(callFrom, callTo)

def doLandlineTest():
	
	print '--Landline Part Test--'
	destList = ['GSMRZ1','unisip', 'sip'] 

	for callTo in destList:

		callFrom = 'landline'
		doTest(callFrom, callTo)

def doGsmrzTest():

	print '--GSM Part Test--'
	destList = ['GSMRZ1','GSMRZ2', 'GSMRZ3']
	callList = ['sip']
	
	for callFrom in callList:

		for callTo in destList:
			doTest(callFrom, callTo)
			resultsList.append([callFrom, callTo, result])
	initTrueTable()
	
def doGsmExtTest():
	
	destList = ['GSMExt.O2', 'GSMExt.Voda', 'GSMExt.Eplus', 'GSMExt.Tm']
	callList = ['sip']
	#callList = ['sip', 'GSMRZ1']

	for callFrom in callList:
		for callTo in destList:
			doTest(callFrom, callTo)
			resultsList.append([callFrom, callTo, result])
	initTrueTable()

def doAllTest():

	doSipTest()
	doLandlineTest()
	doGsmrzTest()
	doGsmExtTest()

def smartTest():
    ping('sip')
    if serverStatus == 0:
	print "Dont have connection to SIP Asterisk server, can't make a test"
	sys.exit(1)

    callerList = ['sip']
    destinationList = ['SIP', 'GSMExt']
    #destinationList = ['GSMExt', 'GSMRZ', 'SIP', 'RZOutgoing', 'RZincoming']
    for callFrom in callerList:
        for destination in destinationList:
            
            if destination == 'GSMRZ':
                print "make a call to GSMRZ1"
                initTest(callFrom,'GSMRZ1')
                
                if result == '200':
                    print "make a call to GSMRZ2"
                    initTest(callFrom,'GSMRZ2')
                    
                    if result == '200':
                        print "make a call to GSMRZ3"
                        initTest(callFrom,'GSMRZ3')
                        
                        if result == '200': 
                            print "all network on GSMRZ are working"
                        elif result == '486':
                            print "BTS 3 Down"
                        else:
                            print "incomplete test, Handler having error, please do one more test"
                    
                    elif result == '486':
                        print "make a call to GSMRZ3"
                        initTest(callFrom,'GSMRZ3')
                        
                        if result == '200':
                            print "BTS 2 Down"
                        elif result == '486':
                            print "BTS 2 and 3 indicate having problem"
                        else:
                            print "incomplete test, Handler having error, please do one more test"
                    else:
                        print "incomplete test, Handler having error, please do one more test"
                
                elif result == '486':
                    print "make a call to GSMRZ2"
                    initTest(callFrom,'GSMRZ2')
                    
                    if result == '200':
                        print "make a call to GSMRZ3"
                        initTest(callFrom,'GSMRZ3')
                        
                        if result == '200': 
                            print "BTS 1 Down"
                        elif result == '486':
                            print "BTS 1 & 3 indicate having problem"
                        else:
                            print "incomplete test, Handler having error, please do one more test"
                    
                    elif result == '486':
                        print "make a call to GSMRZ3"
                        
                        if result == '200':
                            print "BTS 1 & 2 indicate having problem"
                        elif result == '486':
                            print "OpenBSc Down"
                        else:
                            print "incomplete test, Handler having error, please do one more test"
                    else:
                        print "incomplete test, Handler having error, please do one more test"
                else:
                    print "incomplete test, Handler having error, please do one more test"

            
            elif destination == 'GSMExt':
                
                initTest(callFrom,'GSMExt.O2')                  
		if result == '200':
                        
                        initTest(callFrom,'GSMExt.Voda')                        
                        if result == '200':
                            
                            initTest(callFrom,'GSMExt.Eplus')                            
                            if result == '200': 
                                
				initTest(callFrom,'GSMExt.Tm')
                            	if result == '200': 
                                	print "All network on GSM external are working"
                            	elif result == '486':
                                	print "T-Mobile card indicate having problem"
                            	else:
                                	print "incomplete test, Handler having error, please do one more test"

			    elif result == '486':

				initTest(callFrom,'GSMExt.Tm')
                            	if result == '200': 
                                	print "E-Plus card indicate having problem"
                            	elif result == '486':
                                	print "T-Mobile and E-Plus card indicate having problem"
                            	else:
                                	print "incomplete test, Handler having error, please do one more test"

                        elif result == '486':
                            
                            initTest(callFrom,'GSMExt.Eplus')                            
                            if result == '200':
                                
				initTest(callFrom,'GSMExt.Tm')
                            	if result == '200': 
                                	print "Vodaphone card indicate having problem"
                            	elif result == '486':
                                	print "T-Mobile and Vodaphone cards indicate having problem"
                            	else:
                                	print "incomplete test, Handler having error, please do one more test"

                            elif result == '486':
                                
				initTest(callFrom,'GSMExt.Tm')
                            	if result == '200': 
                                	print "Vodaphone and E-Plus card indicate having problem"
                            	elif result == '486':
                                	print "T-Mobile, E-Plus and Vodaphone cards indicate having problem"
                            	else:
                                	print "incomplete test, Handler having error, please do one more test"
                            else:
                                print "Incomplete test, Handler having error, please do one more test"
                    
		elif result == '486':
                        
                        initTest(callFrom,'GSMExt.Voda')                        
                        if result == '200':
                            
                            initTest(callFrom,'GSMExt.Eplus')                            
                            if result == '200': 
                                
				initTest(callFrom,'GSMExt.Tm')
                            	if result == '200': 
                                	print "O2 card indicate having problem"
                            	elif result == '486':
                                	print "T-Mobile and O2 cards indicate having problem"
                            	else:
                                	print "incomplete test, Handler having error, please do one more test"

                            elif result == '486':
                                
				initTest(callFrom,'GSMExt.Tm')
                            	if result == '200': 
                                	print "O2 and E-Plus cards indicate having problem"
                            	elif result == '486':
                                	print "T-Mobile, E-Plus and O2 cards indicate having problem"
                            	else:
                                	print "incomplete test, Handler having error, please do one more test"
			    else:
				print "incomplete test, Handler having error, please do one more test"
                        
                        elif result == '486':
                            
                            initTest(callFrom,'GSMExt.Eplus')                            
                            if result == '200':
                                
				initTest(callFrom,'GSMExt.Tm')
                            	if result == '200': 
                                	print "O2 and Vodaphone cards indicate having problem"
                            	elif result == '486':
                                	print "T-Mobile, O2 and Vodaphone cards indicate having problem"
                            	else:
                                	print "incomplete test, Handler having error, please do one more test"

                            elif result == '486':
                                
				initTest(callFrom,'GSMExt.Tm')
                            	if result == '200': 
                                	print "O2, E-Plus and Vodaphone cards indicate having problem"
                            	elif result == '486':
                                	print "GSM External Modem Down"
                            	else:
                                	print "incomplete test, Handler having error, please do one more test"
                            else:
                                print "incomplete test, Handler having error, please do one more test"
                        else:
                            print "incomplete test, Handler having error, please do one more test"
		else:
			print "incomplete test, Handler having error, please do one more test"
            
            elif destination == 'SIP':
		
                ping('landline')
		if serverStatus <> 0:
                	initTest(callFrom,'landline')
                
                	if result == '200':
                    		ping('unisip')
		    		if serverStatus <> 0:
                    			initTest(callFrom,'unisip')
	                    
                    			if result =='200':
                    	    			print "All SIP network are working"
                    			elif result == '486':
                    	    			print "University telephone network indicate having problem"
                    			else:
                    	    			print "incomplete test, Handler having error, please do one more test"
                    		else:
					print "No connection to University telephone network server, check your connection"

                	elif result == '486':
                    		ping('unisip')
		    		if serverStatus <> 0:
                    			initTest(callFrom,'unisip')
                    
                    			if result == '200':
                        			print "Landline indicate having problem"
                    			elif result == '486':
                        			print "SIP Network Down"
                    			else:
                        			print "incomplete test, Handler having error, please do one more test"
				else:
					print "No connection to University telephone network server, check your connection"
                	else:
                    		print "incomplete test, Handler having error, please do one more test"
		else:
			print "No connection to SIP Gate server, check your connection"

            elif destination == 'RZOutgoing':
		
                ping('landline')
		if serverStatus <> 0:
                	initTest('GSMRZ1','landline')
                
                	if result == '200':
                    		ping('unisip')
		    		if serverStatus <> 0:
                    			initTest('GSMRZ1','unisip')
	                    
                    			if result =='200':
               	    				print "Outgoing call from GSM RZ is working"

                    			elif result == '486':
               	    				print "Outgoing call from GSM RZ to UTN indicate having problem"
                    			else:
                    	    			print "incomplete test, Handler having error, please do one more test"
                    		else:
					print "No connection to University telephone network server, check your connection"

                	elif result == '486':
                    		ping('unisip')
		    		if serverStatus <> 0:
                    			initTest('GSMRZ1','unisip')
                    
                    			if result == '200':
                       				print "Outgoing call from GSM RZ to Landline indicate having problem"

                    			elif result == '486':
                       				print "Outgoing call from GSM RZ to Landline and UTN indicate having problem"
                    			else:
                        			print "incomplete test, Handler having error, please do one more test"
				else:
					print "No connection to University telephone network server, check your connection"
                	else:
                    		print "incomplete test, Handler having error, please do one more test"
		else:
			print "No connection to SIP Gate server, check your connection"

            elif destination == 'RZincoming':
		
                ping('landline')
		if serverStatus <> 0:
                	initTest('landline', 'GSMRZ1')
                
                	if result == '486':

                    		initTest('GSMExt.O2','GSMRZ1')
	                    
                    		if result =='200':
               	    			print "incoming call to GSM RZ working"

                    		elif result == '486':
                    	    			
					initTest('GSMExt.Voda','GSMRZ1')
                    			if result =='200':
                    	    			print "incoming call to GSM RZ working"
                    			elif result == '486':
                    	    			print "incoming call to GSM RZ notworking"
                    			else:
                    	    			print "incomplete test, GSM Handler having error, please do one more test"
                    		else:
                    	    		print "incomplete test, Handler having error, please do one more test"

                	elif result == '200':
                    		print "incoming call to GSM RZ working"
		else:
			print "No connection to SIP Gate server, check your connection"


if len(sys.argv) > 1:

	command = sys.argv[1]
	print ' '

	if command == '--all':
		doAllTest()

	elif command == '--sip':
		doSipTest()

	elif command == '--gsmrz':
		doGsmrzTest()

	elif command == '--gsmext':
		doGsmExtTest()

	elif command == '--landline':
		doLandlineTest()
            
    	elif command == '--smart':
        	smartTest()

	elif command == '--help':
		file = open('help.txt', 'r')
		print file.read()

	else:
		print "command not found, Type '--help', '--credits' for more information."
		print '\n'
else:

	initDB()
	if dbStatus == 1:
	
		if db.anyTasksToDo() == 1:

			#allPing()
			i=0
			for item in db.tasksList:

				taskID = item[0]
				taskNo = item[1]
				callFrom = item[2]
				callTo = item[3]
				tried = item[4]

				
				#if i == 0:
					#db.updatePingResult(taskNo, sipServer, sipGate, unisip, gsmBox1, gsmBox2)
				print '\n'
				print 'Task ID		:', taskID
				print 'Calling From	:', callFrom
				print 'To		:', callTo
			
				ping(callFrom)
				
				if serverStatus <> 0:

					ping(callTo)
					if serverStatus <> 0:

                        			initTest(callFrom,callTo)
					
						db.addResult(taskID, result)

						resultsList.append([callFrom, callTo, result])
						
						db.errorCode(result)
						print 'Result		: ' +result+ ' ' +db.errCode

						db.deleteTempTask(taskID)
						i = i+1

						sleep(5)
                            
					else:
						db.addResult(taskID, '500')
						print '[failed] 500 '+callTo+ ' Server Internal Error'
				else:
					db.addResult(taskID, '500')
					print '[failed] 500 '+callFrom+' Server Internal Error'
			db.cleanTasksList()
            		
            # fetch result list and make adjustment about the result
			print '\n'
			initTrueTable()
		else:
			print "--- No job at all ---"
	else:
		sys.exit(1)