summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortriatmoko2011-06-30 17:17:12 +0200
committertriatmoko2011-06-30 17:17:12 +0200
commit01b558f3e752acd0a34bbfb2b1931c23f440d4f4 (patch)
treebe7b49b1ac3c9bf45231aad98eef70050fcf1082
parentput some test function. (diff)
downloadgsm-selftest-01b558f3e752acd0a34bbfb2b1931c23f440d4f4.tar.gz
gsm-selftest-01b558f3e752acd0a34bbfb2b1931c23f440d4f4.tar.xz
gsm-selftest-01b558f3e752acd0a34bbfb2b1931c23f440d4f4.zip
Maybe you guys can consider new algorithm. this controller use one function to do all test. so just put parameter name of handler and will do the the test base on the handler name.
-rw-r--r--Controller/Controller-SecondType.py388
1 files changed, 388 insertions, 0 deletions
diff --git a/Controller/Controller-SecondType.py b/Controller/Controller-SecondType.py
new file mode 100644
index 0000000..bcf5caa
--- /dev/null
+++ b/Controller/Controller-SecondType.py
@@ -0,0 +1,388 @@
+import sys
+import os
+import re
+import time
+import MySQLdb
+import subprocess
+from time import sleep
+from datetime import datetime
+
+
+stop = "False"
+status = ""
+dbSStatus = ""
+
+global idTask
+global sip2GsmRz
+global sip2LocSip
+global sip2LnLine
+global sip2ExtGsm
+global gsmRz2Gsmrz
+global gsmRz2ExtGsmRz
+global gsmRz2Sip
+global gsmRz2LnLine
+global smRz2LocSip
+global extGsm2Sip
+global extGsm2GsmRz
+global lnLine2GsmRz
+global lnLine2Sip
+global timeStamp
+global status
+
+
+
+#function to check DBconnection
+def FuncDbConnect():
+
+ global dbStatus
+ try:
+ mydb = MySQLdb.connect('localhost', 'root', 'randompasswordSQL','GSMTesting');
+ db=mydb.cursor()
+ dbStatus = "Database connection establish"
+
+ except MySQLdb.Error, e:
+ print "Error %d: %s" % (e.args[0],e.args[1])
+
+
+#function to ping
+def FuncPing(ip):
+
+ global status
+ lifeline = re.compile(r"(\d) received")
+ report = ("No response","Partial Response","Alive")
+
+ A=1,2,3
+ for host in A:
+
+ pingaling = os.popen("ping -q -c2 "+ip,"r")
+
+ while 1:
+ line = pingaling.readline()
+ if not line: break
+ igot = re.findall(lifeline,line)
+ if igot:
+
+ status= report[int(igot[0])]
+
+# class for socket connection
+
+# class for socket connection
+
+class Connection:
+ def __init__(self, h, p):
+ self.host = h
+ self.port = p
+ self.s = None
+ self.connected = 0
+
+ def connect(self):
+ self.s = None
+
+ for res in socket.getaddrinfo(self.host, self.port, socket.AF_UNSPEC, socket.SOCK_STREAM):
+ af, socktype, proto, canonname, sa = res
+ try:
+ self.s = socket.socket(af, socktype, proto)
+ except socket.error, msg:
+ self.s = None
+ self.connected = 0
+ continue
+ try:
+ self.s.connect(sa)
+ except socket.error, msg:
+ self.s.close()
+ self.connected = 0
+ self.s = None
+ continue
+ break
+ if self.s is None:
+ self.connected = 0
+ return '810 General socket layer error: Could not open socket'
+ else:
+ self.connected = 1
+ return '800 Socket connected'
+
+ def send_data(self, data):
+ if self.connected == 1:
+ self.s.send(data)
+
+ def receive_data(self):
+ if self.connected == 1:
+ return self.s.recv(1024)
+ else:
+ return '812 Socket is not connected.'
+
+ def close_connection(self):
+ if self.connected == 1:
+ self.s.close()
+ self.connected = 0
+ return 'Closed'
+
+
+# all Test case function
+
+# One function for all test case
+
+def FuncTest(orig,dest):
+
+ global repeatTest
+ repeatTest = ""
+
+ #first make test from sip to gsm1 rz
+ try:
+ # open SIP caller handler
+ command="--command=python" +orig
+ subprocess.Popen(args=["gnome-terminal", command])
+
+ sleep(5)
+ x = Connection('localhost',50099)
+ print "handler", x.connect()
+ x.send_data('hello Handler')
+
+ # wait respond from handler
+ while 1:
+ origHandler = x.receive_data()
+ if origHandler <> "":
+ break
+ #think about time out
+
+ if origHandler == "ready":
+ print "sip handler ready"
+ try:
+ command="--command=python Client3.py "
+ subprocess.Popen(args=["gnome-terminal", command])
+
+ sleep(5)
+ y = Connection('localhost',50010)
+ print "GSM handler", y.connect()
+ y.send_data('hello GSM 1 RZ, caller number')
+
+ #wait respond from gsm handler
+ while 1:
+ destHandler = y.receive_data()
+ if destHandler <> "":
+ break
+ #should have timeout = think about timeout
+
+ if destHandler == "ready":
+
+ x.send_data("start")
+ sleep(2)
+ x.send_data("destination number")
+ #send destination number to sip caller and signal to start the call
+
+ #wait respond from both of handler
+ while 1:
+ resultOrig = X.receive_data()
+ resultDest = y.receive_data()
+ if resultOrig <> "" or resultDest <> "":
+ break
+
+ #if failed, try one more time
+ if resultOrig == "failed" or resultDest == "failed":
+ y.send_data('hello Destination Handler')
+ x.send_data("start + destination number")
+ while 1:
+ resultOrig = X.receive_data()
+ resultDest = y.receive_data()
+ if resultOrig <> "" or resultDest <> "":
+ break
+
+ #if still failed, save to db and update variable gsmRz2Sip == "1", so we make automatic test vice versa
+ if resultOrig == "failed" or resultDest == "failed":
+ db.execute ("update result table")
+ repeatTest="true"
+
+ else: #save to database, tell handler to terminated
+ db.execute ("update result table")
+ y.send_data("terminated") # signal GSM1 RZ to terminate
+
+ else:
+ statusTest = "604 General Handler Error: Destination handler no respond"
+ #tell SIP handler to terminate
+ x.send_data("terminated")
+
+ y.close_connection()
+
+ except ValueError:
+ print "601 General Handler Error: Could not open Destination handler"
+ else:
+ statusTest = "605 General Handler Error: Origin handler no respond"
+
+ x.close_connection()
+
+ except ValueError:
+ print "602 General Handler Error: Could not open Origin handler"
+
+
+
+# Main software
+
+
+
+# Check DB connection
+FuncDbConnect()
+if dbStatus = "Database connection establish":
+
+ FuncPing("132.230.4.8")
+ sipServerStatus = status
+
+ FuncPing("132.230.4.8")
+ sipLocalStatus = status
+
+ FuncPing("132.230.4.8")
+ sipGateStatus = status
+
+ FuncPing("132.230.4.8")
+ btsBox1Status = status # it will be on building 101
+
+ FuncPing("132.230.4.8")
+ btsBox2Status = status # it will be on the building 52
+
+ FuncPing("132.230.4.8")
+ btsBox3Status = status # dont need, since we put the device on RZ building.just direct connect to the server
+
+# Fetch The task information from DB
+ db.execute ("Select IDTask, SIP2GSMRZ, SIP2LocSIP, SIP2Lnline, SIP2ExtGSM, GSMRZ2GSMRZ, GSMRZ2ExtGSM, GSMRZ2SIP, GSMRZ2Lnline, GSMRZ2LocSIP, ExtGSM2SIP, ExtGSM2GSMRZ, Lnline2GSMRZ, Lnline2SIP, timeStamp, status from TaskTable")
+ rows = db.fetchall()
+
+ for row in rows:
+ idTask=row[0]
+ sip2GsmRz=row[1]
+ sip2LocSip=row[2]
+ sip2LnLine=row[3]
+ sip2ExtGsm=row[4]
+ gsmRz2Gsmrz=row[5]
+ gsmRz2ExtGsmRz=row[6]
+ gsmRz2Sip=row[7]
+ gsmRz2LnLine=row[8]
+ gsmRz2LocSip=row[9]
+ extGsm2Sip=row[10]
+ extGsm2GsmRz=row[11]
+ lnLine2GsmRz=row[12]
+ lnLine2Sip=row[13]
+ timeStamp=row [14]
+ status=row[15]
+
+ if sip2GsmRz == 1 and sipServerStatus <> "No response":
+ #call Function for Sip to Gsm
+ FuncTest("SIPCall.py","RZ1Receiver.py")
+ if repeatTest == "true":
+ gsmRz2Sip = 1
+
+ FuncTest("SIPCall.py","RZ2Receiver.py")
+ if repeatTest == "true":
+ gsmRz2Sip = 1
+
+ FuncTest("SIPCall.py","RZ3Receiver.py")
+ if repeatTest == "true":
+ gsmRz2Sip = 1
+
+ if sip2LocSip == 1 and sipServerStatus <> "No response" and sipLocalStatus <> "No response":
+ # call function for sip to local sip
+ FuncTest("SIPCall.py","LocalReceiver.py")
+
+ if sip2LnLine == 1 and sipServerStatus <> "No response" and sipGateStatus <> "No response":
+
+ if sip2ExtGsm == 1 and sipServerStatus <> "No response":
+
+ if gsmRz2GsmRz == 1:
+ if btsBox1Status <> "No response":
+ if btsBox2Status <> "No response":
+ #call function gsm 1 rz to gsm 2 rz
+ if btsBox3Status <> "No response":
+ #call function gsm 1 rz to gsm 3 rz
+ if btsBox2Status <> "No response" and btsBox3Status <> "No response":
+ # call function gsm 2 rz to gsm 3 rz
+
+ if gsmRz2ExtGsm == 1:
+ if btsBox1Status <> "No response": # I'm not sure with this part, maybe better we make 1 script which can cover all the test to external GSM
+ #call function gsm 1 rz to o2
+ #call function gsm 1 rz to vodaphone
+ #call function gsm 1 rz to Tmobile
+ #call function gsm 1 rz to Eplus
+ if btsBox2Status <> "No response":
+ #call function gsm 2 rz to o2
+ #call function gsm 2 rz to vodaphone
+ #call function gsm 2 rz to Tmobile
+ #call function gsm 2 rz to Eplus
+ if btsBox3Status <> "No response":
+ #call function gsm 3 rz to o2
+ #call function gsm 3 rz to vodaphone
+ #call function gsm 3 rz to Tmobile
+ #call function gsm 3 rz to Eplus
+
+ if gsmRz2SIP == 1:
+ if btsBox1Status <> "No response":
+ #call function gsm 1 rz to SIP
+
+ if btsBox2Status <> "No response":
+ #call function gsm 2 rz to SIP
+
+ if btsBox3Status <> "No response":
+ #call function gsm 3 rz to SIP
+
+ if gsmRz2LnLine == 1 and sipGateStatus <> "No response":
+ if btsBox1Status <> "No response":
+ #call function gsm 1 rz to landline
+
+ if btsBox2Status <> "No response":
+ #call function gsm 2 rz to Landline
+
+ if btsBox3Status <> "No response":
+ #call function gsm 3 rz to Landline
+
+ if gsmRz2LocSip == 1 and sipLocalStatus <> "No response":
+ if btsBox1Status <> "No response":
+ #call function gsm 1 rz to local SIP
+
+ if btsBox2Status <> "No response":
+ #call function gsm 2 rz to local SIP
+
+ if btsBox3Status <> "No response":
+ #call function gsm 3 rz to local SIP
+
+ if extGsm2SIP == 1 and sipServerStatus <> "No response":
+ #call function o2 to SIP
+ #call function vodaphone to SIP
+ #call function Tmobile to SIP
+ #call function Eplus to SIP
+
+ if extGsm2GsmRz == 1:
+ if btsBox1Status <> "No response":
+ #call function o2 to GSM1 RZ
+ #call function vodaphone to GSM1 RZ
+ #call function Tmobile to GSM1 RZ
+ #call function Eplus to GSM1 RZ
+ if btsBox2Status <> "No response":
+ #call function o2 to GSM2 RZ
+ #call function vodaphone to GSM2 RZ
+ #call function Tmobile to GSM2 RZ
+ #call function Eplus to GSM2 RZ
+ if btsBox3Status <> "No response":
+ #call function o2 to GSM3 RZ
+ #call function vodaphone to GSM3 RZ
+ #call function Tmobile to GSM3 RZ
+ #call function Eplus to GSM3 RZ
+
+ if lnLine2GsmRz == 1 and sipGateStatus <> "No response":
+
+ if btsBox1Status <> "No response":
+ #call function landline to GSM1 RZ
+
+ if btsBox2Status <> "No response":
+ #call function landline to GSM2 RZ
+
+ if btsBox3Status <> "No response":
+ #call function landline to GSM3 RZ
+
+ if lnLine2Sip == 1 and sipGateStatus <> "No response":
+ if sipServerStatus <> "No response":
+ #call function landline to SIP
+
+# will exit if DB connection failed
+else:
+ sys.exit(5)
+
+
+
+