summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Controller/Controller-SecondType.py176
-rw-r--r--Handler/localsipReceiver.py5
-rw-r--r--Handler/sipCall.py4
-rw-r--r--Handler/sipReceiver.py2
4 files changed, 112 insertions, 75 deletions
diff --git a/Controller/Controller-SecondType.py b/Controller/Controller-SecondType.py
index b7d9881..31a04e1 100644
--- a/Controller/Controller-SecondType.py
+++ b/Controller/Controller-SecondType.py
@@ -13,17 +13,9 @@ from time import sleep
from datetime import datetime
-user = 'root'
-passw = 'randompasswordSQL' #default password we agree with this password before!
-host = 'localhost'
-dbname = 'gsmselftesting'
-
-stop = False
-status = None
-dbSStatus = None
-
sipNum = "4661929"
landlnNum = "076145875681"
+unisipNum = "076120397897"
sipCall = "sipCall.py"
@@ -42,16 +34,22 @@ tmobileCall = "tmobileCall.py"
tmobilRec = "tmobileReceiver.py"
# One function for all test case
+class TimeoutException(Exception):
+ pass
def FuncTest(orig, origAdd, dest, destAdd, destNo):
+
global repeatTest
global portOrig
global resultOrig
global resultDest
+ global testResult
global x
global y
+ def timeout_handler(signum, frame):
+ raise TimeoutException()
print "====================== Preparing Test ======================"
@@ -81,7 +79,7 @@ def FuncTest(orig, origAdd, dest, destAdd, destNo):
if orig=="SIPCall.py":
portOrig = 50097
- if orig=="gsmcall_.py":
+ if orig=="rz1Call.py":
portOrig = 50098
if orig == "landlineCall.py":
@@ -102,11 +100,18 @@ def FuncTest(orig, origAdd, dest, destAdd, destNo):
x.sendData('hello Handler')
# wait respond from origin handler
+ signal.signal(signal.SIGALRM, timeout_handler)
+ signal.alarm(60)
while 1:
- origHandler = x.receiveData()
- if origHandler <> "":
+ try:
+ origHandler = x.receiveData()
+ if origHandler <> "":
+ break
+
+ except TimeoutException:
+ origHandler = "failed"
break
- #think about time out
+
if origHandler == "ready":
print "Caller handler : Ready"
@@ -134,10 +139,10 @@ def FuncTest(orig, origAdd, dest, destAdd, destNo):
sleep(2)
- if dest=="SIPIncoming.py":
+ if dest=="SIPReceiver.py":
portDest = 50104
- if dest=="gsmincom_.py":
+ if dest=="rz1Receiver.py":
portDest = 50105
if dest == "landlineReceiver.py":
@@ -155,80 +160,97 @@ def FuncTest(orig, origAdd, dest, destAdd, destNo):
print "Receiver handler status:", y.connect()
y.sendData('hello Receiver')
- #wait respond from destination handler
+
+ signal.signal(signal.SIGALRM, timeout_handler)
+ signal.alarm(60)
+
while 1:
- destHandler = y.receiveData()
- if destHandler <> "":
+ try:
+ destHandler = y.receiveData()
+ if destHandler <> "":
+ break
+
+ except TimeoutException:
+ destHandler = "failed"
break
- #should have timeout = think about timeout
if destHandler == "ready":
print "Receiver handler : Ready"
print ""
x.sendData("start")#send message to handler to start the call
- sleep(1)
+ sleep(0.5)
x.sendData(destNo)
- #for refresh socket, so gsm handler can use socket to communicated with the phone
- x.closeConnection()
- x.connect()
+ signal.signal(signal.SIGALRM, timeout_handler)
+ signal.alarm(120)
- #wait respond from both of handler
print "------------ Test Result ------------"
print ""
+
while 1:
- sleep(4)
- x.connect()
- sleep(0.5)
- resultOrig = x.receiveData()
- resultDest = y.receiveData()
+ try:
+ sleep(0.5)
+ resultOrig = x.receiveData()
+ resultDest = y.receiveData()
+
+ if resultOrig <> "" or resultDest <> "":
+ break
- if resultOrig <> "" or resultDest <> "":
+ except TimeoutException:
+ resultOrig = 486
+ resultDest = 486
break
#if failed, tell everybody to try one more time
if resultOrig == 486 or resultDest == 486:
- y.sendData('hello Destination Handler')
+
x.sendData("start")
- sleep(2)
+ sleep(0.5)
x.sendData(destNo)
- #for refresh socket, so gsm handler can use socket to communicated with the phone
- x.closeConnection()
- x.connect()
-
+ signal.signal(signal.SIGALRM, timeout_handler)
+ signal.alarm(120)
+
while 1:
- resultOrig = X.receiveData()
- resultDest = y.receiveData()
- print "Test Result origin: ", resultOrig
- print "Test Result Destination: ", resultDest
+ try:
+ sleep(0.5)
+ resultOrig = x.receiveData()
+ resultDest = y.receiveData()
- if resultOrig <> "" or resultDest <> "":
+ if resultOrig <> "" or resultDest <> "":
+ break
+
+ except TimeoutException:
+ resultOrig = 486
+ resultDest = 486
break
- #if still failed, save to db and return repeat test, so we make automatic test vice versa
- # 486 see wiki error code
+ #if still failed, we make automatic test vice versa
+
if resultOrig == 486 or resultDest == 486:
- #db.execute ("update result table")
+ testResult = 486
repeatTest = True
print "Second test result origin: ", resultOrig
print "Second test result Destination: ", resultDest
else:
+ testResult = 200
print "Second test result origin: ", resultOrig
print "Second test result Destination: ", resultDest
- x.sendData('487') # signal caller to terminate
- y.sendData('487') # signal receiver to terminate
+ x.sendData('487')
+ y.sendData('487')
- else: #save to database, tell handler to terminated
- #db.execute ("update result table")
+ else:
+
+ testResult = 200
print "Test Result origin: ", resultOrig
print "Test Result Destination: ", resultDest
- x.sendData('487') # signal caller to terminate
- y.sendData('487') # signal receiver to terminate
+ x.sendData('487')
+ y.sendData('487')
else:
- statusTest = "604 General Handler Error: Destination handler no respond"
+ testResult = 604
+ print "604 General Handler Error: Destination handler no respond"
#tell Caller handler to terminate because receiver doesnt work
x.sendData('487')
@@ -236,25 +258,26 @@ def FuncTest(orig, origAdd, dest, destAdd, destNo):
except ValueError:
print "601 General Handler Error: Could not open Destination handler"
+ testResult = "601"
else:
- statusTest = "605 General Handler Error: Origin handler no respond"
+ testResult = 605
+ print "605 General Handler Error: Origin handler no respond"
x.closeConnection()
except ValueError:
+ testResult = 602
print "602 General Handler Error: Could not open Origin handler"
# Main software
-
-
# Check DB connection
-x = classDb.DBMySQLConnection(user, passw, host, dbname)
-print "connected to the DB ", x.connectDB()
+db = classDb.DBMySQLConnection('root', 'randompasswordSQL', 'localhost', 'gsmselftesting')
+print "Connecting to DB ", x.connectDB()
print ""
-dbStatus = x.connectDB()
+dbStatus = db.connectDB()
if dbStatus == 1:
@@ -270,9 +293,10 @@ if dbStatus == 1:
sipLocalServerStatus = sipLocalServer.ping(3)
# Fetch The task information from DB
- print "do i have anything to do", x.anyTasksToDo()
+ print "do i have anything to do", db.anyTasksToDo()
- for item in x.tasksList:
+ for item in db.tasksList:
+
taskID = item[0]
callFrom = item[1]
callTo = item[2]
@@ -283,7 +307,7 @@ if dbStatus == 1:
if callFrom == "sip":
if sipServerStatus == 0:
- print "500 Server Internal Error"
+ print "[failed] 500 Server Internal Error"
else:
@@ -291,18 +315,21 @@ if dbStatus == 1:
FuncTest(sipCall, "localhost", "gsmincom_.py", "localhost","4661473")
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
if callTo == "gsmrz2":
if gsmBox1Status == 0:
- print "500 Server Internal Error"
+ print "[failed] 500 Server Internal Error"
else:
FuncTest(sipCall, "localhost", "Box1", "132.0.0.2","404")
+ 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
@@ -311,33 +338,43 @@ if dbStatus == 1:
if callTo == "gsmrz3":
if gsmBox2Status == 0:
- print "500 Server Internal Error"
+ print "[failed] 500 Server Internal Error"
else:
FuncTest(sipCall, "localhost", "Box2", "132.0.0.3","405")
+ 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
if callTo == "landline":
if sipGateSeverStatus == 0:
- print "500 Server Internal Error"
+ print "[failed] 500 Server Internal Error"
else:
FuncTest(sipCall, "localhost", landlnRec, "localhost",landlnNum)
+ db.addResult(taskID, testResult)
if callTo == "localsip":
if sipLocalSeverStatus == 0:
- print "500 Server Internal Error"
+ print "[failed] 500 Server Internal Error"
else:
- FuncTest(sipCall, "localhost", localSipRec, "localhost","405")
+ FuncTest(sipCall, "localhost", localSipRec, "localhost",unisipNum)
+ db.addResult(taskID, testResult)
if callTo == "externalgsm":
FuncTest(sipCall, "localhost", o2Rec, "localhost","405")
+ db.addResult(taskID, testResult)
+
FuncTest(sipCall, "localhost", tmobileRec, "localhost","405")
+ db.addResult(taskID, testResult)
+
FuncTest(sipCall, "localhost", vodafoneRec, "localhost","405")
+ db.addResult(taskID, testResult)
+
FuncTest(sipCall, "localhost", "xx", "localhost","405")
+ db.addResult(taskID, testResult)
@@ -345,26 +382,29 @@ if dbStatus == 1:
if callTo =="sip":
if sipServerStatus == 0:
- print "500 Server Internal Error"
+ print "[failed] 500 Server Internal Error"
else:
FuncTest("gsmcall_.py", "localhost", sipRec, "localhost",sipNum)
+ db.addResult(taskID, testResult)
sleep(10)
if callTo =="gsmrz2":
if gsmBox1Status == 0:
- print "500 Server Internal Error"
+ print "[failed] 500 Server Internal Error"
else:
FuncTest("Box1", "132.0.0.2", sipRec, "localhost",sipNum)
+ db.addResult(taskID, testResult)
if callTo =="gsmrz3":
if gsmBox2Status == 0:
- print "500 Server Internal Error"
+ print "[failed] 500 Server Internal Error"
else:
FuncTest("Box2", "132.0.0.3", sipRec, "localhost",sipNum)
+ db.addResult(taskID, testResult)
diff --git a/Handler/localsipReceiver.py b/Handler/localsipReceiver.py
index 81d7a51..96f058f 100644
--- a/Handler/localsipReceiver.py
+++ b/Handler/localsipReceiver.py
@@ -7,9 +7,6 @@ from time import sleep
from datetime import datetime
stop = False
-server = "132.230.4.8"
-username = "mpselftest2"
-password = "2mpselftest"
LOG_LEVEL=2
current_call = None
@@ -55,7 +52,7 @@ class MyAccountCallback(pj.AccountCallback):
if accept == True:
sleep(0.5)
current_call.answer(200)
- sleep(4)
+ sleep(1.5)
current_call.hangup()
status = 200
server.sendData(success)
diff --git a/Handler/sipCall.py b/Handler/sipCall.py
index 1d626ac..a0b96e5 100644
--- a/Handler/sipCall.py
+++ b/Handler/sipCall.py
@@ -44,12 +44,12 @@ class MyCallCallback(pj.CallCallback):
print "CONNECTING CALL"
print "CALL CONFIRMED and ESTABLISH", self.call.info().state_text
- sleep(5)
+ sleep(2)
current_call.hangup()
status = 200
server.sendData(status)
else:
- sleep(1)
+ sleep(0.5)
if self.call.info().last_reason <> "":
diff --git a/Handler/sipReceiver.py b/Handler/sipReceiver.py
index e5cbba4..607f56d 100644
--- a/Handler/sipReceiver.py
+++ b/Handler/sipReceiver.py
@@ -52,7 +52,7 @@ class MyAccountCallback(pj.AccountCallback):
if accept == True:
sleep(0.5)
current_call.answer(200)
- sleep(4)
+ sleep(1.5)
current_call.hangup()
status = 200
server.sendData(success)