Devin Lim | f517519 | 2018-05-14 19:13:22 -0700 | [diff] [blame^] | 1 | // Copyright 2017 Open Networking Foundation (ONF) |
| 2 | // |
| 3 | // Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>, |
| 4 | // the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>, |
| 5 | // or the System Testing Guide page at <https://wiki.onosproject.org/x/WYQg> |
| 6 | // |
| 7 | // TestON is free software: you can redistribute it and/or modify |
| 8 | // it under the terms of the GNU General Public License as published by |
| 9 | // the Free Software Foundation, either version 2 of the License, or |
| 10 | // (at your option) any later version. |
| 11 | // |
| 12 | // TestON is distributed in the hope that it will be useful, |
| 13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | // GNU General Public License for more details. |
| 16 | // |
| 17 | // You should have received a copy of the GNU General Public License |
| 18 | // along with TestON. If not, see <http://www.gnu.org/licenses/>. |
| 19 | |
| 20 | // This is the dependency Jenkins script. |
| 21 | // it has some common functions that runs test and generate graph. |
| 22 | |
Devin Lim | 6164376 | 2017-12-07 15:55:38 -0800 | [diff] [blame] | 23 | #!groovy |
| 24 | import groovy.time.* |
Devin Lim | b734ea5 | 2018-05-14 14:13:05 -0700 | [diff] [blame] | 25 | generalFuncs = evaluate readTrusted( 'TestON/JenkinsFile/dependencies/GeneralFuncs.groovy' ) |
| 26 | fileRelated = evaluate readTrusted( 'TestON/JenkinsFile/dependencies/JenkinsPathAndFiles.groovy' ) |
Devin Lim | fe9a4cb | 2018-05-11 17:06:21 -0700 | [diff] [blame] | 27 | |
| 28 | fileRelated.init() |
Jeremy Ronquillo | 14ecc17 | 2018-03-05 09:57:17 -0800 | [diff] [blame] | 29 | |
Devin Lim | 6164376 | 2017-12-07 15:55:38 -0800 | [diff] [blame] | 30 | def initializeTrend( machine ){ |
Devin Lim | f517519 | 2018-05-14 19:13:22 -0700 | [diff] [blame^] | 31 | // For initializing any trend graph jobs |
| 32 | // machine : Either VM,BM, or Fabric# |
| 33 | |
Devin Lim | 6164376 | 2017-12-07 15:55:38 -0800 | [diff] [blame] | 34 | table_name = "executed_test_tests" |
| 35 | result_name = "executed_test_results" |
| 36 | testMachine = "TestStation-" + machine + "s"; |
| 37 | this.machine = machine |
| 38 | isSCPF = false |
Devin Lim | 981f80b | 2018-04-09 11:25:59 -0700 | [diff] [blame] | 39 | isTrend = true |
Devin Lim | 6164376 | 2017-12-07 15:55:38 -0800 | [diff] [blame] | 40 | } |
| 41 | def initialize( type, SCPFfuncs ){ |
Devin Lim | f517519 | 2018-05-14 19:13:22 -0700 | [diff] [blame^] | 42 | // Initializing for SCPF tests |
| 43 | // type : type of the test ( SR,FUNC,SCPF... ) |
| 44 | // Passing the SCPFfunction which will be PerformanceFuncs.groovy |
| 45 | |
Devin Lim | 6164376 | 2017-12-07 15:55:38 -0800 | [diff] [blame] | 46 | init( type ) |
| 47 | SCPFfunc = SCPFfuncs |
| 48 | isSCPF = true |
| 49 | machine = machineType[ type ] |
| 50 | } |
| 51 | def initialize( type ){ |
Devin Lim | f517519 | 2018-05-14 19:13:22 -0700 | [diff] [blame^] | 52 | // initializing for FUNC,HA,SR, and USECASE |
| 53 | // type : type of the test ( SR,FUNC,SCPF... ) |
| 54 | |
Devin Lim | 6164376 | 2017-12-07 15:55:38 -0800 | [diff] [blame] | 55 | init( type ) |
| 56 | SCPFfunc = null |
| 57 | table_name = "executed_test_tests" |
| 58 | result_name = "executed_test_results" |
Devin Lim | fe9a4cb | 2018-05-11 17:06:21 -0700 | [diff] [blame] | 59 | trend_generator_file = fileRelated.trendMultiple |
| 60 | build_stats_generator_file = fileRelated.histogramMultiple |
Devin Lim | 6164376 | 2017-12-07 15:55:38 -0800 | [diff] [blame] | 61 | isSCPF = false |
| 62 | } |
| 63 | def init( type ){ |
Devin Lim | f517519 | 2018-05-14 19:13:22 -0700 | [diff] [blame^] | 64 | // type : type of the test ( SR,FUNC,SCPF... ) |
| 65 | |
Devin Lim | 6164376 | 2017-12-07 15:55:38 -0800 | [diff] [blame] | 66 | machineType = [ "FUNC" : "VM", |
| 67 | "HA" : "VM", |
Devin Lim | 431408d | 2018-03-23 17:51:31 -0700 | [diff] [blame] | 68 | "SR" : "Fabric", |
Devin Lim | 6164376 | 2017-12-07 15:55:38 -0800 | [diff] [blame] | 69 | "SCPF" : "BM", |
| 70 | "USECASE" : "BM" ] |
| 71 | testType = type; |
| 72 | testMachine = "TestStation-" + machineType[ type ] + "s"; |
Devin Lim | 981f80b | 2018-04-09 11:25:59 -0700 | [diff] [blame] | 73 | isTrend = false |
Devin Lim | 6164376 | 2017-12-07 15:55:38 -0800 | [diff] [blame] | 74 | } |
Devin Lim | 86e4053 | 2018-04-06 12:44:06 -0700 | [diff] [blame] | 75 | def additionalInitForSR( branch ){ |
Devin Lim | f517519 | 2018-05-14 19:13:22 -0700 | [diff] [blame^] | 76 | // additional setup for SegmentRouting tests to determine the machine depends on the branch it is running. |
| 77 | // branch : branch of the onos. ( master, 1.12, 1.13... ) |
| 78 | |
Devin Lim | c38e693 | 2018-04-06 18:04:33 -0700 | [diff] [blame] | 79 | testMachine = ( ( new StringBuilder( testMachine ) ).insert( testMachine.size()-1, fabricOn( branch ) ) ).toString() |
Devin Lim | 6cccad5 | 2018-04-09 11:32:19 -0700 | [diff] [blame] | 80 | if( isTrend ) |
| 81 | machine += fabricOn( branch ) |
| 82 | else |
| 83 | machineType[ testType ] += fabricOn( branch ) |
Devin Lim | 86e4053 | 2018-04-06 12:44:06 -0700 | [diff] [blame] | 84 | print testMachine |
| 85 | } |
| 86 | def fabricOn( branch ){ |
Devin Lim | f517519 | 2018-05-14 19:13:22 -0700 | [diff] [blame^] | 87 | // gets the fabric machines with the branch of onos. |
| 88 | // branch : master, 1.12, 1.13... |
| 89 | |
Devin Lim | 36fc1e3 | 2018-05-10 15:58:01 -0700 | [diff] [blame] | 90 | return branch.reverse().take(4).reverse() == "1.12" ? '3' : '2' |
Devin Lim | 86e4053 | 2018-04-06 12:44:06 -0700 | [diff] [blame] | 91 | } |
Devin Lim | 6164376 | 2017-12-07 15:55:38 -0800 | [diff] [blame] | 92 | def printType(){ |
Devin Lim | f517519 | 2018-05-14 19:13:22 -0700 | [diff] [blame^] | 93 | // print the test type and test machine that was initialized. |
| 94 | |
Devin Lim | 6164376 | 2017-12-07 15:55:38 -0800 | [diff] [blame] | 95 | echo testType; |
| 96 | echo testMachine; |
| 97 | } |
| 98 | def getProperties(){ |
Devin Lim | f517519 | 2018-05-14 19:13:22 -0700 | [diff] [blame^] | 99 | // get the properties of the test by reading the TestONOS.property |
| 100 | |
Devin Lim | 6164376 | 2017-12-07 15:55:38 -0800 | [diff] [blame] | 101 | node( testMachine ){ |
| 102 | return readProperties( file:'/var/jenkins/TestONOS.property' ); |
| 103 | } |
| 104 | } |
| 105 | def getTestsToRun( testList ){ |
Devin Lim | f517519 | 2018-05-14 19:13:22 -0700 | [diff] [blame^] | 106 | // get test to run by tokenizing the list. |
| 107 | |
Devin Lim | 6164376 | 2017-12-07 15:55:38 -0800 | [diff] [blame] | 108 | testList.tokenize("\n;, ") |
| 109 | } |
| 110 | def getCurrentTime(){ |
Devin Lim | f517519 | 2018-05-14 19:13:22 -0700 | [diff] [blame^] | 111 | // get time of the PST zone. |
| 112 | |
Devin Lim | d1fb8e9 | 2018-02-28 16:29:33 -0800 | [diff] [blame] | 113 | TimeZone.setDefault( TimeZone.getTimeZone('PST') ) |
Devin Lim | 6164376 | 2017-12-07 15:55:38 -0800 | [diff] [blame] | 114 | return new Date(); |
| 115 | } |
| 116 | def getTotalTime( start, end ){ |
Devin Lim | f517519 | 2018-05-14 19:13:22 -0700 | [diff] [blame^] | 117 | // get total time of the test using start and end time. |
| 118 | |
Devin Lim | 6164376 | 2017-12-07 15:55:38 -0800 | [diff] [blame] | 119 | return TimeCategory.minus( end, start ); |
| 120 | } |
| 121 | def printTestToRun( testList ){ |
Devin Lim | f517519 | 2018-05-14 19:13:22 -0700 | [diff] [blame^] | 122 | // printout the list of the test in the list. |
| 123 | |
Devin Lim | 6164376 | 2017-12-07 15:55:38 -0800 | [diff] [blame] | 124 | for ( String test : testList ) { |
| 125 | println test; |
| 126 | } |
| 127 | } |
| 128 | def sendResultToSlack( start, isManualRun, branch ){ |
Devin Lim | f517519 | 2018-05-14 19:13:22 -0700 | [diff] [blame^] | 129 | // send the result of the test to the slack when it is not manually running. |
| 130 | // start : start time of the test |
| 131 | // isManualRun : string that is whether "false" or "true" |
| 132 | // branch : branch of the onos. |
| 133 | |
Devin Lim | 6164376 | 2017-12-07 15:55:38 -0800 | [diff] [blame] | 134 | try{ |
| 135 | if( isManualRun == "false" ){ |
| 136 | end = getCurrentTime(); |
| 137 | TimeDuration duration = TimeCategory.minus( end , start ); |
| 138 | slackSend( color:"#5816EE", |
| 139 | message: testType + "-" + branch + " tests ended at: " + end.toString() + "\nTime took : " + duration ) |
| 140 | } |
| 141 | } |
| 142 | catch( all ){} |
| 143 | } |
| 144 | def initAndRunTest( testName, testCategory ){ |
Devin Lim | f517519 | 2018-05-14 19:13:22 -0700 | [diff] [blame^] | 145 | // Bash script that will |
| 146 | // Initialize the environment to the machine and run the test. |
| 147 | // testName : name of the test |
| 148 | // testCategory : (SR,FUNC ... ) |
| 149 | |
Devin Lim | 6164376 | 2017-12-07 15:55:38 -0800 | [diff] [blame] | 150 | return '''#!/bin/bash -l |
| 151 | set -i # interactive |
| 152 | set +e |
| 153 | shopt -s expand_aliases # expand alias in non-interactive mode |
| 154 | export PYTHONUNBUFFERED=1 |
| 155 | ifconfig |
Devin Lim | 6164376 | 2017-12-07 15:55:38 -0800 | [diff] [blame] | 156 | echo "ONOS Branch is: $ONOSBranch" |
| 157 | echo "TestON Branch is: $TestONBranch" |
| 158 | echo "Test date: " |
| 159 | date |
| 160 | cd ~ |
| 161 | export PATH=$PATH:onos/tools/test/bin |
| 162 | timeout 240 stc shutdown | head -100 |
| 163 | timeout 240 stc teardown | head -100 |
| 164 | timeout 240 stc shutdown | head -100 |
| 165 | cd ~/OnosSystemTest/TestON/bin |
| 166 | git log |head |
| 167 | ./cleanup.sh -f |
Devin Lim | a7b97a4 | 2018-04-09 14:26:38 -0700 | [diff] [blame] | 168 | ''' + "./cli.py run " + ( !isSCPF ? testName : testCategory[ testName ][ 'test' ] ) + " --params GRAPH/nodeCluster=" + machineType[ testType ] + ''' |
Devin Lim | 6164376 | 2017-12-07 15:55:38 -0800 | [diff] [blame] | 169 | ./cleanup.sh -f |
| 170 | # cleanup config changes |
| 171 | cd ~/onos/tools/package/config |
| 172 | git clean -df''' |
| 173 | } |
| 174 | def copyLogs( testName ){ |
Devin Lim | f517519 | 2018-05-14 19:13:22 -0700 | [diff] [blame^] | 175 | // bash script part for copy the logs and other neccessary element for SR tests. |
| 176 | // testName : name of the test. |
| 177 | |
Devin Lim | 6164376 | 2017-12-07 15:55:38 -0800 | [diff] [blame] | 178 | result = "" |
| 179 | if( testType == "SR" ){ |
| 180 | result = ''' |
| 181 | sudo rm /var/jenkins/workspace/SR-log-${WikiPrefix}/* |
| 182 | sudo cp *karaf.log.* /var/jenkins/workspace/SR-log-${WikiPrefix}/ |
| 183 | sudo cp *Flows* /var/jenkins/workspace/SR-log-${WikiPrefix}/ |
| 184 | sudo cp *Groups* /var/jenkins/workspace/SR-log-${WikiPrefix}/ |
Devin Lim | a7b97a4 | 2018-04-09 14:26:38 -0700 | [diff] [blame] | 185 | sudo cp *.tar.gz /var/jenkins/workspace/SR-log-${WikiPrefix}/ |
Devin Lim | 6faa3f9 | 2018-05-01 13:16:25 -0700 | [diff] [blame] | 186 | sudo cp t3-* /var/jenkins/workspace/SR-log-${WikiPrefix}/ |
Devin Lim | 6164376 | 2017-12-07 15:55:38 -0800 | [diff] [blame] | 187 | ''' |
| 188 | } |
| 189 | return result |
| 190 | } |
| 191 | def cleanAndCopyFiles( testName ){ |
Devin Lim | f517519 | 2018-05-14 19:13:22 -0700 | [diff] [blame^] | 192 | // clean up some files that were in the folder and copy the new files from the log |
| 193 | // testName : name of the test |
| 194 | |
Devin Lim | 6164376 | 2017-12-07 15:55:38 -0800 | [diff] [blame] | 195 | return '''#!/bin/bash -i |
| 196 | set +e |
| 197 | echo "ONOS Branch is: ${ONOSBranch}" |
| 198 | echo "TestON Branch is: ${TestONBranch}" |
| 199 | echo "Job name is: "''' + testName + ''' |
| 200 | echo "Workspace is: ${WORKSPACE}/" |
| 201 | echo "Wiki page to post is: ${WikiPrefix}-" |
| 202 | # remove any leftover files from previous tests |
| 203 | sudo rm ${WORKSPACE}/*Wiki.txt |
| 204 | sudo rm ${WORKSPACE}/*Summary.txt |
| 205 | sudo rm ${WORKSPACE}/*Result.txt |
| 206 | sudo rm ${WORKSPACE}/*.csv |
| 207 | #copy files to workspace |
| 208 | cd `ls -t ~/OnosSystemTest/TestON/logs/*/ | head -1 | sed 's/://'` |
| 209 | ''' + copyLogs( testName ) + ''' |
| 210 | sudo cp *.txt ${WORKSPACE}/ |
| 211 | sudo cp *.csv ${WORKSPACE}/ |
| 212 | cd ${WORKSPACE}/ |
| 213 | for i in *.csv |
| 214 | do mv "$i" "$WikiPrefix"-"$i" |
| 215 | done |
| 216 | ls -al |
| 217 | cd ''' |
| 218 | } |
| 219 | def fetchLogs( testName ){ |
Devin Lim | f517519 | 2018-05-14 19:13:22 -0700 | [diff] [blame^] | 220 | // fetch the logs of onos from onos nodes to onos System Test logs |
| 221 | // testName: name of the test |
| 222 | |
Devin Lim | 6164376 | 2017-12-07 15:55:38 -0800 | [diff] [blame] | 223 | return '''#!/bin/bash |
| 224 | set +e |
| 225 | cd ~/OnosSystemTest/TestON/logs |
| 226 | echo "Job Name is: " + ''' + testName + ''' |
| 227 | TestONlogDir=$(ls -t | grep ${TEST_NAME}_ |head -1) |
| 228 | echo "########################################################################################" |
| 229 | echo "##### copying ONOS logs from all nodes to TestON/logs directory: ${TestONlogDir}" |
| 230 | echo "########################################################################################" |
| 231 | cd $TestONlogDir |
| 232 | if [ $? -eq 1 ] |
| 233 | then |
| 234 | echo "Job name does not match any test suite name to move log!" |
| 235 | else |
| 236 | pwd |
| 237 | for i in $OC{1..7}; do onos-fetch-logs $i || echo log does not exist; done |
| 238 | fi |
| 239 | cd''' |
| 240 | } |
| 241 | def isPostingResult( manual, postresult ){ |
Devin Lim | f517519 | 2018-05-14 19:13:22 -0700 | [diff] [blame^] | 242 | // check if it is posting the result. |
| 243 | // posting when it is automatically running or has postResult condition from the manual run |
| 244 | |
Devin Lim | 6164376 | 2017-12-07 15:55:38 -0800 | [diff] [blame] | 245 | return manual == "false" || postresult == "true" |
| 246 | } |
| 247 | def postResult( prop, graphOnly ){ |
Devin Lim | f517519 | 2018-05-14 19:13:22 -0700 | [diff] [blame^] | 248 | // post the result by triggering postjob. |
| 249 | // prop : property dictionary that was read from the machine. |
| 250 | // graphOnly : if it is graph generating job |
| 251 | |
Devin Lim | 6164376 | 2017-12-07 15:55:38 -0800 | [diff] [blame] | 252 | if( graphOnly || isPostingResult( prop[ "manualRun" ], prop[ "postResult" ] ) ){ |
| 253 | def post = build job: "postjob-" + ( graphOnly ? machine : machineType[ testType ] ), propagate: false |
| 254 | } |
| 255 | } |
| 256 | def postLogs( testName, prefix ){ |
Devin Lim | f517519 | 2018-05-14 19:13:22 -0700 | [diff] [blame^] | 257 | // posting logs of the onos jobs specifically SR tests |
| 258 | // testName : name of the test |
| 259 | // prefix : branch prefix ( master, 1.12, 1.13 ... ) |
| 260 | |
Devin Lim | 6164376 | 2017-12-07 15:55:38 -0800 | [diff] [blame] | 261 | resultURL = "" |
| 262 | if( testType == "SR" ){ |
| 263 | def post = build job: "SR-log-" + prefix, propagate: false |
| 264 | resultURL = post.getAbsoluteUrl() |
| 265 | } |
| 266 | return resultURL |
| 267 | } |
| 268 | def getSlackChannel(){ |
Devin Lim | f517519 | 2018-05-14 19:13:22 -0700 | [diff] [blame^] | 269 | // get name of the slack channel. |
| 270 | // if the test is SR, it will return sr-failures |
| 271 | |
Devin Lim | 6164376 | 2017-12-07 15:55:38 -0800 | [diff] [blame] | 272 | return "#" + ( testType == "SR" ? "sr-failures" : "jenkins-related" ) |
| 273 | } |
| 274 | def analyzeResult( prop, workSpace, testName, otherTestName, resultURL, wikiLink, isSCPF ){ |
Devin Lim | f517519 | 2018-05-14 19:13:22 -0700 | [diff] [blame^] | 275 | // analyzing the result of the test and send to slack if the test was failed. |
| 276 | // prop : property dictionary |
| 277 | // workSpace : workSpace where the result file is saved |
| 278 | // testName : real name of the test |
| 279 | // otherTestName : other name of the test for SCPF tests ( SCPFflowTPFobj ) |
| 280 | // resultURL : url for the logs for SR tests. Will not be posted if it is empty |
| 281 | // wikiLink : link of the wiki page where the result was posted |
| 282 | // isSCPF : Check if it is SCPF. If so, it won't post the wiki link. |
| 283 | |
Devin Lim | 6164376 | 2017-12-07 15:55:38 -0800 | [diff] [blame] | 284 | node( testMachine ){ |
| 285 | resultContents = readFile workSpace + "/" + testName + "Result.txt" |
| 286 | resultContents = resultContents.split("\n") |
| 287 | if( resultContents[ 0 ] == "1" ){ |
| 288 | print "All passed" |
| 289 | }else{ |
| 290 | print "Failed" |
| 291 | if( prop[ "manualRun" ] == "false" ){ |
| 292 | slackSend( channel:getSlackChannel(), color:"FF0000", message: "[" + prop[ "ONOSBranch" ] + "]" |
| 293 | + otherTestName + " : Failed!\n" + resultContents[ 1 ] + "\n" |
| 294 | + "[TestON log] : \n" |
Devin Lim | d1fb8e9 | 2018-02-28 16:29:33 -0800 | [diff] [blame] | 295 | + "https://jenkins.onosproject.org/blue/organizations/jenkins/${env.JOB_NAME}/detail/${env.JOB_NAME}/${env.BUILD_NUMBER}/pipeline" |
Devin Lim | 6164376 | 2017-12-07 15:55:38 -0800 | [diff] [blame] | 296 | + ( isSCPF ? "" : ( "\n[Result on Wiki] : \n" + "https://wiki.onosproject.org/display/ONOS/" + wikiLink.replaceAll( "\\s","+" ) ) ) |
| 297 | + ( resultURL != "" ? ( "\n[Karaf log] : \n" + resultURL + "artifact/" ) : "" ), |
| 298 | teamDomain: 'onosproject' ) |
| 299 | } |
| 300 | Failed |
| 301 | } |
| 302 | } |
| 303 | } |
Devin Lim | e89761a | 2018-03-16 17:52:57 -0700 | [diff] [blame] | 304 | def publishToConfluence( isManualRun, isPostResult, wikiLink, file ){ |
Devin Lim | f517519 | 2018-05-14 19:13:22 -0700 | [diff] [blame^] | 305 | // 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 |
| 310 | |
Devin Lim | e89761a | 2018-03-16 17:52:57 -0700 | [diff] [blame] | 311 | if( isPostingResult( isManualRun, isPostResult ) ){ |
Devin Lim | 6164376 | 2017-12-07 15:55:38 -0800 | [diff] [blame] | 312 | publishConfluence siteName: 'wiki.onosproject.org', pageName: wikiLink, spaceName: 'ONOS', |
Devin Lim | 1253ae8 | 2018-02-26 11:13:36 -0800 | [diff] [blame] | 313 | attachArchivedArtifacts: true, buildIfUnstable: true, |
Devin Lim | 6164376 | 2017-12-07 15:55:38 -0800 | [diff] [blame] | 314 | editorList: [ |
| 315 | confluenceWritePage( confluenceFile( file ) ) |
| 316 | ] |
| 317 | } |
| 318 | |
| 319 | } |
| 320 | def runTest( testName, toBeRun, prop, pureTestName, graphOnly, testCategory, graph_generator_file, graph_saved_directory ) { |
Devin Lim | f517519 | 2018-05-14 19:13:22 -0700 | [diff] [blame^] | 321 | // run the test on the machine that contains all the steps : init and run test, copy files, publish result ... |
| 322 | // testName : name of the test |
| 323 | // toBeRun : boolean value whether the test will be run or not. If not, it won't be run but shows up with empty result on pipeline view |
| 324 | // prop : dictionary property on the machine |
| 325 | // pureTestName : Pure name of the test. ( ex. pureTestName of SCPFflowTpFobj will be SCPFflowTp ) |
| 326 | // graphOnly : check if it is generating graph job. If so, it will only generate the generating graph part |
| 327 | // testCategory : category of the test ( SCPF, SR, FUNC ... ) |
| 328 | // graph_generator_file : Rscript file with the full path. |
| 329 | // graph_saved_directory : where the generated graph will be saved to. |
| 330 | |
Devin Lim | 6164376 | 2017-12-07 15:55:38 -0800 | [diff] [blame] | 331 | return { |
| 332 | catchError{ |
| 333 | stage( testName ) { |
| 334 | if ( toBeRun ){ |
| 335 | workSpace = "/var/jenkins/workspace/" + testName |
| 336 | def fileContents = "" |
| 337 | node( testMachine ){ |
| 338 | withEnv( [ 'ONOSBranch=' + prop[ "ONOSBranch" ], |
| 339 | 'ONOSJVMHeap=' + prop[ "ONOSJVMHeap" ], |
| 340 | 'TestONBranch=' + prop[ "TestONBranch" ], |
| 341 | 'ONOSTag=' + prop[ "ONOSTag" ], |
| 342 | 'WikiPrefix=' + prop[ "WikiPrefix" ], |
| 343 | 'WORKSPACE=' + workSpace ] ){ |
| 344 | if( ! graphOnly ){ |
| 345 | sh initAndRunTest( testName, testCategory ) |
| 346 | // For the Wiki page |
| 347 | sh cleanAndCopyFiles( pureTestName ) |
| 348 | } |
| 349 | databaseAndGraph( prop, testName, graphOnly, graph_generator_file, graph_saved_directory ) |
| 350 | if( ! graphOnly ){ |
| 351 | sh fetchLogs( pureTestName ) |
| 352 | if( !isSCPF ) |
Devin Lim | e89761a | 2018-03-16 17:52:57 -0700 | [diff] [blame] | 353 | publishToConfluence( prop[ "manualRun" ], prop[ "postResult" ], |
| 354 | testCategory[ testName ][ 'wiki_link' ], |
| 355 | workSpace + "/" + testCategory[ testName ][ 'wiki_file' ] ) |
Devin Lim | 6164376 | 2017-12-07 15:55:38 -0800 | [diff] [blame] | 356 | } |
| 357 | } |
| 358 | |
| 359 | |
| 360 | } |
| 361 | postResult( prop, graphOnly ) |
| 362 | if( ! graphOnly ){ |
| 363 | resultURL = postLogs( testName, prop[ "WikiPrefix" ] ) |
| 364 | analyzeResult( prop, workSpace, pureTestName, testName, resultURL, isSCPF ? "" : testCategory[ testName ][ 'wiki_link' ], isSCPF ) |
| 365 | } |
| 366 | } |
| 367 | } |
| 368 | } |
| 369 | } |
| 370 | } |
Devin Lim | 6164376 | 2017-12-07 15:55:38 -0800 | [diff] [blame] | 371 | def databaseAndGraph( prop, testName, graphOnly, graph_generator_file, graph_saved_directory ){ |
Devin Lim | f517519 | 2018-05-14 19:13:22 -0700 | [diff] [blame^] | 372 | // part where it insert the data into the database. |
| 373 | // It will use the predefined encrypted variables from the Jenkins. |
| 374 | // prop : property dictionary that was read from the machine |
| 375 | // testName : name of the test |
| 376 | // graphOnly : boolean whether it is graph only or not |
| 377 | // graph_generator_file : Rscript file with the full path. |
| 378 | // graph_saved_directory : where the generated graph will be saved to. |
| 379 | |
Devin Lim | 6164376 | 2017-12-07 15:55:38 -0800 | [diff] [blame] | 380 | if( graphOnly || isPostingResult( prop[ "manualRun" ], prop[ "postResult" ] ) ){ |
| 381 | // Post Results |
| 382 | withCredentials( [ |
| 383 | string( credentialsId: 'db_pass', variable: 'pass' ), |
| 384 | string( credentialsId: 'db_user', variable: 'user' ), |
| 385 | string( credentialsId: 'db_host', variable: 'host' ), |
| 386 | string( credentialsId: 'db_port', variable: 'port' ) ] ) { |
| 387 | def database_command = generalFuncs.database_command_create( pass, host, port, user ) + ( !isSCPF ? sqlCommand( testName ) : SCPFfunc.sqlCommand( testName ) ) |
| 388 | sh '''#!/bin/bash |
| 389 | export DATE=\$(date +%F_%T) |
| 390 | cd ~ |
| 391 | pwd ''' + ( graphOnly ? "" : ( !isSCPF ? databasePart( prop[ "WikiPrefix" ], testName, database_command ) : |
| 392 | SCPFfunc.databasePart( testName, database_command ) ) ) + ''' |
| 393 | ''' + ( !isSCPF ? graphGenerating( host, port, user, pass, testName, prop, graph_saved_directory, graph_generator_file ) : SCPFfunc.getGraphGeneratingCommand( host, port, user, pass, testName, prop ) ) |
| 394 | } |
| 395 | } |
| 396 | } |
Devin Lim | 86e4053 | 2018-04-06 12:44:06 -0700 | [diff] [blame] | 397 | def generateCategoryStatsGraph( testMachineOn, manualRun, postresult, stat_file, pie_file, type, branch, testListPart, save_path, pieTestListPart ){ |
Devin Lim | f517519 | 2018-05-14 19:13:22 -0700 | [diff] [blame^] | 398 | // function that will generate the category stat graphs for the overall test. |
| 399 | // testMachineOn : the machine the graph will be generated. It will be TestStation-VMs for the most cases |
| 400 | // manualRun : string of "true" or "false" |
| 401 | // postresult : string of "true" or "false" |
| 402 | // stat_file : file name with full path for Rscript for the stat graph |
| 403 | // pie_file : file name with full path for Rscript for the pie graph |
| 404 | // type : type of the test ( USECASE, FUNC, HA ) |
| 405 | // branch : branch of the test ( master, onos-1.12, onos-1.13 ) |
| 406 | // testListPart : list of the test to be included |
| 407 | // save_path : path that will save the graphs to |
| 408 | // pieTestListPart : list of the test for pie graph |
Devin Lim | 6164376 | 2017-12-07 15:55:38 -0800 | [diff] [blame] | 409 | |
| 410 | if( isPostingResult( manualRun, postresult ) ){ |
Devin Lim | 86e4053 | 2018-04-06 12:44:06 -0700 | [diff] [blame] | 411 | node( testMachineOn ){ |
Devin Lim | 6164376 | 2017-12-07 15:55:38 -0800 | [diff] [blame] | 412 | |
| 413 | withCredentials( [ |
| 414 | string( credentialsId: 'db_pass', variable: 'pass' ), |
| 415 | string( credentialsId: 'db_user', variable: 'user' ), |
| 416 | string( credentialsId: 'db_host', variable: 'host' ), |
| 417 | string( credentialsId: 'db_port', variable: 'port' ) ] ) { |
| 418 | sh '''#!/bin/bash |
Devin Lim | fe9a4cb | 2018-05-11 17:06:21 -0700 | [diff] [blame] | 419 | ''' + generalFuncs.basicGraphPart( stat_file, host, port, user, pass, type, branch ) + " \"" + testListPart + "\" latest " + save_path + ''' |
| 420 | ''' + getOverallPieGraph( pie_file, host, port, user, pass, branch, type, pieTestListPart, 'y', save_path ) + ''' |
| 421 | ''' + getOverallPieGraph( pie_file, host, port, user, pass, branch, type, pieTestListPart, 'n', save_path ) |
Devin Lim | 6164376 | 2017-12-07 15:55:38 -0800 | [diff] [blame] | 422 | } |
| 423 | } |
| 424 | postResult( [], true ) |
| 425 | } |
| 426 | } |
| 427 | def makeTestList( list, commaNeeded ){ |
Devin Lim | f517519 | 2018-05-14 19:13:22 -0700 | [diff] [blame^] | 428 | // make the list of the test in to a string. |
| 429 | // list : list of the test |
| 430 | // commaNeeded : if comma is needed for the string |
| 431 | |
Devin Lim | 6164376 | 2017-12-07 15:55:38 -0800 | [diff] [blame] | 432 | return generalFuncs.getTestList( list ) + ( commaNeeded ? "," : "" ) |
| 433 | } |
| 434 | def createStatsList( testCategory, list, semiNeeded ){ |
Devin Lim | f517519 | 2018-05-14 19:13:22 -0700 | [diff] [blame^] | 435 | // make the list for stats |
| 436 | // testCategory : category of the test |
| 437 | // list : list of the test |
| 438 | // semiNeeded: if semi colon is needed |
| 439 | |
Devin Lim | 6164376 | 2017-12-07 15:55:38 -0800 | [diff] [blame] | 440 | return testCategory + "-" + generalFuncs.getTestList( list ) + ( semiNeeded ? ";" : "" ) |
| 441 | } |
| 442 | def generateOverallGraph( prop, testCategory, graph_saved_directory ){ |
Devin Lim | f517519 | 2018-05-14 19:13:22 -0700 | [diff] [blame^] | 443 | // generate the overall graph for the test |
Devin Lim | 6164376 | 2017-12-07 15:55:38 -0800 | [diff] [blame] | 444 | |
| 445 | if( isPostingResult( prop[ "manualRun" ], prop[ "postResult" ] ) ){ |
| 446 | node( testMachine ){ |
| 447 | |
| 448 | withCredentials( [ |
| 449 | string( credentialsId: 'db_pass', variable: 'pass' ), |
| 450 | string( credentialsId: 'db_user', variable: 'user' ), |
| 451 | string( credentialsId: 'db_host', variable: 'host' ), |
| 452 | string( credentialsId: 'db_port', variable: 'port' ) ] ) { |
| 453 | testList = generalFuncs.getTestList( testCategory ) |
| 454 | sh '''#!/bin/bash |
| 455 | ''' + generalFuncs.basicGraphPart( trend_generator_file, host, port, user, pass, testType, prop[ "ONOSBranch" ] ) + " " + testList + " 20 " + graph_saved_directory |
| 456 | } |
| 457 | } |
| 458 | postResult( prop, false ) |
| 459 | } |
| 460 | } |
| 461 | def getOverallPieGraph( file, host, port, user, pass, branch, type, testList, yOrN, path ){ |
Devin Lim | f517519 | 2018-05-14 19:13:22 -0700 | [diff] [blame^] | 462 | // Rcommand for the pie graph |
| 463 | |
Devin Lim | 6164376 | 2017-12-07 15:55:38 -0800 | [diff] [blame] | 464 | return generalFuncs.basicGraphPart( file, host, port, user, pass, type, branch ) + " \"" + testList + "\" latest " + yOrN + " " + path |
| 465 | } |
| 466 | def sqlCommand( testName ){ |
Devin Lim | f517519 | 2018-05-14 19:13:22 -0700 | [diff] [blame^] | 467 | // get the inserting sqlCommand for non-SCPF tests. |
| 468 | |
Devin Lim | 6164376 | 2017-12-07 15:55:38 -0800 | [diff] [blame] | 469 | return "\"INSERT INTO " + table_name + " VALUES('\$DATE','" + result_name + "','" + testName + "',\$BUILD_NUMBER, '\$ONOSBranch', \$line);\" " |
| 470 | } |
| 471 | def graphGenerating( host, port, user, pass, testName, prop, graph_saved_directory, graph_generator_file ){ |
Devin Lim | f517519 | 2018-05-14 19:13:22 -0700 | [diff] [blame^] | 472 | // get the graphGenerating R command for non-SCPF tests |
| 473 | |
Devin Lim | 6164376 | 2017-12-07 15:55:38 -0800 | [diff] [blame] | 474 | return generalFuncs.basicGraphPart( graph_generator_file, host, port, user, pass, testName, prop[ "ONOSBranch" ] ) + " 20 " + graph_saved_directory |
| 475 | } |
| 476 | def databasePart( wikiPrefix, testName, database_command ){ |
Devin Lim | f517519 | 2018-05-14 19:13:22 -0700 | [diff] [blame^] | 477 | // to read and insert the data from .csv to the database |
| 478 | |
Devin Lim | 6164376 | 2017-12-07 15:55:38 -0800 | [diff] [blame] | 479 | return ''' |
| 480 | sed 1d ''' + workSpace + "/" + wikiPrefix + "-" + testName + '''.csv | while read line |
| 481 | do |
| 482 | echo \$line |
| 483 | echo ''' + database_command + ''' |
| 484 | done ''' |
| 485 | } |
Devin Lim | 86e4053 | 2018-04-06 12:44:06 -0700 | [diff] [blame] | 486 | def generateStatGraph( testMachineOn, onos_branch, AllTheTests, stat_graph_generator_file, pie_graph_generator_file, graph_saved_directory ){ |
Devin Lim | f517519 | 2018-05-14 19:13:22 -0700 | [diff] [blame^] | 487 | // Will generate the stats graph. |
| 488 | |
Jeremy Ronquillo | 14ecc17 | 2018-03-05 09:57:17 -0800 | [diff] [blame] | 489 | testListPart = createStatsList( "FUNC", AllTheTests[ "FUNC" ], true ) + |
| 490 | createStatsList( "HA", AllTheTests[ "HA" ], true ) + |
| 491 | createStatsList( "USECASE", AllTheTests[ "USECASE" ], false ) |
| 492 | pieTestList = makeTestList( AllTheTests[ "FUNC" ], true ) + |
| 493 | makeTestList( AllTheTests[ "HA" ], true ) + |
| 494 | makeTestList( AllTheTests[ "USECASE" ], false ) |
Devin Lim | 86e4053 | 2018-04-06 12:44:06 -0700 | [diff] [blame] | 495 | generateCategoryStatsGraph( testMachineOn, "false", "true", stat_graph_generator_file, pie_graph_generator_file, "ALL", onos_branch, testListPart, graph_saved_directory, pieTestList ) |
Jeremy Ronquillo | 14ecc17 | 2018-03-05 09:57:17 -0800 | [diff] [blame] | 496 | } |
Jeremy Ronquillo | f78a6ca | 2018-03-12 09:20:57 -0700 | [diff] [blame] | 497 | def branchWithPrefix( branch ){ |
Devin Lim | f517519 | 2018-05-14 19:13:22 -0700 | [diff] [blame^] | 498 | // get the branch with the prefix ( "onos-" ) |
Jeremy Ronquillo | f78a6ca | 2018-03-12 09:20:57 -0700 | [diff] [blame] | 499 | return ( ( branch != "master" ) ? "onos-" : "" ) + branch |
| 500 | } |
Devin Lim | 1253ae8 | 2018-02-26 11:13:36 -0800 | [diff] [blame] | 501 | return this; |