summaryrefslogtreecommitdiffstats
path: root/Under-Testing/Server-Code-New/initTestClass.py
diff options
context:
space:
mode:
authorgsmselftest2011-11-16 18:06:02 +0100
committergsmselftest2011-11-16 18:06:02 +0100
commit8a7755d6f96e599fe75ac8e5e1c6994138f4b99e (patch)
tree9b320feb695cfbadd605808b2db5795e240e9399 /Under-Testing/Server-Code-New/initTestClass.py
parent delete dummy comment (diff)
downloadgsm-selftest-8a7755d6f96e599fe75ac8e5e1c6994138f4b99e.tar.gz
gsm-selftest-8a7755d6f96e599fe75ac8e5e1c6994138f4b99e.tar.xz
gsm-selftest-8a7755d6f96e599fe75ac8e5e1c6994138f4b99e.zip
under Testing folder
Diffstat (limited to 'Under-Testing/Server-Code-New/initTestClass.py')
-rw-r--r--Under-Testing/Server-Code-New/initTestClass.py121
1 files changed, 121 insertions, 0 deletions
diff --git a/Under-Testing/Server-Code-New/initTestClass.py b/Under-Testing/Server-Code-New/initTestClass.py
new file mode 100644
index 0000000..58bf705
--- /dev/null
+++ b/Under-Testing/Server-Code-New/initTestClass.py
@@ -0,0 +1,121 @@
+import sys
+import subprocess, signal
+import os
+import ControllerClass
+import DbClass
+import PingClass
+import random
+from time import sleep
+
+class initTesting:
+
+ def __init__(self):
+ self.messageList = list()
+
+ def pings(self,IP):
+
+ server = PingClass.Ping(IP)
+ self.serverStatus = server.ping(2)
+ return self.serverStatus
+
+ def initDB(self):
+
+ self.db = DbClass.DBMySQLConnection()
+ self.db.connectDB()
+ self.dbStatus = self.db.connectDB()
+
+ def initaccount(self,account,handler):
+ if handler == 'sip' or handler == 'unisip' or handler == 'landline':
+ if account[1] != '' or account[2] != '' or account[3] != '' or account[4] != '':
+ # checking available sip account, is there enough information about the account such as username, password,server
+ self.status = 1
+ else:
+ self.status = 0
+ else:
+ if account[0] != '' or account[1] != '':
+ self.status = 1
+ else:
+ self.status = 0
+
+
+ #kill process to make sure, that the handler is Terminate incase handler having problem receiving terminate message from controller
+ def killProc(self):
+ # define process name of the Handler
+ procNameDest = 'GSM Handler'
+ procNameCall = 'SIP Handler'
+
+ p = subprocess.Popen(['ps', '-A'], stdout=subprocess.PIPE)
+ out, err = p.communicate()
+
+ #search process name and kill it.
+ for line in out.splitlines():
+ if procNameDest in line:
+ pid = int(line.split(None, 1)[0])
+ os.kill(pid, signal.SIGKILL)
+ for line in out.splitlines():
+ if procNameCall in line:
+ pid = int(line.split(None, 1)[0])
+ os.kill(pid, signal.SIGKILL)
+
+
+ def initTest(self, callFrom, callTo):
+
+ self.initDB() # open database connection
+
+ if self.dbStatus != 0: # if connection to db establish, do the test
+
+ #fetch device account detail from database
+ dest = self.db.deviceAddress(str(callTo))
+ caller = self.db.deviceAddress(str(callFrom))
+
+ # check that the caller server allive or not
+ if self.pings(caller[4]) <> 0:
+
+ # check that the destination server allive or not
+ if self.pings(dest[4]) <> 0:
+
+ self.initaccount(caller,callFrom)
+ if self.status == 1:
+ self.initaccount(dest,callTo)
+
+ if self.status == 1:
+ #string = 'Account:username:password:server:ipaddress:portaddress:portnumber'
+
+ callPortName = caller[0]
+ accCaller = caller[2]+':'+caller[3]+':'+caller[4]+':'
+
+ destPortName = dest[0]
+ destNo = dest[1]
+ accDest = dest[2]+':'+dest[3]+':'+dest[4]+':'
+
+ # create controller class object and send the handler information
+ makeTest = ControllerClass.controller(callFrom, callPortName, accCaller, callTo, destPortName, destNo, accDest)
+ makeTest.FuncTest()
+
+ self.result = str(makeTest.testResult)
+ else:
+ self.result = 100
+ else:
+ self.result = 100
+
+ sleep(2)
+ #make sure the handler have been terminated
+ self.killProc() # kill all the handler
+
+ self.db.closeDBConn() #close db connection
+ sleep(1)
+ else:
+ #destintaion server die
+ self.result = 501
+ else:
+ #caller server die
+ self.result = 500
+ self.db.closeDBConn()
+ else:
+ self.result = 333
+
+ return self.result
+
+
+
+