summaryrefslogtreecommitdiffstats
path: root/For Weekly Test
diff options
context:
space:
mode:
Diffstat (limited to 'For Weekly Test')
-rw-r--r--For Weekly Test/20-07-2011/Controller.py63
-rw-r--r--For Weekly Test/20-07-2011/Testing.py4
-rw-r--r--For Weekly Test/20-07-2011/classController.py40
-rw-r--r--For Weekly Test/20-07-2011/classController.pycbin5434 -> 4893 bytes
-rw-r--r--For Weekly Test/20-07-2011/classDb.py212
-rw-r--r--For Weekly Test/20-07-2011/localsipReceiver.py66
-rw-r--r--For Weekly Test/20-07-2011/sipCall.py56
7 files changed, 120 insertions, 321 deletions
diff --git a/For Weekly Test/20-07-2011/Controller.py b/For Weekly Test/20-07-2011/Controller.py
index 50c0f76..c1d63a4 100644
--- a/For Weekly Test/20-07-2011/Controller.py
+++ b/For Weekly Test/20-07-2011/Controller.py
@@ -23,23 +23,13 @@ sipRec = "sipReceiver.py"
landlnCall = "landlineCall.py"
landlnRec = "landlineReceiver.py"
localSipRec = "localsipReceiver.py"
-rz1Call = "rz1Call.py"
-rz1Rec = "rz1Receiver.py"
-o2Call = "o2Call.py"
-o2Rec = "o2Receiver.py"
-vodafoneCall = "vodafoneCall.py"
-vodafoneRec = "vodafoneReceiver.py"
-tmobileCall = "tmobileCall.py"
-tmobilRec = "tmobileReceiver.py"
-
-# One function for all test case
# Main software
# Check DB connection
db = classDb.DBMySQLConnection('root', 'randompasswordSQL', 'localhost', 'gsmselftesting')
-print "Connecting to DB ", db.connectDB()
+db.connectDB()
print ""
dbStatus = db.connectDB()
@@ -57,14 +47,15 @@ if dbStatus == 1:
sipLocalServerStatus = sipLocalServer.ping(3)
# Fetch The task information from DB
- print "do i have anything to do", db.anyTasksToDo()
+ db.anyTasksToDo()
#x = ()
for item in db.tasksList:
taskID = item[0]
- callFrom = item[1]
- callTo = item[2]
+ taskNo = item[1]
+ callFrom = item[2]
+ callTo = item[3]
print "Test ID : " , taskID
print "Caller : " , callFrom
@@ -80,13 +71,11 @@ if dbStatus == 1:
x = classController.test(sipCall, "localhost", "gsmincom_.py", "localhost","4661455")
x.FuncTest()
- print "Finish test"
- db.addResult(taskID, testResult)
- if repeatTest == "true":
- #select temporary table, if there are have test from gsmrz to sip then skip
- #else, update db, put new data to tasktable. from gsmrz to sip
- # waiting db class for repeat test from refik which I ask for.
- update
+
+ db.addResult(taskID, x.testResult)
+
+ if x.repeatTest == True:
+ db.insertTaskIn2(callTo,callFrom,taskNo)
if callTo == "gsmrz2":
@@ -96,13 +85,11 @@ if dbStatus == 1:
else:
x = classController.test(sipCall, "localhost", "Box1", "132.0.0.2","404")
x.FuncTest()
- print ""
- db.addResult(taskID, testResult)
- if repeatTest == "true":
- #select temporary table, if there are have test from gsmrz to sip then skip
- #else, update db, put new data to tasktable. from gsmrz to sip
- update
+ db.addResult(taskID, x.testResult)
+
+ if x.repeatTest == True:
+ db.insertTaskIn2(callTo,callFrom,taskNo)
if callTo == "gsmrz3":
@@ -112,13 +99,12 @@ if dbStatus == 1:
else:
x = classController.test(sipCall, "localhost", "Box2", "132.0.0.3","405")
x.FuncTest()
-
-
- db.addResult(taskID, testResult)
- if repeatTest == "true":
- #select temporary table, if there are have test from gsmrz to sip then skip
- #else, update db, put new data to tasktable. from gsmrz to sip
- update
+
+ db.addResult(taskID, x.testResult)
+
+ if x.repeatTest == True:
+ db.insertTaskIn2(callTo,callFrom,taskNo)
+
if callTo == "landline":
if sipGateServerStatus == 0:
@@ -127,7 +113,12 @@ if dbStatus == 1:
else:
x = classController.test(sipCall, "localhost", landlnRec, "localhost",landlnNum)
x.FuncTest()
+
db.addResult(taskID, x.testResult)
+
+ if x.repeatTest == True:
+ db.insertTaskIn2(callTo,callFrom,taskNo)
+ sleep(5)
if callTo == "localsip":
if sipLocalServerStatus == 0:
@@ -136,7 +127,9 @@ if dbStatus == 1:
else:
x = classController.test(sipCall, "localhost", localSipRec, "localhost",unisipNum)
x.FuncTest()
- db.addResult(taskID, testResult)
+
+ db.addResult(taskID, x.testResult)
+ sleep(5)
if callTo == "externalgsm":
x.FuncTest(sipCall, "localhost", o2Rec, "localhost","405")
diff --git a/For Weekly Test/20-07-2011/Testing.py b/For Weekly Test/20-07-2011/Testing.py
index 4a8a964..34316ee 100644
--- a/For Weekly Test/20-07-2011/Testing.py
+++ b/For Weekly Test/20-07-2011/Testing.py
@@ -19,8 +19,8 @@ x.connect()
origHandler = x.receiveData(0)
print origHandler
-command="--command=python localsipReceiver.py"
-subprocess.Popen(args=["gnome-terminal", command])
+#command="--command=python localsipReceiver.py"
+#subprocess.Popen(args=["gnome-terminal", command])
sleep(5)
y = classClient.Connection("localhost", "50107")
y.connect()
diff --git a/For Weekly Test/20-07-2011/classController.py b/For Weekly Test/20-07-2011/classController.py
index a9c5f82..b7e3bff 100644
--- a/For Weekly Test/20-07-2011/classController.py
+++ b/For Weekly Test/20-07-2011/classController.py
@@ -49,8 +49,8 @@ class test:
print ""
print "Connecting to Caller handler"
- print "Caller handler status :", x.connect()
- x.sendData('hello server please wakeup the handler and be caller')
+ x.connect()
+ x.sendData('be caller')
else:
# open SIP caller handler
@@ -61,10 +61,7 @@ class test:
sleep(5)
if self.orig=="sipCall.py":
- self.portOrig = 50097
-
- if self.orig=="rz1Call.py":
- self.portOrig = 50098
+ self.portOrig = 50097
if self.orig == "landlineCall.py":
self.portOrig = 50099
@@ -75,12 +72,13 @@ class test:
x = classClient.Connection(self.origAdd,self.portOrig)
print ""
- print "Connecting to Caller handler", self.origAdd,self.portOrig
- print "Caller handler status:", x.connect()
+ print "Connecting to Caller handler"
+ x.connect()
# wait respond from origin handler
signal.signal(signal.SIGALRM, timeout_handler)
signal.alarm(60)
+
while 1:
try:
origHandler = x.receiveData(0)
@@ -106,8 +104,8 @@ class test:
y = classClient.Connection(self.destAdd, self.portDest)
print "Connecting to Receiver handler"
- print "Receiver handler status: ", y.connect()
- y.sendData('hello server please wakeup the handler and be receiver')
+ y.connect()
+ y.sendData('receiver')
else:
command="--command=python " +self.dest
@@ -118,22 +116,15 @@ class test:
if self.dest=="SIPReceiver.py":
self.portDest = 50104
- if self.dest=="gsmincom_.py":
- self.portDest = 50105
-
if self.dest == "landlineReceiver.py":
self.portDest = 50106
if self.dest == "localsipReceiver.py":
self.portDest = 50107
-
- #mean external GSM
- #print "not define yet"
- #portDest = 50108
y = classClient.Connection(self.destAdd, self.portDest)
print "Connecting to Receiver handler"
- print "Receiver handler status:", y.connect()
+ y.connect()
signal.signal(signal.SIGALRM, timeout_handler)
@@ -152,14 +143,14 @@ class test:
if destHandler == "ready":
print "Receiver handler : Ready"
- print "self.destNo"
x.sendData("start|"+self.destNo)#send message to handler to start the call
signal.signal(signal.SIGALRM, timeout_handler)
- signal.alarm(1200)
+ signal.alarm(120)
+ print ""
print "------------ Test Result ------------"
print ""
@@ -204,13 +195,13 @@ class test:
if self.resultOrig == 486 or self.resultDest == 486:
self.testResult = 486
- repeatTest = True
+ self.repeatTest = True
print "Second test result origin: ", self.resultOrig
print "Second test result Destination: ", self.resultDest
else:
self.testResult = 200
- return 200
+
print "Second test result origin: ", self.resultOrig
print "Second test result Destination: ", self.resultDest
x.sendData('487')
@@ -220,7 +211,7 @@ class test:
self.testResult = 200
- print "Test Result origin: ", self.resultOrig
+ print "Test Result origin: ", self.resultOrig
print "Test Result Destination: ", self.resultDest
x.sendData('487')
y.sendData('487')
@@ -246,6 +237,3 @@ class test:
testResult = 602
print "602 General Handler Error: Could not open Origin handler"
- def testResult(self):
- return 200
-
diff --git a/For Weekly Test/20-07-2011/classController.pyc b/For Weekly Test/20-07-2011/classController.pyc
index c9e0996..c649bdb 100644
--- a/For Weekly Test/20-07-2011/classController.pyc
+++ b/For Weekly Test/20-07-2011/classController.pyc
Binary files differ
diff --git a/For Weekly Test/20-07-2011/classDb.py b/For Weekly Test/20-07-2011/classDb.py
deleted file mode 100644
index 615b868..0000000
--- a/For Weekly Test/20-07-2011/classDb.py
+++ /dev/null
@@ -1,212 +0,0 @@
-import MySQLdb
-import string
-
-class DBMySQLConnection:
- def __init__(self, username, password, host, dbname):
- #initialize at the start all the user parameters
- self.usern = username
- self.passw = password
- self.host = host
- self.db = dbname
- self.connectionCreated = 0
- self.tasksList = list()
- global debugMode
- debugMode = 0
-
- def connectDB(self):
- try:
- #try the connection
- self.datBaseConn=MySQLdb.connect(self.host,self.usern, self.passw,self.db)
- self.datBaseConn.paramstyle = 'format'
- self.cur = self.datBaseConn.cursor() #make the cursor, used for sending queries
- self.connectionCreated = 1 #use it as an indicator that the connection was created
- return 1
-
- except MySQLdb.Error, e:
- #if we have an error then try to catch it
- error=str(e)
- if error[1:5] == '1045':
- #wrong username or password
- return 0
- elif error[1:5] == '2002':
- #can't connect to mysql, mysql shutdown or wrong host
- return 2
- else:
- if debugMode == 1:
- print error
- return 3
-
- def closeDBConn(self):
- #close the connection to the database here
- if self.connectionCreated == 1:
- try:
- #close the cursor and then the connection to the DB
- self.cur.close()
- self.datBaseConn.close()
- return 1
- except MySQLdb.Error, e:
- #in case of an error
- if debugMode == 1:
- error = str(e)
- print error
- return 3
- else:
- #I never really had a connection
- return 0
-
- def anyTasksToDo(self):
- #see are there any jobs to be executed and make a list out of it
- if self.connectionCreated == 1:
- try:
- self.cur.execute("SELECT * FROM TempTaskTable")
- output = self.cur.fetchall() #get the mysql response
- #parse the output from the mysql by creating a list
- #with lists where each attribue(column) gets independent
- #element of the list
- for record in output:
- columns = list()
- for entry in record:
- columns.append(str(entry))
- self.tasksList.append(columns)
- return 1
- except MySQLdb.Error, e:
- error = str(e)
- if error[1:5] == '1146':
- return 2 #the table doesn't exist
- if debugMode == 1:
- print str(e)
- return 3
- else:
- return 0
-
- def cleanTasksList(self):
- if self.connectionCreated == 1:
- del self.tasksList[:]
- return 1
- else:
- return 0
-
- def removeTaskFromList(self, taskID):
- #remove only one task from the task list
- if self.connectionCreated == 1:
- for index in range(len(self.tasksList)):
- item = self.tasksList[index]
- if item[0] == str(taskID):
- #self.tasksList.remove(index)
- #print 'found it'
- del self.tasksList[index]
- return 1 #deleted taskID
-
- return 2 #didn't find that taskID
- else:
- return 0
-
- def deviceAddress(self,deviceName):
- if self.connectionCreated == 1:
- try:
- successful = self.cur.execute("SELECT `deviceIP` FROM DeviceAddress where `deviceName`=%s", deviceName)
- #self.cur.execute()
- output = self.cur.fetchall() #get the mysql response
- #parse the output from the mysql by creating a list
- #with lists where each attribue(column) gets independent
- #element of the list
- deviceAddr = ''
- for record in output:
- columns = list()
- for entry in record:
- deviceAddr = str(entry)
- return deviceAddr
- except MySQLdb.Error, e:
- error = str(e)
- if error[1:5] == '1146':
- return 2 #the table doesn't exist
- if debugMode == 1:
- print str(e)
- return 3 #some error happened
- else:
- return 0 #I am not connected
-
- def updateTaskResult(self, taskID, status):
- if self.connectionCreated == 1:
- try:
- successful = self.cur.execute("UPDATE TaskTable SET status=%i WHERE taskID=%i"%(int(status), int(taskID)))
- output = self.cur.fetchone()
-
- if debugMode == 1:
- print output
- if successful == 0:
- return 1 #update successful
- else:
- return 4 #taskID doesn't exist
-
- except MySQLdb.Error, e:
- if debugMode == 1:
- print str(e)
- return 3
- else:
- return 0
-
- def updatePingResult(self, taskNo, sipServer, sipGate, sipLoc, gsmBox1, gsmBox2):
- if self.connectionCreated == 1:
- try:
- successful = self.cur.execute("UPDATE PingResultTable SET sipServer=%i, sipGate=%i, sipLoc=%i, gsmBox1=%i, gsmBox2=%i WHERE taskNo=%i"%(int(sipServer), int(sipGate), int(sipLoc), int(gsmBox1), int(gsmBox2), int(taskNo)))
- output = self.cur.fetchone()
-
- if debugMode == 1:
- print output
- if successful == 0:
- return 1 #ping table updated
- else:
- return 4 #the taskNo didn't exist
-
-
- except MySQLdb.Error, e:
- if debugMode == 1:
- print str(e)
- return 3
- else:
- return 0
-
- def deleteTempTask(self, taskID):
- if self.connectionCreated == 1:
- try:
- successful = self.cur.execute("DELETE FROM TempTaskTable WHERE taskID=%i"%(int(taskID)))
- output = self.cur.fetchone()
-
- if debugMode == 1:
- print output
-
- if successful == 1:
- return 1 #deleted it
- else:
- return 4 #that taskID didn't exist or something else
- except MySQLdb.Error, e:
- if debugMode == 1:
- print str(e)
- return 3
-
- else:
- return 0
-
- def addResult(self, taskID, result):
- if self.connectionCreated == 1:
- try:
- successful = self.cur.execute("INSERT INTO ResultTable(taskID, result) VALUES ('%i', '%i')"%(int(taskID), int(result)))
- output = self.cur.fetchone()
-
- if debugMode == 1:
- print output
- if successful == 1:
- return 1 #successfully added the result
- else:
- return 4 #hmmm
- except MySQLdb.Error, e:
- error = str(e)
- if error[1:5] == '1062':
- return 2 #duplicate entry for the key
- if debugMode == 1:
- print str(e)
- return 3
- else:
- return 0
-
diff --git a/For Weekly Test/20-07-2011/localsipReceiver.py b/For Weekly Test/20-07-2011/localsipReceiver.py
index 5739af2..c4f92e2 100644
--- a/For Weekly Test/20-07-2011/localsipReceiver.py
+++ b/For Weekly Test/20-07-2011/localsipReceiver.py
@@ -1,12 +1,14 @@
import sys
import pjsua as pj
import classServer
-from time import sleep
+import LogFileClass
+from time import sleep
+logger = LogFileClass.Logging('UniSIPRecHandler.log')
def log_cb(level, str, len):
- print str, "SIP Handler Receiver Log"
+ print str, "SIP University account Handler Receiver Log"
class MyAccountCallback(pj.AccountCallback):
@@ -14,27 +16,27 @@ class MyAccountCallback(pj.AccountCallback):
def on_incoming_call(self, call):
current_call = call
- print current_call
-
- sleep(1)
- call.answer(200)
+ logger.logEvent(current_call)
+ sleep(0.5)
+ call.answer(200)
+ logger.logEvent("Answer call")
sleep(0.5)
if current_call <> None:
- print "hangup the call"
+ logger.logEvent("Hangup call")
call.hangup()
- print "send result"
server.sendData('200')
-
-
+ logger.logEvent('200')
lib = pj.Lib()
stop = False
+logger.logEvent('')
try:
server = classServer.ServerHandler(50107)
+ logger.logEvent('Connect to Controller via port 50107')
tried = server.openSocket()
lib.init(log_cfg = pj.LogConfig(level=1, callback=log_cb))
@@ -44,49 +46,67 @@ try:
lib.set_null_snd_dev()
try:
+ logger.logEvent('Register Account to University SIP server')
acc_cfg = pj.AccountConfig("132.230.252.228", "4976120397897", "hB8M3WyFt61C")
acc = lib.create_account(acc_cfg, cb=MyAccountCallback())
- print acc.info().reg_status
+
if acc.info().reg_status < 700:
+ logger.logEvent(acc.info().reg_status)
+ sleep(5)
server.sendData('ready')
- server.closeConnection()
- tried = server.openSocket()
+ logger.logEvent('Handler Ready')
+
while stop <> True:
data = server.receiveData(0)
if data == "487":
+ logger.logEvent('Terminate')
stop = True
break
- sleep(3)
transport = None
acc.delete()
+ logger.logEvent('Un-Rigester SIP Account')
acc = None
lib.destroy()
lib = None
server.closeConnection()
+ logger.logEvent('Close Connection to the Controller')
else:
- print "Bad Register"
-
+ logger.logEvent("488 Not Acceptable Here")
lib.destroy()
+
lib = None
acc = None
- server.closeConnection()
+
+ server.closeConnection()
+ logger.logEvent('Close Connection to the Controller')
except pj.Error, e:
print "401 Unauthorized " +str(e)
+ logger.logEvent("401 Unauthorized ")
+
lib.destroy()
lib = None
+
server.closeConnection()
-
+ logger.logEvent('Close Connection to the Controller')
except pj.Error, e:
- print "Exception: " + str(e)
- lib.destroy()
- lib = None
- server.closeConnection()
- del server
+ print "Exception: " + str(e)
+ logger.logEvent(str(e))
+
+ lib.destroy()
+
+ lib = None
+ server.closeConnection()
+ logger.logEvent('Close Connection to the Controller')
+
+
+
+
+
diff --git a/For Weekly Test/20-07-2011/sipCall.py b/For Weekly Test/20-07-2011/sipCall.py
index 2ca7b14..2835b88 100644
--- a/For Weekly Test/20-07-2011/sipCall.py
+++ b/For Weekly Test/20-07-2011/sipCall.py
@@ -1,6 +1,8 @@
import sys
import pjsua as pj
import classServer
+import LogFileClass
+logger = LogFileClass.Logging('sipCallHandler.log')
from time import sleep
@@ -15,21 +17,24 @@ class MyCallCallback(pj.CallCallback):
if self.call.info().state <> pj.CallState.DISCONNECTED:
if self.call.info().state_text == "CONNECTING":
- print "CALL : ", self.call.info().state_text
- sleep(5)
+ logger.logEvent("Call Connecting")
+ sleep(1)
if self.call.info().state <> pj.CallState.DISCONNECTED:
- print "will Hangup call"
+ logger.logEvent("will Hangup call")
current_call.hangup()
- print "send result"
+ logger.logEvent('200')
server.sendData('200')
else:
sleep(0.5)
if self.call.info().last_reason == "Busy Here":
+ logger.logEvent('Number busy or Offline')
server.sendData('486')
+ logger.logEvent('486')
if self.call.info().state == pj.CallState.DISCONNECTED:
+ logger.logEvent('Call Disconnected')
current_call = None
@@ -42,12 +47,14 @@ def make_call(uri):
except pj.Error, e:
print "408 " + str(e)
+ logger.logEvent('408')
return None
lib = pj.Lib()
stop =False
current_call = None
+logger.logEvent('')
while stop <> True:
@@ -59,66 +66,69 @@ while stop <> True:
lib.set_null_snd_dev()
- server = classServer.ServerHandler(50097)
+ server = classServer.ServerHandler(50097)
+ logger.logEvent('Connect to Controller via port 50097')
tried = server.openSocket()
try:
+ logger.logEvent('Register Account to SIP server')
acc_cfg = pj.AccountConfig("132.230.4.8","mpselftest1","1mpselftest")
acc = lib.create_account(acc_cfg, cb=pj.AccountCallback())
+
if acc.info().reg_status < 700:
server.sendData('ready')
- print "Status: ", server.connected
- sleep(10)
+ logger.logEvent('Handler Ready')
+
while 1:
try:
data = server.receiveData(0)
- #data = 334
- #event = "start"
- #num = "076120397897"
event = data[0:5]
num = data[6:]
- print event
+
if event == "start" and num <> "":
-
- print "Make a call to :", num
+
+ logger.logEvent(event)
+ logger.logEvent('Make a call to: ' + num)
number = "sip:"+num+"@132.230.4.8"
current_call = make_call(number)
- sleep(19)
if data == "487":
stop = True
+ logger.logEvent('Terminate')
break
except ValueError:
- print "813 General socket layer error: Failed send message"
+ logger.logEvent("813 General socket layer error: Failed send message")
server.closeConnection()
- del server
+ logger.logEvent('Close Connection to the Controller')
+
server.closeConnection()
- del server
+ logger.logEvent('Close Connection to the Controller')
else:
- Regis_status= "Bad"
- print "488 Not Acceptable Here"
+ logger.logEvent("488 Not Acceptable Here")
lib.destroy()
lib = None
acc = None
- server.closeConnection()
- del server
+ server.closeConnection()
+ logger.logEvent('Close Connection to the Controller')
except ValueError:
print "401 Unauthorized " + str(e)
+ logger.logEvent("401 Unauthorized ")
-print "Goodbye"
+logger.logEvent("Goodbye")
sleep(3)
acc.delete()
+logger.logEvent('Un-Rigester SIP Account')
lib.destroy()
server.closeConnection()
-del server
+logger.logEvent('Close Connection to the Controller')
lib = None
acc = None