import sys import ControllerClass import DbClass import PingClass from time import sleep class doTheTest: def ping(self,handler): if handler == 'landline': server = PingClass.Ping('sipgate.de') self.serverStatus = server.ping(2) elif handler == 'sip': server = PingClass.Ping('132.230.4.8') self.serverStatus = server.ping(2) elif handler == 'unisip': server = PingClass.Ping('132.230.252.228') self.serverStatus = server.ping(2) elif handler == 'GSMRZ3': server = PingClass.Ping('localhost') self.serverStatus = server.ping(2) elif handler == 'GSMRZ2': server = PingClass.Ping('10.4.58.241') self.serverStatus = server.ping(2) else: self.serverStatus = 1 def initDB(self): self.db = DbClass.DBMySQLConnection('root', 'randompasswordSQL', 'localhost', 'gsmselftesting') self.db.connectDB() self.dbStatus = self.db.connectDB() def initaccount(self,account,handler): if handler == 'sip' or handler == 'unisip' or handler == 'landline': if account[2] != '' or account[3] != '' or account[4] != '': self.status = 1 else: self.status = 0 else: self.status = 1 def initTest(self, callFrom, callTo): self.initDB() if self.dbStatus != 0: self.ping(callFrom) if self.serverStatus <> 0: self.ping(callTo) if self.serverStatus <> 0: dest = self.db.deviceAddress(str(callTo)) caller = self.db.deviceAddress(str(callFrom)) self.initaccount(caller,callFrom) if self.status == 1: self.initaccount(dest,callTo) if self.status == 1: callPortAdd = caller[0] accCaller = caller[2]+':'+caller[3]+':'+caller[4]+':' destPortAdd = dest[0] destNo = dest[1] accDest = dest[2]+':'+dest[3]+':'+dest[4]+':' makeTest = ControllerClass.doTheTest(callFrom, callPortAdd, accCaller, callTo, destPortAdd, destNo, accDest) makeTest.FuncTest() self.result = str(makeTest.testResult) else: self.result = 100 else: self.result = 100 sleep(5) else: self.result = 500 else: self.result = 500 else: self.result = 333 return self.result def smartTest(self): global handlerError self.ping('sip') if self.serverStatus == 0: print "Dont have connection to SIP Asterisk server, can't make a test" sys.exit(1) handlerError = "incomplete test, Handler having error, please do one more test" callerList = ['sip'] destinationList = ['SIP'] #destinationList = ['GSMExt', 'GSMRZ', 'SIP', 'RZOutgoing', 'RZincoming'] for callFrom in callerList: for destination in destinationList: if destination == 'GSMRZ': self.initTest(callFrom,'GSMRZ1') if self.result == '200': self.initTest(callFrom,'GSMRZ2') if self.result == '200': self.initTest(callFrom,'GSMRZ3') if self.result == '200': print "all network on GSMRZ are working" elif self.result == '486': print "BTS 3 Down" else: print handlerError elif self.result == '486': self.initTest(callFrom,'GSMRZ3') if self.result == '200': print "BTS 2 Down" elif self.result == '486': print "BTS 2 and 3 indicate having problem" else: print handlerError else: print handlerError elif self.result == '486': self.initTest(callFrom,'GSMRZ2') if self.result == '200': self.initTest(callFrom,'GSMRZ3') if self.result == '200': print "BTS 1 Down" elif self.result == '486': print "BTS 1 & 3 indicate having problem" else: print handlerError elif self.result == '486': self.initTest(callFrom,'GSMRZ3') if self.result == '200': print "BTS 1 & 2 indicate having problem" elif self.result == '486': print "OpenBSc Down" else: print handlerError else: print handlerError else: print handlerError elif destination == 'GSMExt': self.initTest(callFrom,'GSMExt.O2') if self.result == '200': self.initTest(callFrom,'GSMExt.Voda') if self.result == '200': self.initTest(callFrom,'GSMExt.Eplus') if self.result == '200': self.initTest(callFrom,'GSMExt.Tm') if self.result == '200': print "All network on GSM external are working" elif self.result == '486': print "T-Mobile card indicate having problem" else: print handlerError elif self.result == '486': self.initTest(callFrom,'GSMExt.Tm') if self.result == '200': print "E-Plus card indicate having problem" elif self.result == '486': print "T-Mobile and E-Plus card indicate having problem" else: print handlerError elif self.result == '486': self.initTest(callFrom,'GSMExt.Eplus') if self.result == '200': self.initTest(callFrom,'GSMExt.Tm') if self.result == '200': print "Vodaphone card indicate having problem" elif self.result == '486': print "T-Mobile and Vodaphone cards indicate having problem" else: print handlerError elif self.result == '486': self.initTest(callFrom,'GSMExt.Tm') if self.result == '200': print "Vodaphone and E-Plus card indicate having problem" elif self.result == '486': print "T-Mobile, E-Plus and Vodaphone cards indicate having problem" else: print handlerError else: print handlerError else: print handlerError elif self.result == '486': self.initTest(callFrom,'GSMExt.Voda') if self.result == '200': self.initTest(callFrom,'GSMExt.Eplus') if self.result == '200': self.initTest(callFrom,'GSMExt.Tm') if self.result == '200': print "O2 card indicate having problem" elif self.result == '486': print "T-Mobile and O2 cards indicate having problem" else: print handlerError elif self.result == '486': self.initTest(callFrom,'GSMExt.Tm') if self.result == '200': print "O2 and E-Plus cards indicate having problem" elif self.result == '486': print "T-Mobile, E-Plus and O2 cards indicate having problem" else: print handlerError else: print handlerError elif self.result == '486': self.initTest(callFrom,'GSMExt.Eplus') if self.result == '200': self.initTest(callFrom,'GSMExt.Tm') if self.result == '200': print "O2 and Vodaphone cards indicate having problem" elif self.result == '486': print "T-Mobile, O2 and Vodaphone cards indicate having problem" else: print handlerError elif self.result == '486': self.initTest(callFrom,'GSMExt.Tm') if self.result == '200': print "O2, E-Plus and Vodaphone cards indicate having problem" elif self.result == '486': print "GSM External Modem Down" else: print handlerError else: print handlerError else: print handlerError else: print handlerError elif destination == 'SIP': self.ping('landline') if self.serverStatus <> 0: self.initTest(callFrom,'landline') if self.result == '200': self.ping('unisip') if self.serverStatus <> 0: self.initTest(callFrom,'unisip') if self.result =='200': print "All SIP network are working" elif self.result == '486': print "University telephone network indicate having problem" else: print handlerError else: print "No connection to University telephone network server, check your connection" elif self.result == '486': self.ping('unisip') if self.serverStatus <> 0: self.initTest(callFrom,'unisip') if self.result == '200': print "Landline indicate having problem" elif self.result == '486': print "SIP Network Down" else: print handlerError else: print "No connection to University telephone network server, check your connection" else: print handlerError else: print "No connection to SIP Gate server, check your connection" elif destination == 'RZOutgoing': self.ping('landline') if self.serverStatus <> 0: self.initTest('GSMRZ1','landline') if self.result == '200': self.ping('unisip') if self.serverStatus <> 0: self.initTest('GSMRZ1','unisip') if self.result =='200': print "Outgoing call from GSM RZ is working" elif self.result == '486': print "Outgoing call from GSM RZ to UTN indicate having problem" else: print handlerError else: print "No connection to University telephone network server, check your connection" elif self.result == '486': self.ping('unisip') if self.serverStatus <> 0: self.initTest('GSMRZ1','unisip') if self.result == '200': print "Outgoing call from GSM RZ to Landline indicate having problem" elif self.result == '486': print "Outgoing call from GSM RZ to Landline and UTN indicate having problem" else: print handlerError else: print "No connection to University telephone network server, check your connection" else: print handlerError else: print "No connection to SIP Gate server, check your connection" elif destination == 'RZincoming': self.ping('landline') if self.serverStatus <> 0: self.initTest('landline', 'GSMRZ1') if self.result == '486': self.initTest('GSMExt.O2','GSMRZ1') if self.result =='200': print "incoming call to GSM RZ working" elif self.result == '486': self.initTest('GSMExt.Voda','GSMRZ1') if self.result =='200': print "incoming call to GSM RZ working" elif self.result == '486': print "incoming call to GSM RZ notworking" else: print handlerError else: print handlerError elif self.result == '200': print "incoming call to GSM RZ working" else: print "No connection to SIP Gate server, check your connection"