summaryrefslogtreecommitdiffstats
path: root/For Weekly Test/Advance/gsmselftest-website.py
blob: d6534049b28294eef0ed62eb6f4ff9cb1eef4f12 (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
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
#! /usr/bin/env python
from serial import * #serial port library
import sys 
import ControllerClass
import DbClass
import PingClass
import trueTableClass
import initTestClass
import usbDetectClass
from time import sleep

global resultsList
resultsList = list()

GSMListPrefix = [['GSMExt.Tm','0151'],['GSMExt.Tm','0160'],['GSMExt.Tm','0170'],['GSMExt.Tm','0171'],['GSMExt.Tm','0175'],['GSMExt.Voda','0152'],['GSMExt.Voda','0162'],['GSMExt.Voda','0172'],['GSMExt.Voda','0173'],['GSMExt.Voda','0174'],['GSMExt.Eplus','0157'],['GSMExt.Eplus','0177'],['GSMExt.Eplus','0155'],['GSMExt.Eplus','0163'],['GSMExt.Eplus','0178'],['GSMExt.O2','0159'],['GSMExt.O2','0176'],['GSMExt.O2','0179'],['GSMRZ1','0761']]


def allPing():
	
	global sipGate
	global sipServer
	global unisip
	global gsmBox1
	global gsmBox2
		
	server = PingClass.Ping('sipgate.de')
	sipGate = server.ping(2)

	server = PingClass.Ping('132.230.4.8')
	sipServer = server.ping(2)

	server = PingClass.Ping('132.230.252.228')
	unisip = server.ping(2)

	server = PingClass.Ping('localhost')
	gsmBox1 = server.ping(2)

	server = PingClass.Ping('10.4.58.241')
	gsmBox2 = server.ping(2)

def initDB():
    global dbStatus
    global db
    
    db = DbClass.DBMySQLConnection('root', 'randompasswordSQL', 'localhost', 'gsmselftesting')
    db.connectDB()
    dbStatus = db.connectDB()


def initTrueTable(x):
	initResult = trueTableClass.trueTable(x)
	initResult.initTrueTable()
	print '\n'
    	openBSC = None

    	for x in initResult.nanoBts:
        	name = x[0]
        	if x[1] == True:
            		openBSC = True
            		asterikServer = True
        	else:
			if int(x[1]) == 486:
				print name+ ' not Working'
			elif int(x[1]) == 200:
				print name+ ' Working'
			else:
				print name+ ' not Working, handler error'
	print ''
	if openBSC != None:
    		if openBSC == True:
        		print 'openBSC working'
		else:
			print 'openBSC doesnt work'
	print ''

    	if initResult.asteriskServer == True:
        	print 'asterik server is working'
       	print '\n'

    	if initResult.outGoingRZ == True:
        	print 'Outgoing call from RZ is working'
    	elif initResult.outGoingRZ == False:
        	print 'Outgoing call from RZ is not working'

    	if initResult.incomingRZ == True:
        	print 'incoming call from outside RZ to GSM RZ is working'
    	elif initResult.incomingRZ == False:
        	print 'incoming call from outside RZ to GSM RZ is not working'
        print '\n'

        
def doSipTest():

	#destList = ['gsmr1','gsmr2', 'gsmr3', 'landline', 'unisip', 'GSMExt.O2', 'GSMExt.Voda', 'GSMExt.Eplus', 'GSMExt.Tm' ]
	destList = ['landline']
	print "test"
	doTest = initTestClass.doTest()
	print 'iam here'
	for callTo in destList:

		callFrom = 'sip'
		doTest.initTest(callFrom,callTo)
		resultsList.append([callFrom, callTo, doTest.result])

def doLandlineTest():

	destList = ['GSMRZ1','unisip', 'GSMRZ2','GSMRZ3'] 
	doTest = initTestClass.doTest()
	for callTo in destList:

		callFrom = 'landline'
		doTest.initTest(callFrom,callTo)
		resultsList.append([callFrom, callTo, doTest.result])
	initTrueTable(resultsList)

def doGsmrzTest():

	destList = ['GSMRZ1','GSMRZ2', 'GSMRZ3']
	callList = ['sip']
	doTest = initTestClass.doTest()

	for callFrom in callList:

		for callTo in destList:
			doTest.initTest(callFrom,callTo)
			resultsList.append([callFrom, callTo, doTest.result])
	initTrueTable(resultsList)
	
def doGsmExtTest():
	
	destList = ['GSMExt.O2', 'GSMExt.Voda', 'GSMExt.Eplus', 'GSMExt.Tm']
	callList = ['sip']

	doTest = initTestClass.doTest()
	
	for callFrom in callList:
		for callTo in destList:
			doTest.initTest(callFrom,callTo)
			resultsList.append([callFrom, callTo, doTest.result])
	initTrueTable(resultsList)

def doAllTest():

	doSipTest()
	doLandlineTest()
	doGsmrzTest()
	doGsmExtTest()

def regularTest():
	regulartest = initTestClass.doTest()
	regulartest.smartTest()
	initTrueTable(regulartest.smartResultList)

def withDB():

	initDB()
	resultsList = list()
	if dbStatus == 1: # Checking connection to database
		if db.anyTasksToDo() == 1: # Checking task on the table

			allPing()
			i=0
			makeTest = initTestClass.doTest()

			for item in db.tasksList:

				taskID = item[0]
				taskNo = item[1]
				callFrom = item[2]
				callTo = item[3]
				
				if i == 0:
					db.updatePingResult(taskNo, sipServer, sipGate, unisip, gsmBox1, gsmBox2)
				print '\n'
				print 'Task ID		:', taskID
				print 'Calling From	:', callFrom
				print 'To		:', callTo
			

                        	makeTest.initTest(callFrom,callTo)
					
				db.addResult(taskID, makeTest.result)

				resultsList.append([callFrom, callTo, makeTest.result])
						
				db.errorCode(makeTest.result)
				print 'Result		: ' +makeTest.result+ ' ' +db.errCode

				db.deleteTempTask(taskID)
				i = i+1

			db.cleanTasksList()

			print '\n'

			initTrueTable(resultsList)	# fetch result list and make adjustment about the result
			db.closeDBConn()
		else:
			print "--- No job at all ---"
			db.closeDBConn()
	else:
		print 'Cant connect to database'
		sys.exit(1)

def findPort(portName): # take information in existing usb port
	global connect
	global prefix
	global num
	global IMEI
	global portClass
	sleep(0.5)
	portLog = os.popen('dmesg | grep \'pl2303 converter now attached to '+portName+'\'').read()
	sleep(0.5)
	if portLog != '':
		connect = 1
		portClass = usbDetectClass.serialPort(portName)
		portClass.findNumber()
		portClass.findIMEI()
		IMEI = portClass.IMEI
		num = portClass.number
		number = portClass.number
		prefix = number[0:4]
	else:
		connect = 0

def initDevice(deviceName):
	print 'Device Name	:',deviceName 
	print ' Device IMEI	: ',
	imei = sys.stdin.readline().rstrip("\r\n")
	print 'Phone number	: ',
	number = sys.stdin.readline().rstrip("\r\n")
	print 'Port Name	: /dev/',
	portName = sys.stdin.readline().rstrip("\r\n")
	print ''
	
	if imei == '' or portName == '':
		print ' == cant save device configuration, please fill IMEI / port name of the device =='
	else:
		findPort(portName)
		if connect == 1:
			if str(IMEI) != str(imei) and str(num) != str(number):
				print '== error, device not found =='
			elif str(IMEI) == str(imei):
				portClass.initUpdate(deviceName, portName, number)
				print '== Device succeced added =='
			elif str(num) == str(number) and str(IMEI) != str(imei):
				portClass.initUpdate(deviceName, portName, number)
				print '== Device succeced added, but have different IMEI =='
		else:
			print '== error, no device connected =='
	

def updateDevice(): #update port name list of device on DB
	quit = False
    	while quit != True:
		print ''
        	print "USB Mobile device configuration"
        	print "Menu:  a = automatic device configuration, m = Manual configuration, q = quit : ",	
        	input = sys.stdin.readline().rstrip("\r\n")
		print ''
		if input == 'm': # manual configuration
			
			while True:
				print ''
        			print "Mobile device name: "
				print " 1. GSM O2"
				print " 2. GSM Vodafone"
				print " 3. GSM Eplus"
				print " 4. GSM T-Mobile"
				print " 5. GSM RZ 1"
				print " 6. Back to menu"
				print ""
        			print "your choise : ",	
        			input = sys.stdin.readline().rstrip("\r\n")

				if input == '8':
					break
				elif input == '1':
					initDevice('GSMExt.O2')
				elif input == '2':
					initDevice('GSMExt.Voda')
				elif input == '3':
					initDevice('GSMExt.Eplus')
				elif input == '4':
					initDevice('GSMExt.Tm')
				elif input == '5':
					initDevice('GSMRZ1')
				else:
					print 'please choose between 1-6'
		if input == 'a': #automatic configuration
			i = 0
			x = 0
			while i !=10:
				portName ='ttyUSB'+str(i) #checking usb connection
				findPort(portName)
				i=i+1
				if connect == 1:
					for listNum in GSMListPrefix:
						if prefix == listNum[1]:
							print 'Device Name	:',listNum[0]
							print 'IMEI		:',IMEI
							print 'Phone Number	:',num
							print 'Port Name	: /dev/'+portName
							x=x+1
							newPortName = '/dev/'+portName
							portClass.initUpdate(listNum[0], newPortName, num)
							print '\n'
				
			print '== FINISH =='
			print 'Found '+str(x)+' devices'

		if input == "q":
			break
	sys.exit()

def closeFunction(dbConn,serverSocket):
        print 'Release the mutex: ' + str(dbConn.releaseMutex())
        print 'Close the DB Connection: ' + str(dbConn.closeDBConn())
        del dbConn
        del serverSocket
        sys.exit()

if len(sys.argv) > 1:

	command = sys.argv[1]
	print ' '

	if command == '--all':
		resultsList = list()
		doAllTest()

	elif command == '--sip':
		resultsList = list()
		doSipTest()

	elif command == '--gsmrz':
		resultsList = list()
		doGsmrzTest()

	elif command == '--gsmext':
		resultsList = list()
		doGsmExtTest()

	elif command == '--landline':
		resultsList = list()
		doLandlineTest()
            
    	elif command == '--smart':
		resultsList = list()
        	regularTest()

	elif command == '--devconf':
		updateDevice()

	elif command == '--db':
		resultsList = list()
		withDB()

	elif command == '--help':
		file = open('help.txt', 'r')
		print file.read()

	else:
		print "command not found, Type '--help', '--credits' for more information."
		print '\n'
else:

	initDB()
	resultsList = list()
	if dbStatus == 1:
		server = ServerClassSoftware.ServerHandlerSoftware(34500) #define the port
		tried = server.openSocket(3)

		if tried == 'TIMEOUT':
	        	closeFunction(db,server)
	
		test = server.receiveData(2)
		if test == 'TIMEOUT':
        		closeFunction(db,server)

		print test
		if test == 'START TEST':
        		server.sendData('CONFIRM\n')
        		print 'TEST STARTED'
		else:
			sys.exit('WE DIDN\'T RECEIVE THE CONFIRMATION')

		if db.anyTasksToDo() == 1:

			allPing()
			i=0
			makeTest = initTestClass.doTest()
			for item in db.tasksList:

				taskID = item[0]
				taskNo = item[1]
				callFrom = item[2]
				callTo = item[3]
				
				if i == 0:
					db.updatePingResult(taskNo, sipServer, sipGate, unisip, gsmBox1, gsmBox2)
				print '\n'
				print 'Task ID		:', taskID
				print 'Calling From	:', callFrom
				print 'To		:', callTo
			

                        	makeTest.initTest(callFrom,callTo)
					
				db.addResult(taskID, makeTest.result)

				resultsList.append([callFrom, callTo, makeTest.result])
						
				db.errorCode(makeTest.result)
				print 'Result		: ' +makeTest.result+ ' ' +db.errCode
				
				message = '|' + str(callFrom) + '|' + str(callTo) + '|' + str(makeTest.result) + '|' + str(db.errCode)

				if server.sendData(message+ chr(10))  == 1:
                			print 'data sent successfully'
				test = server.receiveData(2)
		        	if test == 'TIMEOUT':
                			closeFunction(db,server)
        			print test
		        	if test == 'CONTINUE':
		              		print 'continue test'

				db.deleteTempTask(taskID)
				i = i+1

			db.cleanTasksList()

            		if server.connected == 1:
        			server.sendData('TEST DONE\n')
			test = server.receiveData(2)

			if test == 'TIMEOUT':
		        	closeFunction(db,server)

			if test == 'DISCONNECT':
        			close = server.closeConnection()
        		if close == 1:
                		print 'Closed connection successfully'

			print 'release mutex says ', db.releaseMutex()
			print '\n'

			#initTrueTable(resultsList)	# fetch result list and make adjustment about the result
		else:
			print "--- No job at all ---"
	else:
		sys.exit(1)

print db.closeDBConn()
del db
del server