summaryrefslogtreecommitdiffstats
path: root/Code/Server-Code/ControllerClass.py
diff options
context:
space:
mode:
Diffstat (limited to 'Code/Server-Code/ControllerClass.py')
-rw-r--r--[-rwxr-xr-x]Code/Server-Code/ControllerClass.py59
1 files changed, 46 insertions, 13 deletions
diff --git a/Code/Server-Code/ControllerClass.py b/Code/Server-Code/ControllerClass.py
index 4f4cef5..4ed0d9d 100755..100644
--- a/Code/Server-Code/ControllerClass.py
+++ b/Code/Server-Code/ControllerClass.py
@@ -4,6 +4,7 @@ import subprocess
import SSHTunnelBoxClass
import ClientClass
import random
+import csv
import LogFileClass
logger = LogFileClass.Logging('TestProcessLog.log')
@@ -46,6 +47,7 @@ class controller:
sleep(2)
self.callerGreeting()
+ logger.logEvent('Status Handler Connection :'+self.connected)
if self.connected == 'OK':
self.caller.sendData('CALLER|'+self.destNo)
@@ -65,8 +67,9 @@ class controller:
else:
#waiting 2 seconds if doesnt use ssh connection until handler ready
sleep(2)
- self.receiverGreeting()
-
+ self.receiverGreeting()
+
+ logger.logEvent('Status Handler Connection :'+self.connected)
if self.connected == 'OK':
self.receiver.sendData('RECEIVER')
@@ -105,7 +108,6 @@ class controller:
self.caller.sendData('TERMINATE CONNECTION')
self.caller.closeConnection()
- self.initCancelTest()
#can connect to handler but device caller not ready to do the test.
elif self.connected == 'DEVICE NOT READY':
@@ -118,6 +120,14 @@ class controller:
self.testResult = 999
logger.logEvent('999 General Handler Error: Could not connect to Caller handler')
+ def writeToFile(self, AccountInfo):
+ try:
+ with open('handler.txt', 'w') as F:
+ writer = csv.writer(F)
+ writer.writerow([AccountInfo])
+ F.close()
+ except ValueError:
+ print "can't write to file"
def initCancelTest(self):
#close SSH connection when using gsmBox and destination doesnt respond. to make sure SSH connection are terminate
@@ -134,16 +144,19 @@ class controller:
self.resultCaller = self.caller.receiveData(20)
#print 'result '+self.resultCaller+'--'+self.resultDest
if self.resultCaller == 'DEVICE NOT READY':
+ logger.logEvent('Task :'+self.callFrom+' - '+self.dest)
logger.logEvent('Caller DEVICE NOT READY')
self.testResult = 801
self.initTerminate()
elif self.dest == 'DEVICE NOT READY':
+ logger.logEvent('Task :'+self.callFrom+' - '+self.dest)
logger.logEvent('Caller DEVICE NOT READY')
self.testResult = 802
self.initTerminate()
elif self.resultCaller == 'CALL OK' and self.resultDest =='CALL OK':
+ logger.logEvent('Task :'+self.callFrom+' - '+self.dest)
logger.logEvent('Test Succeed')
self.testResult = 200
self.initTerminate()
@@ -151,17 +164,20 @@ class controller:
#build specially only for Eplus card. since they use prepaid card.
if self.dest == 'GSMExt.Eplus':
if self.resultCaller == 'CALL OK' and self.resultDest <> 'TIME OUT':
+ logger.logEvent('Task :'+self.callFrom+' - '+self.dest)
logger.logEvent('Test Failed - Eplus No credit on Eplus')
self.testResult = 402
self.initTerminate()
else:
logger.logEvent('Test Failed')
+ logger.logEvent('Task :'+self.callFrom+' - '+self.dest)
self.testResult = 486
self.initTerminate()
else:
#one or both of the handler send un success test. assign failed to this test
if self.resultCaller <> 'CALL OK' or self.resultDest <> 'CALL OK':
+ logger.logEvent('Task :'+self.callFrom+' - '+self.dest)
logger.logEvent('Test Failed')
self.testResult = 486
self.initTerminate()
@@ -172,7 +188,7 @@ class controller:
self.receiver.sendData('RECEIVE START')
self.caller.sendData('CALL START')
- def initAccount(self, account):
+ def initAccount(self, account, handler, PortName, portCom):
accConf = account
self.username = accConf[0:accConf.find(':')]
@@ -183,6 +199,9 @@ class controller:
newLine = line[line.find(':')+1:]
self.server = newLine[0:newLine.find(':')]
+ textFile = 'Account:'+str(self.username)+':'+str(self.password)+':'+str(self.server)+':'+str(handler)+':'+str(PortName)+':'+str(portCom)
+ self.writeToFile(textFile)
+
# define the caller configuration such as port name and port caller.
def initCaller(self):
logger.logEvent('init Caller')
@@ -191,12 +210,15 @@ class controller:
if self.callFrom[0:4] == 'GSMR':
if self.callFrom =="GSMRZ1":
+ self.initAccount(self.accCaller,self.callFrom, self.callPortName,self.portCaller)
self.initGSM(self.portCaller, self.callPortName, self.callFrom)
else:
- self.initAccount(self.accCaller)
+ self.initAccount(self.accCaller, self.callFrom, self.callPortName,self.portCaller)
#open SSH tunneling
+
self.boxCaller = SSHTunnelBoxClass.SSHTunneling(self.portCaller, 50008, self.server, self.username, self.password)
status = self.boxCaller.startTunneling()
+ logger.logEvent('SSH Status :'+str(status))
#check whether the SSH tunneling succes or not, 0 is failed!
if status!= 0:
@@ -204,11 +226,14 @@ class controller:
else:
self.continues = 0
elif self.callFrom[0:4] == 'GSME':
+ self.initAccount(self.accCaller,self.callFrom, self.callPortName,self.portCaller)
self.initGSM(self.portCaller, self.callPortName, self.callFrom)
else:
#open the SIP handler
- subprocess.Popen(args=["gnome-terminal", '--command=python SIPHandler.py '+self.accCaller+ ' ' +str(self.portCaller)])
+ self.initAccount(self.accCaller,self.callFrom, self.callPortName,self.portCaller)
+ script = 'SIPHandler.py'
+ subprocess.Popen(['python',script], shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
# define the destination configuration such as port name and port caller.
def initReceiver(self):
@@ -218,25 +243,31 @@ class controller:
if self.dest[0:4] == 'GSMR':
if self.dest =="GSMRZ1":
+ self.initAccount(self.accDest, self.dest, self.destPortName,self.portDest)
self.initGSM(self.portDest, self.destPortName, self.dest)
else:
- self.initAccount(self.accDest)
+ self.initAccount(self.accDest, self.dest, self.destPortName,self.portDest)
#open SSH tunneling
+
self.boxDest = SSHTunnelBoxClass.SSHTunneling(self.portDest, 50008, self.server, self.username, self.password)
status = self.boxDest.startTunneling()
#check whether the SSH tunneling succes or not, 0 is failed!
+ logger.logEvent('SSH Status :'+str(status))
if status!= 0:
self.continues = 1
else:
self.continues = 0
elif self.dest[0:4] == 'GSME':
- self.initGSM(self.portDest, self.destPortName, self.dest)
+ self.initAccount(self.accDest, self.dest, self.destPortName,self.portDest)
+ self.initGSM(self.portDest, self.destPortName, self.dest)
else:
- self.portDest = 50100
- subprocess.Popen(args=['gnome-terminal', '--command=python SIPHandler.py '+self.accDest+ ' ' +str(self.portDest)])
+ #self.portDest = 50100
+ self.initAccount(self.accDest, self.dest, self.destPortName,self.portDest)
+ script = 'SIPHandler.py'
+ subprocess.Popen(['python',script], shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
# send terminate message to Handlers
def initTerminate(self):
@@ -263,7 +294,7 @@ class controller:
#open connection to the Handler
self.caller = ClientClass.Connection('localhost',self.portCaller)
self.caller.connect()
-
+
if self.caller.connected == 1:
#connection establish and send hallo message to handler
logger.logEvent('Connected to Caller Handler')
@@ -290,10 +321,11 @@ class controller:
def receiverGreeting(self): # send greeting message to the destination handler
logger.logEvent('Receiver Greeting')
self.connected = None
+
#open connection to the Handler
self.receiver = ClientClass.Connection('localhost', self.portDest)
self.receiver.connect()
-
+
if self.receiver.connected == 1:
#connection establish and send hallo message to handler
logger.logEvent('Connected to Receiver Handler')
@@ -321,7 +353,8 @@ class controller:
def initGSM(self, portCommunication, portDevice, handler):
#open GSM Handler
logger.logEvent('Init GSM')
- subprocess.Popen(args=["gnome-terminal", '--command=python GSMHandler.py '+str(portCommunication)+ ' ' +str(portDevice)+' '+str(handler)])
+ script = 'GSMHandler.py'
+ subprocess.Popen(['python',script], shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE)