main.py 31.8 KB
Newer Older
Raphael Defosseux's avatar
Raphael Defosseux committed
1
#/*
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
# * contributor license agreements.  See the NOTICE file distributed with
# * this work for additional information regarding copyright ownership.
# * The OpenAirInterface Software Alliance licenses this file to You under
# * the OAI Public License, Version 1.1  (the "License"); you may not use this file
# * except in compliance with the License.
# * You may obtain a copy of the License at
# *
# *      http://www.openairinterface.org/?page_id=698
# *
# * Unless required by applicable law or agreed to in writing, software
# * distributed under the License is distributed on an "AS IS" BASIS,
# * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# * See the License for the specific language governing permissions and
# * limitations under the License.
# *-------------------------------------------------------------------------------
# * For more information about the OpenAirInterface (OAI) Software Alliance:
# *      contact@openairinterface.org
# */
21
22
23
24
25
26
27
28
29
30
#---------------------------------------------------------------------
# Python for CI of OAI-eNB + COTS-UE
#
#   Required Python Version
#     Python 3.x
#
#   Required Python Package
#     pexpect
#---------------------------------------------------------------------

31
32
33
34
35
36
37


#-----------------------------------------------------------
# Import Components
#-----------------------------------------------------------

import helpreadme as HELP
38
39
import constants as CONST

40

41
42
43
44
45
import cls_oaicitest            #main class for OAI CI test framework
import cls_physim               #class PhySim for physical simulators build and test
import cls_cots_ue              #class CotsUe for Airplane mode control
import cls_containerize         #class Containerize for all container-based operations on RAN/UE objects
import cls_static_code_analysis #class for static code analysis
hardy's avatar
hardy committed
46
import cls_ci_ueinfra			#class defining the multi Ue infrastrucure
Mohammed Ismail's avatar
Mohammed Ismail committed
47
import cls_physim1          #class PhySim for physical simulators deploy and run
48

49
50
51
52
53
import sshconnection 
import epc
import ran
import html

54

55
#-----------------------------------------------------------
56
# Import Libs
57
58
59
#-----------------------------------------------------------
import sys		# arg
import re		# reg
60
import pexpect	# pexpect
61
62
import time		# sleep
import os
63
import subprocess
64
65
66
67
import xml.etree.ElementTree as ET
import logging
import datetime
import signal
Raphael Defosseux's avatar
CI:    
Raphael Defosseux committed
68
from multiprocessing import Process, Lock, SimpleQueue
69
logging.basicConfig(
70
71
	level=logging.DEBUG,
	format="[%(asctime)s] %(name)s:%(levelname)s: %(message)s"
72
73
)

74

75

76
77
78
79
80
81
82

#-----------------------------------------------------------
# General Functions
#-----------------------------------------------------------



83
def CheckClassValidity(xml_class_list,action,id):
84
85
86
87
88
89
	if action not in xml_class_list:
		logging.debug('ERROR: test-case ' + id + ' has unlisted class ' + action + ' ##CHECK xml_class_list.yml')
		resp=False
	else:
		resp=True
	return resp
90

91
92
93

#assigning parameters to object instance attributes (even if the attributes do not exist !!)
def AssignParams(params_dict):
94

95
	for key,value in params_dict.items():
96
		setattr(CiTestObj, key, value)
97
98
99
100
101
102
		setattr(RAN, key, value)
		setattr(HTML, key, value)
		setattr(ldpc, key, value)



103
def GetParametersFromXML(action):
104
	if action == 'Build_eNB' or action == 'Build_Image':
hardy's avatar
hardy committed
105
		RAN.Build_eNB_args=test.findtext('Build_eNB_args')
106
		CONTAINERS.imageKind=test.findtext('kind')
107
108
		forced_workspace_cleanup = test.findtext('forced_workspace_cleanup')
		if (forced_workspace_cleanup is None):
hardy's avatar
hardy committed
109
			RAN.Build_eNB_forced_workspace_cleanup=False
110
			CONTAINERS.forcedWorkspaceCleanup=False
111
112
		else:
			if re.match('true', forced_workspace_cleanup, re.IGNORECASE):
hardy's avatar
hardy committed
113
				RAN.Build_eNB_forced_workspace_cleanup=True
114
				CONTAINERS.forcedWorkspaceCleanup=True
115
			else:
116
117
				RAN.Build_eNB_forced_workspace_cleanup=True
				CONTAINERS.forcedWorkspaceCleanup=False
118
119
120
		eNB_instance=test.findtext('eNB_instance')
		if (eNB_instance is None):
			RAN.eNB_instance=0
121
			CONTAINERS.eNB_instance=0
122
123
		else:
			RAN.eNB_instance=int(eNB_instance)
124
			CONTAINERS.eNB_instance=int(eNB_instance)
125
126
127
		eNB_serverId=test.findtext('eNB_serverId')
		if (eNB_serverId is None):
			RAN.eNB_serverId[RAN.eNB_instance]='0'
128
			CONTAINERS.eNB_serverId[RAN.eNB_instance]='0'
129
130
		else:
			RAN.eNB_serverId[RAN.eNB_instance]=eNB_serverId
131
			CONTAINERS.eNB_serverId[CONTAINERS.eNB_instance]=eNB_serverId
132
133
		xmlBgBuildField = test.findtext('backgroundBuild')
		if (xmlBgBuildField is None):
hardy's avatar
hardy committed
134
			RAN.backgroundBuild=False
135
136
		else:
			if re.match('true', xmlBgBuildField, re.IGNORECASE):
hardy's avatar
hardy committed
137
				RAN.backgroundBuild=True
138
			else:
hardy's avatar
hardy committed
139
				RAN.backgroundBuild=False
140

141
	elif action == 'WaitEndBuild_eNB':
