Jeremy Ronquillo | 21c29fc | 2019-06-05 11:15:24 -0700 | [diff] [blame] | 1 | #!groovy |
| 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 | |
Jeremy Ronquillo | 336110a | 2019-07-11 14:20:40 -0700 | [diff] [blame] | 21 | import groovy.time.TimeCategory |
| 22 | import groovy.time.TimeDuration |
| 23 | |
Jeremy Ronquillo | 21c29fc | 2019-06-05 11:15:24 -0700 | [diff] [blame] | 24 | // read the dependency files |
Jeremy Ronquillo | 336110a | 2019-07-11 14:20:40 -0700 | [diff] [blame] | 25 | graphs = evaluate readTrusted( 'TestON/JenkinsFile/dependencies/JenkinsGraphs.groovy' ) |
Jeremy Ronquillo | 21c29fc | 2019-06-05 11:15:24 -0700 | [diff] [blame] | 26 | test_list = evaluate readTrusted( 'TestON/JenkinsFile/dependencies/JenkinsTestONTests.groovy' ) |
| 27 | fileRelated = evaluate readTrusted( 'TestON/JenkinsFile/dependencies/JenkinsPathAndFiles.groovy' ) |
| 28 | SCPFfuncs = evaluate readTrusted( 'TestON/JenkinsFile/dependencies/PerformanceFuncs.groovy' ) |
| 29 | |
| 30 | category = null |
| 31 | prop = null |
| 32 | testsToRun = null |
Jeremy Ronquillo | a8490fb | 2019-06-26 11:59:50 -0700 | [diff] [blame] | 33 | testsToRunStrList = null |
Jeremy Ronquillo | 21c29fc | 2019-06-05 11:15:24 -0700 | [diff] [blame] | 34 | branch = null |
Jeremy Ronquillo | 336110a | 2019-07-11 14:20:40 -0700 | [diff] [blame] | 35 | branchWithPrefix = null |
Jeremy Ronquillo | a8490fb | 2019-06-26 11:59:50 -0700 | [diff] [blame] | 36 | start = null |
Jeremy Ronquillo | 336110a | 2019-07-11 14:20:40 -0700 | [diff] [blame] | 37 | nodeLabel = null |
Jeremy Ronquillo | 6fbfdd5 | 2019-07-09 13:49:34 -0700 | [diff] [blame] | 38 | testStation = null |
Jeremy Ronquillo | 336110a | 2019-07-11 14:20:40 -0700 | [diff] [blame] | 39 | testsOverride = null |
| 40 | isGraphOnly = false |
| 41 | isSCPF = false |
Jeremy Ronquillo | 6da78cf | 2019-07-29 11:47:19 -0700 | [diff] [blame] | 42 | pipelineTimeout = null |
| 43 | |
Jeremy Ronquillo | 21c29fc | 2019-06-05 11:15:24 -0700 | [diff] [blame] | 44 | testsFromList = [:] |
| 45 | graphPaths = [:] |
| 46 | pipeline = [:] |
| 47 | |
| 48 | main() |
| 49 | |
| 50 | def main(){ |
Jeremy Ronquillo | 892c173 | 2019-07-29 15:22:57 -0700 | [diff] [blame] | 51 | pipelineTimeout = params.TimeOut.toInteger() // integer minutes until the entire pipeline times out. Usually passed from upstream master-trigger job. |
Jeremy Ronquillo | 6da78cf | 2019-07-29 11:47:19 -0700 | [diff] [blame] | 52 | timeout( time: pipelineTimeout, unit: "MINUTES" ){ |
Jeremy Ronquillo | 892c173 | 2019-07-29 15:22:57 -0700 | [diff] [blame] | 53 | init() |
Jeremy Ronquillo | 6da78cf | 2019-07-29 11:47:19 -0700 | [diff] [blame] | 54 | runTests() |
| 55 | generateGraphs() |
| 56 | sendToSlack() |
| 57 | } |
Jeremy Ronquillo | 21c29fc | 2019-06-05 11:15:24 -0700 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | def init(){ |
| 61 | fileRelated.init() |
| 62 | test_list.init() |
| 63 | readParams() |
| 64 | |
Jeremy Ronquillo | b8aac44 | 2019-07-31 13:28:01 -0700 | [diff] [blame] | 65 | if ( branch == "manually" ){ |
| 66 | echo '''Warning: entered branch was: "manually". Defaulting to master branch.''' |
| 67 | branch = "master" |
| 68 | branchWithPrefix = test_list.addPrefixToBranch( branch ) |
| 69 | } |
| 70 | |
Jeremy Ronquillo | 21c29fc | 2019-06-05 11:15:24 -0700 | [diff] [blame] | 71 | if ( category == "SCPF" ){ |
Jeremy Ronquillo | 336110a | 2019-07-11 14:20:40 -0700 | [diff] [blame] | 72 | isSCPF = true |
Jeremy Ronquillo | 21c29fc | 2019-06-05 11:15:24 -0700 | [diff] [blame] | 73 | SCPFfuncs.init() |
Jeremy Ronquillo | 442ce4d | 2019-07-26 16:35:11 -0700 | [diff] [blame] | 74 | graphs.initialize( SCPFfuncs ); |
Jeremy Ronquillo | 336110a | 2019-07-11 14:20:40 -0700 | [diff] [blame] | 75 | prop = getProperties() |
| 76 | isOldFlow = ( prop[ "isOldFlow" ] == "true" ) |
Jeremy Ronquillo | a8490fb | 2019-06-26 11:59:50 -0700 | [diff] [blame] | 77 | SCPFfuncs.oldFlowRuleCheck( isOldFlow, prop[ "ONOSBranch" ] ) |
Jeremy Ronquillo | a8490fb | 2019-06-26 11:59:50 -0700 | [diff] [blame] | 78 | } else { |
Jeremy Ronquillo | 336110a | 2019-07-11 14:20:40 -0700 | [diff] [blame] | 79 | isSCPF = false |
| 80 | graphs.initialize() |
| 81 | prop = getProperties() |
Jeremy Ronquillo | 21c29fc | 2019-06-05 11:15:24 -0700 | [diff] [blame] | 82 | } |
| 83 | |
Jeremy Ronquillo | b8aac44 | 2019-07-31 13:28:01 -0700 | [diff] [blame] | 84 | // get the list of the tests from category |
Jeremy Ronquillo | 21c29fc | 2019-06-05 11:15:24 -0700 | [diff] [blame] | 85 | testsFromList = test_list.getTestsFromCategory( category ) |
| 86 | |
| 87 | initGraphPaths() |
Jeremy Ronquillo | 336110a | 2019-07-11 14:20:40 -0700 | [diff] [blame] | 88 | tokenizeTokens = "\n;, " |
Jeremy Ronquillo | 21c29fc | 2019-06-05 11:15:24 -0700 | [diff] [blame] | 89 | |
Jeremy Ronquillo | 336110a | 2019-07-11 14:20:40 -0700 | [diff] [blame] | 90 | if ( testsOverride == "" || testsOverride == null ){ |
| 91 | testsToRunStrList = prop[ "Tests" ].tokenize( tokenizeTokens ) |
| 92 | } else { |
| 93 | testsToRunStrList = testsOverride.tokenize( tokenizeTokens ) |
| 94 | } |
Jeremy Ronquillo | a8490fb | 2019-06-26 11:59:50 -0700 | [diff] [blame] | 95 | testsToRun = test_list.getTestsFromStringList( testsToRunStrList ) |
Jeremy Ronquillo | 21c29fc | 2019-06-05 11:15:24 -0700 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | def readParams(){ |
Jeremy Ronquillo | 6fbfdd5 | 2019-07-09 13:49:34 -0700 | [diff] [blame] | 99 | category = params.Category // "FUNC", "HA", "USECASE", etc. |
| 100 | branch = params.Branch // "1.15", "2.1", "master", etc. |
Jeremy Ronquillo | 336110a | 2019-07-11 14:20:40 -0700 | [diff] [blame] | 101 | branchWithPrefix = test_list.addPrefixToBranch( branch ) |
Jeremy Ronquillo | 6fbfdd5 | 2019-07-09 13:49:34 -0700 | [diff] [blame] | 102 | testStation = params.TestStation // "TestStation-BMs", etc. |
| 103 | nodeLabel = params.NodeLabel // "BM", "VM", "Fabric-1.x", etc. |
Jeremy Ronquillo | 336110a | 2019-07-11 14:20:40 -0700 | [diff] [blame] | 104 | testsOverride = params.TestsOverride // "FUNCflow, FUNCintent, [...]", overrides property file |
| 105 | isGraphOnly = params.OnlyRefreshGraphs // true or false |
| 106 | } |
| 107 | |
| 108 | def getProperties(){ |
| 109 | // get the properties of the test by reading the TestONOS.property |
| 110 | |
| 111 | filePath = '''/var/jenkins/TestONOS-''' + category + '''-''' + branchWithPrefix + '''.property''' |
| 112 | |
| 113 | node( testStation ) { |
| 114 | return readProperties( file: filePath ) |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | def getCurrentTime(){ |
| 119 | // get time of the PST zone. |
| 120 | |
| 121 | TimeZone.setDefault( TimeZone.getTimeZone( 'PST' ) ) |
| 122 | return new Date() |
Jeremy Ronquillo | 21c29fc | 2019-06-05 11:15:24 -0700 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | def initGraphPaths(){ |
Jeremy Ronquillo | 1e5d7f2 | 2019-07-17 14:18:42 -0700 | [diff] [blame] | 126 | graphPaths.put( "trendIndividual", fileRelated.rScriptPaths[ "scripts" ][ "trendIndividual" ] ) |
Jon Hall | a15854a | 2020-07-23 15:47:00 -0700 | [diff] [blame] | 127 | if ( category == "SR" || category == "SR-StratumBMv2" ){ |
Jeremy Ronquillo | 1e5d7f2 | 2019-07-17 14:18:42 -0700 | [diff] [blame] | 128 | graphPaths.put( "saveDirectory", fileRelated.workspaces[ "base" ] + "postjob-" + ( testStation - "TestStation-" - "s" ) + "/" ) |
Jeremy Ronquillo | 21c29fc | 2019-06-05 11:15:24 -0700 | [diff] [blame] | 129 | } else if ( category == "SRHA" ) { |
Jeremy Ronquillo | 1e5d7f2 | 2019-07-17 14:18:42 -0700 | [diff] [blame] | 130 | graphPaths.put( "saveDirectory", fileRelated.workspaces[ "Fabric" ] ) |
Jeremy Ronquillo | bb3001f | 2019-07-01 12:57:07 -0700 | [diff] [blame] | 131 | } else if ( category == "SCPF" || category == "USECASE" ){ |
Jeremy Ronquillo | 1e5d7f2 | 2019-07-17 14:18:42 -0700 | [diff] [blame] | 132 | graphPaths.put( "saveDirectory", fileRelated.workspaces[ "BM" ] ) |
Jeremy Ronquillo | 21c29fc | 2019-06-05 11:15:24 -0700 | [diff] [blame] | 133 | } else { |
Jeremy Ronquillo | 1e5d7f2 | 2019-07-17 14:18:42 -0700 | [diff] [blame] | 134 | graphPaths.put( "saveDirectory", fileRelated.workspaces[ "VM" ] ) |
Jeremy Ronquillo | 21c29fc | 2019-06-05 11:15:24 -0700 | [diff] [blame] | 135 | } |
| 136 | } |
| 137 | |
| 138 | def runTests(){ |
| 139 | // run the test sequentially and save the function into the dictionary. |
Jeremy Ronquillo | b8aac44 | 2019-07-31 13:28:01 -0700 | [diff] [blame] | 140 | for ( String test : testsFromList.keySet() ){ |
| 141 | toBeRun = testsToRun.keySet().contains( test ) |
Jeremy Ronquillo | 336110a | 2019-07-11 14:20:40 -0700 | [diff] [blame] | 142 | stepName = ( toBeRun ? "" : "Not " ) + "Running $test" |
Jon Hall | 1ef7632 | 2020-07-24 12:26:04 -0700 | [diff] [blame^] | 143 | // pureTestName is what is passed to the cli, here we check to see if there are any params to pass as well |
| 144 | if ( test.contains( "WithFlowObj" ) ){ |
| 145 | pureTestName = test - "WithFlowObj" |
| 146 | } else if ( testsToRun[ test ].keySet().contains( "test" ) ){ |
| 147 | pureTestName = testsToRun[ test ][ "test" ] |
| 148 | } else { |
| 149 | pureTestName = test |
| 150 | } |
Jeremy Ronquillo | 336110a | 2019-07-11 14:20:40 -0700 | [diff] [blame] | 151 | pipeline[ stepName ] = runTest( test, |
| 152 | toBeRun, |
| 153 | prop, |
| 154 | pureTestName, |
| 155 | isGraphOnly, |
| 156 | testsToRun, |
| 157 | graphPaths[ "trendIndividual" ], |
| 158 | graphPaths[ "saveDirectory" ] ) |
Jeremy Ronquillo | 21c29fc | 2019-06-05 11:15:24 -0700 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | // get the start time of the test. |
Jeremy Ronquillo | 336110a | 2019-07-11 14:20:40 -0700 | [diff] [blame] | 162 | start = getCurrentTime() |
Jeremy Ronquillo | 21c29fc | 2019-06-05 11:15:24 -0700 | [diff] [blame] | 163 | |
| 164 | // run the tests sequentially. |
| 165 | for ( test in pipeline.keySet() ){ |
| 166 | pipeline[ test ].call() |
| 167 | } |
| 168 | } |
| 169 | |
Jeremy Ronquillo | 336110a | 2019-07-11 14:20:40 -0700 | [diff] [blame] | 170 | def initTest(){ |
| 171 | return '''#!/bin/bash -l |
| 172 | set -i # interactive |
| 173 | set +e |
| 174 | shopt -s expand_aliases # expand alias in non-interactive mode |
| 175 | export PYTHONUNBUFFERED=1 |
| 176 | ifconfig |
| 177 | echo "ONOS Branch is: $ONOSBranch" |
| 178 | echo "TestON Branch is: $TestONBranch" |
| 179 | echo "Test date: " |
| 180 | date |
| 181 | cd ~ |
| 182 | export PATH=$PATH:onos/tools/test/bin |
| 183 | timeout 240 stc shutdown | head -100 |
| 184 | timeout 240 stc teardown | head -100 |
| 185 | timeout 240 stc shutdown | head -100 |
| 186 | cd ~/OnosSystemTest/TestON/bin |
| 187 | git log | head |
| 188 | ./cleanup.sh -f || true |
| 189 | ''' |
| 190 | } |
| 191 | |
Jeremy Ronquillo | 5ceda07 | 2019-08-12 12:56:43 -0700 | [diff] [blame] | 192 | def configureJavaVersion(){ |
| 193 | java_1_8_branches = [ "1.15" ] |
| 194 | return '''#!/bin/bash -l |
| 195 | ''' + ( java_1_8_branches.contains( branch ) ? '''SET_JAVA_VER=java-8-oracle''' : '''SET_JAVA_VER=java-1.11.0-openjdk-amd64''' ) + |
| 196 | ''' |
| 197 | CELL_COUNT=$( env | egrep "OC[1-9]+" | wc -l ) |
| 198 | for i in $(seq 1 $CELL_COUNT) |
| 199 | do |
| 200 | CELL_TO_SET=$( env | egrep "OC$i" | cut -c5- ) |
| 201 | echo "Setting java to $SET_JAVA_VER on $CELL_TO_SET" |
| 202 | eval ssh $CELL_TO_SET 'sudo update-java-alternatives -s $SET_JAVA_VER' |
| 203 | done |
| 204 | ''' |
| 205 | } |
| 206 | |
Jeremy Ronquillo | 31a3eb3 | 2019-08-02 13:30:37 -0700 | [diff] [blame] | 207 | def runTestCli_py( testName, pureTestName, testCategory ){ |
Jeremy Ronquillo | 336110a | 2019-07-11 14:20:40 -0700 | [diff] [blame] | 208 | // Bash script that will run the test. |
| 209 | // testName : name of the test |
| 210 | // testCategory : (SR,FUNC ... ) |
Jeremy Ronquillo | 31a3eb3 | 2019-08-02 13:30:37 -0700 | [diff] [blame] | 211 | flowObjFlag = false |
Jeremy Ronquillo | 336110a | 2019-07-11 14:20:40 -0700 | [diff] [blame] | 212 | |
Jeremy Ronquillo | 31a3eb3 | 2019-08-02 13:30:37 -0700 | [diff] [blame] | 213 | if ( isSCPF && testName.contains( "WithFlowObj" ) ){ |
| 214 | flowObjFlag = true |
| 215 | } |
| 216 | |
| 217 | command = '''cd ~/OnosSystemTest/TestON/bin |
| 218 | ./cli.py run ''' + pureTestName + ''' --params''' + ( flowObjFlag ? '''TEST/flowObj=True ''' : ''' ''' ) + '''GRAPH/nodeCluster=''' + graphs.getPostjobType( nodeLabel ) + ''' ''' |
| 219 | echo command |
| 220 | |
| 221 | return command |
| 222 | |
| 223 | |
Jeremy Ronquillo | 336110a | 2019-07-11 14:20:40 -0700 | [diff] [blame] | 224 | } |
| 225 | |
| 226 | def concludeRunTest(){ |
| 227 | return '''cd ~/OnosSystemTest/TestON/bin |
| 228 | ./cleanup.sh -f || true |
| 229 | # cleanup config changes |
| 230 | cd ~/onos/tools/package/config |
| 231 | git clean -df''' |
| 232 | } |
| 233 | |
| 234 | def copyLogs(){ |
| 235 | // bash script to copy the logs and other necessary element for SR tests. |
| 236 | |
| 237 | result = "" |
Jon Hall | a15854a | 2020-07-23 15:47:00 -0700 | [diff] [blame] | 238 | if ( category == "SR" || category == "SR-StratumBMv2" ){ |
Jeremy Ronquillo | 336110a | 2019-07-11 14:20:40 -0700 | [diff] [blame] | 239 | result = ''' |
| 240 | sudo rm /var/jenkins/workspace/SR-log-${WikiPrefix}/* |
| 241 | sudo cp *karaf.log.* /var/jenkins/workspace/SR-log-${WikiPrefix}/ |
| 242 | sudo cp *Flows* /var/jenkins/workspace/SR-log-${WikiPrefix}/ |
| 243 | sudo cp *Groups* /var/jenkins/workspace/SR-log-${WikiPrefix}/ |
| 244 | sudo cp *.tar.gz /var/jenkins/workspace/SR-log-${WikiPrefix}/ |
| 245 | sudo cp t3-* /var/jenkins/workspace/SR-log-${WikiPrefix}/ |
| 246 | ''' |
| 247 | } |
| 248 | return result |
| 249 | } |
| 250 | |
| 251 | def cleanAndCopyFiles( testName ){ |
| 252 | // clean up some files that were in the folder and copy the new files from the log |
| 253 | // testName : name of the test |
| 254 | |
| 255 | return '''#!/bin/bash -i |
| 256 | set +e |
| 257 | echo "ONOS Branch is: ${ONOSBranch}" |
| 258 | echo "TestON Branch is: ${TestONBranch}" |
| 259 | echo "Job name is: "''' + testName + ''' |
| 260 | echo "Workspace is: ${WORKSPACE}/" |
| 261 | echo "Wiki page to post is: ${WikiPrefix}-" |
| 262 | # remove any leftover files from previous tests |
| 263 | sudo rm ${WORKSPACE}/*Wiki.txt |
| 264 | sudo rm ${WORKSPACE}/*Summary.txt |
| 265 | sudo rm ${WORKSPACE}/*Result.txt |
| 266 | sudo rm ${WORKSPACE}/*Alarm.txt || true |
| 267 | sudo rm ${WORKSPACE}/*.csv |
| 268 | #copy files to workspace |
| 269 | cd `ls -t ~/OnosSystemTest/TestON/logs/*/ | head -1 | sed 's/://'` |
| 270 | ''' + copyLogs() + ''' |
| 271 | sudo cp *.txt ${WORKSPACE}/ |
| 272 | sudo cp *.csv ${WORKSPACE}/ |
| 273 | cd ${WORKSPACE}/ |
| 274 | for i in *.csv |
| 275 | do mv "$i" "$WikiPrefix"-"$i" |
| 276 | done |
| 277 | ls -al |
| 278 | cd ''' |
| 279 | } |
| 280 | |
| 281 | def fetchLogs( testName ){ |
| 282 | // fetch the logs of onos from onos nodes to onos System Test logs |
| 283 | // testName: name of the test |
| 284 | |
| 285 | return '''#!/bin/bash |
| 286 | set +e |
| 287 | cd ~/OnosSystemTest/TestON/logs |
| 288 | echo "TestON test name is: "''' + testName + ''' |
| 289 | TestONlogDir=$(ls -t | grep ${TEST_NAME}_ |head -1) |
| 290 | echo "########################################################################################" |
| 291 | echo "##### copying ONOS logs from all nodes to TestON/logs directory: ${TestONlogDir}" |
| 292 | echo "########################################################################################" |
| 293 | cd $TestONlogDir |
| 294 | if [ $? -eq 1 ] |
| 295 | then |
| 296 | echo "Job name does not match any test suite name to move log!" |
| 297 | else |
| 298 | pwd |
| 299 | for i in $OC{1..7}; do onos-fetch-logs $i || echo log does not exist for onos $i; done |
| 300 | for i in $OC{1..7}; do atomix-fetch-logs $i || echo log does not exist for atomix $i; done |
| 301 | fi |
| 302 | cd''' |
| 303 | } |
| 304 | |
| 305 | def publishToConfluence( isManualRun, isPostResult, wikiLink, file ){ |
| 306 | // publish HTML script to wiki confluence |
| 307 | // isManualRun : string "true" "false" |
| 308 | // isPostResult : string "true" "false" |
| 309 | // wikiLink : link of the wiki page to publish |
| 310 | // file : name of the file to be published |
| 311 | |
Jeremy Ronquillo | 31a3eb3 | 2019-08-02 13:30:37 -0700 | [diff] [blame] | 312 | if ( graphs.isPostingResult( isManualRun, isPostResult ) ){ |
Jeremy Ronquillo | 336110a | 2019-07-11 14:20:40 -0700 | [diff] [blame] | 313 | publishConfluence siteName: 'wiki.onosproject.org', pageName: wikiLink, spaceName: 'ONOS', |
| 314 | attachArchivedArtifacts: true, buildIfUnstable: true, |
| 315 | editorList: [ confluenceWritePage( confluenceFile( file ) ) ] |
| 316 | } |
| 317 | } |
| 318 | |
| 319 | def postLogs( testName, prefix ){ |
| 320 | // posting logs of the onos jobs specifically SR tests |
| 321 | // testName : name of the test |
| 322 | // prefix : branch prefix ( master, 2.1, 1.15 ... ) |
| 323 | |
| 324 | resultURL = "" |
Jon Hall | a15854a | 2020-07-23 15:47:00 -0700 | [diff] [blame] | 325 | if ( category == "SR" || category == "SR-StratumBMv2" ){ |
Jeremy Ronquillo | 336110a | 2019-07-11 14:20:40 -0700 | [diff] [blame] | 326 | def post = build job: "SR-log-" + prefix, propagate: false |
| 327 | resultURL = post.getAbsoluteUrl() |
| 328 | } |
| 329 | return resultURL |
| 330 | } |
| 331 | |
| 332 | def analyzeResult( prop, workSpace, pureTestName, testName, resultURL, wikiLink, isSCPF ){ |
| 333 | // analyzing the result of the test and send to slack if any abnormal result is logged. |
| 334 | // prop : property dictionary |
| 335 | // workSpace : workSpace where the result file is saved |
| 336 | // pureTestName : TestON name of the test |
| 337 | // testName : Jenkins name of the test. Example: SCPFflowTPFobj |
| 338 | // resultURL : url for the logs for SR tests. Will not be posted if it is empty |
| 339 | // wikiLink : link of the wiki page where the result was posted |
| 340 | // isSCPF : Check if it is SCPF. If so, it won't post the wiki link. |
| 341 | |
| 342 | node( testStation ) { |
| 343 | def alarmFile = workSpace + "/" + pureTestName + "Alarm.txt" |
| 344 | if ( fileExists( alarmFile ) ) { |
| 345 | def alarmContents = readFile( alarmFile ) |
| 346 | slackSend( channel: "#jenkins-related", |
| 347 | color: "FF0000", |
| 348 | message: "[" + prop[ "ONOSBranch" ] + "]" + testName + " : triggered alarms:\n" + |
| 349 | alarmContents + "\n" + |
| 350 | "[TestON log] : \n" + |
| 351 | "https://jenkins.onosproject.org/blue/organizations/jenkins/${ env.JOB_NAME }/detail/${ env.JOB_NAME }/${ env.BUILD_NUMBER }/pipeline" + |
| 352 | ( isSCPF ? "" : ( "\n[Result on Wiki] : \n" + |
| 353 | "https://wiki.onosproject.org/display/ONOS/" + |
| 354 | wikiLink.replaceAll( "\\s", "+" ) ) ) + |
| 355 | ( resultURL != "" ? ( "\n[Karaf log] : \n" + |
| 356 | resultURL + "artifact/" ) : "" ), |
| 357 | teamDomain: 'onosproject' ) |
Jeremy Ronquillo | e4e8391 | 2019-07-29 12:58:48 -0700 | [diff] [blame] | 358 | print "Abnormal test result." |
Jeremy Ronquillo | 336110a | 2019-07-11 14:20:40 -0700 | [diff] [blame] | 359 | throw new Exception( "Abnormal test result." ) |
| 360 | } |
| 361 | else { |
| 362 | print "Test results are OK." |
| 363 | } |
| 364 | } |
| 365 | } |
| 366 | |
| 367 | def runTest( testName, toBeRun, prop, pureTestName, graphOnly, testCategory, graph_generator_file, |
| 368 | graph_saved_directory ){ |
| 369 | // run the test on the machine that contains all the steps : init and run test, copy files, publish result ... |
| 370 | // testName : name of the test in Jenkins |
| 371 | // toBeRun : boolean value whether the test will be run or not. If not, it won't be run but shows up with empty |
| 372 | // result on pipeline view |
| 373 | // prop : dictionary property on the machine |
| 374 | // pureTestName : Pure name of the test. ( ex. pureTestName of SCPFflowTpFobj will be SCPFflowTp ) |
| 375 | // graphOnly : check if it is generating graph job. If so, it will only generate the generating graph part |
| 376 | // testCategory : Map for the test suit ( SCPF, SR, FUNC, ... ) which contains information about the tests |
| 377 | // graph_generator_file : Rscript file with the full path. |
| 378 | // graph_saved_directory : where the generated graph will be saved to. |
| 379 | |
| 380 | return { |
| 381 | catchError { |
| 382 | stage( testName ) { |
| 383 | if ( toBeRun ){ |
| 384 | def workSpace = "/var/jenkins/workspace/" + testName |
| 385 | def fileContents = "" |
| 386 | node( testStation ) { |
| 387 | withEnv( [ 'ONOSBranch=' + prop[ "ONOSBranch" ], |
| 388 | 'ONOSJAVAOPTS=' + prop[ "ONOSJAVAOPTS" ], |
| 389 | 'TestONBranch=' + prop[ "TestONBranch" ], |
| 390 | 'ONOSTag=' + prop[ "ONOSTag" ], |
| 391 | 'WikiPrefix=' + prop[ "WikiPrefix" ], |
| 392 | 'WORKSPACE=' + workSpace ] ) { |
| 393 | if ( !graphOnly ){ |
| 394 | if ( isSCPF ){ |
| 395 | // Remove the old database file |
| 396 | sh SCPFfuncs.cleanupDatabaseFile( testName ) |
| 397 | } |
Jeremy Ronquillo | 5ceda07 | 2019-08-12 12:56:43 -0700 | [diff] [blame] | 398 | sh script: configureJavaVersion(), label: "Configure Java Version" |
Jeremy Ronquillo | 336110a | 2019-07-11 14:20:40 -0700 | [diff] [blame] | 399 | sh script: initTest(), label: "Test Initialization: stc shutdown; stc teardown; ./cleanup.sh" |
| 400 | catchError{ |
Jeremy Ronquillo | 31a3eb3 | 2019-08-02 13:30:37 -0700 | [diff] [blame] | 401 | sh script: runTestCli_py( testName, pureTestName, testCategory ), label: ( "Run Test: ./cli.py run " + testName ) |
Jeremy Ronquillo | 336110a | 2019-07-11 14:20:40 -0700 | [diff] [blame] | 402 | } |
| 403 | catchError{ |
| 404 | sh script: concludeRunTest(), label: "Conclude Running Test: ./cleanup.sh; git clean -df" |
| 405 | } |
| 406 | catchError{ |
| 407 | // For the Wiki page |
| 408 | sh script: cleanAndCopyFiles( pureTestName ), label: "Clean and Copy Files" |
| 409 | } |
| 410 | } |
| 411 | graphs.databaseAndGraph( prop, testName, pureTestName, graphOnly, |
| 412 | graph_generator_file, graph_saved_directory ) |
| 413 | if ( !graphOnly ){ |
| 414 | sh script: fetchLogs( pureTestName ), label: "Fetch Logs" |
| 415 | if ( !isSCPF ){ |
| 416 | publishToConfluence( prop[ "manualRun" ], prop[ "postResult" ], |
| 417 | prop[ "WikiPrefix" ] + "-" + testCategory[ testName ][ 'wikiName' ], |
| 418 | workSpace + "/" + testCategory[ testName ][ 'wikiFile' ] ) |
| 419 | } |
| 420 | } |
| 421 | } |
| 422 | } |
| 423 | graphs.postResult( prop, graphOnly, nodeLabel ) |
| 424 | if ( !graphOnly ){ |
| 425 | def resultURL = postLogs( testName, prop[ "WikiPrefix" ] ) |
| 426 | analyzeResult( prop, workSpace, pureTestName, testName, resultURL, |
| 427 | isSCPF ? "" : testCategory[ testName ][ 'wikiName' ], |
| 428 | isSCPF ) |
| 429 | } |
Jeremy Ronquillo | b8aac44 | 2019-07-31 13:28:01 -0700 | [diff] [blame] | 430 | } else { |
| 431 | echo testName + " is not being run today. Leaving the rest of stage contents blank." |
Jeremy Ronquillo | 336110a | 2019-07-11 14:20:40 -0700 | [diff] [blame] | 432 | } |
| 433 | } |
| 434 | } |
| 435 | } |
| 436 | } |
| 437 | |
Jeremy Ronquillo | 21c29fc | 2019-06-05 11:15:24 -0700 | [diff] [blame] | 438 | def generateGraphs(){ |
Jeremy Ronquillo | 0695099 | 2019-07-09 11:16:49 -0700 | [diff] [blame] | 439 | if ( category != "SCPF" ){ |
| 440 | // generate the overall graph of the non SCPF tests. |
Jeremy Ronquillo | 336110a | 2019-07-11 14:20:40 -0700 | [diff] [blame] | 441 | graphs.generateOverallGraph( prop, testsToRun, graphPaths[ "saveDirectory" ], nodeLabel, category ) |
Jeremy Ronquillo | bb3001f | 2019-07-01 12:57:07 -0700 | [diff] [blame] | 442 | } |
Jeremy Ronquillo | 21c29fc | 2019-06-05 11:15:24 -0700 | [diff] [blame] | 443 | } |
| 444 | |
| 445 | def sendToSlack(){ |
Jeremy Ronquillo | 336110a | 2019-07-11 14:20:40 -0700 | [diff] [blame] | 446 | // send the result of the test to the slack when it is not manually running. |
| 447 | // start : start time of the test |
| 448 | // isManualRun : string that is whether "false" or "true" |
| 449 | // branch : branch of the onos. |
| 450 | |
| 451 | try { |
| 452 | if ( prop[ "manualRun" ] == "false" ){ |
| 453 | end = getCurrentTime() |
| 454 | TimeDuration duration = TimeCategory.minus( end, start ) |
| 455 | // FIXME: for now we disable notifications of normal test results |
| 456 | /* |
| 457 | slackSend( color: "#5816EE", |
| 458 | message: category + "-" + prop[ "WikiPrefix" ] + " tests ended at: " + end.toString() + |
| 459 | "\nTime took : " + duration ) |
| 460 | */ |
| 461 | } |
| 462 | } |
| 463 | catch ( all ){ |
| 464 | } |
Jeremy Ronquillo | 21c29fc | 2019-06-05 11:15:24 -0700 | [diff] [blame] | 465 | } |