summaryrefslogblamecommitdiffstats
path: root/For Weekly Test/19-08-2011/gsmselftest1.py
blob: 92109b1917b026408817817a4cd079adb533f1a5 (plain) (tree)
1
2
3
4
5
6
7
8
9
10






                      


                    















                                                          
                                 


                                                    
                                 

























































                                                                                              


                                                     
        
                                                                                                        

                           
                                         
                                        
                














                                         
                                        




                                          
                        







                                                          
                                        




                                                                           
                                                                     















                                                                                                                          
                                                                     



































































                                                                                                                          
                                                                             

                                                                   
                                                                                               









                                                                              
                                                                             




















                                                                                                    
                                                                             



                                                                                      
                                                                                       








                                                                                                                          
                                                                             



                                                                                     
                                                                                                             








                                                                                                                          
                          


                         
                             


                                     


                                                                      
                                            
                                                                                 





















                                                                                                               
                                                        










                                               

                                                                                                                                      











                                                               


                                                               




                                                



                                                        








                        
                                



































































                                                                                                  
                
                                           


                                   


                                                     

                                                          



                                                                            
                                                                          



                                                                                                      
                            




                                                                              
                                                                                         
                                 
                                                                                                      
                    

                                     


                                                     
                            
                                                          



                                                                       
                                                                                  

                                             
                            
                                                          








                                                                                                      

                                                                                              


                                               
                                          







                                                       
                                                                                   


















                                                                                              
                 







                                

                              



                                     

                                  











                                                                                           
                




















                                                                                                                 







                                                             
                                                                         

                                                                            
                                                                                             























                                                                                                         
                                             




























                                             
#! /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 == 'GSMRZ1':
		server = PingClass.Ping('localhost')
		serverStatus = server.ping(1)

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

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

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

	server = PingClass.Ping('132.230.252.228')
	sipLoc = server.ping(3)

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

	server = PingClass.Ping('132.230.4.64')
	gsmBox2 = server.ping(3)

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.test(callFrom, callAdd, accCaller, callTo, destAdd, destNo, accDest)	
        makeTest.FuncTest()
        
        result = str(makeTest.testResult)
        repeatTest = makeTest.repeatTest
	sleep(5)
    
    else:
        print "No connection to Database"
    
    return result

def initTrueTable(caller):
    
    for x in resultsList:
        caller = x[0]
        destination = x[1]
        result = x[2]
        
        if caller == x[0]:
            
            if destination == 'GSMRZ1': 
                if result =='486':
                
                    for y in resultsList:
                        destination = y[1]
                        result = y[2]
                    	
                        if caller == y[0]:
                            if destination == 'GSMRZ2':
                                if result == '200':
                                
                                    for z in resultsList:
                                    
                                        destination = z[1]
                                        result = z[2]
                                    	
                                        if caller == z[0]:
                                            if destination == 'GSMRZ3':
                                            
                                                if result == '200':
                                                    print "BTS RZ 1 Broken"
                                                elif result == '486':
                                                    print "BTS RZ 1 & 3 indicate having Problem"
                                                else:
                                                    print "incomplete test, Handler having error, please do one more test"
                                
                                elif destination == '486':
                                
                                    for z in resultsList:
                                    
                                        destination = z[1]
                                        result = z[2]
                                    
                                        if caller == z[0]:
                                            if destination == 'GSMRZ3':
                                            
                                                if result == '200':
                                                    print "BTS RZ 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"
            
                elif result =='200':
                
                    for y in resultsList:
                    
                        destination = y[1]
                        result = y[2]
                    
                        if caller == y[0]:
                            if destination == 'GSMRZ2':
                                if result == '200':
                                
                                    for z in resultsList:
                                    
                                        destination = z[1]
                                        result = z[2]
                                    
                                        if caller == z[0]:
                                            if destination == 'GSMRZ3':
                                            
                                                if result != '200':
                                                    print "BTS RZ 3 Broken"
                                                else:
                                                    print "All is Fine"
                                elif result == '486':
                                
                                    for z in resultsList:
                                    
                                        destination = z[1]
                                        result = z[2]
                                    
                                        if caller == z[0]:
                                            if destination == 'GSMRZ3':
                                            
                                                if result == '200':
                                                    print "BTS RZ 2 Broken"
                                                elif result == '486':
                                                    print "BTS RZ 2 & 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"

                else:
                    print "incomplete test, Handler having error, please do one more test"
                                                    
            elif destination == 'GSMExt.O2':
                if result == '486':
                    for y in resultsList:
                        
                        destination = y[1]
                        result = y[2]
                        
                        if caller == y[0]:
                            if destination == 'GSMExt.Voda':
                                if result == '200':
                                    
                                    for z in resultsList:
                                        
                                        destination = z[1]
                                        result = z[2]
                                        
                                        if caller == z[0]:
                                            if destination == 'GSMExt.Eplus':
                                                
                                                if result != '200':
                                                    print "O2 & E-Plus indicate having Problem"
                                                else:
                                                    print "O2 indicate broken"
                                
                                else:
                                    for z in resultsList:
                                        
                                        destination = z[1]
                                        result = z[2]
                                        
                                        if caller == z[0]:
                                            if destination == 'GSMExt.Eplus':
                                                
                                                if result == '200':
                                                    print "O2 and Vodaphone indicate having problem"
                                                else:
                                                    print "GSM External Modem broken"
                elif result == '200':
                    for y in resultsList:
                        
                        destination = y[1]
                        result = y[2]
                        
                        if caller == y[0]:
                            if destination == 'GSMExt.Voda':
                                if result == '200':
                                    
                                    for z in resultsList:
                                        
                                        destination = z[1]
                                        result = z[2]
                                        
                                        if caller == z[0]:
                                            if destination == 'GSMExt.Eplus':
                                                
                                                if result == '200':
                                                    print "GSM external modem is Fine"
                                                elif result == '486':
                                                    print "E-Plus card indicate broken"
                                                else:
                                                    print "incomplete test, Handler having error, please do one more test"
                                elif result == '486':
                                    for z in resultsList:
                                        
                                        destination = z[1]
                                        result = z[2]
                                        
                                        if caller == z[0]:
                                            if destination == 'GSMExt.Eplus':
                                                
                                                if result == '200':
                                                    print "Vodaphone indicate broken"
                                                elif result == '486':
                                                    print "Vodaphone and E-Plus card 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"
                else:
                    print "incomplete test, Handler having error, please do one more test"


def doTest(callFrom,callTo):
    	global resultsList
	testRepeat = None
	ping(callFrom)

	if serverStatus <> 0:

		ping(callTo)
		if serverStatus <> 0:
			
            		initTest(callFrom,callTo)
			resultsList.append([callFrom, callTo, result])
			db.errorCode(result)
			#print 'Result		: ' +str(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 = ['sip', 'gsmr1','gsmr2', 'gsmr3', 'landline', 'unisip', 'gsmeO', 'gsmeV', 'gsmeT', 'gsmeE']
	destList = ['landline']
	for callTo in destList:

		callFrom = 'sip'
		if callFrom <> callTo:
			doTest(callFrom, callTo)
			if repeatTest == True:
				doTest(callTo,callFrom)

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

	for callTo in destList:

		callFrom = 'landline'
		doTest(callFrom, callTo)
		if repeatTest == True:
			doTest(callTo,callFrom)

def doGsmrzTest():

	print '--GSM Part Test--'
	destList = ['sip', 'GSMRZ1','GSMRZ2', 'GSMRZ3', 'landline', 'unisip', 'GSMExt.O2', 'GSMExt.Voda', 'GSMExt.Tm', 'GSMExt.Eplus']
	callList = ['GSMRZ1','GSMRZ2', 'GSMRZ3']
	
	for callFrom in callList:

		for callTo in destList:
			if callTo <> callFrom:
				doTest(callFrom, callTo)
				if repeatTest == True:
					doTest(callTo,callFrom)

	doGsmExtTest()
	
def doGsmExtTest():
	
	destList = ['GSMExt.O2', 'GSMExt.Voda', 'GSMExt.Eplus']
	callList = ['sip']

	for callFrom in callList:
		for callTo in destList:
	
			doTest(callFrom, callTo)
			#if repeatTest == True:
				#doTest(callTo,callFrom)
	callerList = ['sip']    
       	initTrueTable(caller)