hardy's avatar
hardy committed
142
		RAN.Build_eNB_args=test.findtext('Build_eNB_args')
143
144
		eNB_instance=test.findtext('eNB_instance')
		if (eNB_instance is None):
Raphael Defosseux's avatar
Raphael Defosseux committed
145
			RAN.eNB_instance=0
146
147
		else:
			RAN.eNB_instance=int(eNB_instance)
148
149
150
151
152
		eNB_serverId=test.findtext('eNB_serverId')
		if (eNB_serverId is None):
			RAN.eNB_serverId[RAN.eNB_instance]='0'
		else:
			RAN.eNB_serverId[RAN.eNB_instance]=eNB_serverId
153

154
	elif action == 'Initialize_eNB':
155
		RAN.eNB_Trace=test.findtext('eNB_Trace')
hardy's avatar
hardy committed
156
		RAN.Initialize_eNB_args=test.findtext('Initialize_eNB_args')
157
		eNB_instance=test.findtext('eNB_instance')
hardy's avatar
hardy committed
158
159
160
161
162
		USRPIPAddress=test.findtext('USRP_IPAddress')
		if USRPIPAddress is None:
			RAN.USRPIPAddress=''
		else:
			RAN.USRPIPAddress=USRPIPAddress
163
164
165
166
		if (eNB_instance is None):
			RAN.eNB_instance=0
		else:
			RAN.eNB_instance=int(eNB_instance)
167
168
169
170
171
		eNB_serverId=test.findtext('eNB_serverId')
		if (eNB_serverId is None):
			RAN.eNB_serverId[RAN.eNB_instance]='0'
		else:
			RAN.eNB_serverId[RAN.eNB_instance]=eNB_serverId
hardy's avatar
hardy committed
172
173
174
175
			
		#local variable air_interface
		air_interface = test.findtext('air_interface')		
		if (air_interface is None) or (air_interface.lower() not in ['nr','lte','ocp']):
176
			RAN.air_interface[RAN.eNB_instance] = 'lte-softmodem'
hardy's avatar
hardy committed
177
		elif (air_interface.lower() in ['nr','lte']):
178
			RAN.air_interface[RAN.eNB_instance] = air_interface.lower() +'-softmodem'
hardy's avatar
hardy committed
179
		else :
180
			RAN.air_interface[RAN.eNB_instance] = 'ocp-enb'
181

182
	elif action == 'Terminate_eNB':
183
		eNB_instance=test.findtext('eNB_instance')
184
		if (eNB_instance is None):
185
186
187
			RAN.eNB_instance=0
		else:
			RAN.eNB_instance=int(eNB_instance)
188
189
190
191
192
193
		eNB_serverId=test.findtext('eNB_serverId')
		if (eNB_serverId is None):
			RAN.eNB_serverId[RAN.eNB_instance]='0'
		else:
			RAN.eNB_serverId[RAN.eNB_instance]=eNB_serverId

hardy's avatar
hardy committed
194
195
196
		#local variable air_interface
		air_interface = test.findtext('air_interface')		
		if (air_interface is None) or (air_interface.lower() not in ['nr','lte','ocp']):
197
			RAN.air_interface[RAN.eNB_instance] = 'lte-softmodem'
hardy's avatar
hardy committed
198
		elif (air_interface.lower() in ['nr','lte']):
199
			RAN.air_interface[RAN.eNB_instance] = air_interface.lower() +'-softmodem'
hardy's avatar
hardy committed
200
		else :
201
			RAN.air_interface[RAN.eNB_instance] = 'ocp-enb'
202

203
204
	elif action == 'Initialize_UE':
		ue_id = test.findtext('id')
Remi Hardy's avatar
Remi Hardy committed
205
		CiTestObj.ue_trace=test.findtext('UE_Trace')#temporary variable, to be passed to Module_UE in Initialize_UE call
206
207
208
209
210
		if (ue_id is None):
			CiTestObj.ue_id = ""
		else:
			CiTestObj.ue_id = ue_id

hardy's avatar
hardy committed
211
212
213
214
215
216
	elif action == 'Detach_UE':
		ue_id = test.findtext('id')
		if (ue_id is None):
			CiTestObj.ue_id = ""
		else:
			CiTestObj.ue_id = ue_id
217

218
	elif action == 'Attach_UE':
219
220
221
222
223
		ue_id = test.findtext('id')
		if (ue_id is None):
			CiTestObj.ue_id = ""
		else:
			CiTestObj.ue_id = ue_id
224
225
		nbMaxUEtoAttach = test.findtext('nbMaxUEtoAttach')
		if (nbMaxUEtoAttach is None):
226
			CiTestObj.nbMaxUEtoAttach = -1
227
		else:
228
			CiTestObj.nbMaxUEtoAttach = int(nbMaxUEtoAttach)
229

230
231
232
233
234
235
236
237
	elif action == 'Terminate_UE':
		ue_id = test.findtext('id')
		if (ue_id is None):
			CiTestObj.ue_id = ""
		else:
			CiTestObj.ue_id = ue_id


238
	elif action == 'CheckStatusUE':
239
240
		expectedNBUE = test.findtext('expectedNbOfConnectedUEs')
		if (expectedNBUE is None):
241
			CiTestObj.expectedNbOfConnectedUEs = -1
242
		else:
243
			CiTestObj.expectedNbOfConnectedUEs = int(expectedNBUE)
244

245
	elif action == 'Build_OAI_UE':
246
		CiTestObj.Build_OAI_UE_args = test.findtext('Build_OAI_UE_args')
247
248
249
		CiTestObj.clean_repository = test.findtext('clean_repository')
		if (CiTestObj.clean_repository == 'false'):
			CiTestObj.clean_repository = False
250
		else:
