blob: 857ff54ac0cd6a361e6b7f09b06d1d298056654f [file] [log] [blame]
Devin Lim90803a82017-08-29 13:41:44 -07001#!groovy
Devin Lim61657e42017-10-09 17:24:40 -07002import groovy.time.*
Devin Lim90803a82017-08-29 13:41:44 -07003// This is a Jenkinsfile for a scripted pipeline for the FUNC tests
4def prop = null
5node("TestStation-VMs"){
6 prop = readProperties(file:'/var/jenkins/TestONOS.property')
7}
8// TODO: Exception handling around steps
9FUNC = [
10"FUNCipv6Intent" : [wiki_link:prop["WikiPrefix"]+"-"+"FUNCipv6Intent", wiki_file:"FUNCipv6IntentWiki.txt", ],
11"FUNCoptical" : [wiki_link:prop["WikiPrefix"]+"-"+"FUNCoptical", wiki_file:"FUNCopticalWiki.txt"],
12"FUNCflow" : [wiki_link:prop["WikiPrefix"]+"-"+"FUNCflow", wiki_file:"FUNCflowWiki.txt"],
13"FUNCnetCfg": [wiki_link:prop["WikiPrefix"]+"-"+"FUNCnetCfg", wiki_file:"FUNCnetCfgWiki.txt"],
14"FUNCovsdbtest" : [wiki_link:prop["WikiPrefix"]+"-"+"FUNCovsdbtestWiki", wiki_file:"FUNCovsdbtestWiki.txt"],
15"FUNCnetconf" : [wiki_link:prop["WikiPrefix"]+"-"+"FUNCnetconf", wiki_file:"FUNCnetconfWiki.txt"],
16"FUNCgroup" : [wiki_link:prop["WikiPrefix"]+"-"+"FUNCgroup", wiki_file:"FUNCgroupWiki.txt"],
17"FUNCintent" : [wiki_link:prop["WikiPrefix"]+"-"+"FUNCintent", wiki_file:"FUNCintentWiki.txt"],
Devin Lim3ebd5e72017-11-14 10:38:00 -080018"FUNCintentRest" : [wiki_link:prop["WikiPrefix"]+"-"+"FUNCintentRest", wiki_file:"FUNCintentRestWiki.txt"],
19"FUNCformCluster" : [wiki_link:prop["WikiPrefix"]+"-"+"FUNCformCluster", wiki_file:"FUNCformClusterWiki.txt"]
Devin Lim90803a82017-08-29 13:41:44 -070020]
21table_name = "executed_test_tests"
22result_name = "executed_test_results"
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -070023graph_generator_file = "~/OnosSystemTest/TestON/JenkinsFile/scripts/testCaseGraphGenerator.R"
Devin Lim90803a82017-08-29 13:41:44 -070024graph_saved_directory = "/var/jenkins/workspace/Pipeline_postjob_VM/"
25echo("Testcases:")
26def testsToRun = null
27testsToRun = prop["Tests"].tokenize("\n;, ")
28
29for ( String test : testsToRun ) {
30 println test
31}
32def tests = [:]
33for( String test : FUNC.keySet() ){
34 toBeRun = testsToRun.contains( test )
35 def stepName = ( toBeRun ? "" : "Not " ) + "Running $test"
36 tests[stepName] = FUNCTest(test, toBeRun, prop)
37}
38
Devin Lim61657e42017-10-09 17:24:40 -070039def now = new Date()
Devin Lim90803a82017-08-29 13:41:44 -070040// run the tests
41for ( test in tests.keySet() ){
42 tests[test].call()
43}
Devin Lim79af50f2017-10-26 14:26:47 -070044try{
45 if( prop["manualRun"] == "false" ){
46 def end = new Date()
47 TimeDuration duration = TimeCategory.minus( end, now )
48 slackSend( color:"#5816EE", message: "FUNC tests ended at: " + end.toString() + "\nTime took : " + duration )
49 }
Devin Lim61657e42017-10-09 17:24:40 -070050}
Devin Lim79af50f2017-10-26 14:26:47 -070051catch(all){}
Devin Lim90803a82017-08-29 13:41:44 -070052// The testName should be the key from the FUNC
53def FUNCTest( testName, toBeRun, prop ) {
54 return {
Devin Lim79af50f2017-10-26 14:26:47 -070055 catchError{
Devin Lim90803a82017-08-29 13:41:44 -070056 stage(testName) {
57 if ( toBeRun ){
58 workSpace = "/var/jenkins/workspace/"+testName
59 def fileContents = ""
60 node("TestStation-VMs"){
61 withEnv(['ONOSBranch='+prop["ONOSBranch"],
62 'ONOSJVMHeap='+prop["ONOSJVMHeap"],
63 'TestONBranch='+prop["TestONBranch"],
64 'ONOSTag='+prop["ONOSTag"],
65 'WikiPrefix='+prop["WikiPrefix"],
66 'WORKSPACE='+workSpace]){
67 sh '''#!/bin/bash -l
68 set -i # interactive
Devin Lima0e52eb2017-09-13 18:35:12 -070069 set +e
Devin Lim90803a82017-08-29 13:41:44 -070070 shopt -s expand_aliases # expand alias in non-interactive mode
71 export PYTHONUNBUFFERED=1
72
73 ifconfig
74
75 echo "ONOS Branch is: $ONOSBranch"
76 echo "TestON Branch is: $TestONBranch"
77 echo "Test date: "
78 date
79
80 cd ~
81 export PATH=$PATH:onos/tools/test/bin
82
83 timeout 240 stc shutdown | head -100
84 timeout 240 stc teardown | head -100
85 timeout 240 stc shutdown | head -100
86
87 cd ~/OnosSystemTest/TestON/bin
88 git log |head
89 ./cleanup.sh
90 ''' + "./cli.py run " + testName + '''
91 # cleanup config changes
92 cd ~/onos/tools/package/config
93 git clean -df'''
94
95 // For the Wiki page
96 sh '''#!/bin/bash -i
Devin Lima0e52eb2017-09-13 18:35:12 -070097 set +e
Devin Lim90803a82017-08-29 13:41:44 -070098 echo "ONOS Branch is: ${ONOSBranch}"
99 echo "TestON Branch is: ${TestONBranch}"
100
101 echo "Job name is: "''' + testName + '''
102 echo "Workspace is: ${WORKSPACE}/"
103
104 echo "Wiki page to post is: ${WikiPrefix}-"
105
106 # remove any leftover files from previous tests
107 sudo rm ${WORKSPACE}/*Wiki.txt
108 sudo rm ${WORKSPACE}/*Summary.txt
109 sudo rm ${WORKSPACE}/*Result.txt
110 sudo rm ${WORKSPACE}/*.csv
111
112 #copy files to workspace
113 cd `ls -t ~/OnosSystemTest/TestON/logs/*/ | head -1 | sed 's/://'`
114 sudo cp *.txt ${WORKSPACE}/
115 sudo cp *.csv ${WORKSPACE}/
116 cd ${WORKSPACE}/
117 for i in *.csv
118 do mv "$i" "$WikiPrefix"-"$i"
119 done
120 ls -al
121 cd '''
Devin Lim3ebd5e72017-11-14 10:38:00 -0800122 if( prop["manualRun"] == "false" || prop["postResult"] == "true" ){
Devin Lim90803a82017-08-29 13:41:44 -0700123 // Post Results
124 withCredentials([
125 string(credentialsId: 'db_pass', variable: 'pass'),
126 string(credentialsId: 'db_user', variable: 'user'),
127 string(credentialsId: 'db_host', variable: 'host'),
128 string(credentialsId: 'db_port', variable: 'port')]) {
129 def database_command = pass + "|psql --host=" + host + " --port=" + port + " --username=" + user + " --password --dbname onostest -c \"INSERT INTO " + table_name + " VALUES('\$DATE','" + result_name + "','" + testName + "',\$BUILD_NUMBER, '\$ONOSBranch', \$line);\""
130
131 sh '''#!/bin/bash
Devin Lim90803a82017-08-29 13:41:44 -0700132 export DATE=\$(date +%F_%T)
133 cd ~
134 pwd
135 sed 1d ''' + workSpace + "/" + prop["WikiPrefix"] + "-" + testName + '''.csv | while read line
136 do
137 echo \$line
138 echo ''' + database_command + '''
139
140 done
141 Rscript ''' + graph_generator_file + " " + host + " " + port + " " + user + " " + pass + " " + testName + " " + prop["ONOSBranch"] + " 20 " + graph_saved_directory
142
143 }
144 }
145 // Fetch Logs
146 sh '''#!/bin/bash
Devin Lima0e52eb2017-09-13 18:35:12 -0700147 set +e
Devin Lim90803a82017-08-29 13:41:44 -0700148 cd ~/OnosSystemTest/TestON/logs
149 echo "Job Name is: " + ''' + testName + '''
150 TestONlogDir=$(ls -t | grep ${TEST_NAME}_ |head -1)
151 echo "########################################################################################"
152 echo "##### copying ONOS logs from all nodes to TestON/logs directory: ${TestONlogDir}"
153 echo "########################################################################################"
154 cd $TestONlogDir
155 if [ $? -eq 1 ]
156 then
157 echo "Job name does not match any test suite name to move log!"
158 else
159 pwd
160 for i in $OC{1..7}; do onos-fetch-logs $i || echo log does not exist; done
161 fi
162 cd'''
163 fileContents = readFile workSpace+"/"+FUNC[testName]['wiki_file']
164 }
165 }
166
Devin Lim3ebd5e72017-11-14 10:38:00 -0800167 if( prop["manualRun"] == "false" || prop["postResult"] == "true" ){
Devin Lim90803a82017-08-29 13:41:44 -0700168 def post = build job: "Pipeline_postjob_VM", propagate: false,
169 parameters: [
170 string(name: 'Wiki_Contents', value: fileContents),
171 string(name: 'Wiki_Link', value: FUNC[testName]['wiki_link'])
172 ]
173 }
174 node("TestStation-VMs"){
Devin Lim79af50f2017-10-26 14:26:47 -0700175 resultContents = readFile workSpace + "/" + testName + "Result.txt"
176 resultContents = resultContents.split("\n")
177 if( resultContents[ 0 ] == "1" ){
178 print "All passed"
179 }else{
180 print "Failed"
181 if( prop["manualRun"] == "false" )
182 slackSend(color:"FF0000", message: "[" + prop["ONOSBranch"] + "]" + testName + " : Failed!\n"
183 + resultContents[ 1 ] + "\n"
184 + "https://onos-jenkins.onlab.us/blue/organizations/jenkins/${env.JOB_NAME}/detail/${env.JOB_NAME}/${env.BUILD_NUMBER}/pipeline" )
185 Failed
186 }
Devin Lim90803a82017-08-29 13:41:44 -0700187 }
188 }
189 }
Devin Lim90803a82017-08-29 13:41:44 -0700190 }
191 }
192}