blob: 6b6112dd43d326a05febcaf7075f4c72eacc3a36 [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 Lim61657e42017-10-09 17:24:40 -070043if( prop["manualRun"] == "false" ){
44 def end = new Date()
45 TimeDuration duration = TimeCategory.minus( end, now )
46 slackSend( color:"#5816EE", message: "FUNC tests ended at: " + end.toString() + "\nTime took : " + duration )
47}
Devin Lim90803a82017-08-29 13:41:44 -070048// The testName should be the key from the FUNC
49def FUNCTest( testName, toBeRun, prop ) {
50 return {
Devin Lim61657e42017-10-09 17:24:40 -070051 try{
Devin Lim90803a82017-08-29 13:41:44 -070052 stage(testName) {
53 if ( toBeRun ){
54 workSpace = "/var/jenkins/workspace/"+testName
55 def fileContents = ""
56 node("TestStation-VMs"){
57 withEnv(['ONOSBranch='+prop["ONOSBranch"],
58 'ONOSJVMHeap='+prop["ONOSJVMHeap"],
59 'TestONBranch='+prop["TestONBranch"],
60 'ONOSTag='+prop["ONOSTag"],
61 'WikiPrefix='+prop["WikiPrefix"],
62 'WORKSPACE='+workSpace]){
63 sh '''#!/bin/bash -l
64 set -i # interactive
Devin Lima0e52eb2017-09-13 18:35:12 -070065 set +e
Devin Lim90803a82017-08-29 13:41:44 -070066 shopt -s expand_aliases # expand alias in non-interactive mode
67 export PYTHONUNBUFFERED=1
68
69 ifconfig
70
71 echo "ONOS Branch is: $ONOSBranch"
72 echo "TestON Branch is: $TestONBranch"
73 echo "Test date: "
74 date
75
76 cd ~
77 export PATH=$PATH:onos/tools/test/bin
78
79 timeout 240 stc shutdown | head -100
80 timeout 240 stc teardown | head -100
81 timeout 240 stc shutdown | head -100
82
83 cd ~/OnosSystemTest/TestON/bin
84 git log |head
85 ./cleanup.sh
86 ''' + "./cli.py run " + testName + '''
87 # cleanup config changes
88 cd ~/onos/tools/package/config
89 git clean -df'''
90
91 // For the Wiki page
92 sh '''#!/bin/bash -i
Devin Lima0e52eb2017-09-13 18:35:12 -070093 set +e
Devin Lim90803a82017-08-29 13:41:44 -070094 echo "ONOS Branch is: ${ONOSBranch}"
95 echo "TestON Branch is: ${TestONBranch}"
96
97 echo "Job name is: "''' + testName + '''
98 echo "Workspace is: ${WORKSPACE}/"
99
100 echo "Wiki page to post is: ${WikiPrefix}-"
101
102 # remove any leftover files from previous tests
103 sudo rm ${WORKSPACE}/*Wiki.txt
104 sudo rm ${WORKSPACE}/*Summary.txt
105 sudo rm ${WORKSPACE}/*Result.txt
106 sudo rm ${WORKSPACE}/*.csv
107
108 #copy files to workspace
109 cd `ls -t ~/OnosSystemTest/TestON/logs/*/ | head -1 | sed 's/://'`
110 sudo cp *.txt ${WORKSPACE}/
111 sudo cp *.csv ${WORKSPACE}/
112 cd ${WORKSPACE}/
113 for i in *.csv
114 do mv "$i" "$WikiPrefix"-"$i"
115 done
116 ls -al
117 cd '''
118 if( prop["manualRun"] == "false" ){
119 // Post Results
120 withCredentials([
121 string(credentialsId: 'db_pass', variable: 'pass'),
122 string(credentialsId: 'db_user', variable: 'user'),
123 string(credentialsId: 'db_host', variable: 'host'),
124 string(credentialsId: 'db_port', variable: 'port')]) {
125 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);\""
126
127 sh '''#!/bin/bash
Devin Lim90803a82017-08-29 13:41:44 -0700128 export DATE=\$(date +%F_%T)
129 cd ~
130 pwd
131 sed 1d ''' + workSpace + "/" + prop["WikiPrefix"] + "-" + testName + '''.csv | while read line
132 do
133 echo \$line
134 echo ''' + database_command + '''
135
136 done
137 Rscript ''' + graph_generator_file + " " + host + " " + port + " " + user + " " + pass + " " + testName + " " + prop["ONOSBranch"] + " 20 " + graph_saved_directory
138
139 }
140 }
141 // Fetch Logs
142 sh '''#!/bin/bash
Devin Lima0e52eb2017-09-13 18:35:12 -0700143 set +e
Devin Lim90803a82017-08-29 13:41:44 -0700144 cd ~/OnosSystemTest/TestON/logs
145 echo "Job Name is: " + ''' + testName + '''
146 TestONlogDir=$(ls -t | grep ${TEST_NAME}_ |head -1)
147 echo "########################################################################################"
148 echo "##### copying ONOS logs from all nodes to TestON/logs directory: ${TestONlogDir}"
149 echo "########################################################################################"
150 cd $TestONlogDir
151 if [ $? -eq 1 ]
152 then
153 echo "Job name does not match any test suite name to move log!"
154 else
155 pwd
156 for i in $OC{1..7}; do onos-fetch-logs $i || echo log does not exist; done
157 fi
158 cd'''
159 fileContents = readFile workSpace+"/"+FUNC[testName]['wiki_file']
160 }
161 }
162
163 if( prop["manualRun"] == "false" ){
164 def post = build job: "Pipeline_postjob_VM", propagate: false,
165 parameters: [
166 string(name: 'Wiki_Contents', value: fileContents),
167 string(name: 'Wiki_Link', value: FUNC[testName]['wiki_link'])
168 ]
169 }
170 node("TestStation-VMs"){
171 sh '''#!/bin/bash
172
173 if [ -e ''' + workSpace + "/" + testName + "Result.txt ] && grep -q \"1\" " + workSpace + "/" + testName + "Result.txt" + '''
174 then
175 echo ''' + testName + " : All passed." + '''
176 else
177 echo ''' + testName + " : not all passed." + '''
178 DoingThisToSetTheResultFalse
179 fi'''
180 }
181 }
182 }
Devin Lim61657e42017-10-09 17:24:40 -0700183 }catch (all) {
184 catchError{
185 if( prop["manualRun"] == "false" )
186 slackSend(color:"FF0000", message: "[" + prop["TestONBranch"] + "]" + testName + " : Failed!\nURL:${BUILD_URL}")
187 Failed
188 }
Devin Lim90803a82017-08-29 13:41:44 -0700189 }
190 }
191}