251
			CiTestObj.clean_repository = True
Boris Djalal's avatar
Boris Djalal committed
252

253
	elif action == 'Initialize_OAI_UE':
254
		CiTestObj.Initialize_OAI_UE_args = test.findtext('Initialize_OAI_UE_args')
255
256
257
258
259
		UE_instance = test.findtext('UE_instance')
		if (UE_instance is None):
			CiTestObj.UE_instance = 0
		else:
			CiTestObj.UE_instance = UE_instance
hardy's avatar
hardy committed
260
261
262
263
			
		#local variable air_interface
		air_interface = test.findtext('air_interface')		
		if (air_interface is None) or (air_interface.lower() not in ['nr','lte','ocp']):
264
			CiTestObj.air_interface = 'lte-uesoftmodem'
hardy's avatar
hardy committed
265
		elif (air_interface.lower() in ['nr','lte']):
266
			CiTestObj.air_interface = air_interface.lower() +'-uesoftmodem'
hardy's avatar
hardy committed
267
		else :
268
269
			#CiTestObj.air_interface = 'ocp-enb'
			logging.error('OCP UE -- NOT SUPPORTED')
Boris Djalal's avatar
Boris Djalal committed
270

271
	elif action == 'Terminate_OAI_UE':
272
273
		UE_instance=test.findtext('UE_instance')
		if (UE_instance is None):
274
			CiTestObj.UE_instance = '0'
275
276
		else:
			CiTestObj.UE_instance = int(UE_instance)
277
278
279
280
281
282
283
284
285
286
		
		#local variable air_interface
		air_interface = test.findtext('air_interface')		
		if (air_interface is None) or (air_interface.lower() not in ['nr','lte','ocp']):
			CiTestObj.air_interface = 'lte-uesoftmodem'
		elif (air_interface.lower() in ['nr','lte']):
			CiTestObj.air_interface = air_interface.lower() +'-uesoftmodem'
		else :
			#CiTestObj.air_interface = 'ocp-enb'
			logging.error('OCP UE -- NOT SUPPORTED')
Boris Djalal's avatar
Boris Djalal committed
287

288
	elif (action == 'Ping') or (action == 'Ping_CatM_module'):
289
290
		CiTestObj.ping_args = test.findtext('ping_args')
		CiTestObj.ping_packetloss_threshold = test.findtext('ping_packetloss_threshold')
291
292
293
294
295
		ue_id = test.findtext('id')
		if (ue_id is None):
			CiTestObj.ue_id = ""
		else:
			CiTestObj.ue_id = ue_id
296

297
	elif action == 'Iperf':
298
		CiTestObj.iperf_args = test.findtext('iperf_args')
299
300
301
302
303
304
		ue_id = test.findtext('id')
		if (ue_id is None):
			CiTestObj.ue_id = ""
		else:
			CiTestObj.ue_id = ue_id
		CiTestObj.iperf_direction = test.findtext('direction')#used for modules only	
305
306
307
308
		CiTestObj.iperf_packetloss_threshold = test.findtext('iperf_packetloss_threshold')
		CiTestObj.iperf_profile = test.findtext('iperf_profile')
		if (CiTestObj.iperf_profile is None):
			CiTestObj.iperf_profile = 'balanced'
309
		else:
310
311
312
			if CiTestObj.iperf_profile != 'balanced' and CiTestObj.iperf_profile != 'unbalanced' and CiTestObj.iperf_profile != 'single-ue':
				logging.debug('ERROR: test-case has wrong profile ' + CiTestObj.iperf_profile)
				CiTestObj.iperf_profile = 'balanced'
313
314
315
		CiTestObj.iperf_options = test.findtext('iperf_options')
		if (CiTestObj.iperf_options is None):
			CiTestObj.iperf_options = 'check'
316
		else:
317
318
319
			if CiTestObj.iperf_options != 'check' and CiTestObj.iperf_options != 'sink':
				logging.debug('ERROR: test-case has wrong option ' + CiTestObj.iperf_options)
				CiTestObj.iperf_options = 'check'
320

321
	elif action == 'IdleSleep':
322
323
		string_field = test.findtext('idle_sleep_time_in_sec')
		if (string_field is None):
324
			CiTestObj.idle_sleep_time = 5
325
		else:
326
			CiTestObj.idle_sleep_time = int(string_field)
327

328
	elif action == 'Perform_X2_Handover':
329
330
		string_field = test.findtext('x2_ho_options')
		if (string_field is None):
331
			CiTestObj.x2_ho_options = 'network'
332
333
334
		else:
			if string_field != 'network':
				logging.error('ERROR: test-case has wrong option ' + string_field)
335
				CiTestObj.x2_ho_options = 'network'
336
			else:
337
				CiTestObj.x2_ho_options = string_field
338

339
	elif action == 'Build_PhySim':
340
		ldpc.buildargs  = test.findtext('physim_build_args')
Remi Hardy's avatar
Remi Hardy committed
341
342
343
344
345
346
347
348
		forced_workspace_cleanup = test.findtext('forced_workspace_cleanup')
		if (forced_workspace_cleanup is None):
			ldpc.forced_workspace_cleanup=False
		else:
			if re.match('true', forced_workspace_cleanup, re.IGNORECASE):
				ldpc.forced_workspace_cleanup=True
			else:
				ldpc.forced_workspace_cleanup=False
349

Raphael Defosseux's avatar
Raphael Defosseux committed
350
351
352
353
354
	elif action == 'Initialize_MME':
		string_field = test.findtext('option')
		if (string_field is not None):
			EPC.mmeConfFile = string_field

355
356
357
358
359
	elif action == 'Deploy_EPC':
		string_field = test.findtext('parameters')
		if (string_field is not None):
			EPC.yamlPath = string_field

