#! /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 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('132.230.4.64') 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) repeatTest = makeTest.repeatTest else: print "No connection to Database" return result def initTrueTable(caller): for x in resultsList: 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 GSM RZ are working" 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 == '486': for A in resultsList: destination = A[1] result = A[2] if caller == A[0]: if destination == 'GSMExt.Tm': if result == '200': print "O2 & E-Plus 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" elif result == '200': for A in resultsList: destination = A[1] result = A[2] if caller == A[0]: if destination == 'GSMExt.Tm': if result == '200': print "O2 cards 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" 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': for A in resultsList: destination = A[1] result = A[2] if caller == A[0]: if destination == 'GSMExt.Tm': if result == '200': print "O2 and Vodaphone cards indicate having problem" elif result == '486': print "T-Mobile, Vodaphone and O2 cards indicate having problem" else: print "incomplete test, Handler having error, please do one more test" elif result == '486': for A in resultsList: destination = A[1] result = A[2] if caller == A[0]: if destination == 'GSMExt.Tm': if result == '200': print "O2, E-Plus and Vodaphone cards indicate having problem" elif result == '486': print "GSM External Modem broken" 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 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': for A in resultsList: destination = A[1] result = A[2] if caller == A[0]: if destination == 'GSMExt.Tm': if result == '200': print "GSM external modem is 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': for A in resultsList: destination = A[1] result = A[2] if caller == A[0]: if destination == 'GSMExt.Tm': if result == '200': print "E-Plus card indicate broken" elif result == '486': print "T-Mobile and E-plus 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': for z in resultsList: destination = z[1] result = z[2] if caller == z[0]: if destination == 'GSMExt.Eplus': if result == '200': for A in resultsList: destination = A[1] result = A[2] if caller == A[0]: if destination == 'GSMExt.Tm': if result == '200': print "Vodaphone indicate broken" 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': for A in resultsList: destination = A[1] result = A[2] if caller == A[0]: if destination == 'GSMExt.Tm': if result == '200': print "Vodaphone and E-plus cards indicate broken" 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" 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': if result =='486': for y in resultsList: destination = y[1] result = y[2] if caller == y[0]: if destination == 'landline': if result == '200': for z in resultsList: destination = z[1] result = z[2] if caller == z[0]: if destination == 'unisip': if result == '200': print "Asterisk server down" elif result == '486': print "Asterisk server and University telephone network 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 == 'unisip': if result == '200': print "Asterisk server & SIPGate indicate having Problem" elif result == '486': print "All SIP server working" 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 == 'landline': if result == '200': for z in resultsList: destination = z[1] result = z[2] if caller == z[0]: if destination == 'unisip': if result != '200': print "University telephone network down" else: print "All SIP are working" elif result == '486': for z in resultsList: destination = z[1] result = z[2] if caller == z[0]: if destination == 'unisip': if result == '200': print "SIPGate down" elif result == '486': print "SIPGate and University telephone network 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: print 'Call from : ', callFrom print 'Call to : ', callTo initTest(callFrom,callTo) #resultsList.append([callFrom, callTo, result])#should be put on another function to prevent repeat test 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) 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 = ['GSMRZ1','GSMRZ2', 'GSMRZ3'] callList = ['sip'] for callFrom in callList: for callTo in destList: doTest(callFrom, callTo) if repeatTest == True: doTest(callTo,callFrom) doGsmExtTest() def doGsmExtTest(): destList = ['GSMExt.O2', 'GSMExt.Voda', 'GSMExt.Eplus'] callList = ['sip'] #callList = ['sip', 'GSMRZ1'] for callFrom in callList: for callTo in destList: doTest(callFrom, callTo)#external GSM dont need make repeat test, since we test outgoing call not ingoing call from external #if repeatTest == True: # doTest(callTo,callFrom) # resultsList.append([callFrom, callTo, result]) #else: resultsList.append([callFrom, callTo, result]) for caller in callList: initTrueTable(caller) def doAllTest(): doSipTest() doLandlineTest() doGsmTest() 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'] 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 netwrok on GSMRZ are working" elif result == '486': print "BTS 3 Down" else: print "have problem with handler" 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 netwrok 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 telphone 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" 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 resultsList = list() 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) #if repeatTest == True and tried <> '1': # db.insertTaskIn2(callTo,callFrom,taskNo, '1') #if tried == '1': resultsList.append([callTo, callFrom, result]) #elif tried != '1' and repeatTest != True: # resultsList.append([callFrom, callTo, result]) db.errorCode(result) print 'Result : ' +result+ ' ' +db.errCode #print 'list 2:', db.tasksList #db.tasksList.remove(item) #db.tasksList.insert(i,'') 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 initTrueTable(caller) else: print "--- No job at all ---" else: sys.exit(1)