summaryrefslogtreecommitdiffstats
path: root/For Weekly Test/tricode/gsmselftest-website2.py
diff options
context:
space:
mode:
Diffstat (limited to 'For Weekly Test/tricode/gsmselftest-website2.py')
-rwxr-xr-xFor Weekly Test/tricode/gsmselftest-website2.py537
1 files changed, 0 insertions, 537 deletions
diff --git a/For Weekly Test/tricode/gsmselftest-website2.py b/For Weekly Test/tricode/gsmselftest-website2.py
deleted file mode 100755
index 71c7c03..0000000
--- a/For Weekly Test/tricode/gsmselftest-website2.py
+++ /dev/null
@@ -1,537 +0,0 @@
-#! /usr/bin/env python
-from serial import * #serial port library
-import sys
-import ControllerClass
-import DbClass
-import PingClass
-import trueTableClass
-import initTestClass
-import usbDetectClass
-import ServerClassSoftware
-import signal
-from time import sleep
-
-class bcolors:
- HEADER = '\033[95m'
- OKBLUE = '\033[94m'
- OKGREEN = '\033[92m'
- WARNING = '\033[93m'
- FAIL = '\033[91m'
- ENDC = '\033[0m'
-
- def disable(self):
- self.HEADER = ''
- self.OKBLUE = ''
- self.OKGREEN = ''
- self.WARNING = ''
- self.FAIL = ''
- self.ENDC = ''
-class TimeoutException(Exception):
- pass
-
-global resultsList
-resultsList = list()
-
-def timeout_handler(signum, frame):
- raise TimeoutException()
-
-def allPing(): #ping all existing devices
-
- global sipGate
- global sipServer
- global unisip
- global gsmBox1
- global gsmBox2
-
- serverAdd = db.deviceAddress(str('landline'))
- server = PingClass.Ping(str(serverAdd[4]))
- sipGate = server.ping(2)
-
- serverAdd = db.deviceAddress(str('sip'))
- server = PingClass.Ping(str(serverAdd[4]))
- sipServer = server.ping(2)
-
- serverAdd = db.deviceAddress(str('unisip'))
- server = PingClass.Ping(str(serverAdd[4]))
- unisip = server.ping(2)
-
- serverAdd = db.deviceAddress(str('GSMRZ2'))
- server = PingClass.Ping(str(serverAdd[4]))
- gsmBox1 = server.ping(2)
-
- serverAdd = db.deviceAddress(str('GSMRZ3'))
- server = PingClass.Ping(str(serverAdd[4]))
- gsmBox2 = server.ping(2)
-
-def initDB(): # function for connection database
- global dbStatus
- global db
-
- db = DbClass.DBMySQLConnection('root', 'randompasswordSQL', 'localhost', 'gsmselftesting')
- db.connectDB()
- dbStatus = db.connectDB()
- if dbStatus == 1:
- print 'Lock the mutex: ' + str(db.lockMutex(600))
-
-def initTrueTable(x):
- initResult = trueTableClass.trueTable(x)
- initResult.initTrueTable()
- global finalResult
- print '\n'
- openBSC = None
- asterikServer = None
- finalResult = list()
- for x in initResult.nanoBts:
- finalResult.append(x)
- name = x[0]
- if x[1] == True:
- openBSC = True
- asterikServer = True
- print bcolors.OKGREEN +name+ ' Working'+ bcolors.ENDC
-
- else:
- if int(x[1]) == 486:
- print bcolors.FAIL+name+ ' not Working' + bcolors.ENDC
- elif int(x[1]) == 200:
- print bcolors.OKGREEN +name+ ' Working'
- asterikServer = True
- elif int(x[1]) == 402:
- print bcolors.WARNING +name+ ' not Working need top up the credit'
- asterikServer = True
- elif int(x[1]) == 998 or int(x[1]) == 999:
- print bcolors.FAIL+name+ ' not Working, handler error'+ bcolors.ENDC
- else:
- print bcolors.OKGREEN +name+ ' not Working'+ bcolors.ENDC
-
- finalResult.append(['openBSC', openBSC])
- finalResult.append(['asterikServer', asterikServer])
-
- print ''
- if openBSC != None:
- if openBSC == True:
- print bcolors.OKGREEN +'openBSC working'+ bcolors.ENDC
- else:
- print bcolors.FAIL+'openBSC doesnt work'+ bcolors.ENDC
- print ''
-
- if initResult.asteriskServer == True or asterikServer == True:
- print bcolors.OKGREEN +'asterik server is working'+ bcolors.ENDC
- print ''
-
- if initResult.outGoingRZ == True:
- print bcolors.OKGREEN +'Outgoing call from RZ is working'+ bcolors.ENDC
- elif initResult.outGoingRZ == False:
- print bcolors.FAIL+'Outgoing call from RZ is not working'+ bcolors.ENDC
-
- if initResult.incomingRZ == True:
- print bcolors.OKGREEN +'incoming call from outside RZ to GSM RZ is working'+ bcolors.ENDC
- elif initResult.incomingRZ == False:
- print bcolors.FAIL+'incoming call from outside RZ to GSM RZ is not working'+ bcolors.ENDC
- print '\n'
-
-def doSipTest():
-
- #destList = ['gsmr1','gsmr2', 'gsmr3', 'landline', 'unisip', 'GSMExt.O2', 'GSMExt.Voda', 'GSMExt.Eplus', 'GSMExt.Tm' ]
- destList = ['landline', 'unisip']
- doTest = initTestClass.doTest()
- for callTo in destList:
-
- callFrom = 'sip'
- doTest.initTest(callFrom,callTo)
- resultsList.append([callFrom, callTo, doTest.result])
- initTrueTable(resultsList)
-def doIncomingTest(): #incoming call to RZ network
-
- destList = ['GSMRZ1','unisip', 'GSMRZ2','GSMRZ3']
- doTest = initTestClass.doTest()
- for callTo in destList:
- callFrom = 'landline'
- doTest.initTest(callFrom,callTo)
- resultsList.append([callFrom, callTo, doTest.result])
- initTrueTable(resultsList)
-
-def doGsmrzTest():
-
- destList = ['GSMRZ1','GSMRZ2', 'GSMRZ3']
- callList = ['sip']
- doTest = initTestClass.doTest()
-
- for callFrom in callList:
- for callTo in destList:
- doTest.initTest(callFrom,callTo)
- resultsList.append([callFrom, callTo, doTest.result])
- initTrueTable(resultsList)
-
-def doGsmExtTest():
-
- destList = ['GSMExt.O2', 'GSMExt.Voda', 'GSMExt.Eplus', 'GSMExt.Tm']
- callList = ['sip']
-
- doTest = initTestClass.doTest()
-
- for callFrom in callList:
- for callTo in destList:
- doTest.initTest(callFrom,callTo)
- resultsList.append([callFrom, callTo, doTest.result])
- initTrueTable(resultsList)
-
-def doAllTest():
-
- doSipTest()
- doIncomingTest()
- doGsmrzTest()
- doGsmExtTest()
-
-def regularTest(x):
- initDB()
- allPing()
- db.updatePingResult('0', sipServer, sipGate, unisip, gsmBox1, gsmBox2)
- regulartest = initTestClass.doTest()
- regulartest.smartTest()
- if x == True:
- for messages in regulartest.messageList:
- sendResultWebsite(messages)
- print messages
- sleep(0.25)
- initTrueTable(regulartest.smartResultList)
- #for result in finalResult:
-
- # message = '|' + str(result[0]) + '|' + str(0) + '|' + str(result[1])+ '|' + str(0)
- # sendResultWebsite(message)
- # sleep(0.25)
- sendFinishMessage()
- initTrueTable(regulartest.smartResultList)
-
-def sendResultWebsite(message):
- if server.sendData(message+ chr(10)) == 1:
- print 'data sent successfully'
- test = server.receiveData(5)
- if test == 'TIMEOUT':
- closeFunction(db,server)
- if test == 'CONTINUE':
- print 'continue'
-
-def sendFinishMessage():
- if server.connected == 1:
- server.sendData('TEST DONE\n')
- test = server.receiveData(5)
- if test == 'TIMEOUT':
- closeFunction(db,server)
- if test == 'DISCONNECT':
- close = server.closeConnection()
- if close == 1:
- print 'Closed connection successfully'
-
- print 'release mutex says ', db.releaseMutex()
-
-def withDB(x):
-
- initDB()
- resultsList = list()
- if dbStatus == 1: # Checking connection to database
- if db.anyTasksToDo() == 1: # Checking task on the table
-
- allPing()
- i=0
- makeTest = initTestClass.doTest()
-
- for item in db.tasksList:
-
- taskID = item[0]
- taskNo = item[1]
- callFrom = item[2]
- callTo = item[3]
-
- if i == 0:
- db.updatePingResult(taskNo, sipServer, sipGate, unisip, gsmBox1, gsmBox2)
- print '\n'
- print 'Task ID :', taskID
- print 'Calling From :', callFrom
- print 'To :', callTo
-
-
- makeTest.initTest(callFrom,callTo)
-
- db.addResult(taskID, makeTest.result)
-
- resultsList.append([callFrom, callTo, makeTest.result])
-
- db.errorCode(makeTest.result)
- if int(makeTest.result) == 200:
- print bcolors.OKGREEN +'Result : ' +makeTest.result+ ' ' +db.errCode + bcolors.ENDC
- else:
- print bcolors.FAIL+'Result : ' +makeTest.result+ ' ' +db.errCode + bcolors.ENDC
-
- if x == True: # if x = True means that this function call by website
-
- message = '|' + str(callFrom) + '|' + str(callTo) + '|' + str(makeTest.result) + '|' + str(db.errCode)
- sendResultWebsite(message) # send result to website
-
- db.deleteTempTask(taskID)
- i = i+1
-
- db.cleanTasksList()
-
- if x == True:
- sendFinishMessage() #send finish message to website and close the connection
-
- print '\n'
-
- initTrueTable(resultsList) # fetch result list and make adjustment about the result
- db.closeDBConn()
- else:
- print bcolors.FAIL+"--- No job at all ---" + bcolors.ENDC
- db.closeDBConn()
- else:
- print bcolors.FAIL+'Cant connect to database'+ bcolors.ENDC
- sys.exit(1)
-
-def findPort(portName): # take information in existing usb port
- global connect
- global prefix
- global num
- global IMEI
- global portClass
- sleep(0.5)
- portLog = os.popen('dmesg | grep \'pl2303 converter now attached to '+portName+'\'').read()
- sleep(0.5)
- if portLog != '':
- connect = 1
- portClass = usbDetectClass.serialPort(portName)
- portClass.findNumber()
- portClass.findIMEI()
- IMEI = portClass.IMEI
- num = portClass.number
- number = portClass.number
- prefix = number[0:4]
- else:
- connect = 0
-
-def initDevice(deviceName):
- print 'Device Name :',deviceName
- print ' Device IMEI : ',
- imei = sys.stdin.readline().rstrip("\r\n")
- print 'Phone number : ',
- number = sys.stdin.readline().rstrip("\r\n")
- print 'Port Name : /dev/',
- portName = sys.stdin.readline().rstrip("\r\n")
- print ''
-
- if imei == '' or portName == '':
- print bcolors.FAIL+' == cant save device configuration, please fill IMEI / port name of the device =='+ bcolors.ENDC
- else:
- findPort(portName)
- if connect == 1:
- if str(IMEI) != str(imei) and str(num) != str(number):
- print bcolors.FAIL+'== error, device not found =='+ bcolors.ENDC
- elif str(IMEI) == str(imei):
- portClass.initUpdate(deviceName, portName, number)
- print bcolors.OKGREEN +'== Device succeced added =='+ bcolors.ENDC
- elif str(num) == str(number) and str(IMEI) != str(imei):
- portClass.initUpdate(deviceName, portName, number)
- print bcolors.WARNING+'== Device succeced added, but have different IMEI =='+ bcolors.ENDC
- else:
- print bcolors.FAIL+'== error, no device connected =='+ bcolors.ENDC
-
-def autoUpdateDevice(status):
- initDB()
- GSMListPrefix = list()
- GSMListPrefix = db.GSMPrefix()
- i = 0
- x = 0
- count = 0
- while i !=10:
- portName ='ttyUSB'+str(i) #checking usb connection
-
- i=i+1
- old_handler = signal.signal(signal.SIGALRM, timeout_handler)
- signal.alarm(15)
- try:
- findPort(portName)
- signal.signal(signal.SIGALRM, old_handler)
- signal.alarm(0)
- if connect == 1:
- for listNum in GSMListPrefix:
- if prefix == listNum[1]:
- print 'Device Name :',listNum[0]
- print 'IMEI :',IMEI
- print 'Phone Number :',num
- print 'Port Name : /dev/'+portName
- x=x+1
- newPortName = '/dev/'+portName
- portClass.initUpdate(listNum[0], newPortName, num)
- print '\n'
- except TimeoutException:
- signal.signal(signal.SIGALRM, old_handler)
- signal.alarm(0)
- count = count + 1
- message = "Timeout"
- #if status == True:
- # message = listNum[0]+' - /dev/'+portName+' - '+num+ ' update'
-
- if status == True:
- #if count != 0:
- # message = 'Found '+str(x)+' devices, with '+str(count)+' error'
- #else:
- # message = 'Found '+str(x)+' devices'
- #sendResultWebsite(messages)
- #sleep(5)
- sendFinishMessage()
- else:
-
- print '== FINISH =='
- print 'Found '+str(x)+' devices'
-
-def updateDevice(): #update port name list of device on DB
- quit = False
- while quit != True:
- print ''
- print "Mobile device configuration"
- print "Menu: a = automatic device configuration, m = Manual configuration, q = quit : ",
- input = sys.stdin.readline().rstrip("\r\n")
- print ''
- if input == 'm': # manual configuration
-
- while True:
- print ''
- print "Mobile device name: "
- print " 1. GSM O2"
- print " 2. GSM Vodafone"
- print " 3. GSM Eplus"
- print " 4. GSM T-Mobile"
- print " 5. GSM RZ 1"
- print " 6. Back to menu"
- print ""
- print "your choise : ",
- input = sys.stdin.readline().rstrip("\r\n")
-
- if input == '6':
- break
- elif input == '1':
- initDevice('GSMExt.O2')
- elif input == '2':
- initDevice('GSMExt.Voda')
- elif input == '3':
- initDevice('GSMExt.Eplus')
- elif input == '4':
- initDevice('GSMExt.Tm')
- elif input == '5':
- initDevice('GSMRZ1')
- else:
- print 'please choose between 1-6'
-
- if input == 'a': #automatic configuration
- autoUpdateDevice(False)
-
- if input == "q":
- break
- sys.exit()
-
-def closeFunction(dbConn,serverSocket):
- print 'Release the mutex: ' + str(dbConn.releaseMutex())
- print 'Close the DB Connection: ' + str(dbConn.closeDBConn())
- del dbConn
- del serverSocket
- sys.exit()
-
-if len(sys.argv) > 1:
-
- command = sys.argv[1]
- print ' '
-
- if command == '--all':
- resultsList = list()
- doAllTest()
-
- elif command == '--sip':
- resultsList = list()
- doSipTest()
-
- elif command == '--gsmrz':
- resultsList = list()
- doGsmrzTest()
-
- elif command == '--gsmext':
- resultsList = list()
- doGsmExtTest()
-
- elif command == '--incoming':
- resultsList = list()
- doIncomingTest()
-
- elif command == '--smart':
- resultsList = list()
- regularTest(False)
-
- elif command == '--devconf':
- updateDevice()
-
- elif command == '--db':
- resultsList = list()
- withDB(False)
-
- 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 server
- global tried
-
- initDB() # should put db condition
- server = ServerClassSoftware.ServerHandlerSoftware(34500) #define the port
- tried = server.openSocket(10)
-
- if tried == 'TIMEOUT':
- closeFunction(db,server)
-
- test = server.receiveData(10)
- if test == 'TIMEOUT':
- closeFunction(db,server)
-
- if test == 'START TEST':
- server.sendData('CONFIRM\n')
- print 'TEST STARTED'
- withDB(True)
-
- if test == 'SMART TEST':
- server.sendData('CONFIRM\n')
- print 'SMART TEST STARTED'
- resultsList = list()
- regularTest(True)
-
- if test == 'UPDATE DEVICE':
- server.sendData('CONFIRM\n')
- print 'UPDATE DEVICE STARTED'
- autoUpdateDevice(True)
- else:
- sys.exit('WE DIDN\'T RECEIVE THE CONFIRMATION')
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-