360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
	elif action == 'Deploy_Object' or action == 'Undeploy_Object':
		eNB_instance=test.findtext('eNB_instance')
		if (eNB_instance is None):
			CONTAINERS.eNB_instance=0
		else:
			CONTAINERS.eNB_instance=int(eNB_instance)
		eNB_serverId=test.findtext('eNB_serverId')
		if (eNB_serverId is None):
			CONTAINERS.eNB_serverId[CONTAINERS.eNB_instance]='0'
		else:
			CONTAINERS.eNB_serverId[CONTAINERS.eNB_instance]=eNB_serverId
		string_field = test.findtext('yaml_path')
		if (string_field is not None):
			CONTAINERS.yamlPath[CONTAINERS.eNB_instance] = string_field


376
	else: # ie action == 'Run_PhySim':
377
		ldpc.runargs = test.findtext('physim_run_args')
hardy's avatar
hardy committed
378
		
379

380
381
382
383
384
385
386
387
388
389
390
391
#check if given test is in list
#it is in list if one of the strings in 'list' is at the beginning of 'test'
def test_in_list(test, list):
	for check in list:
		check=check.replace('+','')
		if (test.startswith(check)):
			return True
	return False

def receive_signal(signum, frame):
	sys.exit(1)

392
393
394
395
396





397
#-----------------------------------------------------------
398
# MAIN PART
399
#-----------------------------------------------------------
400
401
402

#loading xml action list from yaml
import yaml
403
xml_class_list_file='xml_class_list.yml'
hardy's avatar
hardy committed
404
if (os.path.isfile(xml_class_list_file)):
405
406
407
	yaml_file=xml_class_list_file
elif (os.path.isfile('ci-scripts/'+xml_class_list_file)):
	yaml_file='ci-scripts/'+xml_class_list_file
408
409
410
else:
	logging.error("XML action list yaml file cannot be found")
	sys.exit("XML action list yaml file cannot be found")
Remi Hardy's avatar
Remi Hardy committed
411

412
413
414
415
416
with open(yaml_file,'r') as f:
    # The FullLoader parameter handles the conversion-$
    #from YAML scalar values to Python dictionary format$
    xml_class_list = yaml.load(f,Loader=yaml.FullLoader)

hardy's avatar
hardy committed
417

hardy's avatar
hardy committed
418
419
420
421
422
423
424
425
426
427

#loading UE infrastructure from yaml
ue_infra_file='ci_ueinfra.yaml'
if (os.path.isfile(ue_infra_file)):
	yaml_file=ue_infra_file
elif (os.path.isfile('ci-scripts/'+ue_infra_file)):
	yaml_file='ci-scripts/'+ue_infra_file
else:
	logging.error("UE infrastructure yaml file cannot be found")
	sys.exit("UE infrastructure file cannot be found")
428
InfraUE=cls_ci_ueinfra.InfraUE() #initialize UE infrastructure class
hardy's avatar
hardy committed
429
InfraUE.Get_UE_Infra(yaml_file) #read the UE infra, filename is hardcoded and unique for the moment but should be passed as parameter from the test suite
430
431


432

433
mode = ''
434

435
CiTestObj = cls_oaicitest.OaiCiTest()
436
437
438
439
440
 
SSH = sshconnection.SSHConnection()
EPC = epc.EPCManagement()
RAN = ran.RANManagement()
HTML = html.HTMLManagement()
441
CONTAINERS = cls_containerize.Containerize()
442
SCA = cls_static_code_analysis.StaticCodeAnalysis()
Mohammed Ismail's avatar
Mohammed Ismail committed
443
PHYSIM = cls_physim1.PhySim()
444

445
446
ldpc=cls_physim.PhySim()    #create an instance for LDPC test using GPU or CPU build

hardy's avatar
hardy committed
447

448
#-----------------------------------------------------------
449
# Parsing Command Line Arguments
450
451
#-----------------------------------------------------------

452
import args_parse
Mohammed Ismail's avatar
Mohammed Ismail committed
453
py_param_file_present, py_params, mode = args_parse.ArgsParse(sys.argv,CiTestObj,RAN,HTML,EPC,ldpc,CONTAINERS,HELP,SCA,PHYSIM)
454

455

Remi Hardy's avatar
Remi Hardy committed
456

457
#-----------------------------------------------------------
458
# TEMPORARY params management (UNUSED)
459
460
461
#-----------------------------------------------------------
#temporary solution for testing:
if py_param_file_present == True:
462
463
	AssignParams(py_params)

464

465
466
467
#-----------------------------------------------------------
# COTS UE instanciation
#-----------------------------------------------------------
468
469
470
#COTS_UE instanciation and ADB server init
#ue id and ue mode are retrieved from xml
COTS_UE=cls_cots_ue.CotsUe(CiTestObj.ADBIPAddress, CiTestObj.ADBUserName,CiTestObj.ADBPassword)
Remi Hardy's avatar
Remi Hardy committed
471
472


473
#-----------------------------------------------------------
474
# mode amd XML class (action) analysis
475
#-----------------------------------------------------------
476
cwd = os.getcwd()
Remi Hardy's avatar
Remi Hardy committed
477

478
if re.match('^TerminateeNB$', mode, re.IGNORECASE):
hardy's avatar
hardy committed
479
	if RAN.eNBIPAddress == '' or RAN.eNBUserName == '' or RAN.eNBPassword == '':
480
		HELP.GenericHelp(CONST.Version)
481
		sys.exit('Insufficient Parameter')
Raphael Defosseux's avatar
Raphael Defosseux committed
482
	RAN.eNB_instance=0
483
	RAN.eNB_serverId[0]='0'
hardy's avatar
hardy committed
484
	RAN.eNBSourceCodePath='/tmp/'
