summaryrefslogtreecommitdiffstats
path: root/Controller/Controller.py
blob: 8e8f1959687f34d067096727872d286b460108e8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
import sys
import os
import re
import time
import MySQLdb
import subprocess
from time import sleep
from datetime import datetime


stop = "False"
status = ""
dbSStatus = ""

#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])]

# all Test case function

# Begin test case SIP to GSM RZ

def FuncSip2GsmRz(idTask):
	
	#first make test from sip to gsm1 rz
	try:
		# open SIP caller handler
		command="--command=python SIPCall3.py"
		subprocess.Popen(args=["gnome-terminal", command])
		
		# wait respond from handler
		if sipHandle == "ok":
			
			try:
				command="--command=python GSMCaller.py "+idTask +callerNumber # get test id and caller number
				subprocess.Popen(args=["gnome-terminal", command])
		
			#wait respond from gsm handler

				if gsmHandler == "ok":
					#send destination number to sip caller and signal to start the call
					#wait respond from both of handler
					#if failed, try one more time
						#if still failed, save to db and update variable gsmRz2SIP == "1", so we make automatic test vice versa
					# else: save to database, tell handler to terminated
				else:
					statusTest = "444, GSM Reciever handler no respond"
					#tell handler to terminate
					break

			except ValueError:    
				print "444, Error to open Handler"
				break

		else:
			statusTest = "444, SIP call handler no respond"
			break
				
	except ValueError:    
		print "444, Error to open Handler"

	#seconde make test from sip to gsm2 rz
	try:
		# open SIP caller handler
		command="--command=python SIPCall3.py"
		subprocess.Popen(args=["gnome-terminal", command])
		
		# wait respond from handler
		if sipHandle == "ok":
			
			try:
				command="--command=python GSMCaller.py "+idTask +callerNumber # get test id and caller number
				subprocess.Popen(args=["gnome-terminal", command])
		
			#wait respond from gsm handler

				if gsmHandler == "ok":
					#send destination number to sip caller and signal to start the call
					#wait respond from both of handler
					#if failed, try one more time
						#if still failed, save to db and update variable gsmRz2SIP == "1", so we make automatic test vice versa
					# else: save to database, tell handler to terminated
				else:
					statusTest = "444, GSM Reciever handler no respond"
					#tell handler to terminate
					break

			except ValueError:    
				print "444, Error to open Handler"
				break

		else:
			statusTest = "444, SIP call handler no respond"
			break
				
	except ValueError:    
		print "444, Error to open Handler"	
		
# Begin test case SIP to Local SIP

# Begin test case SIP to Landline

# Begin test case SIP to Ext. GSM

# Begin test case GSM 1 RZ to GSM 2 RZ

# Begin test case GSM 1 RZ to GSM 3 RZ

# Begin test case GSM 2 RZ to GSM 3 RZ

# Begin test case GSM RZ to Ext. GSM

# Begin test case GSM RZ to SIP, if already have SIP - GSM RZ dont do this test. (we can easy update variable gsm2Sip when SIP to gsm rz test succed from 1 to 0 because 1 mean do the test) but if the result failed, do it.

# Begin test case GSM RZ to Landline

# Begin test case GSM RZ to Local SIP

# Begin test case Ext. GSM to SIP, if already have SIP to Ext. GSM don do this. but if the result failed, do it.

# Begin test case Ext. GSM - GSM RZ, if already have GSM to Ext. GSM test, dont do this. but if the result failed, do it.

# Begin test case Landline to GSM RZ, if already have GSM RZ to Landline, dont do this. but if the result failed, do it.

# Begin test case Landline to SIP, if already have SIP to Landline, Dont do this. but if the result failed, do it.

# 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 TaskInformation")
	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
		FuncSip2GsmRz(idTask)

	if sip2LocSip == "1" and sipServerStatus <> "No response" and sipLocalStatus <> "No response":
		# call function for sip to local sip
	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)