summaryrefslogblamecommitdiffstats
path: root/For Weekly Test/30-07-2011/gsmselftest.py
blob: 1f9c4e5077630fb85c1adc1f24725d9406e57a74 (plain) (tree)
1
2
3
4
5
6
                      

                      
              
                
                         
























                                                          

                                
 





















                                                  
 
 


                            
                      
                                                   






                                                 
                                                




                                                   

                                                                                

                                                                                                        



                                                       
                                                                       

                                
                                                                              
             
                                                                        


                


                                                                                                              


                                

                                                

                                                       


                     
                                      





                                                      

                                               


                  

                                                                                                              
                                             
        
                                 
 


                                                        

                                                               
 




                                                     
                                                       
 





                                                       







                        
 
                             
                  

















                                            
                                                                                           
                          
     
                  






                                                                                                  
 
                                  

                                                 
                                          



                                                  
                                               







                                                                           


                                                                                                                 



                                                           
                                          




                                                                    

                                              
                                








                                                                                                                                


                                                                                                     
 
                                                                                               



                                                                         
 



                                                        
                                                                           
                                                                                                      
                                     
                                                                   
                                                                                               







                                             
 




















 
#! /usr/bin/env python
import sys
import ControllerClass
import DbClass
import PingClass
import DeviceAddressClass
from time import sleep

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

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

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

	elif handler == 'gsmr1':
		server = PingClass.Ping('localhost')
		serverStatus = server.ping(3)

	elif handler == 'gsmr2':
		server = PingClass.Ping('132.230.4.64')
		serverStatus = server.ping(3)
	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 doTest(callFrom,callTo):
	global testRepeat
	testRepeat = None
	ping(callFrom)
	device = DeviceAddressClass.DeviceAddress()

	if serverStatus <> 0:

		ping(callTo)
		if serverStatus <> 0:
			device.findDevice(callTo)
			recAdd = device.add
			destNo = str(device.num)

			device.findDevice(callFrom)
			callAdd = device.add

			print '\n'
			print 'Caller		:', callFrom
			print 'Destination	:', callTo			
			makeTest = ControllerClass.test(callFrom, callAdd, callTo, recAdd, destNo)	
			makeTest.FuncTest()

			if makeTest.repeatTest == True:
				testRepeat = True

			print 'Result		:', makeTest.testResult
			sleep(3)
		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 = ['unisip']
	for callTo in destList:

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

def doLandlineTest():
	
	print '--Landline Part Test--'
	destList = ['gsmr1', 'gsmr2', 'gsmr3', 'sip'] 

	for callTo in destList:

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

def doGsmrzTest():

	print '--GSM Part Test--'
	destList = ['sip', 'gsmr1','gsmr2', 'gsmr3', 'landline', 'unisip', 'gsmeO', 'gsmeV', 'gsmeT', 'gsmeE']
	callList = ['gsmr1','gsmr2', 'gsmr3']
	
	for callFrom in callList:

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

	doGsmExtTest()
	
def doGsmExtTest():

	destList = ['sip', 'gsmr1','gsmr2', 'gsmr3'] 
	callList = ['gsmeO', 'gsmeV', 'gsmeT', 'gsmeE']

	for callFrom in callList:
		for callTo in destList:
	
			doTest(callFrom, callTo)
			if testRepeat == True:
				doTest(callTo,callFrom)

def doAllTest():

	doSipTest()
	doLandlineTest()
	doGsmTest()

if len(sys.argv) > 1:

	command = sys.argv[1]
	print '\n'

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

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

	elif command == '--gsm':
		doGsmTest()

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

	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:
	print '\n'
	db = DbClass.DBMySQLConnection('root', 'randompasswordSQL', 'localhost', 'gsmselftesting')
	db.connectDB()
	dbStatus = db.connectDB()

	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]

	        		destination = db.deviceAddress(str(callTo))

				caller = db.deviceAddress(str(callFrom))

				callAdd = caller[0]
				recAdd = destination[0]
				destNo = destination[1]
				
				#if i == 0:
				#	db.updatePingResult(taskNo, sipServer, sipGate, sipLoc, gsmBox1, gsmBox2)
			
				if callFrom == 'unisip':
					destNo = destNo[7:]

				print '\n'
				print 'Task ID		:', taskID
				print 'Calling From	:', callFrom
				print 'To		:', callTo
				print 'number		:', destNo
				print 'status		:', tried
			
				ping(callFrom)
				
				if serverStatus <> 0:

					ping(callTo)
					if serverStatus <> 0:

						makeTest = ControllerClass.test(callFrom, callAdd, callTo, recAdd, destNo)	
						makeTest.FuncTest()
					
						db.addResult(taskID, makeTest.testResult)
				
						if makeTest.repeatTest == True and tried <> '1':
							db.insertTaskIn2(callTo,callFrom,taskNo, '1')

						print 'Result 		:', makeTest.testResult
	
						db.deleteTempTask(taskID)
						db.tasksList.remove(item)
						db.tasksList.insert(i,'')

						i = i+1

						sleep(3)
					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()
		else:
			print "No job at all"
	else:
		sys.exit(5)