blob: 4f03fcb1a2541ad4c00c87d4ee26b43121b10fbc [file] [log] [blame]
Jeremy Ronquilloc3188b62019-08-19 15:51:17 -07001#!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
21test_list = evaluate readTrusted( 'TestON/JenkinsFile/dependencies/JenkinsTestONTests.groovy' )
22fileRelated = evaluate readTrusted( 'TestON/JenkinsFile/dependencies/JenkinsPathAndFiles.groovy' )
23
24category = null
25prop = null
26testsToRun = null
27testsToRunStrList = null
28branch = null
29branchWithPrefix = null
30nodeLabel = null
31testStation = null
32testsOverride = null
33pipelineTimeout = null
34
35testsFromList = [:]
36pipeline = [:]
37
38def 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
46main()
47
48def 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
73def 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
83def 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 Ronquillof5482c92020-12-09 16:30:49 -080088 nodeLabel = params.NodeLabel // "BM", "VM", "Fabric-LTS1", etc.
Jeremy Ronquilloc3188b62019-08-19 15:51:17 -070089 testsOverride = params.TestsOverride // "FUNCflow, FUNCintent, [...]", overrides property file
90}
91
92def 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 Ronquillof6170012019-08-22 11:05:16 -0700107// Set of setps to execute before the micro-onos test is run
108def 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.
116def runMicroOnosTest( run ){
117 return '''make ''' + run + '''
118 '''
119}
120
121def cleanupTest(){
122 return '''. ~/.profile
123 cd ~/onos-test
124 make clean
125 '''
126}
127
128def 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 Ronquilloc3188b62019-08-19 15:51:17 -0700140def runMOtest( test, toBeRun ){
141 return {
142 catchError {
143 stage( test ){
144 if ( toBeRun ){
Jeremy Ronquillof6170012019-08-22 11:05:16 -0700145 didTestFail = true
146 didCleanupFail = true
Jeremy Ronquilloc3188b62019-08-19 15:51:17 -0700147 node( testStation ) {
Jeremy Ronquillof6170012019-08-22 11:05:16 -0700148 catchError{
149 run = test.toLowerCase() - "momake"
150 sh script: prepareRunningTest() +
Jeremy Ronquillo8d86f5a2019-08-22 14:48:34 -0700151 runMicroOnosTest( run ), label: "Prepare and Run: make " + run
Jeremy Ronquillof6170012019-08-22 11:05:16 -0700152 didTestFail = false
153 }
154 catchError{
155 sh script: cleanupTest(), label: "Clean Up Test"
156 didCleanupFail = false
157 }
Jeremy Ronquilloc3188b62019-08-19 15:51:17 -0700158 }
Jeremy Ronquillof6170012019-08-22 11:05:16 -0700159 analyzeResult( didTestFail, didCleanupFail )
160 } else {
161 echo test + " is not being run today. Leaving the rest of stage contents blank."
Jeremy Ronquilloc3188b62019-08-19 15:51:17 -0700162 }
163 }
164 }
165 }
166}