def doAllTest():

	doSipTest()
	doLandlineTest()
	doGsmTest()

def smartTest():
    callerList = ['sip']
    destinationList = ['GSMExt']
    for callFrom in callerList:
        for destination in destinationList:
            
            if destination == 'GSMRZ':
                print "make a call to GSMRZ1"
                initTest('sip','GSMRZ1')
                
                if result == '200':
                    print "make a call to GSMRZ2"
                    initTest('sip','GSMRZ2')
                    
                    if result == '200':
                        print "make a call to GSMRZ3"
                        initTest('sip','GSMRZ3')
                        
                        if result == '200': 
                            print "all netwrok on GSMRZ are fine"
                        elif result == '486':
                            print "BTS 3 Down"
                        else:
                            print "have problem with handler"
                    
                    elif result == '486':
                        print "make a call to GSMRZ3"
                        initTest('sip','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('sip','GSMRZ2')
                    
                    if result == '200':
                        print "make a call to GSMRZ3"
                        initTest('sip','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('sip','GSMExt.O2')
                  
		if result == '200':
                        
                        initTest('sip','GSMExt.Voda')
                        
                        if result == '200':
                            
                            initTest('sip','GSMExt.Eplus')
                            
                            if result == '200': 
                                print "All netwrok on GSM external are fine"
                            elif result == '486':
                                print "Eplus card indicate having problem"
                            else:
                                print "incomplete test, Handler having error, please do one more test"
                        
                        elif result == '486':
                            
                            initTest('sip','GSMExt.Tm')
                            
                            if result == '200':
                                print "Vodaphone card indicate having problem"
                            elif result == '486':
                                print "Vodaphone and E-Plus card indicate having problem"
                            else:
                                print "Incomplete test, Handler having error, please do one more test"
                    
		elif result == '486':
                        
                        initTest('sip','GSMExt.Voda')
                        
                        if result == '200':
                            
                            initTest('sip','GSMExt.Eplus')
                            
                            if result == '200': 
                                print "O2 card indicate having problem"
                            elif result == '486':
                                print "O2 and E-Plus card indicate having problem"
                        
                        elif result == '486':
                            
                            initTest('sip','GSMExt.Eplus')
                            
                            if result == '200':
                                print "O2 and Vodaphone card 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"
            
            elif destination == 'SIP':
                print "make a call to Landline"
                initTest('sip','landline')
                
                if result == '200':
                    print "make a call to UNISIP"
                    initTest('sip','unisip')
                    
                    if result =='200':
                        print "All SIP network is fine"
                    elif result == '486':
                        print "University telphone network indicate having problem"
                    else:
                        print "incomplete test, Handler having error, please do one more test"
                
                elif result == '486':
                    print "making a call to UNISIP"
                    initTest('sip','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 "incomplete test, Handler having error, please do one more test"

if len(sys.argv) > 1:

	command = sys.argv[1]
	print ' '

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

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

	elif command == '--gsm':
		#doGsmTest()
		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:
	global resultList
	print '\n'
	resultsList = list()
	initDB()
	if dbStatus == 1:
	
		if db.anyTasksToDo() == 1:

			#allPing()
			i=0
			for item in db.tasksList:
				print item
				taskID = item[0]
				taskNo = item[1]
				callFrom = item[2]
				callTo = item[3]
				tried = item[4]

				
				#if i == 0:
				#	db.updatePingResult(taskNo, sipServer, sipGate, sipLoc, 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)
						resultList.append([callFrom, callTo, result])

						if repeatTest == True and tried <> '1':
							db.insertTaskIn2(callTo,callFrom,taskNo, '1')

						db.errorCode(result)
						print 'Result		: ' +str(result)+ ' ' +db.errCode
	
						db.deleteTempTask(taskID)
						db.tasksList.remove(item)
						db.tasksList.insert(i,'')

						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
               		initTrueTable(caller)
		else:
			print "No job at all"
	else:
		sys.exit(1)