blob: 1c70e6cebf99fbdf70932671577c771ec9d708f5 [file] [log] [blame]
#!groovy
import groovy.time.*
def init( type ){
machineType = [ "FUNC" : "VM",
"HA" : "VM",
"SCPF" : "BM",
"USECASE" : "BM" ]
testType = type;
testMachine = "TestStation-" + machineType[ type ] + "s";
}
def printType(){
echo testType;
echo testMachine;
}
def getProperties(){
node( testMachine ){
return readProperties(file:'/var/jenkins/TestONOS.property');
}
}
def getTestsToRun( testList ){
testList.tokenize("\n;, ")
}
def getCurrentTime(){
return new Date();
}
def getTotalTime( start, end ){
return TimeCategory.minus( end, start );
}
def printTestToRun( testList ){
for ( String test : testList ) {
println test;
}
}
def sendResultToSlack( start, isManualRun ){
try{
if( isManualRun == "false" ){
end = getCurrentTime();
TimeDuration duration = TimeCategory.minus( end , start );
slackSend( color:"#5816EE", message: testType + " tests ended at: " + end.toString() + "\nTime took : " + duration )
}
}
catch(all){}
}
def initAndRunTest( testName ){
return '''#!/bin/bash -l
set -i # interactive
set +e
shopt -s expand_aliases # expand alias in non-interactive mode
export PYTHONUNBUFFERED=1
ifconfig
echo "ONOS Branch is: $ONOSBranch"
echo "TestON Branch is: $TestONBranch"
echo "Test date: "
date
cd ~
export PATH=$PATH:onos/tools/test/bin
timeout 240 stc shutdown | head -100
timeout 240 stc teardown | head -100
timeout 240 stc shutdown | head -100
cd ~/OnosSystemTest/TestON/bin
git log |head
./cleanup.sh -f
''' + "./cli.py run " + testName + '''
./cleanup.sh -f
# cleanup config changes
cd ~/onos/tools/package/config
git clean -df'''
}
def cleanAndCopyFiles( testName ){
return '''#!/bin/bash -i
set +e
echo "ONOS Branch is: ${ONOSBranch}"
echo "TestON Branch is: ${TestONBranch}"
echo "Job name is: "''' + testName + '''
echo "Workspace is: ${WORKSPACE}/"
echo "Wiki page to post is: ${WikiPrefix}-"
# remove any leftover files from previous tests
sudo rm ${WORKSPACE}/*Wiki.txt
sudo rm ${WORKSPACE}/*Summary.txt
sudo rm ${WORKSPACE}/*Result.txt
sudo rm ${WORKSPACE}/*.csv
#copy files to workspace
cd `ls -t ~/OnosSystemTest/TestON/logs/*/ | head -1 | sed 's/://'`
sudo cp *.txt ${WORKSPACE}/
sudo cp *.csv ${WORKSPACE}/
cd ${WORKSPACE}/
for i in *.csv
do mv "$i" "$WikiPrefix"-"$i"
done
ls -al
cd '''
}
def fetchLogs( testName ){
return '''#!/bin/bash
set +e
cd ~/OnosSystemTest/TestON/logs
echo "Job Name is: " + ''' + testName + '''
TestONlogDir=$(ls -t | grep ${TEST_NAME}_ |head -1)
echo "########################################################################################"
echo "##### copying ONOS logs from all nodes to TestON/logs directory: ${TestONlogDir}"
echo "########################################################################################"
cd $TestONlogDir
if [ $? -eq 1 ]
then
echo "Job name does not match any test suite name to move log!"
else
pwd
for i in $OC{1..7}; do onos-fetch-logs $i || echo log does not exist; done
fi
cd'''
}
def postResult( prop, params ){
if( prop["manualRun"] == "false" || prop["postResult"] == "true" ){
def post = build job: "Pipeline_postjob_" + machineType[ testType ], propagate: false, parameters: params
}
}
def analyzeResult( prop, workSpace, testName, otherTestName ){
node( testMachine ){
resultContents = readFile workSpace + "/" + testName + "Result.txt"
resultContents = resultContents.split("\n")
if( resultContents[ 0 ] == "1" ){
print "All passed"
}else{
print "Failed"
if( prop["manualRun"] == "false" )
slackSend(color:"FF0000", message: "[" + prop["ONOSBranch"] + "]" + otherTestName + " : Failed!\n"
+ resultContents[ 1 ] + "\n"
+ "https://onos-jenkins.onlab.us/blue/organizations/jenkins/${env.JOB_NAME}/detail/${env.JOB_NAME}/${env.BUILD_NUMBER}/pipeline" )
Failed
}
}
}