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