From 6b38334767088a954e9b680c4e5ce036cc742966 Mon Sep 17 00:00:00 2001 From: Raphael Defosseux <raphael.defosseux@eurecom.fr> Date: Thu, 5 Jul 2018 10:04:07 +0200 Subject: [PATCH] CI: integration of the "test with equipment" script -- temporary into a separate jenkins job -- parameters are not in the pipeline script file they have to be set up manually in the Jenkins GUI configuration page they are then check if present in pipeline script -- call to python script -- build on a server with RF HW capabilities for the moment USRP B2x0 also handles merge request process for gitlab -- since it is for CI, it is a clean build -- connect to an EPC (OAI or LTEBOX) -- terminates eNB / EPC -- log collection Signed-off-by: Raphael Defosseux <raphael.defosseux@eurecom.fr> --- ci-scripts/Jenkinsfile-tmp-ran | 204 ++++++++++ ci-scripts/fail.sh | 3 + ci-scripts/main.py | 697 +++++++++++++++++++++++++++++++++ ci-scripts/test_case_list.xml | 52 +++ 4 files changed, 956 insertions(+) create mode 100644 ci-scripts/Jenkinsfile-tmp-ran create mode 100755 ci-scripts/fail.sh create mode 100644 ci-scripts/main.py create mode 100644 ci-scripts/test_case_list.xml diff --git a/ci-scripts/Jenkinsfile-tmp-ran b/ci-scripts/Jenkinsfile-tmp-ran new file mode 100644 index 0000000000..8fa405a218 --- /dev/null +++ b/ci-scripts/Jenkinsfile-tmp-ran @@ -0,0 +1,204 @@ +// Comments + +pipeline { + // The node should be selected with a 'label' parameter + // trying to use NodeLabel plugin to pass it, currently failing to do so + agent { + label 'bellatrix' + } + options { + disableConcurrentBuilds() + timestamps() + // When performing commit status updates and merge requests comments + // the connection name SHALL be here. + // So please use the same connection name and use proper credentials + gitLabConnection('OAI GitLab') + } + // the following parameter options are commented out so it shows the ones + // that you SHALL have to run the job. + // You can use them as template + /* + parameters { + //eNB parameters + string(name: 'eNB_IPAddress', defaultValue: '192.168.XX.XX', description: 'IP Address of eNB') + credentials(name: 'eNB_Credentials', defaultValue: 'XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX', credentialType: "Username with password", required: true, description: 'Credentials for eNB') + string(name: 'eNB_SourceCodePath', defaultValue: '/home/starsky/CI-enb', description: 'Full path of eNB source code') + + //EPC parameters + string(name: 'EPC_IPAddress', defaultValue: '192.168.XX.XX', description: 'IP Address of EPC') + string(name: 'EPC_Type', defaultValue: 'OAI', description: 'EPC type: OAI or ltebox') + credentials(name: 'EPC_Credentials', defaultValue: 'XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX', credentialType: "Username with password", required: true, description: 'Credentials for EPC') + string(name: 'EPC_SourceCodePath', defaultValue: '/home/nano/CI_oai-cn/openair-cn', description: 'Full path of EPC source code') + + //ADB server parameters + string(name: 'ADB_IPAddress', defaultValue: '192.168.XX.XX', description: 'IP Address of ADB server') + credentials(name: 'ADB_Credentials', defaultValue: 'XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX', credentialType: "Username with password", required: true, description: 'Credentials for ADB') + } + */ + + stages { + stage ("Verify Parameters") { + steps { + script { + def allParametersPresent = true + if (params.CI_MASTER_NODE != null) { + echo "eNB CI parameter node : $params.CI_MASTER_NODE" + } else { + echo "eNB CI master node : $NODE_NAME" + } + + if (params.eNB_IPAddress == null) { + allParametersPresent = false + } + if (params.eNB_SourceCodePath == null) { + allParametersPresent = false + } + if (params.eNB_Credentials == null) { + allParametersPresent = false + } + + if (params.EPC_IPAddress == null) { + allParametersPresent = false + } + if (params.EPC_Type == null) { + allParametersPresent = false + } + if (params.EPC_SourceCodePath == null) { + allParametersPresent = false + } + if (params.EPC_Credentials == null) { + allParametersPresent = false + } + + if (params.ADB_IPAddress == null) { + allParametersPresent = false + } + if (params.ADB_Credentials == null) { + allParametersPresent = false + } + + if (allParametersPresent) { + echo "All parameters are present" + } else { + echo "Some parameters are missing" + sh "./ci-scripts/fail.sh" + } + } + } + } + stage ("Build on eNB server") { + steps { + script { + dir ('ci-scripts') { + try { + withCredentials([ + [$class: 'UsernamePasswordMultiBinding', credentialsId: "${params.eNB_Credentials}", usernameVariable: 'eNB_Username', passwordVariable: 'eNB_Password'], + [$class: 'UsernamePasswordMultiBinding', credentialsId: "${params.EPC_Credentials}", usernameVariable: 'EPC_Username', passwordVariable: 'EPC_Password'], + [$class: 'UsernamePasswordMultiBinding', credentialsId: "${params.ADB_Credentials}", usernameVariable: 'ADB_Username', passwordVariable: 'ADB_Password'] + ]) { + sh "python3 main.py --mode=TesteNB --eNBIPAddress=${params.eNB_IPAddress} --eNBRepository=${GIT_URL} --eNBBranch=${GIT_BRANCH} --eNBCommitID=${GIT_COMMIT} --eNBUserName=${eNB_Username} --eNBPassword=${eNB_Password} --eNBSourceCodePath=${params.eNB_SourceCodePath} --EPCIPAddress=${params.EPC_IPAddress} --EPCType=${params.EPC_Type} --EPCUserName=${EPC_Username} --EPCPassword=${EPC_Password} --EPCSourceCodePath=${params.EPC_SourceCodePath} --ADBIPAddress=${params.ADB_IPAddress} --ADBUserName=${ADB_Username} --ADBPassword=${ADB_Password}" + } + } catch (Exception e) { + //sh "./ci-scripts/fail.sh" + currentBuild.result = 'FAILURE' + } + } + } + } + } + stage('Log Collection') { + parallel { + stage('Log Collection (eNB)') { + steps { + script { + dir ('ci-scripts') { + withCredentials([ + [$class: 'UsernamePasswordMultiBinding', credentialsId: "${params.eNB_Credentials}", usernameVariable: 'eNB_Username', passwordVariable: 'eNB_Password'] + ]) { + sh "python3 main.py --mode=LogCollectBuild --eNBIPAddress=${params.eNB_IPAddress} --eNBUserName=${eNB_Username} --eNBPassword=${eNB_Password} --eNBSourceCodePath=${params.eNB_SourceCodePath}" + sh "python3 main.py --mode=LogCollecteNB --eNBIPAddress=${params.eNB_IPAddress} --eNBUserName=${eNB_Username} --eNBPassword=${eNB_Password} --eNBSourceCodePath=${params.eNB_SourceCodePath}" + sh "sshpass -p \'${eNB_Password}\' scp -o 'StrictHostKeyChecking no' -o 'ConnectTimeout 10' ${eNB_Username}@${params.eNB_IPAddress}:${eNB_SourceCodePath}/cmake_targets/build.log.zip ./build.log.${env.BUILD_ID}.zip || true" + sh "sshpass -p \'${eNB_Password}\' scp -o 'StrictHostKeyChecking no' -o 'ConnectTimeout 10' ${eNB_Username}@${params.eNB_IPAddress}:${eNB_SourceCodePath}/cmake_targets/enb.log.zip ./enb.log.${env.BUILD_ID}.zip || true" + // No need to remove since we are wiping out the folder on the eNB server during build + // sh "sshpass -p \'${eNB_Password}\' ssh -t -t -o 'StrictHostKeyChecking no' -o 'ConnectTimeout 10' ${eNB_Username}@${params.eNB_IPAddress} 'cd ${eNB_SourceCodePath}; cd cmake_targets; if [ -e build.log.zip ]; then rm build.log.zip; fi;'" + // sh "sshpass -p \'${eNB_Password}\' ssh -t -t -o 'StrictHostKeyChecking no' -o 'ConnectTimeout 10' ${eNB_Username}@${params.eNB_IPAddress} 'cd ${eNB_SourceCodePath}; cd cmake_targets; if [ -e enb.log.zip ]; then rm enb.log.zip; fi;'" + if(fileExists("build.log.${env.BUILD_ID}.zip")) { + archiveArtifacts "build.log.${env.BUILD_ID}.zip" + // Same thing here, no need to remove. + // SCM folder is wiped out at build start on node + // sh "rm build.log.${env.BUILD_ID}.zip" + } + if(fileExists("enb.log.${env.BUILD_ID}.zip")) { + archiveArtifacts "enb.log.${env.BUILD_ID}.zip" + // Same thing here, no need to remove. + // SCM folder is wiped out at build start on node + // sh "rm enb.log.${env.BUILD_ID}.zip" + } + } + } + } + } + } + stage('Log Collection (EPC)') { + steps { + script { + dir ('ci-scripts') { + withCredentials([ + [$class: 'UsernamePasswordMultiBinding', credentialsId: "${params.EPC_Credentials}", usernameVariable: 'EPC_Username', passwordVariable: 'EPC_Password'] + ]) { + sh "python3 main.py --mode=LogCollectSPGW --EPCIPAddress=${params.EPC_IPAddress} --EPCUserName=${EPC_Username} --EPCPassword=${EPC_Password} --EPCSourceCodePath=${params.EPC_SourceCodePath} --EPCType=${params.EPC_Type} " + sh "python3 main.py --mode=LogCollectMME --EPCIPAddress=${params.EPC_IPAddress} --EPCUserName=${EPC_Username} --EPCPassword=${EPC_Password} --EPCSourceCodePath=${params.EPC_SourceCodePath} --EPCType=${params.EPC_Type} " + sh "python3 main.py --mode=LogCollectHSS --EPCIPAddress=${params.EPC_IPAddress} --EPCUserName=${EPC_Username} --EPCPassword=${EPC_Password} --EPCSourceCodePath=${params.EPC_SourceCodePath} --EPCType=${params.EPC_Type} " + if ("OAI".equals(params.EPC_Type)) { + sh "sshpass -p \'${EPC_Password}\' scp -o 'StrictHostKeyChecking no' -o 'ConnectTimeout 10' ${EPC_Username}@${params.EPC_IPAddress}:${EPC_SourceCodePath}/scripts/spgw.log.zip ./spgw.log.${env.BUILD_ID}.zip || true" + sh "sshpass -p \'${EPC_Password}\' scp -o 'StrictHostKeyChecking no' -o 'ConnectTimeout 10' ${EPC_Username}@${params.EPC_IPAddress}:${EPC_SourceCodePath}/scripts/mme.log.zip ./mme.log.${env.BUILD_ID}.zip || true" + sh "sshpass -p \'${EPC_Password}\' scp -o 'StrictHostKeyChecking no' -o 'ConnectTimeout 10' ${EPC_Username}@${params.EPC_IPAddress}:${EPC_SourceCodePath}/scripts/hss.log.zip ./hss.log.${env.BUILD_ID}.zip || true" + sh "sshpass -p \'${EPC_Password}\' ssh -t -t -o 'StrictHostKeyChecking no' -o 'ConnectTimeout 10' ${EPC_Username}@${params.EPC_IPAddress} 'cd ${EPC_SourceCodePath}; cd scripts; if [ -e spgw.log.zip ]; then rm spgw.log.zip; fi;'" + sh "sshpass -p \'${EPC_Password}\' ssh -t -t -o 'StrictHostKeyChecking no' -o 'ConnectTimeout 10' ${EPC_Username}@${params.EPC_IPAddress} 'cd ${EPC_SourceCodePath}; cd scripts; if [ -e mme.log.zip ]; then rm mme.log.zip; fi;'" + sh "sshpass -p \'${EPC_Password}\' ssh -t -t -o 'StrictHostKeyChecking no' -o 'ConnectTimeout 10' ${EPC_Username}@${params.EPC_IPAddress} 'cd ${EPC_SourceCodePath}; cd scripts; if [ -e hss.log.zip ]; then rm hss.log.zip; fi;'" + } else { + sh "sshpass -p \'${EPC_Password}\' scp -o 'StrictHostKeyChecking no' -o 'ConnectTimeout 10' ${EPC_Username}@${params.EPC_IPAddress}:/home/${EPC_Username}/spgw.log.zip ./spgw.log.${env.BUILD_ID}.zip || true" + sh "sshpass -p \'${EPC_Password}\' scp -o 'StrictHostKeyChecking no' -o 'ConnectTimeout 10' ${EPC_Username}@${params.EPC_IPAddress}:/home/${EPC_Username}/mme.log.zip ./mme.log.${env.BUILD_ID}.zip || true" + sh "sshpass -p \'${EPC_Password}\' scp -o 'StrictHostKeyChecking no' -o 'ConnectTimeout 10' ${EPC_Username}@${params.EPC_IPAddress}:/home/${EPC_Username}/hss.log.zip ./hss.log.${env.BUILD_ID}.zip || true" + sh "sshpass -p \'${EPC_Password}\' ssh -t -t -o 'StrictHostKeyChecking no' -o 'ConnectTimeout 10' ${EPC_Username}@${params.EPC_IPAddress} 'cd /home/${EPC_Username}; if [ -e spgw.log.zip ]; then rm spgw.log.zip; fi;'" + sh "sshpass -p \'${EPC_Password}\' ssh -t -t -o 'StrictHostKeyChecking no' -o 'ConnectTimeout 10' ${EPC_Username}@${params.EPC_IPAddress} 'cd /home/${EPC_Username}; if [ -e mme.log.zip ]; then rm mme.log.zip; fi;'" + sh "sshpass -p \'${EPC_Password}\' ssh -t -t -o 'StrictHostKeyChecking no' -o 'ConnectTimeout 10' ${EPC_Username}@${params.EPC_IPAddress} 'cd /home/${EPC_Username}; if [ -e hss.log.zip ]; then rm hss.log.zip; fi;'" + } + if(fileExists("spgw.log.${env.BUILD_ID}.zip")) { + archiveArtifacts "spgw.log.${env.BUILD_ID}.zip" + sh "rm spgw.log.${env.BUILD_ID}.zip" + } + if(fileExists("mme.log.${env.BUILD_ID}.zip")) { + archiveArtifacts "mme.log.${env.BUILD_ID}.zip" + sh "rm mme.log.${env.BUILD_ID}.zip" + } + if(fileExists("hss.log.${env.BUILD_ID}.zip")) { + archiveArtifacts "hss.log.${env.BUILD_ID}.zip" + sh "rm hss.log.${env.BUILD_ID}.zip" + } + } + } + } + } + } + } + } + } + + post { + always { + echo "Archiving Jenkins console log" + // Not working in Eurecom environment + /* + sh "wget --no-check-certificate --no-proxy ${env.JENKINS_URL}/job/${env.JOB_NAME}/${env.BUILD_ID}/consoleText -O consoleText.log || true" + sh "zip -m consoleText.log.${env.BUILD_ID}.zip consoleText.log || true" + script { + if(fileExists("consoleText.log.${env.BUILD_ID}.zip")) { + archiveArtifacts "consoleText.log.${env.BUILD_ID}.zip" + sh "rm consoleText.log.${env.BUILD_ID}.zip" + } + } + */ + } + } +} diff --git a/ci-scripts/fail.sh b/ci-scripts/fail.sh new file mode 100755 index 0000000000..978b63c7c7 --- /dev/null +++ b/ci-scripts/fail.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +exit -1 diff --git a/ci-scripts/main.py b/ci-scripts/main.py new file mode 100644 index 0000000000..37eeefbce8 --- /dev/null +++ b/ci-scripts/main.py @@ -0,0 +1,697 @@ +#--------------------------------------------------------------------- +# Python for CI of OAI-eNB + COTS-UE +# +# Required Python Version +# Python 3.x +# +# Required Python Package +# pexpect +#--------------------------------------------------------------------- + +#----------------------------------------------------------- +# Version +#----------------------------------------------------------- +Version = '0.1' + +#----------------------------------------------------------- +# Import +#----------------------------------------------------------- +import sys # arg +import re # reg +import pexpect # pexpect +import time # sleep +import os +import xml.etree.ElementTree as ET +import logging +import datetime +import signal +from multiprocessing import Process,Lock +logging.basicConfig( + level=logging.DEBUG, + format="[%(asctime)s] %(name)s:%(levelname)s: %(message)s" +) + +#----------------------------------------------------------- +# Class Declaration +#----------------------------------------------------------- +class SSHConnection(): + def __init__(self): + self.eNBIPAddress = '' + self.eNBRepository = '' + self.eNBBranch = '' + self.eNBCommitID = '' + self.eNBUserName = '' + self.eNBPassword = '' + self.eNBSourceCodePath = '' + self.EPCIPAddress = '' + self.EPCUserName = '' + self.EPCPassword = '' + self.EPCSourceCodePath = '' + self.EPCType = '' + self.ADBIPAddress = '' + self.ADBUserName = '' + self.ADBPassword = '' + self.testCase_id = '' + self.desc = '' + self.Build_eNB_args = '' + self.Initialize_eNB_args = '' + self.ping_args = '' + self.ping_packetloss_threshold = '' + self.iperf_args = '' + self.iperf_packetloss_threshold = '' + self.UEDevices = [] + self.UEIPAddresses = [] + def open(self, ipaddress, username, password): + self.ssh = pexpect.spawn('ssh', [username + '@' + ipaddress], timeout = 10) + self.ssh.delaybeforesend = None + self.sshresponse = self.ssh.expect(['Are you sure you want to continue connecting (yes/no)?', 'password:', pexpect.TIMEOUT, pexpect.EOF]) + if self.sshresponse == 0: + self.ssh.sendline('yes') + self.ssh.expect('password:') + self.ssh.sendline(password) + self.sshresponse = self.ssh.expect(['\$', 'Permission denied', 'password:', pexpect.EOF, pexpect.TIMEOUT]) + if self.sshresponse == 0: + pass + else: + logging.debug('self.sshresponse = ' + str(self.sshresponse)) + sys.exit('SSH Connection Failed') + elif self.sshresponse == 1: + self.ssh.sendline(password) + self.sshresponse = self.ssh.expect(['\$', 'Permission denied', 'password:', pexpect.EOF, pexpect.TIMEOUT]) + if self.sshresponse == 0: + pass + else: + logging.debug('self.sshresponse = ' + str(self.sshresponse)) + sys.exit('SSH Connection Failed') + elif self.sshresponse == 2: + pass + logging.debug('Connected to server') + else: + logging.debug('self.sshresponse = ' + str(self.sshresponse)) + sys.exit('SSH Connection Failed!!!') + def command(self, commandline, expectedline, timeout): + logging.debug(commandline) + self.ssh.timeout = timeout + self.ssh.sendline(commandline) + self.sshresponse = self.ssh.expect([expectedline, pexpect.EOF, pexpect.TIMEOUT]) + if self.sshresponse == 0: + pass + elif self.sshresponse == 1: + logging.debug('\u001B[1;37;41m Unexpected EOF \u001B[0m') + logging.debug('Expected Line : ' + expectedline) + sys.exit(self.sshresponse) + elif self.sshresponse == 2: + logging.debug('\u001B[1;37;41m Unexpected TIMEOUT \u001B[0m') + logging.debug('Expected Line : ' + expectedline) + sys.exit(self.sshresponse) + else: + logging.debug('\u001B[1;37;41m Unexpected Others \u001B[0m') + logging.debug('Expected Line : ' + expectedline) + sys.exit(self.sshresponse) + def close(self): + self.ssh.timeout = 5 + self.ssh.sendline('exit') + self.sshresponse = self.ssh.expect([pexpect.EOF, pexpect.TIMEOUT]) + if self.sshresponse == 0: + pass + elif self.sshresponse == 1: + logging.debug('\u001B[1;37;41m Unexpected TIMEOUT \u001B[0m') + else: + logging.debug('\u001B[1;37;41m Unexpected Others \u001B[0m') + + def BuildeNB(self): + if self.eNBIPAddress == '' or self.eNBRepository == '' or self.eNBBranch == '' or self.eNBUserName == '' or self.eNBPassword == '' or self.eNBSourceCodePath == '': + Usage() + sys.exit('Insufficient Parameter') + self.open(self.eNBIPAddress, self.eNBUserName, self.eNBPassword) + # We are in the context of CI. We are starting from a clean slate + # So we are removing the whole CI folder and starting from scratch + # Also we are not necessary always on the same branch. The path might differ + self.command('if [ -d ' + self.eNBSourceCodePath +' ]; rm -Rf ' + self.eNBSourceCodePath + '; fi', '\$', 5) + self.command('mkdir -p ' + self.eNBSourceCodePath, '\$', 5) + self.command('cd ' + self.eNBSourceCodePath, '\$', 5) + self.command('git clone -b ' + self.eNBBranch + ' ' + self.eNBRepository + ' .', '\$', 600) + self.command('git config user.email "jenkins@openairinterface.org"', '\$', 5) + self.command('git config user.name "OAI Jenkins"', '\$', 5) + # if the commit ID is provided use it to point to it + if self.eNBCommitID != '': + self.command('git checkout -f ' + self.eNBCommitID, '\$', 5) + # if the branch is not develop, then it is a merge request and we need to do + # the potential merge. Note that merge conflicts should already been checked earlier + if self.eNBBranch != 'develop': + self.command('git merge --ff origin/develop', '\$', 5) + self.command('source oaienv', '\$', 5) + self.command('cd cmake_targets', '\$', 5) + self.command('mkdir -p log', '\$', 5) + self.command('cd log', '\$', 5) + self.command('echo ' + self.eNBPassword + ' | sudo -S rm -f *', '\$', 5) + self.command('cd ..', '\$', 5) + self.command('echo ' + self.eNBPassword + ' | sudo -S stdbuf -o0 ./build_oai ' + self.Build_eNB_args + ' 2>&1 | stdbuf -o0 tee -a compile_oai_enb.log', 'Bypassing the Tests', 600) + self.command('mkdir -p build_log_' + SSH.testCase_id, '\$', 5) + self.command('echo ' + self.eNBPassword + ' | sudo -S mv log/* ' + 'build_log_' + SSH.testCase_id, '\$', 5) + self.command('echo ' + self.eNBPassword + ' | sudo -S mv compile_oai_enb.log ' + 'build_log_' + SSH.testCase_id, '\$', 5) + self.close() + + def InitializeHSS(self): + if self.EPCIPAddress == '' or self.EPCUserName == '' or self.EPCPassword == '' or self.EPCSourceCodePath == '' or self.EPCType == '': + Usage() + sys.exit('Insufficient Parameter') + self.open(self.EPCIPAddress, self.EPCUserName, self.EPCPassword) + self.command('cd ' + self.EPCSourceCodePath, '\$', 5) + if re.match('OAI', self.EPCType, re.IGNORECASE): + logging.debug('Using the OAI EPC HSS') + self.command('source oaienv', '\$', 5) + self.command('cd scripts', '\$', 5) + self.command('echo ' + self.EPCPassword + ' | sudo -S ./run_hss 2>&1 | stdbuf -o0 tee -a hss_' + SSH.testCase_id + '.log &', 'Core state: 2 -> 3', 35) +# self.command('echo ' + self.EPCPassword + ' | sudo -S ./run_hss 2>&1 | stdbuf -o0 awk \'{ print strftime("[%Y/%m/%d %H:%M:%S] ",systime()) $0 }\' | stdbuf -o0 tee -a hss_' + SSH.testCase_id + '.log &', 'Initializing s6a layer: DONE', 35) + else: + logging.debug('Using the ltebox simulated HSS') + self.command('cd hss_sim0609', '\$', 5) + self.command('echo ' + self.EPCPassword + ' | sudo -S echo "Starting sudo session" && sudo daemon --unsafe --name=simulated_hss --chdir=/opt/hss_sim0609 ./starthss_real ', '\$', 5) + self.close() + + def InitializeMME(self): + if self.EPCIPAddress == '' or self.EPCUserName == '' or self.EPCPassword == '' or self.EPCSourceCodePath == '' or self.EPCType == '': + Usage() + sys.exit('Insufficient Parameter') + self.open(self.EPCIPAddress, self.EPCUserName, self.EPCPassword) + self.command('cd ' + self.EPCSourceCodePath, '\$', 5) + if re.match('OAI', self.EPCType, re.IGNORECASE): + self.command('source oaienv', '\$', 5) + self.command('cd scripts', '\$', 5) + self.command('hostname', '\$', 5) + result = re.search('hostname\\\\r\\\\n(?P<host_name>[a-zA-Z0-9\-\_]+)\\\\r\\\\n', str(self.ssh.before)) + if result is None: + logging.debug('\u001B[1;37;41m Hostname Not Found! \u001B[0m') + sys.exit(1) + host_name = result.group('host_name') + self.command('echo ' + self.EPCPassword + ' | sudo -S ./run_mme 2>&1 | stdbuf -o0 tee -a mme_' + SSH.testCase_id + '.log &', 'MME app initialization complete', 100) + else: + self.command('cd ltebox/tools', '\$', 5) + self.command('echo ' + self.EPCPassword + ' | sudo -S ./start_mme', '\$', 5) + self.close() + + def InitializeSPGW(self): + if self.EPCIPAddress == '' or self.EPCUserName == '' or self.EPCPassword == '' or self.EPCSourceCodePath == '' or self.EPCType == '': + Usage() + sys.exit('Insufficient Parameter') + self.open(self.EPCIPAddress, self.EPCUserName, self.EPCPassword) + self.command('cd ' + self.EPCSourceCodePath, '\$', 5) + if re.match('OAI', self.EPCType, re.IGNORECASE): + self.command('source oaienv', '\$', 5) + self.command('cd scripts', '\$', 5) + self.command('echo ' + self.EPCPassword + ' | sudo -S ./run_spgw 2>&1 | stdbuf -o0 tee -a spgw_' + SSH.testCase_id + '.log &', 'Initializing SPGW-APP task interface: DONE', 30) + else: + self.command('cd ltebox/tools', '\$', 5) + self.command('echo ' + self.EPCPassword + ' | sudo -S ./start_xGw', '\$', 5) + self.close() + + def InitializeeNB(self): + if self.eNBIPAddress == '' or self.eNBUserName == '' or self.eNBPassword == '' or self.eNBSourceCodePath == '': + Usage() + sys.exit('Insufficient Parameter') + self.CheckHSSProcess() + self.CheckMMEProcess() + self.CheckSPGWProcess() + self.open(self.eNBIPAddress, self.eNBUserName, self.eNBPassword) + self.command('cd ' + self.eNBSourceCodePath, '\$', 5) + self.command('cd targets/PROJECTS/GENERIC-LTE-EPC/CONF/', '\$', 5) + self.command('cp ' + self.Initialize_eNB_args + ' ci-' + self.Initialize_eNB_args, '\$', 5) + self.command('sed -i -e \'s/mme_ip_address.*$/mme_ip_address = ( { ipv4 = "' + self.EPCIPAddress + '";/\' ci-' + self.Initialize_eNB_args, '\$', 2); + self.command('sed -i -e \'s/ENB_IPV4_ADDRESS_FOR_S1_MME.*$/ENB_IPV4_ADDRESS_FOR_S1_MME = "' + self.eNBIPAddress + '";/\' ci-' + self.Initialize_eNB_args, '\$', 2); + self.command('sed -i -e \'s/ENB_IPV4_ADDRESS_FOR_S1U.*$/ENB_IPV4_ADDRESS_FOR_S1U = "' + self.eNBIPAddress + '";/\' ci-' + self.Initialize_eNB_args, '\$', 2); + self.command('cd ' + self.eNBSourceCodePath, '\$', 5) + self.command('source oaienv', '\$', 5) + self.command('cd cmake_targets', '\$', 5) + self.command('echo ' + self.eNBPassword + ' | ' + 'sudo -S -E ./lte_build_oai/build/lte-softmodem -O ' + self.eNBSourceCodePath + '/targets/PROJECTS/GENERIC-LTE-EPC/CONF/ci-' + self.Initialize_eNB_args + ' 2>&1 | stdbuf -o0 tee -a enb_' + SSH.testCase_id + '.log &', 'got sync', 60) + self.close() + + def CheckeNBProcess(self): + self.open(self.eNBIPAddress, self.eNBUserName, self.eNBPassword) + self.command('echo ' + self.eNBPassword + ' | ps -aux | grep -v grep | grep lte-softmodem', '\$', 5) + result = re.search('lte-softmodem', str(self.ssh.before)) + if result is None: + logging.debug('\u001B[1;37;41m eNB Process Not Found! \u001B[0m') + sys.exit(1) + self.close() + + def CheckHSSProcess(self): + self.open(self.EPCIPAddress, self.EPCUserName, self.EPCPassword) + self.command('ps -aux | grep -v grep | grep hss > hss_processes.txt', '\$', 5) + # If we don't timeout we are OK + if re.match('OAI', self.EPCType, re.IGNORECASE): + self.command('cat hss_processes.txt', '/bin/bash ./run_', 5) + else: + self.command('cat hss_processes.txt', 'hss_sim s6as diam_hss', 5) + self.command('rm hss_processes.txt', '\$', 5) + self.close() + + def CheckMMEProcess(self): + self.open(self.EPCIPAddress, self.EPCUserName, self.EPCPassword) + self.command('ps -aux | grep -v grep | grep mme > mme_processes.txt', '\$', 5) + # If we don't timeout we are OK + if re.match('OAI', self.EPCType, re.IGNORECASE): + self.command('cat mme_processes.txt', '/bin/bash ./run_', 5) + else: + self.command('cat mme_processes.txt', 'mme', 5) + self.command('rm mme_processes.txt', '\$', 5) + self.close() + + def CheckSPGWProcess(self): + self.open(self.EPCIPAddress, self.EPCUserName, self.EPCPassword) + # If we don't timeout we are OK + if re.match('OAI', self.EPCType, re.IGNORECASE): + self.command('ps -aux | grep -v grep | grep spgw > spgw_processes.txt', '\$', 5) + self.command('cat spgw_processes.txt', '/bin/bash ./run_', 5) + else: + self.command('ps -aux | grep -v grep | grep xGw > spgw_processes.txt', '\$', 5) + self.command('cat spgw_processes.txt', 'xGw', 5) + self.command('rm spgw_processes.txt', '\$', 5) + self.close() + + def TerminateeNB(self): + self.open(self.eNBIPAddress, self.eNBUserName, self.eNBPassword) + self.command('echo ' + self.eNBPassword + ' | sudo -S killall --signal SIGINT lte-softmodem || true', '\$', 5) + time.sleep(5) + self.command('echo ' + self.eNBPassword + ' | ps -aux | grep -v grep | grep lte-softmodem', '\$', 5) + result = re.search('lte-softmodem', str(self.ssh.before)) + if result is not None: + self.command('echo ' + self.eNBPassword + ' | sudo -S killall --signal SIGKILL lte-softmodem || true', '\$', 5) + self.close() + + def TerminateHSS(self): + self.open(self.EPCIPAddress, self.EPCUserName, self.EPCPassword) + if re.match('OAI', self.EPCType, re.IGNORECASE): + self.command('echo ' + self.EPCPassword + ' | sudo -S killall --signal SIGINT run_hss oai_hss || true', '\$', 5) + time.sleep(2) + self.command('ps -aux | grep -v grep | grep hss', '\$', 5) + result = re.search('\/bin\/bash .\/run_', str(self.ssh.before)) + if result is not None: + self.command('echo ' + self.EPCPassword + ' | sudo -S killall --signal SIGKILL run_hss oai_hss || true', '\$', 5) + else: + self.command('echo ' + self.EPCPassword + ' | sudo -S daemon --name=simulated_hss --stop', '\$', 5) + time.sleep(2) + self.command('ps -aux | egrep "hss_sim|simulated_hss" | grep -v grep | awk \'BEGIN{n=0}{pidId[n]=$2;n=n+1}END{print "kill -9 " pidId[0] " " pidId[1]}\' > /home/' + self.EPCUserName + '/kill_hss.sh', '\$', 5) + self.command('chmod 755 /home/' + self.EPCUserName + '/kill_hss.sh', '\$', 5) + self.command('echo ' + self.EPCPassword + ' | sudo -S /home/' + self.EPCUserName + '/kill_hss.sh', '\$', 5) + self.command('rm /home/' + self.EPCUserName + '/kill_hss.sh', '\$', 5) + self.close() + + def TerminateMME(self): + self.open(self.EPCIPAddress, self.EPCUserName, self.EPCPassword) + if re.match('OAI', self.EPCType, re.IGNORECASE): + self.command('echo ' + self.EPCPassword + ' | sudo -S killall --signal SIGINT run_mme mme || true', '\$', 5) + time.sleep(2) + self.command('echo ' + self.EPCPassword + ' | ps -aux | grep -v grep | grep mme', '\$', 5) + result = re.search('\/bin\/bash .\/run_', str(self.ssh.before)) + if result is not None: + self.command('echo ' + self.EPCPassword + ' | sudo -S killall --signal SIGKILL run_mme mme || true', '\$', 5) + else: + self.command('cd ltebox/tools', '\$', 5) + self.command('echo ' + self.EPCPassword + ' | sudo -S ./stop_mme', '\$', 5) + self.close() + + def TerminateSPGW(self): + self.open(self.EPCIPAddress, self.EPCUserName, self.EPCPassword) + if re.match('OAI', self.EPCType, re.IGNORECASE): + self.command('echo ' + self.EPCPassword + ' | sudo -S killall --signal SIGINT run_spgw spgw || true', '\$', 5) + time.sleep(2) + self.command('echo ' + self.EPCPassword + ' | ps -aux | grep -v grep | grep spgw', '\$', 5) + result = re.search('\/bin\/bash .\/run_', str(self.ssh.before)) + if result is not None: + self.command('echo ' + self.EPCPassword + ' | sudo -S killall --signal SIGKILL run_spgw spgw || true', '\$', 5) + else: + self.command('cd ltebox/tools', '\$', 5) + self.command('echo ' + self.EPCPassword + ' | sudo -S ./stop_xGw', '\$', 5) + self.close() + + def LogCollectBuild(self): + self.open(self.eNBIPAddress, self.eNBUserName, self.eNBPassword) + self.command('cd ' + self.eNBSourceCodePath, '\$', 5) + self.command('cd cmake_targets', '\$', 5) + self.command('zip build.log.zip build_log_*/*', '\$', 60) + self.command('rm -rf build_log_*', '\$', 5) + self.close() + + def LogCollecteNB(self): + self.open(self.eNBIPAddress, self.eNBUserName, self.eNBPassword) + self.command('cd ' + self.eNBSourceCodePath, '\$', 5) + self.command('cd cmake_targets', '\$', 5) + self.command('zip enb.log.zip enb*.log', '\$', 60) + self.command('rm enb*.log', '\$', 5) + self.close() + + def LogCollectPing(self): + self.open(self.EPCIPAddress, self.EPCUserName, self.EPCPassword) + self.command('cd ' + self.EPCSourceCodePath, '\$', 5) + self.command('cd scripts', '\$', 5) + self.command('zip ping.log.zip ping*.log', '\$', 60) + self.command('rm ping*.log', '\$', 5) + self.close() + + def LogCollectIperf(self): + self.open(self.EPCIPAddress, self.EPCUserName, self.EPCPassword) + self.command('cd ' + self.EPCSourceCodePath, '\$', 5) + self.command('cd scripts', '\$', 5) + self.command('zip iperf.log.zip iperf*.log', '\$', 60) + self.command('rm iperf*.log', '\$', 5) + self.close() + + def LogCollectHSS(self): + self.open(self.EPCIPAddress, self.EPCUserName, self.EPCPassword) + if re.match('OAI', self.EPCType, re.IGNORECASE): + self.command('cd ' + self.EPCSourceCodePath, '\$', 5) + self.command('cd scripts', '\$', 5) + self.command('zip hss.log.zip hss*.log', '\$', 60) + self.command('rm hss*.log', '\$', 5) + self.close() + + def LogCollectMME(self): + self.open(self.EPCIPAddress, self.EPCUserName, self.EPCPassword) + self.command('cd ' + self.EPCSourceCodePath, '\$', 5) + if re.match('OAI', self.EPCType, re.IGNORECASE): + self.command('cd scripts', '\$', 5) + self.command('zip mme.log.zip mme*.log', '\$', 60) + self.command('rm mme*.log', '\$', 5) + else: + self.command('cd ltebox/var/log', '\$', 5) + self.command('zip /home/' + self.EPCUserName + '/mme.log.zip mmeLog.0 s1apcLog.0 s1apsLog.0 s11cLog.0 libLog.0 s1apCodecLog.0', '\$', 60) + self.close() + + def LogCollectSPGW(self): + self.open(self.EPCIPAddress, self.EPCUserName, self.EPCPassword) + self.command('cd ' + self.EPCSourceCodePath, '\$', 5) + if re.match('OAI', self.EPCType, re.IGNORECASE): + self.command('cd scripts', '\$', 5) + self.command('zip spgw.log.zip spgw*.log', '\$', 60) + self.command('rm spgw*.log', '\$', 5) + else: + self.command('cd ltebox/var/log', '\$', 5) + self.command('zip /home/' + self.EPCUserName + '/spgw.log.zip xGwLog.0', '\$', 60) + self.close() +#----------------------------------------------------------- +# Usage() +#----------------------------------------------------------- +def Usage(): + print('------------------------------------------------------------') + print('main.py Ver:' + Version) + print('------------------------------------------------------------') + print('Usage: python main.py [options]') + print(' --help Show this help.') + print(' --mode=[Mode]') + print(' TesteNB') + print(' TerminateeNB, TerminateEPC') + print(' LogCollectBuild, LogCollecteNB, LogCollectEPC, LogCollectADB') + print(' --eNBIPAddress=[eNB\'s IP Address]') + print(' --eNBRepository=[eNB\'s Repository URL]') + print(' --eNBBranch=[eNB\'s Branch Name]') + print(' --eNBCommitID=[eNB\'s Commit Number]') + print(' --eNBUserName=[eNB\'s Login User Name]') + print(' --eNBPassword=[eNB\'s Login Password]') + print(' --eNBSourceCodePath=[eNB\'s Source Code Path]') + print(' --EPCIPAddress=[EPC\'s IP Address]') + print(' --EPCUserName=[EPC\'s Login User Name]') + print(' --EPCPassword=[EPC\'s Login Password]') + print(' --EPCSourceCodePath=[EPC\'s Source Code Path]') + print(' --EPCType=[EPC\'s Type: OAI or ltebox]') + print(' --ADBIPAddress=[ADB\'s IP Address]') + print(' --ADBUserName=[ADB\'s Login User Name]') + print(' --ADBPassword=[ADB\'s Login Password]') + print('------------------------------------------------------------') + +#----------------------------------------------------------- +# ShowTestID() +#----------------------------------------------------------- +def ShowTestID(): + logging.debug('\u001B[1m----------------------------------------\u001B[0m') + logging.debug('\u001B[1mTest ID:' + SSH.testCase_id + '\u001B[0m') + logging.debug('\u001B[1m' + SSH.desc + '\u001B[0m') + logging.debug('\u001B[1m----------------------------------------\u001B[0m') + +def CheckClassValidity(action,id): + if action != 'Build_eNB' and action != 'Initialize_eNB' and action != 'Terminate_eNB' and action != 'Initialize_UE' and action != 'Terminate_UE' and action != 'Attach_UE' and action != 'Detach_UE' and action != 'Ping' and action != 'Iperf' and action != 'Reboot_UE' and action != 'Initialize_HSS' and action != 'Terminate_HSS' and action != 'Initialize_MME' and action != 'Terminate_MME' and action != 'Initialize_SPGW' and action != 'Terminate_SPGW': + logging.debug('ERROR: test-case ' + id + ' has wrong class ' + action) + return False + return True + +def GetParametersFromXML(action): + if action == 'Build_eNB': + SSH.Build_eNB_args = test.findtext('Build_eNB_args') + + if action == 'Initialize_eNB': + SSH.Initialize_eNB_args = test.findtext('Initialize_eNB_args') + + if action == 'Ping': + SSH.ping_args = test.findtext('ping_args') + SSH.ping_packetloss_threshold = test.findtext('ping_packetloss_threshold') + + if action == 'Iperf': + SSH.iperf_args = test.findtext('iperf_args') + SSH.iperf_packetloss_threshold = test.findtext('iperf_packetloss_threshold') + +#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) + +#----------------------------------------------------------- +# Parameter Check +#----------------------------------------------------------- +mode = '' +SSH = SSHConnection() + +argvs = sys.argv +argc = len(argvs) + +while len(argvs) > 1: + myArgv = argvs.pop(1) # 0th is this file's name + if re.match('^\-\-help$', myArgv, re.IGNORECASE): + Usage() + sys.exit(0) + elif re.match('^\-\-mode=(.+)$', myArgv, re.IGNORECASE): + matchReg = re.match('^\-\-mode=(.+)$', myArgv, re.IGNORECASE) + mode = matchReg.group(1) + elif re.match('^\-\-eNBIPAddress=(.+)$', myArgv, re.IGNORECASE): + matchReg = re.match('^\-\-eNBIPAddress=(.+)$', myArgv, re.IGNORECASE) + SSH.eNBIPAddress = matchReg.group(1) + elif re.match('^\-\-eNBRepository=(.+)$', myArgv, re.IGNORECASE): + matchReg = re.match('^\-\-eNBRepository=(.+)$', myArgv, re.IGNORECASE) + SSH.eNBRepository = matchReg.group(1) + elif re.match('^\-\-eNBBranch=(.+)$', myArgv, re.IGNORECASE): + matchReg = re.match('^\-\-eNBBranch=(.+)$', myArgv, re.IGNORECASE) + SSH.eNBBranch = matchReg.group(1) + elif re.match('^\-\-eNBCommitID=(.*)$', myArgv, re.IGNORECASE): + matchReg = re.match('^\-\-eNBCommitID=(.*)$', myArgv, re.IGNORECASE) + SSH.eNBCommitID = matchReg.group(1) + elif re.match('^\-\-eNBUserName=(.+)$', myArgv, re.IGNORECASE): + matchReg = re.match('^\-\-eNBUserName=(.+)$', myArgv, re.IGNORECASE) + SSH.eNBUserName = matchReg.group(1) + elif re.match('^\-\-eNBPassword=(.+)$', myArgv, re.IGNORECASE): + matchReg = re.match('^\-\-eNBPassword=(.+)$', myArgv, re.IGNORECASE) + SSH.eNBPassword = matchReg.group(1) + elif re.match('^\-\-eNBSourceCodePath=(.+)$', myArgv, re.IGNORECASE): + matchReg = re.match('^\-\-eNBSourceCodePath=(.+)$', myArgv, re.IGNORECASE) + SSH.eNBSourceCodePath = matchReg.group(1) + elif re.match('^\-\-EPCIPAddress=(.+)$', myArgv, re.IGNORECASE): + matchReg = re.match('^\-\-EPCIPAddress=(.+)$', myArgv, re.IGNORECASE) + SSH.EPCIPAddress = matchReg.group(1) + elif re.match('^\-\-EPCBranch=(.+)$', myArgv, re.IGNORECASE): + matchReg = re.match('^\-\-EPCBranch=(.+)$', myArgv, re.IGNORECASE) + SSH.EPCBranch = matchReg.group(1) + elif re.match('^\-\-EPCUserName=(.+)$', myArgv, re.IGNORECASE): + matchReg = re.match('^\-\-EPCUserName=(.+)$', myArgv, re.IGNORECASE) + SSH.EPCUserName = matchReg.group(1) + elif re.match('^\-\-EPCPassword=(.+)$', myArgv, re.IGNORECASE): + matchReg = re.match('^\-\-EPCPassword=(.+)$', myArgv, re.IGNORECASE) + SSH.EPCPassword = matchReg.group(1) + elif re.match('^\-\-EPCSourceCodePath=(.+)$', myArgv, re.IGNORECASE): + matchReg = re.match('^\-\-EPCSourceCodePath=(.+)$', myArgv, re.IGNORECASE) + SSH.EPCSourceCodePath = matchReg.group(1) + elif re.match('^\-\-EPCType=(.+)$', myArgv, re.IGNORECASE): + matchReg = re.match('^\-\-EPCType=(.+)$', myArgv, re.IGNORECASE) + if re.match('OAI', matchReg.group(1), re.IGNORECASE) or re.match('ltebox', matchReg.group(1), re.IGNORECASE): + SSH.EPCType = matchReg.group(1) + else: + sys.exit('Invalid EPC Type: ' + matchReg.group(1) + ' -- (should be OAI or ltebox)') + elif re.match('^\-\-ADBIPAddress=(.+)$', myArgv, re.IGNORECASE): + matchReg = re.match('^\-\-ADBIPAddress=(.+)$', myArgv, re.IGNORECASE) + SSH.ADBIPAddress = matchReg.group(1) + elif re.match('^\-\-ADBUserName=(.+)$', myArgv, re.IGNORECASE): + matchReg = re.match('^\-\-ADBUserName=(.+)$', myArgv, re.IGNORECASE) + SSH.ADBUserName = matchReg.group(1) + elif re.match('^\-\-ADBPassword=(.+)$', myArgv, re.IGNORECASE): + matchReg = re.match('^\-\-ADBPassword=(.+)$', myArgv, re.IGNORECASE) + SSH.ADBPassword = matchReg.group(1) + else: + Usage() + sys.exit('Invalid Parameter: ' + myArgv) + +if re.match('^TerminateeNB$', mode, re.IGNORECASE): + if SSH.eNBIPAddress == '' or SSH.eNBUserName == '' or SSH.eNBPassword == '': + Usage() + sys.exit('Insufficient Parameter') + SSH.TerminateeNB() +elif re.match('^TerminateUE$', mode, re.IGNORECASE): + if SSH.ADBIPAddress == '' or SSH.ADBUserName == '' or SSH.ADBPassword == '': + Usage() + sys.exit('Insufficient Parameter') + signal.signal(signal.SIGUSR1, receive_signal) + SSH.TerminateUE() +elif re.match('^TerminateHSS$', mode, re.IGNORECASE): + if SSH.EPCIPAddress == '' or SSH.EPCUserName == '' or SSH.EPCPassword == '': + Usage() + sys.exit('Insufficient Parameter') + SSH.TerminateHSS() +elif re.match('^TerminateMME$', mode, re.IGNORECASE): + if SSH.EPCIPAddress == '' or SSH.EPCUserName == '' or SSH.EPCPassword == '': + Usage() + sys.exit('Insufficient Parameter') + SSH.TerminateMME() +elif re.match('^TerminateSPGW$', mode, re.IGNORECASE): + if SSH.EPCIPAddress == '' or SSH.EPCUserName == '' or SSH.EPCPassword == '': + Usage() + sys.exit('Insufficient Parameter') + SSH.TerminateSPGW() +elif re.match('^LogCollectBuild$', mode, re.IGNORECASE): + if SSH.eNBIPAddress == '' or SSH.eNBUserName == '' or SSH.eNBPassword == '' or SSH.eNBSourceCodePath == '': + Usage() + sys.exit('Insufficient Parameter') + SSH.LogCollectBuild() +elif re.match('^LogCollecteNB$', mode, re.IGNORECASE): + if SSH.eNBIPAddress == '' or SSH.eNBUserName == '' or SSH.eNBPassword == '' or SSH.eNBSourceCodePath == '': + Usage() + sys.exit('Insufficient Parameter') + SSH.LogCollecteNB() +elif re.match('^LogCollectHSS$', mode, re.IGNORECASE): + if SSH.EPCIPAddress == '' or SSH.EPCUserName == '' or SSH.EPCPassword == '' or SSH.EPCSourceCodePath == '': + Usage() + sys.exit('Insufficient Parameter') + SSH.LogCollectHSS() +elif re.match('^LogCollectMME$', mode, re.IGNORECASE): + if SSH.EPCIPAddress == '' or SSH.EPCUserName == '' or SSH.EPCPassword == '' or SSH.EPCSourceCodePath == '': + Usage() + sys.exit('Insufficient Parameter') + SSH.LogCollectMME() +elif re.match('^LogCollectSPGW$', mode, re.IGNORECASE): + if SSH.EPCIPAddress == '' or SSH.EPCUserName == '' or SSH.EPCPassword == '' or SSH.EPCSourceCodePath == '': + Usage() + sys.exit('Insufficient Parameter') + SSH.LogCollectSPGW() +elif re.match('^LogCollectPing$', mode, re.IGNORECASE): + if SSH.EPCIPAddress == '' or SSH.EPCUserName == '' or SSH.EPCPassword == '' or SSH.EPCSourceCodePath == '': + Usage() + sys.exit('Insufficient Parameter') + SSH.LogCollectPing() +elif re.match('^LogCollectIperf$', mode, re.IGNORECASE): + if SSH.EPCIPAddress == '' or SSH.EPCUserName == '' or SSH.EPCPassword == '' or SSH.EPCSourceCodePath == '': + Usage() + sys.exit('Insufficient Parameter') + SSH.LogCollectIperf() +elif re.match('^TesteNB$', mode, re.IGNORECASE): + if SSH.eNBIPAddress == '' or SSH.eNBRepository == '' or SSH.eNBBranch == '' or SSH.eNBUserName == '' or SSH.eNBPassword == '' or SSH.eNBSourceCodePath == '' or SSH.EPCIPAddress == '' or SSH.EPCUserName == '' or SSH.EPCPassword == '' or SSH.EPCType == '' or SSH.EPCSourceCodePath == '' or SSH.ADBIPAddress == '' or SSH.ADBUserName == '' or SSH.ADBPassword == '': + Usage() + sys.exit('Insufficient Parameter') + #read test_case_list.xml file + xml_test_file = sys.path[0] + "/test_case_list.xml" + + xmlTree = ET.parse(xml_test_file) + xmlRoot = xmlTree.getroot() + + exclusion_tests=xmlRoot.findtext('TestCaseExclusionList',default='') + requested_tests=xmlRoot.findtext('TestCaseRequestedList',default='') + 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) + + #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: + logging.debug('INFO: test will be run: ' + test) + todo_tests.append(test) + + signal.signal(signal.SIGUSR1, receive_signal) + + for test_case_id in todo_tests: + for test in all_tests: + id = test.get('id') + if test_case_id != id: + continue + SSH.testCase_id = id + SSH.desc = test.findtext('desc') + action = test.findtext('class') + if (CheckClassValidity(action, id) == False): + continue + ShowTestID() + GetParametersFromXML(action) + if action == 'Initialize_UE' or action == 'Attach_UE' or action == 'Detach_UE' or action == 'Ping' or action == 'Iperf' or action == 'Reboot_UE': + SSH.GetAllUEDevices() + if action == 'Build_eNB': + SSH.BuildeNB() + elif action == 'Initialize_eNB': + SSH.InitializeeNB() + elif action == 'Terminate_eNB': + SSH.TerminateeNB() + elif action == 'Initialize_UE': + SSH.InitializeUE() + elif action == 'Terminate_UE': + SSH.TerminateUE() + elif action == 'Attach_UE': + SSH.AttachUE() + elif action == 'Detach_UE': + SSH.DetachUE() + elif action == 'Ping': + SSH.Ping() + elif action == 'Iperf': + SSH.Iperf() + elif action == 'Reboot_UE': + SSH.RebootUE() + elif action == 'Initialize_HSS': + SSH.InitializeHSS() + elif action == 'Terminate_HSS': + SSH.TerminateHSS() + elif action == 'Initialize_MME': + SSH.InitializeMME() + elif action == 'Terminate_MME': + SSH.TerminateMME() + elif action == 'Initialize_SPGW': + SSH.InitializeSPGW() + elif action == 'Terminate_SPGW': + SSH.TerminateSPGW() + else: + sys.exit('Invalid action') +else: + Usage() + sys.exit('Invalid mode') +sys.exit(0) diff --git a/ci-scripts/test_case_list.xml b/ci-scripts/test_case_list.xml new file mode 100644 index 0000000000..3d683f5d13 --- /dev/null +++ b/ci-scripts/test_case_list.xml @@ -0,0 +1,52 @@ +<testCaseList> + <TestCaseRequestedList>010101 050101 060101 070101 030101 030201 050201 060201 070201</TestCaseRequestedList> + <TestCaseExclusionList></TestCaseExclusionList> + + <testCase id="010101"> + <class>Build_eNB</class> + <desc>Build eNB (USRP)</desc> + <Build_eNB_args>-w USRP -x -c --eNB</Build_eNB_args> + </testCase> + + <testCase id="030101"> + <class>Initialize_eNB</class> + <desc>Initialize eNB (FDD/Band1/5MHz/info)</desc> + <Initialize_eNB_args>enb.band7.tm1.50PRB.usrpb210.conf</Initialize_eNB_args> + </testCase> + + <testCase id="030201"> + <class>Terminate_eNB</class> + <desc>Terminate eNB</desc> + </testCase> + + <testCase id="050101"> + <class>Initialize_HSS</class> + <desc>Initialize HSS</desc> + </testCase> + + <testCase id="050201"> + <class>Terminate_HSS</class> + <desc>Terminate HSS</desc> + </testCase> + + <testCase id="060101"> + <class>Initialize_MME</class> + <desc>Initialize MME</desc> + </testCase> + + <testCase id="060201"> + <class>Terminate_MME</class> + <desc>Terminate MME</desc> + </testCase> + + <testCase id="070101"> + <class>Initialize_SPGW</class> + <desc>Initialize SPGW</desc> + </testCase> + + <testCase id="070201"> + <class>Terminate_SPGW</class> + <desc>Terminate SPGW</desc> + </testCase> + +</testCaseList> -- GitLab