summaryrefslogblamecommitdiffstats
path: root/For Weekly Test/19-08-2011/gsmselftest.py
blob: f8a385c8fdc55d6b8f733ba415fd7289b21ad700 (plain) (tree)




































































































































































































































































































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

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

	elif handler == 'gsmr2':
		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 doTest(callFrom,callTo):


	global testRepeat

	testRepeat = None
	ping(callFrom)

	db = DbClass.DBMySQLConnection('root', 'randompasswordSQL', 'localhost', 'gsmselftesting')
	db.connectDB()
	dbStatus = db.connectDB()


	if serverStatus <> 0 and dbStatus == 1:

		ping(callTo)
		if serverStatus <> 0:
	        	destination = db.deviceAddress(str(callTo))
			caller = db.deviceAddress(str(callFrom))

			callAdd = caller[0]
			accCaller = caller[2]+':'+caller[3]+':'+caller[4]+':'

			recAdd = destination[0]
			destNo = destination[1]
			accDest = destination[2]+':'+destination[3]+':'+destination[4]+':'

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

			if makeTest.repeatTest == True:
				testRepeat = True
			db.errorCode(makeTest.testResult)
			print 'Result		: ' +str(makeTest.testResult)+ ' ' +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 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 initResult(i, result):
	global resultsList
	
	


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

	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]
				accCaller = caller[2]+':'+caller[3]+':'+caller[4]+':'

				recAdd = destination[0]
				destNo = destination[1]
				accDest = destination[2]+':'+destination[3]+':'+destination[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
				print 'number		:', destNo
				print 'status		:', tried
			
				ping(callFrom)
				
				if serverStatus <> 0:

					ping(callTo)
					if serverStatus <> 0:

						makeTest = ControllerClass.test(callFrom, callAdd, accCaller, callTo, recAdd, destNo, accDest)	
						makeTest.FuncTest()
					
						db.addResult(taskID, makeTest.testResult)
						resultList.append([callTo, callFrom, makeTest.testResult])

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

						db.errorCode(makeTest.testResult)
						print 'Result		: ' +str(makeTest.testResult)+ ' ' +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()
		else:
			print "No job at all"
	else:
		sys.exit(1)