blob: 26e846c3583ece792f40a98e17ff42637749e263 [file] [log] [blame]
Devin Lime1346f42018-05-15 15:41:36 -07001#!groovy
Devin Limf5175192018-05-14 19:13:22 -07002// Copyright 2017 Open Networking Foundation (ONF)
3//
4// Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>,
5// the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>,
6// or the System Testing Guide page at <https://wiki.onosproject.org/x/WYQg>
7//
8// TestON is free software: you can redistribute it and/or modify
9// it under the terms of the GNU General Public License as published by
10// the Free Software Foundation, either version 2 of the License, or
11// (at your option) any later version.
12//
13// TestON is distributed in the hope that it will be useful,
14// but WITHOUT ANY WARRANTY; without even the implied warranty of
15// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16// GNU General Public License for more details.
17//
18// You should have received a copy of the GNU General Public License
19// along with TestON. If not, see <http://www.gnu.org/licenses/>.
20
21// This is the dependency Jenkins script.
22// it has some common functions that runs test and generate graph.
23
Jon Hall6af749d2018-05-29 12:59:47 -070024import groovy.time.TimeCategory
25import groovy.time.TimeDuration
26
Devin Limb734ea52018-05-14 14:13:05 -070027generalFuncs = evaluate readTrusted( 'TestON/JenkinsFile/dependencies/GeneralFuncs.groovy' )
28fileRelated = evaluate readTrusted( 'TestON/JenkinsFile/dependencies/JenkinsPathAndFiles.groovy' )
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -070029test_list = evaluate readTrusted( 'TestON/JenkinsFile/dependencies/JenkinsTestONTests.groovy' )
Devin Limfe9a4cb2018-05-11 17:06:21 -070030
31fileRelated.init()
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -070032test_list.init()
Jeremy Ronquillo14ecc172018-03-05 09:57:17 -080033
Jeremy Ronquillo6fbfdd52019-07-09 13:49:34 -070034nodeLabel = null
35testStation = null
36
Devin Lim61643762017-12-07 15:55:38 -080037def initializeTrend( machine ){
Jon Hall6af749d2018-05-29 12:59:47 -070038 // For initializing any trend graph jobs
39 // machine : Either VM,BM, or Fabric#
Devin Limf5175192018-05-14 19:13:22 -070040
Jon Hall6af749d2018-05-29 12:59:47 -070041 table_name = "executed_test_tests"
42 result_name = "executed_test_results"
Jeremy Ronquillo6fbfdd52019-07-09 13:49:34 -070043 testStation = "TestStation-" + machine + "s"
Jon Hall6af749d2018-05-29 12:59:47 -070044 this.machine = machine
45 isSCPF = false
46 isTrend = true
Devin Lim61643762017-12-07 15:55:38 -080047}
Jon Hall6af749d2018-05-29 12:59:47 -070048
Jeremy Ronquillo6fbfdd52019-07-09 13:49:34 -070049def initialize( type, testS, nodeL, SCPFfuncs=null ){
Jon Hall6af749d2018-05-29 12:59:47 -070050 // initializing for FUNC,HA,SR, and USECASE
51 // type : type of the test ( SR,FUNC,SCPF... )
Devin Limf5175192018-05-14 19:13:22 -070052
Jeremy Ronquillo6fbfdd52019-07-09 13:49:34 -070053 testStation = testS
54 testType = type
55 nodeLabel = nodeL
Jeremy Ronquilloc6a862f2019-07-02 15:53:44 -070056 isSCPF = ( type == "SCPF" )
Jeremy Ronquillo62199e72019-07-02 14:24:31 -070057 SCPFfunc = SCPFfuncs
58
Jon Hall6af749d2018-05-29 12:59:47 -070059 table_name = "executed_test_tests"
60 result_name = "executed_test_results"
Jeremy Ronquillo1e5d7f22019-07-17 14:18:42 -070061 trend_generator_file = fileRelated.rScriptPaths[ "scripts" ][ "trendMultiple" ]
62 build_stats_generator_file = fileRelated.rScriptPaths[ "scripts" ][ "histogramMultiple" ]
Jon Hall6af749d2018-05-29 12:59:47 -070063 isTrend = false
Devin Lim61643762017-12-07 15:55:38 -080064}
Jon Hall6af749d2018-05-29 12:59:47 -070065
Jeremy Ronquillo21c29fc2019-06-05 11:15:24 -070066def getProperties( category, branchWithPrefix ){
Jon Hall6af749d2018-05-29 12:59:47 -070067 // get the properties of the test by reading the TestONOS.property
68
Jeremy Ronquillo21c29fc2019-06-05 11:15:24 -070069 filePath = '''/var/jenkins/TestONOS-''' + category + '''-''' + branchWithPrefix + '''.property'''
70
Jeremy Ronquillo6fbfdd52019-07-09 13:49:34 -070071 node( testStation ) {
Jeremy Ronquillo21c29fc2019-06-05 11:15:24 -070072 return readProperties( file: filePath )
Jon Hall6af749d2018-05-29 12:59:47 -070073 }
74}
75
76def getTestsToRun( testList ){
77 // get test to run by tokenizing the list.
78
79 testList.tokenize( "\n;, " )
80}
81
82def getCurrentTime(){
83 // get time of the PST zone.
84
85 TimeZone.setDefault( TimeZone.getTimeZone( 'PST' ) )
86 return new Date()
87}
88
Jon Hall6af749d2018-05-29 12:59:47 -070089def sendResultToSlack( start, isManualRun, branch ){
90 // send the result of the test to the slack when it is not manually running.
91 // start : start time of the test
92 // isManualRun : string that is whether "false" or "true"
93 // branch : branch of the onos.
94
95 try {
96 if ( isManualRun == "false" ){
97 end = getCurrentTime()
98 TimeDuration duration = TimeCategory.minus( end, start )
You Wang28cb8552019-02-19 16:11:52 -080099 // FIXME: for now we disable notifications of normal test results
100 /*
Jon Hall6af749d2018-05-29 12:59:47 -0700101 slackSend( color: "#5816EE",
102 message: testType + "-" + branch + " tests ended at: " + end.toString() +
103 "\nTime took : " + duration )
You Wang28cb8552019-02-19 16:11:52 -0800104 */
Jon Hall6af749d2018-05-29 12:59:47 -0700105 }
106 }
107 catch ( all ){
108 }
109}
110
111def initAndRunTest( testName, testCategory ){
112 // Bash script that will
113 // Initialize the environment to the machine and run the test.
114 // testName : name of the test
115 // testCategory : (SR,FUNC ... )
116
117 return '''#!/bin/bash -l
Devin Lim61643762017-12-07 15:55:38 -0800118 set -i # interactive
119 set +e
120 shopt -s expand_aliases # expand alias in non-interactive mode
121 export PYTHONUNBUFFERED=1
122 ifconfig
Devin Lim61643762017-12-07 15:55:38 -0800123 echo "ONOS Branch is: $ONOSBranch"
124 echo "TestON Branch is: $TestONBranch"
125 echo "Test date: "
126 date
127 cd ~
128 export PATH=$PATH:onos/tools/test/bin
129 timeout 240 stc shutdown | head -100
130 timeout 240 stc teardown | head -100
131 timeout 240 stc shutdown | head -100
132 cd ~/OnosSystemTest/TestON/bin
Jon Hall2ee92f82018-06-07 13:07:33 -0700133 git log | head
Devin Lim61643762017-12-07 15:55:38 -0800134 ./cleanup.sh -f
Jon Hall6af749d2018-05-29 12:59:47 -0700135 ''' + "./cli.py run " +
Jeremy Ronquillo62199e72019-07-02 14:24:31 -0700136 testName +
Jeremy Ronquillo6fbfdd52019-07-09 13:49:34 -0700137 " --params GRAPH/nodeCluster=" + nodeLabel + '''
Devin Lim61643762017-12-07 15:55:38 -0800138 ./cleanup.sh -f
139 # cleanup config changes
140 cd ~/onos/tools/package/config
141 git clean -df'''
142}
Devin Limf5175192018-05-14 19:13:22 -0700143
Jon Hall8b1e92c2018-06-13 14:07:22 -0700144def copyLogs(){
145 // bash script to copy the logs and other necessary element for SR tests.
Jon Hall6af749d2018-05-29 12:59:47 -0700146
147 result = ""
148 if ( testType == "SR" ){
149 result = '''
Devin Lim61643762017-12-07 15:55:38 -0800150 sudo rm /var/jenkins/workspace/SR-log-${WikiPrefix}/*
151 sudo cp *karaf.log.* /var/jenkins/workspace/SR-log-${WikiPrefix}/
152 sudo cp *Flows* /var/jenkins/workspace/SR-log-${WikiPrefix}/
153 sudo cp *Groups* /var/jenkins/workspace/SR-log-${WikiPrefix}/
Devin Lima7b97a42018-04-09 14:26:38 -0700154 sudo cp *.tar.gz /var/jenkins/workspace/SR-log-${WikiPrefix}/
Devin Lim6faa3f92018-05-01 13:16:25 -0700155 sudo cp t3-* /var/jenkins/workspace/SR-log-${WikiPrefix}/
Devin Lim61643762017-12-07 15:55:38 -0800156 '''
Jon Hall6af749d2018-05-29 12:59:47 -0700157 }
158 return result
Devin Lim61643762017-12-07 15:55:38 -0800159}
Devin Limf5175192018-05-14 19:13:22 -0700160
Jon Hall6af749d2018-05-29 12:59:47 -0700161def cleanAndCopyFiles( testName ){
162 // clean up some files that were in the folder and copy the new files from the log
163 // testName : name of the test
164
165 return '''#!/bin/bash -i
Devin Lim61643762017-12-07 15:55:38 -0800166 set +e
167 echo "ONOS Branch is: ${ONOSBranch}"
168 echo "TestON Branch is: ${TestONBranch}"
169 echo "Job name is: "''' + testName + '''
170 echo "Workspace is: ${WORKSPACE}/"
171 echo "Wiki page to post is: ${WikiPrefix}-"
172 # remove any leftover files from previous tests
173 sudo rm ${WORKSPACE}/*Wiki.txt
174 sudo rm ${WORKSPACE}/*Summary.txt
175 sudo rm ${WORKSPACE}/*Result.txt
You Wangaa7bc722019-02-21 17:55:39 -0800176 sudo rm ${WORKSPACE}/*Alarm.txt || true
Devin Lim61643762017-12-07 15:55:38 -0800177 sudo rm ${WORKSPACE}/*.csv
178 #copy files to workspace
179 cd `ls -t ~/OnosSystemTest/TestON/logs/*/ | head -1 | sed 's/://'`
Jon Hall8b1e92c2018-06-13 14:07:22 -0700180 ''' + copyLogs() + '''
Devin Lim61643762017-12-07 15:55:38 -0800181 sudo cp *.txt ${WORKSPACE}/
182 sudo cp *.csv ${WORKSPACE}/
183 cd ${WORKSPACE}/
184 for i in *.csv
185 do mv "$i" "$WikiPrefix"-"$i"
186 done
187 ls -al
188 cd '''
189}
Devin Limf5175192018-05-14 19:13:22 -0700190
Jon Hall6af749d2018-05-29 12:59:47 -0700191def fetchLogs( testName ){
192 // fetch the logs of onos from onos nodes to onos System Test logs
193 // testName: name of the test
194
195 return '''#!/bin/bash
Devin Lim61643762017-12-07 15:55:38 -0800196 set +e
197 cd ~/OnosSystemTest/TestON/logs
Jon Hall8b1e92c2018-06-13 14:07:22 -0700198 echo "TestON test name is: "''' + testName + '''
Devin Lim61643762017-12-07 15:55:38 -0800199 TestONlogDir=$(ls -t | grep ${TEST_NAME}_ |head -1)
200 echo "########################################################################################"
201 echo "##### copying ONOS logs from all nodes to TestON/logs directory: ${TestONlogDir}"
202 echo "########################################################################################"
203 cd $TestONlogDir
204 if [ $? -eq 1 ]
205 then
206 echo "Job name does not match any test suite name to move log!"
207 else
208 pwd
Jon Hall3e6edb32018-08-21 16:20:30 -0700209 for i in $OC{1..7}; do onos-fetch-logs $i || echo log does not exist for onos $i; done
210 for i in $OC{1..7}; do atomix-fetch-logs $i || echo log does not exist for atomix $i; done
Devin Lim61643762017-12-07 15:55:38 -0800211 fi
212 cd'''
213}
Jon Hall6af749d2018-05-29 12:59:47 -0700214
Devin Lim61643762017-12-07 15:55:38 -0800215def isPostingResult( manual, postresult ){
Jon Hall6af749d2018-05-29 12:59:47 -0700216 // check if it is posting the result.
217 // posting when it is automatically running or has postResult condition from the manual run
Devin Limf5175192018-05-14 19:13:22 -0700218
Jon Hall6af749d2018-05-29 12:59:47 -0700219 return manual == "false" || postresult == "true"
Devin Lim61643762017-12-07 15:55:38 -0800220}
Jon Hall6af749d2018-05-29 12:59:47 -0700221
Devin Lim61643762017-12-07 15:55:38 -0800222def postResult( prop, graphOnly ){
Jon Hall6af749d2018-05-29 12:59:47 -0700223 // post the result by triggering postjob.
224 // prop : property dictionary that was read from the machine.
225 // graphOnly : if it is graph generating job
Jeremy Ronquillobd26bdb2019-07-08 16:15:45 -0700226
Jeremy Ronquillo6fbfdd52019-07-09 13:49:34 -0700227 if ( graphOnly || isPostingResult( prop[ "manualRun" ], prop[ "postResult" ] ) ){
Jeremy Ronquillo35562ef2019-07-22 11:08:29 -0700228 postjob_type = ""
229 switch ( nodeLabel ){
230 case "Fabric-1.x":
231 postjob_type = "Fabric2"
232 break
233 case "Fabric-2.x":
234 postjob_type = "Fabric3"
235 break
236 case "Fabric-master":
237 postjob_type = "Fabric4"
238 break
239 default:
240 postjob_type = nodeLabel
241 break
242 }
243
244 def post = build job: "postjob-" + postjob_type, propagate: false
Devin Lim61643762017-12-07 15:55:38 -0800245 }
Devin Lim61643762017-12-07 15:55:38 -0800246}
Jon Hall6af749d2018-05-29 12:59:47 -0700247
248def postLogs( testName, prefix ){
249 // posting logs of the onos jobs specifically SR tests
250 // testName : name of the test
You Wangf043d0a2019-04-22 16:30:40 -0700251 // prefix : branch prefix ( master, 2.1, 1.15 ... )
Jon Hall6af749d2018-05-29 12:59:47 -0700252
253 resultURL = ""
254 if ( testType == "SR" ){
255 def post = build job: "SR-log-" + prefix, propagate: false
256 resultURL = post.getAbsoluteUrl()
257 }
258 return resultURL
259}
260
261def getSlackChannel(){
262 // get name of the slack channel.
263 // if the test is SR, it will return sr-failures
264
You Wang28cb8552019-02-19 16:11:52 -0800265 // FIXME: For now we move all notifications to #jenkins-related
266 // return "#" + ( testType == "SR" ? "sr-failures" : "jenkins-related" )
267 return "#jenkins-related"
Jon Hall6af749d2018-05-29 12:59:47 -0700268}
269
Jon Hall8b1e92c2018-06-13 14:07:22 -0700270def analyzeResult( prop, workSpace, pureTestName, testName, resultURL, wikiLink, isSCPF ){
You Wang28cb8552019-02-19 16:11:52 -0800271 // analyzing the result of the test and send to slack if any abnormal result is logged.
Jon Hall6af749d2018-05-29 12:59:47 -0700272 // prop : property dictionary
273 // workSpace : workSpace where the result file is saved
Jon Hall8b1e92c2018-06-13 14:07:22 -0700274 // pureTestName : TestON name of the test
275 // testName : Jenkins name of the test. Example: SCPFflowTPFobj
Jon Hall6af749d2018-05-29 12:59:47 -0700276 // resultURL : url for the logs for SR tests. Will not be posted if it is empty
277 // wikiLink : link of the wiki page where the result was posted
278 // isSCPF : Check if it is SCPF. If so, it won't post the wiki link.
279
Jeremy Ronquillo6fbfdd52019-07-09 13:49:34 -0700280 node( testStation ) {
You Wang28cb8552019-02-19 16:11:52 -0800281 def alarmFile = workSpace + "/" + pureTestName + "Alarm.txt"
282 if ( fileExists( alarmFile ) ) {
You Wang28cb8552019-02-19 16:11:52 -0800283 def alarmContents = readFile( alarmFile )
You Wang2dcde682019-02-21 12:18:15 -0800284 slackSend( channel: getSlackChannel(),
285 color: "FF0000",
286 message: "[" + prop[ "ONOSBranch" ] + "]" + testName + " : triggered alarms:\n" +
287 alarmContents + "\n" +
288 "[TestON log] : \n" +
289 "https://jenkins.onosproject.org/blue/organizations/jenkins/${ env.JOB_NAME }/detail/${ env.JOB_NAME }/${ env.BUILD_NUMBER }/pipeline" +
290 ( isSCPF ? "" : ( "\n[Result on Wiki] : \n" +
291 "https://wiki.onosproject.org/display/ONOS/" +
292 wikiLink.replaceAll( "\\s", "+" ) ) ) +
293 ( resultURL != "" ? ( "\n[Karaf log] : \n" +
294 resultURL + "artifact/" ) : "" ),
295 teamDomain: 'onosproject' )
Jeremy Ronquillo21c29fc2019-06-05 11:15:24 -0700296 throw new Exception( "Abnormal test result." )
Jon Hall6af749d2018-05-29 12:59:47 -0700297 }
You Wang28cb8552019-02-19 16:11:52 -0800298 else {
Jeremy Ronquillo06950992019-07-09 11:16:49 -0700299 print "Test results are OK."
You Wang28cb8552019-02-19 16:11:52 -0800300 }
Jon Hall6af749d2018-05-29 12:59:47 -0700301 }
302}
303
Devin Lime89761a2018-03-16 17:52:57 -0700304def publishToConfluence( isManualRun, isPostResult, wikiLink, file ){
Jon Hall6af749d2018-05-29 12:59:47 -0700305 // publish HTML script to wiki confluence
306 // isManualRun : string "true" "false"
307 // isPostResult : string "true" "false"
308 // wikiLink : link of the wiki page to publish
309 // file : name of the file to be published
Devin Limf5175192018-05-14 19:13:22 -0700310
Jon Hall6af749d2018-05-29 12:59:47 -0700311 if ( isPostingResult( isManualRun, isPostResult ) ){
312 publishConfluence siteName: 'wiki.onosproject.org', pageName: wikiLink, spaceName: 'ONOS',
313 attachArchivedArtifacts: true, buildIfUnstable: true,
314 editorList: [ confluenceWritePage( confluenceFile( file ) ) ]
315 }
Devin Lim61643762017-12-07 15:55:38 -0800316
317}
Devin Limf5175192018-05-14 19:13:22 -0700318
Jon Hall6af749d2018-05-29 12:59:47 -0700319def runTest( testName, toBeRun, prop, pureTestName, graphOnly, testCategory, graph_generator_file,
320 graph_saved_directory ){
321 // run the test on the machine that contains all the steps : init and run test, copy files, publish result ...
Jon Hall8b1e92c2018-06-13 14:07:22 -0700322 // testName : name of the test in Jenkins
Jon Hall6af749d2018-05-29 12:59:47 -0700323 // toBeRun : boolean value whether the test will be run or not. If not, it won't be run but shows up with empty
324 // result on pipeline view
325 // prop : dictionary property on the machine
326 // pureTestName : Pure name of the test. ( ex. pureTestName of SCPFflowTpFobj will be SCPFflowTp )
327 // graphOnly : check if it is generating graph job. If so, it will only generate the generating graph part
Jon Hall2ee92f82018-06-07 13:07:33 -0700328 // testCategory : Map for the test suit ( SCPF, SR, FUNC, ... ) which contains information about the tests
Jon Hall6af749d2018-05-29 12:59:47 -0700329 // graph_generator_file : Rscript file with the full path.
330 // graph_saved_directory : where the generated graph will be saved to.
331
332 return {
333 catchError {
334 stage( testName ) {
335 if ( toBeRun ){
336 def workSpace = "/var/jenkins/workspace/" + testName
337 def fileContents = ""
Jeremy Ronquillo6fbfdd52019-07-09 13:49:34 -0700338 node( testStation ) {
Jon Hall6af749d2018-05-29 12:59:47 -0700339 withEnv( [ 'ONOSBranch=' + prop[ "ONOSBranch" ],
You Wang8e4f4c02019-01-03 10:49:46 -0800340 'ONOSJAVAOPTS=' + prop[ "ONOSJAVAOPTS" ],
Jon Hall6af749d2018-05-29 12:59:47 -0700341 'TestONBranch=' + prop[ "TestONBranch" ],
342 'ONOSTag=' + prop[ "ONOSTag" ],
343 'WikiPrefix=' + prop[ "WikiPrefix" ],
344 'WORKSPACE=' + workSpace ] ) {
345 if ( !graphOnly ){
You Wang6d171942018-10-17 11:45:05 -0700346 if ( isSCPF ){
347 // Remove the old database file
348 sh SCPFfunc.cleanupDatabaseFile( testName )
349 }
Jon Hall6af749d2018-05-29 12:59:47 -0700350 sh initAndRunTest( testName, testCategory )
351 // For the Wiki page
352 sh cleanAndCopyFiles( pureTestName )
353 }
Jon Hall8b1e92c2018-06-13 14:07:22 -0700354 databaseAndGraph( prop, testName, pureTestName, graphOnly,
355 graph_generator_file, graph_saved_directory )
Jon Hall6af749d2018-05-29 12:59:47 -0700356 if ( !graphOnly ){
357 sh fetchLogs( pureTestName )
358 if ( !isSCPF ){
359 publishToConfluence( prop[ "manualRun" ], prop[ "postResult" ],
Jeremy Ronquillo5b6279b2019-06-18 14:25:45 -0700360 prop[ "WikiPrefix" ] + "-" + testCategory[ testName ][ 'wikiName' ],
Jeremy Ronquilloa833e962019-06-18 13:50:40 -0700361 workSpace + "/" + testCategory[ testName ][ 'wikiFile' ] )
Jon Hall6af749d2018-05-29 12:59:47 -0700362 }
363 }
Devin Lim61643762017-12-07 15:55:38 -0800364 }
Jon Hall6af749d2018-05-29 12:59:47 -0700365 }
Devin Lim61643762017-12-07 15:55:38 -0800366 postResult( prop, graphOnly )
Jon Hall6af749d2018-05-29 12:59:47 -0700367 if ( !graphOnly ){
Jon Hall8b1e92c2018-06-13 14:07:22 -0700368 def resultURL = postLogs( testName, prop[ "WikiPrefix" ] )
Jon Hall6af749d2018-05-29 12:59:47 -0700369 analyzeResult( prop, workSpace, pureTestName, testName, resultURL,
Jeremy Ronquilloa833e962019-06-18 13:50:40 -0700370 isSCPF ? "" : testCategory[ testName ][ 'wikiName' ],
Jon Hall6af749d2018-05-29 12:59:47 -0700371 isSCPF )
372 }
373 }
374 }
375 }
376 }
Devin Lim61643762017-12-07 15:55:38 -0800377}
Devin Limf5175192018-05-14 19:13:22 -0700378
Jon Hall8b1e92c2018-06-13 14:07:22 -0700379def databaseAndGraph( prop, testName, pureTestName, graphOnly, graph_generator_file, graph_saved_directory ){
Jon Hall6af749d2018-05-29 12:59:47 -0700380 // part where it insert the data into the database.
381 // It will use the predefined encrypted variables from the Jenkins.
382 // prop : property dictionary that was read from the machine
Jon Hall8b1e92c2018-06-13 14:07:22 -0700383 // testName : Jenkins name for the test
384 // pureTestName : TestON name for the test
Jon Hall6af749d2018-05-29 12:59:47 -0700385 // graphOnly : boolean whether it is graph only or not
386 // graph_generator_file : Rscript file with the full path.
387 // graph_saved_directory : where the generated graph will be saved to.
Jon Hall6af749d2018-05-29 12:59:47 -0700388 if ( graphOnly || isPostingResult( prop[ "manualRun" ], prop[ "postResult" ] ) ){
389 // Post Results
390 withCredentials( [
391 string( credentialsId: 'db_pass', variable: 'pass' ),
392 string( credentialsId: 'db_user', variable: 'user' ),
393 string( credentialsId: 'db_host', variable: 'host' ),
394 string( credentialsId: 'db_port', variable: 'port' ) ] ) {
395 def database_command = generalFuncs.database_command_create( pass, host, port, user ) +
396 ( !isSCPF ? sqlCommand( testName ) : SCPFfunc.sqlCommand( testName ) )
397 sh '''#!/bin/bash
Devin Lim61643762017-12-07 15:55:38 -0800398 export DATE=\$(date +%F_%T)
399 cd ~
Jon Hall6af749d2018-05-29 12:59:47 -0700400 pwd ''' + ( graphOnly ? "" :
Jon Hall8b1e92c2018-06-13 14:07:22 -0700401 ( !isSCPF ? databasePart( prop[ "WikiPrefix" ], pureTestName, database_command ) :
Jon Hall6af749d2018-05-29 12:59:47 -0700402 SCPFfunc.databasePart( testName, database_command ) ) ) + '''
403 ''' + ( !isSCPF ? graphGenerating( host, port, user, pass, testName, prop, graph_saved_directory,
404 graph_generator_file ) :
405 SCPFfunc.getGraphGeneratingCommand( host, port, user, pass, testName, prop ) )
Devin Lim61643762017-12-07 15:55:38 -0800406 }
Devin Lim61643762017-12-07 15:55:38 -0800407 }
408}
Jon Hall6af749d2018-05-29 12:59:47 -0700409
410def generateCategoryStatsGraph( testMachineOn, manualRun, postresult, stat_file, pie_file, type, branch, testListPart,
411 save_path, pieTestListPart ){
412 // function that will generate the category stat graphs for the overall test.
413 // testMachineOn : the machine the graph will be generated. It will be TestStation-VMs for the most cases
414 // manualRun : string of "true" or "false"
415 // postresult : string of "true" or "false"
416 // stat_file : file name with full path for Rscript for the stat graph
417 // pie_file : file name with full path for Rscript for the pie graph
418 // type : type of the test ( USECASE, FUNC, HA )
You Wangf043d0a2019-04-22 16:30:40 -0700419 // branch : branch of the test ( master, onos-2.1, onos-1.15 )
Jon Hall6af749d2018-05-29 12:59:47 -0700420 // testListPart : list of the test to be included
421 // save_path : path that will save the graphs to
422 // pieTestListPart : list of the test for pie graph
423
424 if ( isPostingResult( manualRun, postresult ) ){
425 node( testMachineOn ) {
426
427 withCredentials( [
428 string( credentialsId: 'db_pass', variable: 'pass' ),
429 string( credentialsId: 'db_user', variable: 'user' ),
430 string( credentialsId: 'db_host', variable: 'host' ),
431 string( credentialsId: 'db_port', variable: 'port' ) ] ) {
432 sh '''#!/bin/bash
433 ''' + generalFuncs.basicGraphPart( stat_file, host, port, user, pass, type,
434 branch ) + " \"" + testListPart + "\" latest " + save_path + '''
435 ''' + getOverallPieGraph( pie_file, host, port, user, pass, branch, type, pieTestListPart, 'y',
436 save_path ) + '''
437 ''' +
438 getOverallPieGraph( pie_file, host, port, user, pass, branch, type, pieTestListPart, 'n', save_path )
439 }
440 }
441 postResult( [ ], true )
442 }
443}
444
Jon Hall6af749d2018-05-29 12:59:47 -0700445
Jeremy Ronquillo06950992019-07-09 11:16:49 -0700446def generateOverallGraph( prop, tests, graph_saved_directory ){
Jon Hall6af749d2018-05-29 12:59:47 -0700447 // generate the overall graph for the test
Devin Lim61643762017-12-07 15:55:38 -0800448
Jon Hall6af749d2018-05-29 12:59:47 -0700449 if ( isPostingResult( prop[ "manualRun" ], prop[ "postResult" ] ) ){
Jeremy Ronquillo6fbfdd52019-07-09 13:49:34 -0700450 node( testStation ) {
Devin Lim61643762017-12-07 15:55:38 -0800451
Jon Hall6af749d2018-05-29 12:59:47 -0700452 withCredentials( [
453 string( credentialsId: 'db_pass', variable: 'pass' ),
454 string( credentialsId: 'db_user', variable: 'user' ),
455 string( credentialsId: 'db_host', variable: 'host' ),
456 string( credentialsId: 'db_port', variable: 'port' ) ] ) {
Jeremy Ronquillo06950992019-07-09 11:16:49 -0700457 testList = test_list.getTestListAsString( tests )
Jon Hall6af749d2018-05-29 12:59:47 -0700458 sh '''#!/bin/bash
459 ''' +
460 generalFuncs.basicGraphPart( trend_generator_file, host, port,
461 user, pass, testType,
462 prop[ "ONOSBranch" ] ) + " " + testList + " 20 " + graph_saved_directory
463 }
Devin Lim61643762017-12-07 15:55:38 -0800464 }
Jon Hall6af749d2018-05-29 12:59:47 -0700465 postResult( prop, false )
Devin Lim61643762017-12-07 15:55:38 -0800466 }
467}
Jon Hall6af749d2018-05-29 12:59:47 -0700468
Devin Lim61643762017-12-07 15:55:38 -0800469def getOverallPieGraph( file, host, port, user, pass, branch, type, testList, yOrN, path ){
Jon Hall6af749d2018-05-29 12:59:47 -0700470 // Rcommand for the pie graph
Devin Limf5175192018-05-14 19:13:22 -0700471
Jon Hall6af749d2018-05-29 12:59:47 -0700472 return generalFuncs.basicGraphPart( file, host, port, user, pass, type, branch ) +
473 " \"" + testList + "\" latest " + yOrN + " " + path
Devin Lim61643762017-12-07 15:55:38 -0800474}
Jon Hall6af749d2018-05-29 12:59:47 -0700475
Devin Lim61643762017-12-07 15:55:38 -0800476def sqlCommand( testName ){
Jon Hall6af749d2018-05-29 12:59:47 -0700477 // get the inserting sqlCommand for non-SCPF tests.
Devin Limf5175192018-05-14 19:13:22 -0700478
Jon Hall6af749d2018-05-29 12:59:47 -0700479 return "\"INSERT INTO " + table_name + " VALUES('\$DATE','" + result_name + "','" +
480 testName + "',\$BUILD_NUMBER, '\$ONOSBranch', \$line);\" "
Devin Lim61643762017-12-07 15:55:38 -0800481}
Jon Hall6af749d2018-05-29 12:59:47 -0700482
Devin Lim61643762017-12-07 15:55:38 -0800483def graphGenerating( host, port, user, pass, testName, prop, graph_saved_directory, graph_generator_file ){
Jon Hall6af749d2018-05-29 12:59:47 -0700484 // get the graphGenerating R command for non-SCPF tests
Devin Limf5175192018-05-14 19:13:22 -0700485
Jon Hall6af749d2018-05-29 12:59:47 -0700486 return generalFuncs.basicGraphPart( graph_generator_file, host, port, user, pass, testName,
487 prop[ "ONOSBranch" ] ) + " 20 " + graph_saved_directory
Devin Lim61643762017-12-07 15:55:38 -0800488}
Devin Limf5175192018-05-14 19:13:22 -0700489
Jon Hall6af749d2018-05-29 12:59:47 -0700490def databasePart( wikiPrefix, testName, database_command ){
491 // to read and insert the data from .csv to the database
492
493 return '''
Devin Lim61643762017-12-07 15:55:38 -0800494 sed 1d ''' + workSpace + "/" + wikiPrefix + "-" + testName + '''.csv | while read line
495 do
496 echo \$line
497 echo ''' + database_command + '''
498 done '''
499}
Jon Hall6af749d2018-05-29 12:59:47 -0700500
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -0700501def generateStatGraph( testMachineOn, onos_branch, stat_graph_generator_file, pie_graph_generator_file,
Jon Hall6af749d2018-05-29 12:59:47 -0700502 graph_saved_directory ){
Devin Limf5175192018-05-14 19:13:22 -0700503
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -0700504 // Will generate the stats graph.
505 FUNCtestsStr = test_list.getTestListAsString( test_list.getTestsFromCategory( "FUNC" ) )
506 HAtestsStr = test_list.getTestListAsString( test_list.getTestsFromCategory( "HA" ) )
507 USECASEtestsStr = test_list.getTestListAsString( test_list.getTestsFromCategory( "USECASE" ) )
508
509 testListParam = "FUNC-" + FUNCtestsStr + ";" +
510 "HA-" + HAtestsStr + ";" +
511 "USECASE-" + USECASEtestsStr
512
513 pieTestListParam = FUNCtestsStr + "," +
514 HAtestsStr + "," +
515 USECASEtestsStr
516
Jon Hall6af749d2018-05-29 12:59:47 -0700517 generateCategoryStatsGraph( testMachineOn, "false", "true", stat_graph_generator_file, pie_graph_generator_file,
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -0700518 "ALL", onos_branch, testListParam, graph_saved_directory, pieTestListParam )
Jeremy Ronquillo14ecc172018-03-05 09:57:17 -0800519}
Jon Hall6af749d2018-05-29 12:59:47 -0700520
Jon Hall6af749d2018-05-29 12:59:47 -0700521return this