Jeremy Ronquillo | c3188b6 | 2019-08-19 15:51:17 -0700 | [diff] [blame] | 1 | #!groovy |
| 2 | // Copyright 2019 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 | test_list = evaluate readTrusted( 'TestON/JenkinsFile/dependencies/JenkinsTestONTests.groovy' ) |
| 22 | fileRelated = evaluate readTrusted( 'TestON/JenkinsFile/dependencies/JenkinsPathAndFiles.groovy' ) |
| 23 | |
| 24 | category = null |
| 25 | prop = null |
| 26 | testsToRun = null |
| 27 | testsToRunStrList = null |
| 28 | branch = null |
| 29 | branchWithPrefix = null |
| 30 | nodeLabel = null |
| 31 | testStation = null |
| 32 | testsOverride = null |
| 33 | pipelineTimeout = null |
| 34 | |
| 35 | testsFromList = [:] |
| 36 | pipeline = [:] |
| 37 | |
| 38 | def main(){ |
| 39 | pipelineTimeout = params.TimeOut.toInteger() // integer minutes until the entire pipeline times out. Usually passed from upstream master-trigger job. |
| 40 | timeout( time: pipelineTimeout, unit: "MINUTES" ){ |
| 41 | init() |
| 42 | runTests() |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | main() |
| 47 | |
| 48 | def init(){ |
| 49 | fileRelated.init() |
| 50 | test_list.init() |
| 51 | readParams() |
| 52 | |
| 53 | if ( branch == "manually" ){ |
| 54 | echo '''Warning: entered branch was: "manually". Defaulting to master branch.''' |
| 55 | branch = "master" |
| 56 | branchWithPrefix = test_list.addPrefixToBranch( branch ) |
| 57 | } |
| 58 | prop = getProperties() |
| 59 | |
| 60 | // get the list of the tests from category |
| 61 | testsFromList = test_list.getTestsFromCategory( category ) |
| 62 | |
| 63 | tokenizeTokens = "\n;, " |
| 64 | |
| 65 | if ( testsOverride == "" || testsOverride == null ){ |
| 66 | testsToRunStrList = prop[ "Tests" ].tokenize( tokenizeTokens ) |
| 67 | } else { |
| 68 | testsToRunStrList = testsOverride.tokenize( tokenizeTokens ) |
| 69 | } |
| 70 | testsToRun = test_list.getTestsFromStringList( testsToRunStrList ) |
| 71 | } |
| 72 | |
| 73 | def getProperties(){ |
| 74 | // get the properties of the test by reading the TestONOS.property |
| 75 | |
| 76 | filePath = '''/var/jenkins/TestONOS-''' + category + '''-''' + branchWithPrefix + '''.property''' |
| 77 | |
| 78 | node( testStation ) { |
| 79 | return readProperties( file: filePath ) |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | def readParams(){ |
| 84 | category = params.Category // "MO", etc. |
| 85 | branch = params.Branch // "1.15", "2.1", "master", etc. |
| 86 | branchWithPrefix = test_list.addPrefixToBranch( branch ) |
| 87 | testStation = params.TestStation // "TestStation-BMs", etc. |
Jeremy Ronquillo | f5482c9 | 2020-12-09 16:30:49 -0800 | [diff] [blame] | 88 | nodeLabel = params.NodeLabel // "BM", "VM", "Fabric-LTS1", etc. |
Jeremy Ronquillo | c3188b6 | 2019-08-19 15:51:17 -0700 | [diff] [blame] | 89 | testsOverride = params.TestsOverride // "FUNCflow, FUNCintent, [...]", overrides property file |
| 90 | } |
| 91 | |
| 92 | def runTests(){ |
| 93 | // run the test sequentially and save the function into the dictionary. |
| 94 | for ( String test : testsFromList.keySet() ){ |
| 95 | toBeRun = testsToRun.keySet().contains( test ) |
| 96 | stepName = ( toBeRun ? "" : "Not " ) + "Running $test" |
| 97 | pipeline[ stepName ] = runMOtest( test, |
| 98 | toBeRun ) |
| 99 | } |
| 100 | |
| 101 | // run the tests sequentially. |
| 102 | for ( test in pipeline.keySet() ){ |
| 103 | pipeline[ test ].call() |
| 104 | } |
| 105 | } |
| 106 | |
Jeremy Ronquillo | f617001 | 2019-08-22 11:05:16 -0700 | [diff] [blame] | 107 | // Set of setps to execute before the micro-onos test is run |
| 108 | def prepareRunningTest(){ |
| 109 | return '''. ~/.profile |
| 110 | cd ~/onos-test |
| 111 | make clean |
| 112 | ''' |
| 113 | } |
| 114 | |
| 115 | // TODO: currently this step is hardcoded to run `make` commands. |
| 116 | def runMicroOnosTest( run ){ |
| 117 | return '''make ''' + run + ''' |
| 118 | ''' |
| 119 | } |
| 120 | |
| 121 | def cleanupTest(){ |
| 122 | return '''. ~/.profile |
| 123 | cd ~/onos-test |
| 124 | make clean |
| 125 | ''' |
| 126 | } |
| 127 | |
| 128 | def analyzeResult( didTestFail, didCleanupFail ){ |
| 129 | if ( didTestFail ){ |
| 130 | echo "Abnormal Test Result." |
| 131 | throw new Exception( "Abnormal Test Result." ) |
| 132 | } else if ( didCleanupFail ){ |
| 133 | echo "Cleanup Failure." |
| 134 | throw new Exception( "Cleanup Failure." ) |
| 135 | } else { |
| 136 | echo "Test results are OK." |
| 137 | } |
| 138 | } |
| 139 | |
Jeremy Ronquillo | c3188b6 | 2019-08-19 15:51:17 -0700 | [diff] [blame] | 140 | def runMOtest( test, toBeRun ){ |
| 141 | return { |
| 142 | catchError { |
| 143 | stage( test ){ |
| 144 | if ( toBeRun ){ |
Jeremy Ronquillo | f617001 | 2019-08-22 11:05:16 -0700 | [diff] [blame] | 145 | didTestFail = true |
| 146 | didCleanupFail = true |
Jeremy Ronquillo | c3188b6 | 2019-08-19 15:51:17 -0700 | [diff] [blame] | 147 | node( testStation ) { |
Jeremy Ronquillo | f617001 | 2019-08-22 11:05:16 -0700 | [diff] [blame] | 148 | catchError{ |
| 149 | run = test.toLowerCase() - "momake" |
| 150 | sh script: prepareRunningTest() + |
Jeremy Ronquillo | 8d86f5a | 2019-08-22 14:48:34 -0700 | [diff] [blame] | 151 | runMicroOnosTest( run ), label: "Prepare and Run: make " + run |
Jeremy Ronquillo | f617001 | 2019-08-22 11:05:16 -0700 | [diff] [blame] | 152 | didTestFail = false |
| 153 | } |
| 154 | catchError{ |
| 155 | sh script: cleanupTest(), label: "Clean Up Test" |
| 156 | didCleanupFail = false |
| 157 | } |
Jeremy Ronquillo | c3188b6 | 2019-08-19 15:51:17 -0700 | [diff] [blame] | 158 | } |
Jeremy Ronquillo | f617001 | 2019-08-22 11:05:16 -0700 | [diff] [blame] | 159 | analyzeResult( didTestFail, didCleanupFail ) |
| 160 | } else { |
| 161 | echo test + " is not being run today. Leaving the rest of stage contents blank." |
Jeremy Ronquillo | c3188b6 | 2019-08-19 15:51:17 -0700 | [diff] [blame] | 162 | } |
| 163 | } |
| 164 | } |
| 165 | } |
| 166 | } |