485
	RAN.TerminateeNB(HTML, EPC)
486
elif re.match('^TerminateUE$', mode, re.IGNORECASE):
487
	if (CiTestObj.ADBIPAddress == '' or CiTestObj.ADBUserName == '' or CiTestObj.ADBPassword == ''):
488
		HELP.GenericHelp(CONST.Version)
489
490
		sys.exit('Insufficient Parameter')
	signal.signal(signal.SIGUSR1, receive_signal)
491
	CiTestObj.TerminateUE(HTML,COTS_UE,InfraUE,CiTestObj.ue_trace)
Boris Djalal's avatar
Boris Djalal committed
492
elif re.match('^TerminateOAIUE$', mode, re.IGNORECASE):
493
	if CiTestObj.UEIPAddress == '' or CiTestObj.UEUserName == '' or CiTestObj.UEPassword == '':
494
		HELP.GenericHelp(CONST.Version)
Boris Djalal's avatar
Boris Djalal committed
495
496
		sys.exit('Insufficient Parameter')
	signal.signal(signal.SIGUSR1, receive_signal)
497
	CiTestObj.TerminateOAIUE(HTML,RAN,COTS_UE,EPC,InfraUE)
498
elif re.match('^TerminateHSS$', mode, re.IGNORECASE):
499
	if EPC.IPAddress == '' or EPC.UserName == '' or EPC.Password == '' or EPC.Type == '' or EPC.SourceCodePath == '':
500
		HELP.GenericHelp(CONST.Version)
501
		sys.exit('Insufficient Parameter')
502
	EPC.TerminateHSS(HTML)
503
elif re.match('^TerminateMME$', mode, re.IGNORECASE):
504
	if EPC.IPAddress == '' or EPC.UserName == '' or EPC.Password == '' or EPC.Type == '' or EPC.SourceCodePath == '':
505
		HELP.GenericHelp(CONST.Version)
506
		sys.exit('Insufficient Parameter')
507
	EPC.TerminateMME(HTML)
508
elif re.match('^TerminateSPGW$', mode, re.IGNORECASE):
509
	if EPC.IPAddress == '' or EPC.UserName == '' or EPC.Password == '' or EPC.Type == '' or EPC.SourceCodePath== '':
510
		HELP.GenericHelp(CONST.Version)
511
		sys.exit('Insufficient Parameter')
512
	EPC.TerminateSPGW(HTML)
513
elif re.match('^LogCollectBuild$', mode, re.IGNORECASE):
hardy's avatar
hardy committed
514
	if (RAN.eNBIPAddress == '' or RAN.eNBUserName == '' or RAN.eNBPassword == '' or RAN.eNBSourceCodePath == '') and (CiTestObj.UEIPAddress == '' or CiTestObj.UEUserName == '' or CiTestObj.UEPassword == '' or CiTestObj.UESourceCodePath == ''):
515
		HELP.GenericHelp(CONST.Version)
516
		sys.exit('Insufficient Parameter')
517
	CiTestObj.LogCollectBuild(RAN)
518
elif re.match('^LogCollecteNB$', mode, re.IGNORECASE):
hardy's avatar
hardy committed
519
	if RAN.eNBIPAddress == '' or RAN.eNBUserName == '' or RAN.eNBPassword == '' or RAN.eNBSourceCodePath == '':
520
		HELP.GenericHelp(CONST.Version)
521
		sys.exit('Insufficient Parameter')
Raphael Defosseux's avatar
Raphael Defosseux committed
522
	RAN.LogCollecteNB()
523
elif re.match('^LogCollectHSS$', mode, re.IGNORECASE):
524
	if EPC.IPAddress == '' or EPC.UserName == '' or EPC.Password == '' or EPC.Type == '' or EPC.SourceCodePath == '':
525
		HELP.GenericHelp(CONST.Version)
526
		sys.exit('Insufficient Parameter')
527
	EPC.LogCollectHSS()
528
elif re.match('^LogCollectMME$', mode, re.IGNORECASE):
529
	if EPC.IPAddress == '' or EPC.UserName == '' or EPC.Password == '' or EPC.Type == '' or EPC.SourceCodePath == '':
530
		HELP.GenericHelp(CONST.Version)
531
		sys.exit('Insufficient Parameter')
532
	EPC.LogCollectMME()
533
elif re.match('^LogCollectSPGW$', mode, re.IGNORECASE):
534
	if EPC.IPAddress == '' or EPC.UserName == '' or EPC.Password == '' or EPC.Type == '' or EPC.SourceCodePath == '':
535
		HELP.GenericHelp(CONST.Version)
536
		sys.exit('Insufficient Parameter')
537
	EPC.LogCollectSPGW()
538
elif re.match('^LogCollectPing$', mode, re.IGNORECASE):
539
	if EPC.IPAddress == '' or EPC.UserName == '' or EPC.Password == '' or EPC.SourceCodePath == '':
540
		HELP.GenericHelp(CONST.Version)
541
		sys.exit('Insufficient Parameter')
542
	CiTestObj.LogCollectPing(EPC)
543
elif re.match('^LogCollectIperf$', mode, re.IGNORECASE):
544
	if EPC.IPAddress == '' or EPC.UserName == '' or EPC.Password == '' or EPC.SourceCodePath == '':
545
		HELP.GenericHelp(CONST.Version)
546
		sys.exit('Insufficient Parameter')
547
	CiTestObj.LogCollectIperf(EPC)
Boris Djalal's avatar
Boris Djalal committed
548
elif re.match('^LogCollectOAIUE$', mode, re.IGNORECASE):
549
	if CiTestObj.UEIPAddress == '' or CiTestObj.UEUserName == '' or CiTestObj.UEPassword == '' or CiTestObj.UESourceCodePath == '':
