blob: 3555299cd15c91fa00855633e9cb8455faacbce8 [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"],
18"FUNCintentRest" : [wiki_link:prop["WikiPrefix"]+"-"+"FUNCintentRest", wiki_file:"FUNCintentRestWiki.txt"]
19]
20table_name = "executed_test_tests"
21result_name = "executed_test_results"
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -070022graph_generator_file = "~/OnosSystemTest/TestON/JenkinsFile/scripts/testCaseGraphGenerator.R"
Devin Lim90803a82017-08-29 13:41:44 -070023graph_saved_directory = "/var/jenkins/workspace/Pipeline_postjob_VM/"
24echo("Testcases:")
25def testsToRun = null
26testsToRun = prop["Tests"].tokenize("\n;, ")
27
28for ( String test : testsToRun ) {
29 println test
30}
31def tests = [:]
32for( String test : FUNC.keySet() ){
33 toBeRun = testsToRun.contains( test )
34 def stepName = ( toBeRun ? "" : "Not " ) + "Running $test"
35 tests[stepName] = FUNCTest(test, toBeRun, prop)
36}
37
Devin Lim61657e42017-10-09 17:24:40 -070038def now = new Date()
Devin Lim90803a82017-08-29 13:41:44 -070039// run the tests
40for ( test in tests.keySet() ){
41 tests[test].call()
42}
Devin Lim79af50f2017-10-26 14:26:47 -070043try{
44 if( prop["manualRun"] == "false" ){
45 def end = new Date()
46 TimeDuration duration = TimeCategory.minus( end, now )
47 slackSend( color:"#5816EE", message: "FUNC tests ended at: " + end.toString() + "\nTime took : " + duration )
48 }
Devin Lim61657e42017-10-09 17:24:40 -070049}
Devin Lim79af50f2017-10-26 14:26:47 -070050catch(all){}
Devin Lim90803a82017-08-29 13:41:44 -070051// The testName should be the key from the FUNC
52def FUNCTest( testName, toBeRun, prop ) {
53 return {
Devin Lim79af50f2017-10-26 14:26:47 -070054 catchError{
Devin Lim90803a82017-08-29 13:41:44 -070055 stage(testName) {
56 if ( toBeRun ){
57 workSpace = "/var/jenkins/workspace/"+testName
58 def fileContents = ""
59 node("TestStation-VMs"){
60 withEnv(['ONOSBranch='+prop["ONOSBranch"],
61 'ONOSJVMHeap='+prop["ONOSJVMHeap"],
62 'TestONBranch='+prop["TestONBranch"],
63 'ONOSTag='+prop["ONOSTag"],
64 'WikiPrefix='+prop["WikiPrefix"],
65 'WORKSPACE='+workSpace]){
66 sh '''#!/bin/bash -l
67 set -i # interactive
Devin Lima0e52eb2017-09-13 18:35:12 -070068 set +e
Devin Lim90803a82017-08-29 13:41:44 -070069 shopt -s expand_aliases # expand alias in non-interactive mode
70 export PYTHONUNBUFFERED=1
71
72 ifconfig
73
74 echo "ONOS Branch is: $ONOSBranch"
75 echo "TestON Branch is: $TestONBranch"
76 echo "Test date: "
77 date
78
79 cd ~
80 export PATH=$PATH:onos/tools/test/bin
81
82 timeout 240 stc shutdown | head -100
83 timeout 240 stc teardown | head -100
84 timeout 240 stc shutdown | head -100
85
86 cd ~/OnosSystemTest/TestON/bin
87 git log |head
88 ./cleanup.sh
89 ''' + "./cli.py run " + testName + '''
90 # cleanup config changes
91 cd ~/onos/tools/package/config
92 git clean -df'''
93
94 // For the Wiki page
95 sh '''#!/bin/bash -i
Devin Lima0e52eb2017-09-13 18:35:12 -070096 set +e
Devin Lim90803a82017-08-29 13:41:44 -070097 echo "ONOS Branch is: ${ONOSBranch}"
98 echo "TestON Branch is: ${TestONBranch}"
99
100 echo "Job name is: "''' + testName + '''
101 echo "Workspace is: ${WORKSPACE}/"
102
103 echo "Wiki page to post is: ${WikiPrefix}-"
104
105 # remove any leftover files from previous tests
106 sudo rm ${WORKSPACE}/*Wiki.txt
107 sudo rm ${WORKSPACE}/*Summary.txt
108 sudo rm ${WORKSPACE}/*Result.txt
109 sudo rm ${WORKSPACE}/*.csv
110
111 #copy files to workspace
112 cd `ls -t ~/OnosSystemTest/TestON/logs/*/ | head -1 | sed 's/://'`
113 sudo cp *.txt ${WORKSPACE}/
114 sudo cp *.csv ${WORKSPACE}/
115 cd ${WORKSPACE}/
116 for i in *.csv
117 do mv "$i" "$WikiPrefix"-"$i"
118 done
119 ls -al
120 cd '''
121 if( prop["manualRun"] == "false" ){
122 // Post Results
123 withCredentials([
124 string(credentialsId: 'db_pass', variable: 'pass'),
125 string(credentialsId: 'db_user', variable: 'user'),
126 string(credentialsId: 'db_host', variable: 'host'),
127 string(credentialsId: 'db_port', variable: 'port')]) {
128 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);\""
129
130 sh '''#!/bin/bash
Devin Lim90803a82017-08-29 13:41:44 -0700131 export DATE=\$(date +%F_%T)
132 cd ~
133 pwd
134 sed 1d ''' + workSpace + "/" + prop["WikiPrefix"] + "-" + testName + '''.csv | while read line
135 do
136 echo \$line
137 echo ''' + database_command + '''
138
139 done
140 Rscript ''' + graph_generator_file + " " + host + " " + port + " " + user + " " + pass + " " + testName + " " + prop["ONOSBranch"] + " 20 " + graph_saved_directory
141
142 }
143 }
144 // Fetch Logs
145 sh '''#!/bin/bash
Devin Lima0e52eb2017-09-13 18:35:12 -0700146 set +e
Devin Lim90803a82017-08-29 13:41:44 -0700147 cd ~/OnosSystemTest/TestON/logs
148 echo "Job Name is: " + ''' + testName + '''
149 TestONlogDir=$(ls -t | grep ${TEST_NAME}_ |head -1)
150 echo "########################################################################################"
151 echo "##### copying ONOS logs from all nodes to TestON/logs directory: ${TestONlogDir}"
152 echo "########################################################################################"
153 cd $TestONlogDir
154 if [ $? -eq 1 ]
155 then
156 echo "Job name does not match any test suite name to move log!"
157 else
158 pwd
159 for i in $OC{1..7}; do onos-fetch-logs $i || echo log does not exist; done
160 fi
161 cd'''
162 fileContents = readFile workSpace+"/"+FUNC[testName]['wiki_file']
163 }
164 }
165
166 if( prop["manualRun"] == "false" ){
167 def post = build job: "Pipeline_postjob_VM", propagate: false,
168 parameters: [
169 string(name: 'Wiki_Contents', value: fileContents),
170 string(name: 'Wiki_Link', value: FUNC[testName]['wiki_link'])
171 ]
172 }
173 node("TestStation-VMs"){
Devin Lim79af50f2017-10-26 14:26:47 -0700174 resultContents = readFile workSpace + "/" + testName + "Result.txt"
175 resultContents = resultContents.split("\n")
176 if( resultContents[ 0 ] == "1" ){
177 print "All passed"
178 }else{
179 print "Failed"
180 if( prop["manualRun"] == "false" )
181 slackSend(color:"FF0000", message: "[" + prop["ONOSBranch"] + "]" + testName + " : Failed!\n"
182 + resultContents[ 1 ] + "\n"
183 + "https://onos-jenkins.onlab.us/blue/organizations/jenkins/${env.JOB_NAME}/detail/${env.JOB_NAME}/${env.BUILD_NUMBER}/pipeline" )
184 Failed
185 }
Devin Lim90803a82017-08-29 13:41:44 -0700186 }
187 }
188 }
Devin Lim90803a82017-08-29 13:41:44 -0700189 }
190 }
191}