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