550
		HELP.GenericHelp(CONST.Version)
551
		sys.exit('Insufficient Parameter')
552
	CiTestObj.LogCollectOAIUE()
553
elif re.match('^InitiateHtml$', mode, re.IGNORECASE):
554
	if (CiTestObj.ADBIPAddress == '' or CiTestObj.ADBUserName == '' or CiTestObj.ADBPassword == ''):
555
		HELP.GenericHelp(CONST.Version)
556
557
		sys.exit('Insufficient Parameter')
	count = 0
558
	foundCount = 0
559
	while (count < HTML.nbTestXMLfiles):
560
		#xml_test_file = cwd + "/" + CiTestObj.testXMLfiles[count]
561
		xml_test_file = sys.path[0] + "/" + CiTestObj.testXMLfiles[count]
562
		if (os.path.isfile(xml_test_file)):
563
564
565
566
			try:
				xmlTree = ET.parse(xml_test_file)
			except:
				print("Error while parsing file: " + xml_test_file)
567
			xmlRoot = xmlTree.getroot()
568
569
570
			HTML.htmlTabRefs.append(xmlRoot.findtext('htmlTabRef',default='test-tab-' + str(count)))
			HTML.htmlTabNames.append(xmlRoot.findtext('htmlTabName',default='test-tab-' + str(count)))
			HTML.htmlTabIcons.append(xmlRoot.findtext('htmlTabIcon',default='info-sign'))
571
			foundCount += 1
572
		count += 1
573
574
	if foundCount != HTML.nbTestXMLfiles:
		HTML.nbTestXMLfiles=foundCount
575
576
577
578
579
580
	
	if (CiTestObj.ADBIPAddress != 'none'):
		terminate_ue_flag = False
		CiTestObj.GetAllUEDevices(terminate_ue_flag)
		CiTestObj.GetAllCatMDevices(terminate_ue_flag)
		HTML.SethtmlUEConnected(len(CiTestObj.UEDevices) + len(CiTestObj.CatMDevices))
581
582
		HTML.htmlNb_Smartphones=len(CiTestObj.UEDevices)
		HTML.htmlNb_CATM_Modules=len(CiTestObj.CatMDevices)
583
	HTML.CreateHtmlHeader(CiTestObj.ADBIPAddress)
584
elif re.match('^FinalizeHtml$', mode, re.IGNORECASE):
585
586
587
588
	logging.debug('\u001B[1m----------------------------------------\u001B[0m')
	logging.debug('\u001B[1m  Creating HTML footer \u001B[0m')
	logging.debug('\u001B[1m----------------------------------------\u001B[0m')

589
590
	CiTestObj.RetrieveSystemVersion('eNB',HTML,RAN)
	CiTestObj.RetrieveSystemVersion('UE',HTML,RAN)
591
	HTML.CreateHtmlFooter(CiTestObj.finalStatus)
592
elif re.match('^TesteNB$', mode, re.IGNORECASE) or re.match('^TestUE$', mode, re.IGNORECASE):
593
	logging.debug('\u001B[1m----------------------------------------\u001B[0m')
594
	logging.debug('\u001B[1m  Starting Scenario: ' + CiTestObj.testXMLfiles[0] + '\u001B[0m')
595
	logging.debug('\u001B[1m----------------------------------------\u001B[0m')
596
	if re.match('^TesteNB$', mode, re.IGNORECASE):
hardy's avatar
hardy committed
597
		if RAN.eNBIPAddress == '' or RAN.ranRepository == '' or RAN.ranBranch == '' or RAN.eNBUserName == '' or RAN.eNBPassword == '' or RAN.eNBSourceCodePath == '' or EPC.IPAddress == '' or EPC.UserName == '' or EPC.Password == '' or EPC.Type == '' or EPC.SourceCodePath == '' or CiTestObj.ADBIPAddress == '' or CiTestObj.ADBUserName == '' or CiTestObj.ADBPassword == '':
598
			HELP.GenericHelp(CONST.Version)
599
600
			if EPC.IPAddress == '' or EPC.UserName == '' or EPC.Password == '' or EPC.SourceCodePath == '' or EPC.Type == '':
				HELP.EPCSrvHelp(EPC.IPAddress, EPC.UserName, EPC.Password, EPC.SourceCodePath, EPC.Type)
hardy's avatar
hardy committed
601
602
603
604
			if RAN.ranRepository == '':
				HELP.GitSrvHelp(RAN.ranRepository, RAN.ranBranch, RAN.ranCommitID, RAN.ranAllowMerge, RAN.ranTargetBranch)
			if RAN.eNBIPAddress == ''  or RAN.eNBUserName == '' or RAN.eNBPassword == '' or RAN.eNBSourceCodePath == '':
				HELP.eNBSrvHelp(RAN.eNBIPAddress, RAN.eNBUserName, RAN.eNBPassword, RAN.eNBSourceCodePath)
605
606
			sys.exit('Insufficient Parameter')

607
608
609
		if (EPC.IPAddress!= '') and (EPC.IPAddress != 'none'):
			SSH.copyout(EPC.IPAddress, EPC.UserName, EPC.Password, cwd + "/tcp_iperf_stats.awk", "/tmp")
			SSH.copyout(EPC.IPAddress, EPC.UserName, EPC.Password, cwd + "/active_net_interfaces.awk", "/tmp")
610
	else:
611
612
		if CiTestObj.UEIPAddress == '' or CiTestObj.ranRepository == '' or CiTestObj.ranBranch == '' or CiTestObj.UEUserName == '' or CiTestObj.UEPassword == '' or CiTestObj.UESourceCodePath == '':
			HELP.GenericHelp(CONST.Version)
613
			sys.exit('UE: Insufficient Parameter')
