blob: 47359886f1960434125689991c4e5a5b02568e6b [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" ] ) ){
228 def post = build job: "postjob-" + nodeLabel, propagate: false
Devin Lim61643762017-12-07 15:55:38 -0800229 }
Devin Lim61643762017-12-07 15:55:38 -0800230}
Jon Hall6af749d2018-05-29 12:59:47 -0700231
232def postLogs( testName, prefix ){
233 // posting logs of the onos jobs specifically SR tests
234 // testName : name of the test
You Wangf043d0a2019-04-22 16:30:40 -0700235 // prefix : branch prefix ( master, 2.1, 1.15 ... )
Jon Hall6af749d2018-05-29 12:59:47 -0700236
237 resultURL = ""
238 if ( testType == "SR" ){
239 def post = build job: "SR-log-" + prefix, propagate: false
240 resultURL = post.getAbsoluteUrl()
241 }
242 return resultURL
243}
244
245def getSlackChannel(){
246 // get name of the slack channel.
247 // if the test is SR, it will return sr-failures
248
You Wang28cb8552019-02-19 16:11:52 -0800249 // FIXME: For now we move all notifications to #jenkins-related
250 // return "#" + ( testType == "SR" ? "sr-failures" : "jenkins-related" )
251 return "#jenkins-related"
Jon Hall6af749d2018-05-29 12:59:47 -0700252}
253
Jon Hall8b1e92c2018-06-13 14:07:22 -0700254def analyzeResult( prop, workSpace, pureTestName, testName, resultURL, wikiLink, isSCPF ){
You Wang28cb8552019-02-19 16:11:52 -0800255 // analyzing the result of the test and send to slack if any abnormal result is logged.
Jon Hall6af749d2018-05-29 12:59:47 -0700256 // prop : property dictionary
257 // workSpace : workSpace where the result file is saved
Jon Hall8b1e92c2018-06-13 14:07:22 -0700258 // pureTestName : TestON name of the test
259 // testName : Jenkins name of the test. Example: SCPFflowTPFobj
Jon Hall6af749d2018-05-29 12:59:47 -0700260 // resultURL : url for the logs for SR tests. Will not be posted if it is empty
261 // wikiLink : link of the wiki page where the result was posted
262 // isSCPF : Check if it is SCPF. If so, it won't post the wiki link.
263
Jeremy Ronquillo6fbfdd52019-07-09 13:49:34 -0700264 node( testStation ) {
You Wang28cb8552019-02-19 16:11:52 -0800265 def alarmFile = workSpace + "/" + pureTestName + "Alarm.txt"
266 if ( fileExists( alarmFile ) ) {
You Wang28cb8552019-02-19 16:11:52 -0800267 def alarmContents = readFile( alarmFile )
You Wang2dcde682019-02-21 12:18:15 -0800268 slackSend( channel: getSlackChannel(),
269 color: "FF0000",
270 message: "[" + prop[ "ONOSBranch" ] + "]" + testName + " : triggered alarms:\n" +
271 alarmContents + "\n" +
272 "[TestON log] : \n" +
273 "https://jenkins.onosproject.org/blue/organizations/jenkins/${ env.JOB_NAME }/detail/${ env.JOB_NAME }/${ env.BUILD_NUMBER }/pipeline" +
274 ( isSCPF ? "" : ( "\n[Result on Wiki] : \n" +
275 "https://wiki.onosproject.org/display/ONOS/" +
276 wikiLink.replaceAll( "\\s", "+" ) ) ) +
277 ( resultURL != "" ? ( "\n[Karaf log] : \n" +
278 resultURL + "artifact/" ) : "" ),
279 teamDomain: 'onosproject' )
Jeremy Ronquillo21c29fc2019-06-05 11:15:24 -0700280 throw new Exception( "Abnormal test result." )
Jon Hall6af749d2018-05-29 12:59:47 -0700281 }
You Wang28cb8552019-02-19 16:11:52 -0800282 else {
Jeremy Ronquillo06950992019-07-09 11:16:49 -0700283 print "Test results are OK."
You Wang28cb8552019-02-19 16:11:52 -0800284 }
Jon Hall6af749d2018-05-29 12:59:47 -0700285 }
286}
287
Devin Lime89761a2018-03-16 17:52:57 -0700288def publishToConfluence( isManualRun, isPostResult, wikiLink, file ){
Jon Hall6af749d2018-05-29 12:59:47 -0700289 // publish HTML script to wiki confluence
290 // isManualRun : string "true" "false"
291 // isPostResult : string "true" "false"
292 // wikiLink : link of the wiki page to publish
293 // file : name of the file to be published
Devin Limf5175192018-05-14 19:13:22 -0700294
Jon Hall6af749d2018-05-29 12:59:47 -0700295 if ( isPostingResult( isManualRun, isPostResult ) ){
296 publishConfluence siteName: 'wiki.onosproject.org', pageName: wikiLink, spaceName: 'ONOS',
297 attachArchivedArtifacts: true, buildIfUnstable: true,
298 editorList: [ confluenceWritePage( confluenceFile( file ) ) ]
299 }
Devin Lim61643762017-12-07 15:55:38 -0800300
301}
Devin Limf5175192018-05-14 19:13:22 -0700302
Jon Hall6af749d2018-05-29 12:59:47 -0700303def runTest( testName, toBeRun, prop, pureTestName, graphOnly, testCategory, graph_generator_file,
304 graph_saved_directory ){
305 // 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 -0700306 // testName : name of the test in Jenkins
Jon Hall6af749d2018-05-29 12:59:47 -0700307 // toBeRun : boolean value whether the test will be run or not. If not, it won't be run but shows up with empty
308 // result on pipeline view
309 // prop : dictionary property on the machine
310 // pureTestName : Pure name of the test. ( ex. pureTestName of SCPFflowTpFobj will be SCPFflowTp )
311 // 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 -0700312 // testCategory : Map for the test suit ( SCPF, SR, FUNC, ... ) which contains information about the tests
Jon Hall6af749d2018-05-29 12:59:47 -0700313 // graph_generator_file : Rscript file with the full path.
314 // graph_saved_directory : where the generated graph will be saved to.
315
316 return {
317 catchError {
318 stage( testName ) {
319 if ( toBeRun ){
320 def workSpace = "/var/jenkins/workspace/" + testName
321 def fileContents = ""
Jeremy Ronquillo6fbfdd52019-07-09 13:49:34 -0700322 node( testStation ) {
Jon Hall6af749d2018-05-29 12:59:47 -0700323 withEnv( [ 'ONOSBranch=' + prop[ "ONOSBranch" ],
You Wang8e4f4c02019-01-03 10:49:46 -0800324 'ONOSJAVAOPTS=' + prop[ "ONOSJAVAOPTS" ],
Jon Hall6af749d2018-05-29 12:59:47 -0700325 'TestONBranch=' + prop[ "TestONBranch" ],
326 'ONOSTag=' + prop[ "ONOSTag" ],
327 'WikiPrefix=' + prop[ "WikiPrefix" ],
328 'WORKSPACE=' + workSpace ] ) {
329 if ( !graphOnly ){
You Wang6d171942018-10-17 11:45:05 -0700330 if ( isSCPF ){
331 // Remove the old database file
332 sh SCPFfunc.cleanupDatabaseFile( testName )
333 }
Jon Hall6af749d2018-05-29 12:59:47 -0700334 sh initAndRunTest( testName, testCategory )
335 // For the Wiki page
336 sh cleanAndCopyFiles( pureTestName )
337 }
Jon Hall8b1e92c2018-06-13 14:07:22 -0700338 databaseAndGraph( prop, testName, pureTestName, graphOnly,
339 graph_generator_file, graph_saved_directory )
Jon Hall6af749d2018-05-29 12:59:47 -0700340 if ( !graphOnly ){
341 sh fetchLogs( pureTestName )
342 if ( !isSCPF ){
343 publishToConfluence( prop[ "manualRun" ], prop[ "postResult" ],
Jeremy Ronquillo5b6279b2019-06-18 14:25:45 -0700344 prop[ "WikiPrefix" ] + "-" + testCategory[ testName ][ 'wikiName' ],
Jeremy Ronquilloa833e962019-06-18 13:50:40 -0700345 workSpace + "/" + testCategory[ testName ][ 'wikiFile' ] )
Jon Hall6af749d2018-05-29 12:59:47 -0700346 }
347 }
Devin Lim61643762017-12-07 15:55:38 -0800348 }
Jon Hall6af749d2018-05-29 12:59:47 -0700349 }
Devin Lim61643762017-12-07 15:55:38 -0800350 postResult( prop, graphOnly )
Jon Hall6af749d2018-05-29 12:59:47 -0700351 if ( !graphOnly ){
Jon Hall8b1e92c2018-06-13 14:07:22 -0700352 def resultURL = postLogs( testName, prop[ "WikiPrefix" ] )
Jon Hall6af749d2018-05-29 12:59:47 -0700353 analyzeResult( prop, workSpace, pureTestName, testName, resultURL,
Jeremy Ronquilloa833e962019-06-18 13:50:40 -0700354 isSCPF ? "" : testCategory[ testName ][ 'wikiName' ],
Jon Hall6af749d2018-05-29 12:59:47 -0700355 isSCPF )
356 }
357 }
358 }
359 }
360 }
Devin Lim61643762017-12-07 15:55:38 -0800361}
Devin Limf5175192018-05-14 19:13:22 -0700362
Jon Hall8b1e92c2018-06-13 14:07:22 -0700363def databaseAndGraph( prop, testName, pureTestName, graphOnly, graph_generator_file, graph_saved_directory ){
Jon Hall6af749d2018-05-29 12:59:47 -0700364 // part where it insert the data into the database.
365 // It will use the predefined encrypted variables from the Jenkins.
366 // prop : property dictionary that was read from the machine
Jon Hall8b1e92c2018-06-13 14:07:22 -0700367 // testName : Jenkins name for the test
368 // pureTestName : TestON name for the test
Jon Hall6af749d2018-05-29 12:59:47 -0700369 // graphOnly : boolean whether it is graph only or not
370 // graph_generator_file : Rscript file with the full path.
371 // graph_saved_directory : where the generated graph will be saved to.
Jon Hall6af749d2018-05-29 12:59:47 -0700372 if ( graphOnly || isPostingResult( prop[ "manualRun" ], prop[ "postResult" ] ) ){
373 // Post Results
374 withCredentials( [
375 string( credentialsId: 'db_pass', variable: 'pass' ),
376 string( credentialsId: 'db_user', variable: 'user' ),
377 string( credentialsId: 'db_host', variable: 'host' ),
378 string( credentialsId: 'db_port', variable: 'port' ) ] ) {
379 def database_command = generalFuncs.database_command_create( pass, host, port, user ) +
380 ( !isSCPF ? sqlCommand( testName ) : SCPFfunc.sqlCommand( testName ) )
381 sh '''#!/bin/bash
Devin Lim61643762017-12-07 15:55:38 -0800382 export DATE=\$(date +%F_%T)
383 cd ~
Jon Hall6af749d2018-05-29 12:59:47 -0700384 pwd ''' + ( graphOnly ? "" :
Jon Hall8b1e92c2018-06-13 14:07:22 -0700385 ( !isSCPF ? databasePart( prop[ "WikiPrefix" ], pureTestName, database_command ) :
Jon Hall6af749d2018-05-29 12:59:47 -0700386 SCPFfunc.databasePart( testName, database_command ) ) ) + '''
387 ''' + ( !isSCPF ? graphGenerating( host, port, user, pass, testName, prop, graph_saved_directory,
388 graph_generator_file ) :
389 SCPFfunc.getGraphGeneratingCommand( host, port, user, pass, testName, prop ) )
Devin Lim61643762017-12-07 15:55:38 -0800390 }
Devin Lim61643762017-12-07 15:55:38 -0800391 }
392}
Jon Hall6af749d2018-05-29 12:59:47 -0700393
394def generateCategoryStatsGraph( testMachineOn, manualRun, postresult, stat_file, pie_file, type, branch, testListPart,
395 save_path, pieTestListPart ){
396 // function that will generate the category stat graphs for the overall test.
397 // testMachineOn : the machine the graph will be generated. It will be TestStation-VMs for the most cases
398 // manualRun : string of "true" or "false"
399 // postresult : string of "true" or "false"
400 // stat_file : file name with full path for Rscript for the stat graph
401 // pie_file : file name with full path for Rscript for the pie graph
402 // type : type of the test ( USECASE, FUNC, HA )
You Wangf043d0a2019-04-22 16:30:40 -0700403 // branch : branch of the test ( master, onos-2.1, onos-1.15 )
Jon Hall6af749d2018-05-29 12:59:47 -0700404 // testListPart : list of the test to be included
405 // save_path : path that will save the graphs to
406 // pieTestListPart : list of the test for pie graph
407
408 if ( isPostingResult( manualRun, postresult ) ){
409 node( testMachineOn ) {
410
411 withCredentials( [
412 string( credentialsId: 'db_pass', variable: 'pass' ),
413 string( credentialsId: 'db_user', variable: 'user' ),
414 string( credentialsId: 'db_host', variable: 'host' ),
415 string( credentialsId: 'db_port', variable: 'port' ) ] ) {
416 sh '''#!/bin/bash
417 ''' + generalFuncs.basicGraphPart( stat_file, host, port, user, pass, type,
418 branch ) + " \"" + testListPart + "\" latest " + save_path + '''
419 ''' + getOverallPieGraph( pie_file, host, port, user, pass, branch, type, pieTestListPart, 'y',
420 save_path ) + '''
421 ''' +
422 getOverallPieGraph( pie_file, host, port, user, pass, branch, type, pieTestListPart, 'n', save_path )
423 }
424 }
425 postResult( [ ], true )
426 }
427}
428
Jon Hall6af749d2018-05-29 12:59:47 -0700429
Jeremy Ronquillo06950992019-07-09 11:16:49 -0700430def generateOverallGraph( prop, tests, graph_saved_directory ){
Jon Hall6af749d2018-05-29 12:59:47 -0700431 // generate the overall graph for the test
Devin Lim61643762017-12-07 15:55:38 -0800432
Jon Hall6af749d2018-05-29 12:59:47 -0700433 if ( isPostingResult( prop[ "manualRun" ], prop[ "postResult" ] ) ){
Jeremy Ronquillo6fbfdd52019-07-09 13:49:34 -0700434 node( testStation ) {
Devin Lim61643762017-12-07 15:55:38 -0800435
Jon Hall6af749d2018-05-29 12:59:47 -0700436 withCredentials( [
437 string( credentialsId: 'db_pass', variable: 'pass' ),
438 string( credentialsId: 'db_user', variable: 'user' ),
439 string( credentialsId: 'db_host', variable: 'host' ),
440 string( credentialsId: 'db_port', variable: 'port' ) ] ) {
Jeremy Ronquillo06950992019-07-09 11:16:49 -0700441 testList = test_list.getTestListAsString( tests )
Jon Hall6af749d2018-05-29 12:59:47 -0700442 sh '''#!/bin/bash
443 ''' +
444 generalFuncs.basicGraphPart( trend_generator_file, host, port,
445 user, pass, testType,
446 prop[ "ONOSBranch" ] ) + " " + testList + " 20 " + graph_saved_directory
447 }
Devin Lim61643762017-12-07 15:55:38 -0800448 }
Jon Hall6af749d2018-05-29 12:59:47 -0700449 postResult( prop, false )
Devin Lim61643762017-12-07 15:55:38 -0800450 }
451}
Jon Hall6af749d2018-05-29 12:59:47 -0700452
Devin Lim61643762017-12-07 15:55:38 -0800453def getOverallPieGraph( file, host, port, user, pass, branch, type, testList, yOrN, path ){
Jon Hall6af749d2018-05-29 12:59:47 -0700454 // Rcommand for the pie graph
Devin Limf5175192018-05-14 19:13:22 -0700455
Jon Hall6af749d2018-05-29 12:59:47 -0700456 return generalFuncs.basicGraphPart( file, host, port, user, pass, type, branch ) +
457 " \"" + testList + "\" latest " + yOrN + " " + path
Devin Lim61643762017-12-07 15:55:38 -0800458}
Jon Hall6af749d2018-05-29 12:59:47 -0700459
Devin Lim61643762017-12-07 15:55:38 -0800460def sqlCommand( testName ){
Jon Hall6af749d2018-05-29 12:59:47 -0700461 // get the inserting sqlCommand for non-SCPF tests.
Devin Limf5175192018-05-14 19:13:22 -0700462
Jon Hall6af749d2018-05-29 12:59:47 -0700463 return "\"INSERT INTO " + table_name + " VALUES('\$DATE','" + result_name + "','" +
464 testName + "',\$BUILD_NUMBER, '\$ONOSBranch', \$line);\" "
Devin Lim61643762017-12-07 15:55:38 -0800465}
Jon Hall6af749d2018-05-29 12:59:47 -0700466
Devin Lim61643762017-12-07 15:55:38 -0800467def graphGenerating( host, port, user, pass, testName, prop, graph_saved_directory, graph_generator_file ){
Jon Hall6af749d2018-05-29 12:59:47 -0700468 // get the graphGenerating R command for non-SCPF tests
Devin Limf5175192018-05-14 19:13:22 -0700469
Jon Hall6af749d2018-05-29 12:59:47 -0700470 return generalFuncs.basicGraphPart( graph_generator_file, host, port, user, pass, testName,
471 prop[ "ONOSBranch" ] ) + " 20 " + graph_saved_directory
Devin Lim61643762017-12-07 15:55:38 -0800472}
Devin Limf5175192018-05-14 19:13:22 -0700473
Jon Hall6af749d2018-05-29 12:59:47 -0700474def databasePart( wikiPrefix, testName, database_command ){
475 // to read and insert the data from .csv to the database
476
477 return '''
Devin Lim61643762017-12-07 15:55:38 -0800478 sed 1d ''' + workSpace + "/" + wikiPrefix + "-" + testName + '''.csv | while read line
479 do
480 echo \$line
481 echo ''' + database_command + '''
482 done '''
483}
Jon Hall6af749d2018-05-29 12:59:47 -0700484
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -0700485def generateStatGraph( testMachineOn, onos_branch, stat_graph_generator_file, pie_graph_generator_file,
Jon Hall6af749d2018-05-29 12:59:47 -0700486 graph_saved_directory ){
Devin Limf5175192018-05-14 19:13:22 -0700487
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -0700488 // Will generate the stats graph.
489 FUNCtestsStr = test_list.getTestListAsString( test_list.getTestsFromCategory( "FUNC" ) )
490 HAtestsStr = test_list.getTestListAsString( test_list.getTestsFromCategory( "HA" ) )
491 USECASEtestsStr = test_list.getTestListAsString( test_list.getTestsFromCategory( "USECASE" ) )
492
493 testListParam = "FUNC-" + FUNCtestsStr + ";" +
494 "HA-" + HAtestsStr + ";" +
495 "USECASE-" + USECASEtestsStr
496
497 pieTestListParam = FUNCtestsStr + "," +
498 HAtestsStr + "," +
499 USECASEtestsStr
500
Jon Hall6af749d2018-05-29 12:59:47 -0700501 generateCategoryStatsGraph( testMachineOn, "false", "true", stat_graph_generator_file, pie_graph_generator_file,
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -0700502 "ALL", onos_branch, testListParam, graph_saved_directory, pieTestListParam )
Jeremy Ronquillo14ecc172018-03-05 09:57:17 -0800503}
Jon Hall6af749d2018-05-29 12:59:47 -0700504
Jon Hall6af749d2018-05-29 12:59:47 -0700505return this