summaryrefslogtreecommitdiffstats
path: root/notFinishedCode
diff options
context:
space:
mode:
authortriatmoko2011-07-16 14:08:58 +0200
committertriatmoko2011-07-16 14:08:58 +0200
commitcf101261cc3070fb24b27ebd607e93b60b02607b (patch)
tree5bbdfbf2e7669d293369c39b4e0e9d93ab173157 /notFinishedCode
parentupdate sip handler (diff)
downloadgsm-selftest-cf101261cc3070fb24b27ebd607e93b60b02607b.tar.gz
gsm-selftest-cf101261cc3070fb24b27ebd607e93b60b02607b.tar.xz
gsm-selftest-cf101261cc3070fb24b27ebd607e93b60b02607b.zip
managing file.
Diffstat (limited to 'notFinishedCode')
-rw-r--r--notFinishedCode/Controller-SecondType.py427
-rw-r--r--notFinishedCode/classPing.py28
2 files changed, 427 insertions, 28 deletions
diff --git a/notFinishedCode/Controller-SecondType.py b/notFinishedCode/Controller-SecondType.py
new file mode 100644
index 0000000..66cdf09
--- /dev/null
+++ b/notFinishedCode/Controller-SecondType.py
@@ -0,0 +1,427 @@
+import sys
+import os
+import time
+import MySQLdb
+import subprocess
+
+
+import classClient #import class socket
+import classDb #import class db
+import classPing
+
+from time import sleep
+from datetime import datetime
+
+
+sipNum = "4661929"
+landlnNum = "076145875681"
+unisipNum = "076120397897"
+
+
+sipCall = "sipCall.py"
+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
+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 ======================"
+
+ try:
+
+ if dest =="gsmBox1" or dest =="gsmBox2":
+
+ if dest =="gsmBox1":
+ portOrig = 50095
+
+ if dest =="gsmBox2":
+ portOrig = 50096
+
+ print ""
+ print "Connecting to Caller handler"
+ print "Caller handler status :", x.connect()
+ x.sendData('hello server please wakeup the handler and be caller')
+
+ else:
+ # open SIP caller handler
+
+ command="--command=python " +orig
+ subprocess.Popen(args=["gnome-terminal", command])
+
+ sleep(5)
+
+ if orig=="SIPCall.py":
+ portOrig = 50097
+
+ if orig=="rz1Call.py":
+ portOrig = 50098
+
+ if orig == "landlineCall.py":
+ portOrig = 50099
+
+ if orig == "LocalSIPCall.py":
+ portOrig = 50100
+
+ #else: #mean external GSM
+ # print "have not yet define"
+ #portOrig = 50101
+
+ x = classClient.Connection(origAdd,portOrig)
+ print ""
+ print "Connecting to Caller handler"
+ print "Caller handler status:", x.connect()
+
+ x.sendData('hello Handler')
+
+ # wait respond from origin handler
+ signal.signal(signal.SIGALRM, timeout_handler)
+ signal.alarm(60)
+ while 1:
+ try:
+ origHandler = x.receiveData()
+ if origHandler <> "":
+ break
+
+ except TimeoutException:
+ origHandler = "failed"
+ break
+
+
+ if origHandler == "ready":
+ print "Caller handler : Ready"
+ print ""
+ try:
+ y = None
+ global portDest
+
+ if dest =="gsmBox1" or dest =="gsmBox2":
+
+ if dest =="gsmBox1":
+ portDest = 50102
+
+ if dest =="gsmBox2":
+ portDest = 50103
+
+ y = classClient.Connection(destAdd,portDest)
+ print "Connecting to Receiver handler"
+ print "Receiver handler status: ", y.connect()
+ y.sendData('hello server please wakeup the handler and be receiver')
+
+ else:
+ command="--command=python " +dest
+ subprocess.Popen(args=["gnome-terminal", command])
+
+ sleep(2)
+
+ if dest=="SIPReceiver.py":
+ portDest = 50104
+
+ if dest=="rz1Receiver.py":
+ portDest = 50105
+
+ if dest == "landlineReceiver.py":
+ portDest = 50106
+
+ if dest == "LocalSIPReceiver.py":
+ portDest = 50107
+
+ #mean external GSM
+ #print "not define yet"
+ #portDest = 50108
+
+ y = classClient.Connection(destAdd,portDest)
+ print "Connecting to Receiver handler"
+ print "Receiver handler status:", y.connect()
+ y.sendData('hello Receiver')
+
+
+ signal.signal(signal.SIGALRM, timeout_handler)
+ signal.alarm(60)
+
+ while 1:
+ try:
+ destHandler = y.receiveData()
+ if destHandler <> "":
+ break
+
+ except TimeoutException:
+ destHandler = "failed"
+ break
+
+ if destHandler == "ready":
+
+ print "Receiver handler : Ready"
+ print ""
+ x.sendData("start")#send message to handler to start the call
+ sleep(0.5)
+ x.sendData(destNo)
+
+ x.closeConnection()
+ x.connect()
+
+ y.closeConnection()
+ y.connect()
+
+ signal.signal(signal.SIGALRM, timeout_handler)
+ signal.alarm(120)
+
+ print "------------ Test Result ------------"
+ print ""
+
+ while 1:
+ try:
+ sleep(0.5)
+ resultOrig = x.receiveData()
+ resultDest = y.receiveData()
+
+ if resultOrig <> "" or resultDest <> "":
+ break
+
+ except TimeoutException:
+ resultOrig = 486
+ resultDest = 486
+ break
+
+ #if failed, tell everybody to try one more time
+ if resultOrig == 486 or resultDest == 486:
+
+ x.sendData("start")
+ sleep(0.5)
+ x.sendData(destNo)
+
+ x.closeConnection()
+ x.connect()
+
+ y.closeConnection()
+ y.connect()
+
+ signal.signal(signal.SIGALRM, timeout_handler)
+ signal.alarm(120)
+
+ while 1:
+ try:
+ sleep(0.5)
+ resultOrig = x.receiveData()
+ resultDest = y.receiveData()
+
+ if resultOrig <> "" or resultDest <> "":
+ break
+
+ except TimeoutException:
+ resultOrig = 486
+ resultDest = 486
+ break
+
+ #if still failed, we make automatic test vice versa
+
+ if resultOrig == 486 or resultDest == 486:
+ 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')
+ y.sendData('487')
+
+ else:
+
+ testResult = 200
+ print "Test Result origin: ", resultOrig
+ print "Test Result Destination: ", resultDest
+ x.sendData('487')
+ y.sendData('487')
+
+ else:
+ testResult = 604
+ print "604 General Handler Error: Destination handler no respond"
+ #tell Caller handler to terminate because receiver doesnt work
+ x.sendData('487')
+
+ y.closeConnection()
+
+ except ValueError:
+ print "601 General Handler Error: Could not open Destination handler"
+ testResult = "601"
+ else:
+ 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
+db = classDb.DBMySQLConnection('root', 'randompasswordSQL', 'localhost', 'gsmselftesting')
+print "Connecting to DB ", x.connectDB()
+print ""
+dbStatus = db.connectDB()
+
+
+if dbStatus == 1:
+
+ # Check Ping to the Every Handler
+ sipServer = PingClass.Ping('132.230.4.60')
+ sipServerStatus = sipServer.ping(3)
+
+ sipGateServer = PingClass.Ping('sipgate.de')
+ sipGateServerStatus = sipGateServer.ping(3)
+
+ sipLocalServer = PingClass.Ping('132.230.4.60')
+ sipLocalServerStatus = sipLocalServer.ping(3)
+
+# Fetch The task information from DB
+ print "do i have anything to do", db.anyTasksToDo()
+
+ for item in db.tasksList:
+
+ taskID = item[0]
+ callFrom = item[1]
+ callTo = item[2]
+
+ print "Test ID : " , taskID
+ print "Caller : " , callFrom
+ print "Receiver : " , callTo
+
+ if callFrom == "sip":
+ if sipServerStatus == 0:
+ print "[failed] 500 Server Internal Error"
+
+ else:
+
+ if callTo == "gsmrz1":
+
+ 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 "[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
+ update
+
+ if callTo == "gsmrz3":
+
+ if gsmBox2Status == 0:
+ 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 "[failed] 500 Server Internal Error"
+
+ else:
+ FuncTest(sipCall, "localhost", landlnRec, "localhost",landlnNum)
+ db.addResult(taskID, testResult)
+
+ if callTo == "localsip":
+ if sipLocalSeverStatus == 0:
+ print "[failed] 500 Server Internal Error"
+
+ else:
+ 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)
+
+
+
+ if callFrom =="gsmrz1":
+
+ if callTo =="sip":
+ if sipServerStatus == 0:
+ 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 "[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 "[failed] 500 Server Internal Error"
+
+ else:
+ FuncTest("Box2", "132.0.0.3", sipRec, "localhost",sipNum)
+ db.addResult(taskID, testResult)
+
+
+
+
+# will exit if DB connection failed
+else:
+ sys.exit(5)
+
diff --git a/notFinishedCode/classPing.py b/notFinishedCode/classPing.py
deleted file mode 100644
index e13b32b..0000000
--- a/notFinishedCode/classPing.py
+++ /dev/null
@@ -1,28 +0,0 @@
-import subprocess
-import string
-
-class Ping:
-
- def __init__(self, pingAddress):
- self.pingAddress = pingAddress
-
- def ping(self,numberTries):
- tried = 1
- while numberTries >= tried:
- tried += 1
- #the parameter c 1 means only one ping to be sent, parameter W 3 means how many seconds the time out should be, 3 seconds
- ping_cmd = subprocess.Popen(['ping', self.pingAddress, '-c', '1', '-W', '2'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT).communicate()[0]
-
- pingAlive = int(string.find(ping_cmd, '1 received'))
- unknownHost = int(string.find(ping_cmd, 'unknown host'))
-
-
- if pingAlive != -1:
- break
-
- if unknownHost != -1:
- return 2 #unknown host
- if pingAlive != -1:
- return 1 #ping works fine
- else:
- return 0 #no ping response