614

615
	#read test_case_list.xml file
616
	# if no parameters for XML file, use default value
617
	if (HTML.nbTestXMLfiles != 1):
618
		xml_test_file = cwd + "/test_case_list.xml"
619
	else:
620
		xml_test_file = cwd + "/" + CiTestObj.testXMLfiles[0]
621
622
623
624
625
626

	xmlTree = ET.parse(xml_test_file)
	xmlRoot = xmlTree.getroot()

	exclusion_tests=xmlRoot.findtext('TestCaseExclusionList',default='')
	requested_tests=xmlRoot.findtext('TestCaseRequestedList',default='')
627
628
629
	if (HTML.nbTestXMLfiles == 1):
		HTML.htmlTabRefs.append(xmlRoot.findtext('htmlTabRef',default='test-tab-0'))
		HTML.htmlTabNames.append(xmlRoot.findtext('htmlTabName',default='Test-0'))
630
		repeatCount = xmlRoot.findtext('repeatCount',default='1')
631
		testStability = xmlRoot.findtext('TestUnstable',default='False')
632
		CiTestObj.repeatCounts.append(int(repeatCount))
633
634
635
636
637
638
		if testStability == 'True':
			CiTestObj.testUnstable = True
			HTML.testUnstable = True
			CiTestObj.testMinStableId = xmlRoot.findtext('TestMinId',default='999999')
			HTML.testMinStableId = CiTestObj.testMinStableId
			logging.debug('Test is tagged as Unstable -- starting from TestID ' + str(CiTestObj.testMinStableId))
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
	all_tests=xmlRoot.findall('testCase')

	exclusion_tests=exclusion_tests.split()
	requested_tests=requested_tests.split()

	#check that exclusion tests are well formatted
	#(6 digits or less than 6 digits followed by +)
	for test in exclusion_tests:
		if     (not re.match('^[0-9]{6}$', test) and
				not re.match('^[0-9]{1,5}\+$', test)):
			logging.debug('ERROR: exclusion test is invalidly formatted: ' + test)
			sys.exit(1)
		else:
			logging.debug(test)

	#check that requested tests are well formatted
	#(6 digits or less than 6 digits followed by +)
	#be verbose
	for test in requested_tests:
		if     (re.match('^[0-9]{6}$', test) or
				re.match('^[0-9]{1,5}\+$', test)):
			logging.debug('INFO: test group/case requested: ' + test)
		else:
			logging.debug('ERROR: requested test is invalidly formatted: ' + test)
			sys.exit(1)
664
	if (EPC.IPAddress != '') and (EPC.IPAddress != 'none'):
665
		CiTestObj.CheckFlexranCtrlInstallation(RAN,EPC,CONTAINERS)
666
		EPC.SetMmeIPAddress()
667
		EPC.SetAmfIPAddress()
668
669
670
671
672
673
674

	#get the list of tests to be done
	todo_tests=[]
	for test in requested_tests:
		if    (test_in_list(test, exclusion_tests)):
			logging.debug('INFO: test will be skipped: ' + test)
		else:
675
			#logging.debug('INFO: test will be run: ' + test)
676
			todo_tests.append(test)
677

678
	signal.signal(signal.SIGUSR1, receive_signal)
679

680
681
682
683
684
685
686
687
	if (CiTestObj.ADBIPAddress != 'none'):
		terminate_ue_flag = False
		CiTestObj.GetAllUEDevices(terminate_ue_flag)
		CiTestObj.GetAllCatMDevices(terminate_ue_flag)
	else:
		CiTestObj.UEDevices.append('OAI-UE')
	HTML.SethtmlUEConnected(len(CiTestObj.UEDevices) + len(CiTestObj.CatMDevices))
	HTML.CreateHtmlTabHeader()
688

689
	CiTestObj.FailReportCnt = 0
hardy's avatar
hardy committed
690
	RAN.prematureExit=True
691
	HTML.startTime=int(round(time.time() * 1000))
hardy's avatar
hardy committed
692
693
	while CiTestObj.FailReportCnt < CiTestObj.repeatCounts[0] and RAN.prematureExit:
		RAN.prematureExit=False
694
		# At every iteratin of the retry loop, a separator will be added
695
696
		# pass CiTestObj.FailReportCnt as parameter of HTML.CreateHtmlRetrySeparator
		HTML.CreateHtmlRetrySeparator(CiTestObj.FailReportCnt)
697
		for test_case_id in todo_tests:
hardy's avatar
hardy committed
698
			if RAN.prematureExit:
699
				break
700
			for test in all_tests:
hardy's avatar
hardy committed
701
				if RAN.prematureExit:
702
					break
703
704
705
				id = test.get('id')
				if test_case_id != id:
					continue
706
				CiTestObj.testCase_id = id
707
708
				HTML.testCase_id=CiTestObj.testCase_id
				EPC.testCase_id=CiTestObj.testCase_id
709
				CiTestObj.desc = test.findtext('desc')
710
				HTML.desc=CiTestObj.desc
711
				action = test.findtext('class')
712
				if (CheckClassValidity(xml_class_list, action, id) == False):
713
					continue
714
				CiTestObj.ShowTestID()
715
716
				GetParametersFromXML(action)
				if action == 'Initialize_UE' or action == 'Attach_UE' or action == 'Detach_UE' or action == 'Ping' or action == 'Iperf' or action == 'Reboot_UE' or action == 'DataDisable_UE' or action == 'DataEnable_UE' or action == 'CheckStatusUE':
717
					if (CiTestObj.ADBIPAddress != 'none'):
718
719
						#in these cases, having no devices is critical, GetAllUEDevices function has to manage it as a critical error, reason why terminate_ue_flag is set to True
						terminate_ue_flag = True 
