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