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 |
Jeremy Ronquillo | a8490fb | 2019-06-26 11:59:50 -0700 | [diff] [blame] | 32 | testsToRunStrList = null |
Jeremy Ronquillo | 21c29fc | 2019-06-05 11:15:24 -0700 | [diff] [blame] | 33 | branch = null |
Jeremy Ronquillo | 336110a | 2019-07-11 14:20:40 -0700 | [diff] [blame] | 34 | branchWithPrefix = null |
Jeremy Ronquillo | a8490fb | 2019-06-26 11:59:50 -0700 | [diff] [blame] | 35 | start = null |
Jeremy Ronquillo | 336110a | 2019-07-11 14:20:40 -0700 | [diff] [blame] | 36 | nodeLabel = null |
Jeremy Ronquillo | 6fbfdd5 | 2019-07-09 13:49:34 -0700 | [diff] [blame] | 37 | testStation = null |
Jeremy Ronquillo | 336110a | 2019-07-11 14:20:40 -0700 | [diff] [blame] | 38 | testsOverride = null |
| 39 | isGraphOnly = false |
| 40 | isSCPF = false |
Jeremy Ronquillo | 6da78cf | 2019-07-29 11:47:19 -0700 | [diff] [blame] | 41 | pipelineTimeout = null |
| 42 | |
Jon Hall | f29368d | 2020-07-31 12:23:56 -0700 | [diff] [blame] | 43 | testsToRun = [:] |
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. |
Jeremy Ronquillo | f5482c9 | 2020-12-09 16:30:49 -0800 | [diff] [blame] | 103 | nodeLabel = params.NodeLabel // "BM", "VM", "Fabric-LTS1", 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 | 4dc60b1 | 2020-12-15 16:46:06 -0800 | [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" ) + "/" ) |
Jon Hall | 4dc60b1 | 2020-12-15 16:46:06 -0800 | [diff] [blame] | 129 | } else if ( category == "SR-Tofino" ){ |
| 130 | graphPaths.put( "saveDirectory", fileRelated.workspaces[ "QA-POD" ] ) |
Jeremy Ronquillo | 21c29fc | 2019-06-05 11:15:24 -0700 | [diff] [blame] | 131 | } else if ( category == "SRHA" ) { |
Jeremy Ronquillo | 1e5d7f2 | 2019-07-17 14:18:42 -0700 | [diff] [blame] | 132 | graphPaths.put( "saveDirectory", fileRelated.workspaces[ "Fabric" ] ) |
Jeremy Ronquillo | bb3001f | 2019-07-01 12:57:07 -0700 | [diff] [blame] | 133 | } else if ( category == "SCPF" || category == "USECASE" ){ |
Jeremy Ronquillo | 1e5d7f2 | 2019-07-17 14:18:42 -0700 | [diff] [blame] | 134 | graphPaths.put( "saveDirectory", fileRelated.workspaces[ "BM" ] ) |
Jeremy Ronquillo | 21c29fc | 2019-06-05 11:15:24 -0700 | [diff] [blame] | 135 | } else { |
Jeremy Ronquillo | 1e5d7f2 | 2019-07-17 14:18:42 -0700 | [diff] [blame] | 136 | graphPaths.put( "saveDirectory", fileRelated.workspaces[ "VM" ] ) |
Jeremy Ronquillo | 21c29fc | 2019-06-05 11:15:24 -0700 | [diff] [blame] | 137 | } |
| 138 | } |
| 139 | |
| 140 | def runTests(){ |
| 141 | // run the test sequentially and save the function into the dictionary. |
Jon Hall | d4f33e1 | 2020-07-29 14:50:34 -0700 | [diff] [blame] | 142 | for ( String JenkinsLabel : testsFromList.keySet() ){ |
| 143 | toBeRun = testsToRun.keySet().contains( JenkinsLabel ) |
| 144 | stepName = ( toBeRun ? "" : "Not " ) + "Running $JenkinsLabel" |
| 145 | |
Jon Hall | f29368d | 2020-07-31 12:23:56 -0700 | [diff] [blame] | 146 | TestONTest = ( toBeRun && testsToRun[ JenkinsLabel ].keySet().contains( "test" ) ) ? testsToRun[ JenkinsLabel ][ "test" ] : JenkinsLabel |
Jon Hall | d4f33e1 | 2020-07-29 14:50:34 -0700 | [diff] [blame] | 147 | |
| 148 | pipeline[ stepName ] = runTest( JenkinsLabel, |
Jeremy Ronquillo | 336110a | 2019-07-11 14:20:40 -0700 | [diff] [blame] | 149 | toBeRun, |
| 150 | prop, |
Jon Hall | d4f33e1 | 2020-07-29 14:50:34 -0700 | [diff] [blame] | 151 | TestONTest, |
Jeremy Ronquillo | 336110a | 2019-07-11 14:20:40 -0700 | [diff] [blame] | 152 | isGraphOnly, |
| 153 | testsToRun, |
| 154 | graphPaths[ "trendIndividual" ], |
| 155 | graphPaths[ "saveDirectory" ] ) |
Jeremy Ronquillo | 21c29fc | 2019-06-05 11:15:24 -0700 | [diff] [blame] | 156 | } |
| 157 | |
| 158 | // get the start time of the test. |
Jeremy Ronquillo | 336110a | 2019-07-11 14:20:40 -0700 | [diff] [blame] | 159 | start = getCurrentTime() |
Jeremy Ronquillo | 21c29fc | 2019-06-05 11:15:24 -0700 | [diff] [blame] | 160 | |
| 161 | // run the tests sequentially. |
Jon Hall | d4f33e1 | 2020-07-29 14:50:34 -0700 | [diff] [blame] | 162 | for ( JenkinsLabel in pipeline.keySet() ){ |
| 163 | pipeline[ JenkinsLabel ].call() |
Jeremy Ronquillo | 21c29fc | 2019-06-05 11:15:24 -0700 | [diff] [blame] | 164 | } |
| 165 | } |
| 166 | |
Jeremy Ronquillo | 336110a | 2019-07-11 14:20:40 -0700 | [diff] [blame] | 167 | def initTest(){ |
| 168 | return '''#!/bin/bash -l |
| 169 | set -i # interactive |
| 170 | set +e |
| 171 | shopt -s expand_aliases # expand alias in non-interactive mode |
| 172 | export PYTHONUNBUFFERED=1 |
| 173 | ifconfig |
| 174 | echo "ONOS Branch is: $ONOSBranch" |
| 175 | echo "TestON Branch is: $TestONBranch" |
| 176 | echo "Test date: " |
| 177 | date |
| 178 | cd ~ |
| 179 | export PATH=$PATH:onos/tools/test/bin |
| 180 | timeout 240 stc shutdown | head -100 |
| 181 | timeout 240 stc teardown | head -100 |
| 182 | timeout 240 stc shutdown | head -100 |
| 183 | cd ~/OnosSystemTest/TestON/bin |
| 184 | git log | head |
| 185 | ./cleanup.sh -f || true |
| 186 | ''' |
| 187 | } |
| 188 | |
Jeremy Ronquillo | 5ceda07 | 2019-08-12 12:56:43 -0700 | [diff] [blame] | 189 | def configureJavaVersion(){ |
| 190 | java_1_8_branches = [ "1.15" ] |
| 191 | return '''#!/bin/bash -l |
| 192 | ''' + ( java_1_8_branches.contains( branch ) ? '''SET_JAVA_VER=java-8-oracle''' : '''SET_JAVA_VER=java-1.11.0-openjdk-amd64''' ) + |
| 193 | ''' |
| 194 | CELL_COUNT=$( env | egrep "OC[1-9]+" | wc -l ) |
| 195 | for i in $(seq 1 $CELL_COUNT) |
| 196 | do |
| 197 | CELL_TO_SET=$( env | egrep "OC$i" | cut -c5- ) |
| 198 | echo "Setting java to $SET_JAVA_VER on $CELL_TO_SET" |
| 199 | eval ssh $CELL_TO_SET 'sudo update-java-alternatives -s $SET_JAVA_VER' |
| 200 | done |
| 201 | ''' |
| 202 | } |
| 203 | |
Jon Hall | d4f33e1 | 2020-07-29 14:50:34 -0700 | [diff] [blame] | 204 | def runTestCli_py( testName, testArguments ){ |
Jeremy Ronquillo | 336110a | 2019-07-11 14:20:40 -0700 | [diff] [blame] | 205 | // Bash script that will run the test. |
Jon Hall | d4f33e1 | 2020-07-29 14:50:34 -0700 | [diff] [blame] | 206 | // testName : name of the test in TestON |
| 207 | // testArguments : Arguments to be passed to the test framework |
Jeremy Ronquillo | 31a3eb3 | 2019-08-02 13:30:37 -0700 | [diff] [blame] | 208 | |
| 209 | command = '''cd ~/OnosSystemTest/TestON/bin |
Jon Hall | d4f33e1 | 2020-07-29 14:50:34 -0700 | [diff] [blame] | 210 | ./cli.py run ''' + testName + ''' --params GRAPH/nodeCluster=''' + graphs.getPostjobType( nodeLabel ) + ''' ''' + testArguments |
Jeremy Ronquillo | 31a3eb3 | 2019-08-02 13:30:37 -0700 | [diff] [blame] | 211 | echo command |
| 212 | |
| 213 | return command |
| 214 | |
| 215 | |
Jeremy Ronquillo | 336110a | 2019-07-11 14:20:40 -0700 | [diff] [blame] | 216 | } |
| 217 | |
| 218 | def concludeRunTest(){ |
Jon Hall | d4f33e1 | 2020-07-29 14:50:34 -0700 | [diff] [blame] | 219 | // TODO: Add cleanup for if we use docker containers |
Jeremy Ronquillo | 336110a | 2019-07-11 14:20:40 -0700 | [diff] [blame] | 220 | return '''cd ~/OnosSystemTest/TestON/bin |
| 221 | ./cleanup.sh -f || true |
| 222 | # cleanup config changes |
| 223 | cd ~/onos/tools/package/config |
| 224 | git clean -df''' |
| 225 | } |
| 226 | |
| 227 | def copyLogs(){ |
| 228 | // bash script to copy the logs and other necessary element for SR tests. |
| 229 | |
| 230 | result = "" |
Jon Hall | c68e216 | 2020-07-29 10:50:09 -0700 | [diff] [blame] | 231 | if ( category == "SR" || category == "SR-StratumBMv2" || category == "SR-Tofino" ){ |
Jeremy Ronquillo | 336110a | 2019-07-11 14:20:40 -0700 | [diff] [blame] | 232 | result = ''' |
| 233 | sudo rm /var/jenkins/workspace/SR-log-${WikiPrefix}/* |
| 234 | sudo cp *karaf.log.* /var/jenkins/workspace/SR-log-${WikiPrefix}/ |
| 235 | sudo cp *Flows* /var/jenkins/workspace/SR-log-${WikiPrefix}/ |
| 236 | sudo cp *Groups* /var/jenkins/workspace/SR-log-${WikiPrefix}/ |
| 237 | sudo cp *.tar.gz /var/jenkins/workspace/SR-log-${WikiPrefix}/ |
| 238 | sudo cp t3-* /var/jenkins/workspace/SR-log-${WikiPrefix}/ |
| 239 | ''' |
| 240 | } |
| 241 | return result |
| 242 | } |
| 243 | |
Jon Hall | d4f33e1 | 2020-07-29 14:50:34 -0700 | [diff] [blame] | 244 | def cleanAndCopyFiles( JenkinsLabel ){ |
Jeremy Ronquillo | 336110a | 2019-07-11 14:20:40 -0700 | [diff] [blame] | 245 | // clean up some files that were in the folder and copy the new files from the log |
Jon Hall | d4f33e1 | 2020-07-29 14:50:34 -0700 | [diff] [blame] | 246 | // JenkinsLabel : name of the test in Jenkins |
Jeremy Ronquillo | 336110a | 2019-07-11 14:20:40 -0700 | [diff] [blame] | 247 | |
| 248 | return '''#!/bin/bash -i |
| 249 | set +e |
| 250 | echo "ONOS Branch is: ${ONOSBranch}" |
| 251 | echo "TestON Branch is: ${TestONBranch}" |
Jon Hall | d4f33e1 | 2020-07-29 14:50:34 -0700 | [diff] [blame] | 252 | echo "Job name is: "''' + JenkinsLabel + ''' |
Jeremy Ronquillo | 336110a | 2019-07-11 14:20:40 -0700 | [diff] [blame] | 253 | echo "Workspace is: ${WORKSPACE}/" |
| 254 | echo "Wiki page to post is: ${WikiPrefix}-" |
| 255 | # remove any leftover files from previous tests |
| 256 | sudo rm ${WORKSPACE}/*Wiki.txt |
| 257 | sudo rm ${WORKSPACE}/*Summary.txt |
| 258 | sudo rm ${WORKSPACE}/*Result.txt |
| 259 | sudo rm ${WORKSPACE}/*Alarm.txt || true |
| 260 | sudo rm ${WORKSPACE}/*.csv |
| 261 | #copy files to workspace |
| 262 | cd `ls -t ~/OnosSystemTest/TestON/logs/*/ | head -1 | sed 's/://'` |
| 263 | ''' + copyLogs() + ''' |
| 264 | sudo cp *.txt ${WORKSPACE}/ |
| 265 | sudo cp *.csv ${WORKSPACE}/ |
| 266 | cd ${WORKSPACE}/ |
| 267 | for i in *.csv |
| 268 | do mv "$i" "$WikiPrefix"-"$i" |
| 269 | done |
| 270 | ls -al |
| 271 | cd ''' |
| 272 | } |
| 273 | |
Jon Hall | d4f33e1 | 2020-07-29 14:50:34 -0700 | [diff] [blame] | 274 | def fetchLogs( JenkinsLabel ){ |
Jeremy Ronquillo | 336110a | 2019-07-11 14:20:40 -0700 | [diff] [blame] | 275 | // fetch the logs of onos from onos nodes to onos System Test logs |
Jon Hall | d4f33e1 | 2020-07-29 14:50:34 -0700 | [diff] [blame] | 276 | // JenkinsLabel : name of the test in Jenkins |
Jeremy Ronquillo | 336110a | 2019-07-11 14:20:40 -0700 | [diff] [blame] | 277 | |
| 278 | return '''#!/bin/bash |
| 279 | set +e |
| 280 | cd ~/OnosSystemTest/TestON/logs |
Jon Hall | d4f33e1 | 2020-07-29 14:50:34 -0700 | [diff] [blame] | 281 | echo "TestON test name is: "''' + JenkinsLabel + ''' |
Jeremy Ronquillo | 336110a | 2019-07-11 14:20:40 -0700 | [diff] [blame] | 282 | TestONlogDir=$(ls -t | grep ${TEST_NAME}_ |head -1) |
| 283 | echo "########################################################################################" |
| 284 | echo "##### copying ONOS logs from all nodes to TestON/logs directory: ${TestONlogDir}" |
| 285 | echo "########################################################################################" |
| 286 | cd $TestONlogDir |
| 287 | if [ $? -eq 1 ] |
| 288 | then |
| 289 | echo "Job name does not match any test suite name to move log!" |
| 290 | else |
| 291 | pwd |
| 292 | for i in $OC{1..7}; do onos-fetch-logs $i || echo log does not exist for onos $i; done |
| 293 | for i in $OC{1..7}; do atomix-fetch-logs $i || echo log does not exist for atomix $i; done |
| 294 | fi |
| 295 | cd''' |
| 296 | } |
| 297 | |
| 298 | def publishToConfluence( isManualRun, isPostResult, wikiLink, file ){ |
| 299 | // publish HTML script to wiki confluence |
| 300 | // isManualRun : string "true" "false" |
| 301 | // isPostResult : string "true" "false" |
| 302 | // wikiLink : link of the wiki page to publish |
| 303 | // file : name of the file to be published |
| 304 | |
Jeremy Ronquillo | 31a3eb3 | 2019-08-02 13:30:37 -0700 | [diff] [blame] | 305 | if ( graphs.isPostingResult( isManualRun, isPostResult ) ){ |
Jeremy Ronquillo | 336110a | 2019-07-11 14:20:40 -0700 | [diff] [blame] | 306 | publishConfluence siteName: 'wiki.onosproject.org', pageName: wikiLink, spaceName: 'ONOS', |
| 307 | attachArchivedArtifacts: true, buildIfUnstable: true, |
| 308 | editorList: [ confluenceWritePage( confluenceFile( file ) ) ] |
| 309 | } |
| 310 | } |
| 311 | |
Jon Hall | d4f33e1 | 2020-07-29 14:50:34 -0700 | [diff] [blame] | 312 | def postLogs( prefix ){ |
Jeremy Ronquillo | 336110a | 2019-07-11 14:20:40 -0700 | [diff] [blame] | 313 | // posting logs of the onos jobs specifically SR tests |
Jeremy Ronquillo | 336110a | 2019-07-11 14:20:40 -0700 | [diff] [blame] | 314 | // prefix : branch prefix ( master, 2.1, 1.15 ... ) |
| 315 | |
| 316 | resultURL = "" |
Jon Hall | c68e216 | 2020-07-29 10:50:09 -0700 | [diff] [blame] | 317 | if ( category == "SR" || category == "SR-StratumBMv2" || category == "SR-Tofino" ){ |
Jon Hall | 7701891 | 2020-12-11 18:54:01 -0800 | [diff] [blame] | 318 | if ( category == "SR-Tofino" ){ |
| 319 | prefix = "Tofino" |
| 320 | } |
| 321 | node( params.assignedNode ) { |
| 322 | def post = build job: "SR-log-" + prefix, propagate: false |
| 323 | resultURL = post.getAbsoluteUrl() |
| 324 | } |
Jeremy Ronquillo | 336110a | 2019-07-11 14:20:40 -0700 | [diff] [blame] | 325 | } |
| 326 | return resultURL |
| 327 | } |
| 328 | |
Jon Hall | d4f33e1 | 2020-07-29 14:50:34 -0700 | [diff] [blame] | 329 | def analyzeResult( prop, workSpace, TestONTest, JenkinsLabel, resultURL, wikiLink, isSCPF ){ |
Jeremy Ronquillo | 336110a | 2019-07-11 14:20:40 -0700 | [diff] [blame] | 330 | // analyzing the result of the test and send to slack if any abnormal result is logged. |
| 331 | // prop : property dictionary |
| 332 | // workSpace : workSpace where the result file is saved |
Jon Hall | d4f33e1 | 2020-07-29 14:50:34 -0700 | [diff] [blame] | 333 | // TestONTest : TestON name of the test |
| 334 | // JenkinsLabel : Jenkins name of the test. Example: SCPFflowTPFobj |
Jeremy Ronquillo | 336110a | 2019-07-11 14:20:40 -0700 | [diff] [blame] | 335 | // resultURL : url for the logs for SR tests. Will not be posted if it is empty |
| 336 | // wikiLink : link of the wiki page where the result was posted |
| 337 | // isSCPF : Check if it is SCPF. If so, it won't post the wiki link. |
| 338 | |
| 339 | node( testStation ) { |
Jon Hall | d4f33e1 | 2020-07-29 14:50:34 -0700 | [diff] [blame] | 340 | def alarmFile = workSpace + "/" + TestONTest + "Alarm.txt" |
Jeremy Ronquillo | 336110a | 2019-07-11 14:20:40 -0700 | [diff] [blame] | 341 | if ( fileExists( alarmFile ) ) { |
| 342 | def alarmContents = readFile( alarmFile ) |
| 343 | slackSend( channel: "#jenkins-related", |
| 344 | color: "FF0000", |
Jon Hall | d4f33e1 | 2020-07-29 14:50:34 -0700 | [diff] [blame] | 345 | message: "[" + prop[ "ONOSBranch" ] + "] " + JenkinsLabel + " : triggered alarms:\n" + |
Jeremy Ronquillo | 336110a | 2019-07-11 14:20:40 -0700 | [diff] [blame] | 346 | alarmContents + "\n" + |
| 347 | "[TestON log] : \n" + |
| 348 | "https://jenkins.onosproject.org/blue/organizations/jenkins/${ env.JOB_NAME }/detail/${ env.JOB_NAME }/${ env.BUILD_NUMBER }/pipeline" + |
| 349 | ( isSCPF ? "" : ( "\n[Result on Wiki] : \n" + |
| 350 | "https://wiki.onosproject.org/display/ONOS/" + |
| 351 | wikiLink.replaceAll( "\\s", "+" ) ) ) + |
| 352 | ( resultURL != "" ? ( "\n[Karaf log] : \n" + |
| 353 | resultURL + "artifact/" ) : "" ), |
You Wang | 2610329 | 2020-08-03 15:36:49 -0700 | [diff] [blame] | 354 | teamDomain: 'onf-community' ) |
Jeremy Ronquillo | e4e8391 | 2019-07-29 12:58:48 -0700 | [diff] [blame] | 355 | print "Abnormal test result." |
Jeremy Ronquillo | 336110a | 2019-07-11 14:20:40 -0700 | [diff] [blame] | 356 | throw new Exception( "Abnormal test result." ) |
| 357 | } |
| 358 | else { |
| 359 | print "Test results are OK." |
| 360 | } |
| 361 | } |
| 362 | } |
| 363 | |
Jon Hall | d4f33e1 | 2020-07-29 14:50:34 -0700 | [diff] [blame] | 364 | def runTest( JenkinsLabel, toBeRun, prop, TestONTest, graphOnly, testCategory, |
| 365 | graph_generator_file, graph_saved_directory ){ |
Jeremy Ronquillo | 336110a | 2019-07-11 14:20:40 -0700 | [diff] [blame] | 366 | // run the test on the machine that contains all the steps : init and run test, copy files, publish result ... |
Jon Hall | d4f33e1 | 2020-07-29 14:50:34 -0700 | [diff] [blame] | 367 | // JenkinsLabel : name of the test in Jenkins |
Jeremy Ronquillo | 336110a | 2019-07-11 14:20:40 -0700 | [diff] [blame] | 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 |
Jon Hall | d4f33e1 | 2020-07-29 14:50:34 -0700 | [diff] [blame] | 371 | // TestONTest : Pure name of the test. ( ex. TestONTest of SCPFflowTpFobj will be SCPFflowTp ) |
Jeremy Ronquillo | 336110a | 2019-07-11 14:20:40 -0700 | [diff] [blame] | 372 | // graphOnly : check if it is generating graph job. If so, it will only generate the generating graph part |
| 373 | // testCategory : Map for the test suit ( SCPF, SR, FUNC, ... ) which contains information about the tests |
| 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 { |
Jon Hall | d4f33e1 | 2020-07-29 14:50:34 -0700 | [diff] [blame] | 379 | stage( JenkinsLabel ) { |
Jeremy Ronquillo | 336110a | 2019-07-11 14:20:40 -0700 | [diff] [blame] | 380 | if ( toBeRun ){ |
Jon Hall | d4f33e1 | 2020-07-29 14:50:34 -0700 | [diff] [blame] | 381 | def workSpace = "/var/jenkins/workspace/" + JenkinsLabel |
Jeremy Ronquillo | 336110a | 2019-07-11 14:20:40 -0700 | [diff] [blame] | 382 | def fileContents = "" |
Jon Hall | 1d1c451 | 2020-07-29 16:10:40 -0700 | [diff] [blame] | 383 | testArguments = testCategory[ JenkinsLabel ].keySet().contains( "arguments" ) ? testCategory[ JenkinsLabel ][ "arguments" ] : "" |
Jon Hall | 4dc60b1 | 2020-12-15 16:46:06 -0800 | [diff] [blame] | 384 | isTofino = testCategory[ JenkinsLabel ][ "category" ] == "SR-Tofino" |
Jeremy Ronquillo | 336110a | 2019-07-11 14:20:40 -0700 | [diff] [blame] | 385 | node( testStation ) { |
| 386 | withEnv( [ 'ONOSBranch=' + prop[ "ONOSBranch" ], |
| 387 | 'ONOSJAVAOPTS=' + prop[ "ONOSJAVAOPTS" ], |
| 388 | 'TestONBranch=' + prop[ "TestONBranch" ], |
| 389 | 'ONOSTag=' + prop[ "ONOSTag" ], |
| 390 | 'WikiPrefix=' + prop[ "WikiPrefix" ], |
| 391 | 'WORKSPACE=' + workSpace ] ) { |
| 392 | if ( !graphOnly ){ |
| 393 | if ( isSCPF ){ |
| 394 | // Remove the old database file |
Jon Hall | d4f33e1 | 2020-07-29 14:50:34 -0700 | [diff] [blame] | 395 | sh SCPFfuncs.cleanupDatabaseFile( JenkinsLabel ) |
Jeremy Ronquillo | 336110a | 2019-07-11 14:20:40 -0700 | [diff] [blame] | 396 | } |
Jon Hall | 4dc60b1 | 2020-12-15 16:46:06 -0800 | [diff] [blame] | 397 | if ( !isTofino ) { |
| 398 | sh script: configureJavaVersion(), label: "Configure Java Version" |
| 399 | sh script: initTest(), label: "Test Initialization: stc shutdown; stc teardown; ./cleanup.sh" |
| 400 | } |
Jeremy Ronquillo | 336110a | 2019-07-11 14:20:40 -0700 | [diff] [blame] | 401 | catchError{ |
Jon Hall | d4f33e1 | 2020-07-29 14:50:34 -0700 | [diff] [blame] | 402 | sh script: runTestCli_py( TestONTest, testArguments ), label: ( "Run Test: ./cli.py run " + TestONTest + " " + testArguments ) |
Jeremy Ronquillo | 336110a | 2019-07-11 14:20:40 -0700 | [diff] [blame] | 403 | } |
Jon Hall | 4dc60b1 | 2020-12-15 16:46:06 -0800 | [diff] [blame] | 404 | if ( !isTofino ) { |
| 405 | catchError{ |
| 406 | sh script: concludeRunTest(), label: "Conclude Running Test: ./cleanup.sh; git clean -df" |
| 407 | } |
Jeremy Ronquillo | 336110a | 2019-07-11 14:20:40 -0700 | [diff] [blame] | 408 | } |
| 409 | catchError{ |
| 410 | // For the Wiki page |
Jon Hall | d4f33e1 | 2020-07-29 14:50:34 -0700 | [diff] [blame] | 411 | sh script: cleanAndCopyFiles( TestONTest ), label: "Clean and Copy Files" |
Jeremy Ronquillo | 336110a | 2019-07-11 14:20:40 -0700 | [diff] [blame] | 412 | } |
| 413 | } |
Jon Hall | d4f33e1 | 2020-07-29 14:50:34 -0700 | [diff] [blame] | 414 | graphs.databaseAndGraph( prop, JenkinsLabel, TestONTest, graphOnly, |
| 415 | graph_generator_file, graph_saved_directory ) |
Jeremy Ronquillo | 336110a | 2019-07-11 14:20:40 -0700 | [diff] [blame] | 416 | if ( !graphOnly ){ |
Jon Hall | d4f33e1 | 2020-07-29 14:50:34 -0700 | [diff] [blame] | 417 | sh script: fetchLogs( TestONTest ), label: "Fetch Logs" |
Jeremy Ronquillo | 336110a | 2019-07-11 14:20:40 -0700 | [diff] [blame] | 418 | if ( !isSCPF ){ |
| 419 | publishToConfluence( prop[ "manualRun" ], prop[ "postResult" ], |
Jon Hall | d4f33e1 | 2020-07-29 14:50:34 -0700 | [diff] [blame] | 420 | prop[ "WikiPrefix" ] + "-" + testCategory[ JenkinsLabel ][ 'wikiName' ], |
| 421 | workSpace + "/" + testCategory[ JenkinsLabel ][ 'wikiFile' ] ) |
Jeremy Ronquillo | 336110a | 2019-07-11 14:20:40 -0700 | [diff] [blame] | 422 | } |
| 423 | } |
| 424 | } |
| 425 | } |
| 426 | graphs.postResult( prop, graphOnly, nodeLabel ) |
| 427 | if ( !graphOnly ){ |
Jon Hall | d4f33e1 | 2020-07-29 14:50:34 -0700 | [diff] [blame] | 428 | def resultURL = postLogs( prop[ "WikiPrefix" ] ) |
| 429 | analyzeResult( prop, workSpace, TestONTest, JenkinsLabel, resultURL, |
| 430 | isSCPF ? "" : testCategory[ JenkinsLabel ][ 'wikiName' ], |
Jeremy Ronquillo | 336110a | 2019-07-11 14:20:40 -0700 | [diff] [blame] | 431 | isSCPF ) |
| 432 | } |
Jeremy Ronquillo | b8aac44 | 2019-07-31 13:28:01 -0700 | [diff] [blame] | 433 | } else { |
Jon Hall | d4f33e1 | 2020-07-29 14:50:34 -0700 | [diff] [blame] | 434 | echo JenkinsLabel + " is not being run today. Leaving the rest of stage contents blank." |
Jeremy Ronquillo | 336110a | 2019-07-11 14:20:40 -0700 | [diff] [blame] | 435 | } |
| 436 | } |
| 437 | } |
| 438 | } |
| 439 | } |
| 440 | |
Jeremy Ronquillo | 21c29fc | 2019-06-05 11:15:24 -0700 | [diff] [blame] | 441 | def generateGraphs(){ |
Jeremy Ronquillo | 0695099 | 2019-07-09 11:16:49 -0700 | [diff] [blame] | 442 | if ( category != "SCPF" ){ |
| 443 | // generate the overall graph of the non SCPF tests. |
Jeremy Ronquillo | 336110a | 2019-07-11 14:20:40 -0700 | [diff] [blame] | 444 | graphs.generateOverallGraph( prop, testsToRun, graphPaths[ "saveDirectory" ], nodeLabel, category ) |
Jeremy Ronquillo | bb3001f | 2019-07-01 12:57:07 -0700 | [diff] [blame] | 445 | } |
Jeremy Ronquillo | 21c29fc | 2019-06-05 11:15:24 -0700 | [diff] [blame] | 446 | } |
| 447 | |
| 448 | def sendToSlack(){ |
Jeremy Ronquillo | 336110a | 2019-07-11 14:20:40 -0700 | [diff] [blame] | 449 | // send the result of the test to the slack when it is not manually running. |
| 450 | // start : start time of the test |
| 451 | // isManualRun : string that is whether "false" or "true" |
| 452 | // branch : branch of the onos. |
| 453 | |
| 454 | try { |
| 455 | if ( prop[ "manualRun" ] == "false" ){ |
| 456 | end = getCurrentTime() |
| 457 | TimeDuration duration = TimeCategory.minus( end, start ) |
| 458 | // FIXME: for now we disable notifications of normal test results |
| 459 | /* |
| 460 | slackSend( color: "#5816EE", |
| 461 | message: category + "-" + prop[ "WikiPrefix" ] + " tests ended at: " + end.toString() + |
| 462 | "\nTime took : " + duration ) |
| 463 | */ |
| 464 | } |
| 465 | } |
| 466 | catch ( all ){ |
| 467 | } |
Jeremy Ronquillo | 21c29fc | 2019-06-05 11:15:24 -0700 | [diff] [blame] | 468 | } |