720
721
722
723
724
						# Now we stop properly the test-suite --> clean reporting
						status = CiTestObj.GetAllUEDevices(terminate_ue_flag)
						if not status:
							RAN.prematureExit = True
							break
725
				if action == 'Build_eNB':
Raphael Defosseux's avatar
Raphael Defosseux committed
726
					RAN.BuildeNB(HTML)
727
				elif action == 'WaitEndBuild_eNB':
Raphael Defosseux's avatar
Raphael Defosseux committed
728
					RAN.WaitBuildeNBisFinished(HTML)
729
				elif action == 'Initialize_eNB':
730
731
					check_eNB = False
					check_OAI_UE = False
732
					RAN.pStatus=CiTestObj.CheckProcessExist(check_eNB, check_OAI_UE,RAN,EPC)
Raphael Defosseux's avatar
Raphael Defosseux committed
733
					RAN.InitializeeNB(HTML, EPC)
734
				elif action == 'Terminate_eNB':
Raphael Defosseux's avatar
Raphael Defosseux committed
735
					RAN.TerminateeNB(HTML, EPC)
736
				elif action == 'Initialize_UE':
Remi Hardy's avatar
Remi Hardy committed
737
					CiTestObj.InitializeUE(HTML,RAN, EPC, COTS_UE, InfraUE, CiTestObj.ue_trace)
738
				elif action == 'Terminate_UE':
Remi Hardy's avatar
Remi Hardy committed
739
					CiTestObj.TerminateUE(HTML,COTS_UE, InfraUE, CiTestObj.ue_trace)
740
				elif action == 'Attach_UE':
741
					CiTestObj.AttachUE(HTML,RAN,EPC,COTS_UE,InfraUE)
742
				elif action == 'Detach_UE':
743
					CiTestObj.DetachUE(HTML,RAN,EPC,COTS_UE,InfraUE)
744
				elif action == 'DataDisable_UE':
745
					CiTestObj.DataDisableUE(HTML)
746
				elif action == 'DataEnable_UE':
747
					CiTestObj.DataEnableUE(HTML)
748
				elif action == 'CheckStatusUE':
749
					CiTestObj.CheckStatusUE(HTML,RAN,EPC,COTS_UE,InfraUE)
750
				elif action == 'Build_OAI_UE':
751
					CiTestObj.BuildOAIUE(HTML)
752
				elif action == 'Initialize_OAI_UE':
753
					CiTestObj.InitializeOAIUE(HTML,RAN,EPC,COTS_UE,InfraUE)
754
				elif action == 'Terminate_OAI_UE':
755
					CiTestObj.TerminateOAIUE(HTML,RAN,COTS_UE,EPC,InfraUE)
756
				elif action == 'Initialize_CatM_module':
757
					CiTestObj.InitializeCatM(HTML)
758
				elif action == 'Terminate_CatM_module':
759
					CiTestObj.TerminateCatM(HTML)
760
				elif action == 'Attach_CatM_module':
761
					CiTestObj.AttachCatM(HTML,RAN,COTS_UE,EPC,InfraUE)
762
				elif action == 'Detach_CatM_module':
763
					CiTestObj.TerminateCatM(HTML)
764
				elif action == 'Ping_CatM_module':
765
					CiTestObj.PingCatM(HTML,RAN,EPC,COTS_UE,EPC,InfraUE)
766
				elif action == 'Ping':
767
					CiTestObj.Ping(HTML,RAN,EPC,COTS_UE, InfraUE)
768
				elif action == 'Iperf':
769
					CiTestObj.Iperf(HTML,RAN,EPC,COTS_UE, InfraUE)
770
				elif action == 'Reboot_UE':
771
					CiTestObj.RebootUE(HTML,RAN,EPC)
772
				elif action == 'Initialize_HSS':
Raphael Defosseux's avatar
Raphael Defosseux committed
773
					EPC.InitializeHSS(HTML)
774
				elif action == 'Terminate_HSS':
Raphael Defosseux's avatar
Raphael Defosseux committed
775
					EPC.TerminateHSS(HTML)
776
				elif action == 'Initialize_MME':
Raphael Defosseux's avatar
Raphael Defosseux committed
777
					EPC.InitializeMME(HTML)
778
				elif action == 'Terminate_MME':
Raphael Defosseux's avatar
Raphael Defosseux committed
779
					EPC.TerminateMME(HTML)
780
				elif action == 'Initialize_SPGW':
Raphael Defosseux's avatar
Raphael Defosseux committed
781
					EPC.InitializeSPGW(HTML)
782
				elif action == 'Terminate_SPGW':
Raphael Defosseux's avatar
Raphael Defosseux committed
783
					EPC.TerminateSPGW(HTML)
784
785
786
787
				elif action == 'Initialize_5GCN':
					EPC.Initialize5GCN(HTML)
				elif action == 'Terminate_5GCN':
					EPC.Terminate5GCN(HTML)
788
				elif action == 'Deploy_EPC':
Raphael Defosseux's avatar
Raphael Defosseux committed
789
					EPC.DeployEpc(HTML)
790
				elif action == 'Undeploy_EPC':
Raphael Defosseux's avatar
Raphael Defosseux committed
791
					EPC.UndeployEpc(HTML)
792
				elif action == 'Initialize_FlexranCtrl':
793
					CiTestObj.InitializeFlexranCtrl(HTML,RAN,EPC)
794
				elif action == 'Terminate_FlexranCtrl':
795
					CiTestObj.TerminateFlexranCtrl(HTML,RAN,EPC)
796
				elif action == 'IdleSleep':
797
					CiTestObj.IdleSleep(HTML)
798
				elif action == 'Perform_X2_Handover':
799
					CiTestObj.Perform_X2_Handover(HTML,RAN