blob: c35a94e65d23be16768267f4842f047b2b97820b [file] [log] [blame]
Devin Lime1346f42018-05-15 15:41:36 -07001#!groovy
2
Devin Limf5175192018-05-14 19:13:22 -07003// Copyright 2017 Open Networking Foundation (ONF)
4//
5// Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>,
6// the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>,
7// or the System Testing Guide page at <https://wiki.onosproject.org/x/WYQg>
8//
9// TestON is free software: you can redistribute it and/or modify
10// it under the terms of the GNU General Public License as published by
11// the Free Software Foundation, either version 2 of the License, or
12// (at your option) any later version.
13//
14// TestON is distributed in the hope that it will be useful,
15// but WITHOUT ANY WARRANTY; without even the implied warranty of
16// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17// GNU General Public License for more details.
18//
19// You should have received a copy of the GNU General Public License
20// along with TestON. If not, see <http://www.gnu.org/licenses/>.
21
22// This is the dependency Jenkins script.
23// This will provide the portion that will set up the environment of the machine
24// and trigger the corresponding jobs.
25
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -070026test_list = evaluate readTrusted( 'TestON/JenkinsFile/dependencies/JenkinsTestONTests.groovy' )
27test_list.init()
Jon Hall6af749d2018-05-29 12:59:47 -070028
Devin Lim431408d2018-03-23 17:51:31 -070029def init( commonFuncs ){
30 funcs = commonFuncs
31}
Jon Hall6af749d2018-05-29 12:59:47 -070032
Devin Lim431408d2018-03-23 17:51:31 -070033def lastCommaRemover( str ){
Devin Limf5175192018-05-14 19:13:22 -070034 // function that will remove the last comma from the string
35
Devin Lim431408d2018-03-23 17:51:31 -070036 if ( str.size() > 0 && str[ str.size() - 1 ] == ',' ){
Jon Hall6af749d2018-05-29 12:59:47 -070037 str = str.substring( 0, str.size() - 1 )
Devin Lim431408d2018-03-23 17:51:31 -070038 }
39 return str
40}
Jon Hall6af749d2018-05-29 12:59:47 -070041
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -070042def printDaysForTest(){
Devin Limf5175192018-05-14 19:13:22 -070043 // Print the days for what test has.
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -070044 AllTheTests = test_list.getAllTests()
Devin Limf5175192018-05-14 19:13:22 -070045
Devin Lim431408d2018-03-23 17:51:31 -070046 result = ""
47 for ( String test in AllTheTests.keySet() ){
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -070048 result += test + ": ["
49 test_schedule = test_list.getTestSchedule( test )
50 for ( String sch in test_schedule.keySet() ){
51 for ( String day in convertScheduleKeyToDays( sch ) ){
52 result += day + " "
53 }
Devin Lim431408d2018-03-23 17:51:31 -070054 }
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -070055 result += "]\n"
Devin Lim431408d2018-03-23 17:51:31 -070056 }
57 return result
58}
Jon Hall6af749d2018-05-29 12:59:47 -070059
Devin Lim431408d2018-03-23 17:51:31 -070060def runTestSeq( testList ){
Devin Limf5175192018-05-14 19:13:22 -070061 // Running the test sequentially
Jon Hall6af749d2018-05-29 12:59:47 -070062 return {
Devin Lim431408d2018-03-23 17:51:31 -070063 for ( test in testList.keySet() ){
64 testList[ test ].call()
65 }
66 }
67}
Jon Hall6af749d2018-05-29 12:59:47 -070068
Devin Lim431408d2018-03-23 17:51:31 -070069def print_tests( tests ){
Devin Limf5175192018-05-14 19:13:22 -070070 // print the list of the tsets to be run
71
Jon Hall6af749d2018-05-29 12:59:47 -070072 for ( String test in tests.keySet() ){
73 if ( tests[ test ][ "tests" ] != "" ){
Devin Lim431408d2018-03-23 17:51:31 -070074 println test + ":"
75 println tests[ test ][ "tests" ]
76 }
77 }
78}
Jon Hall6af749d2018-05-29 12:59:47 -070079
Devin Lim431408d2018-03-23 17:51:31 -070080def organize_tests( tests, testcases ){
Devin Limf5175192018-05-14 19:13:22 -070081 // organize the test to its category using its name.
82 // most of the time it will use the first two character of the test name
83 // but there are some exceptions like FUNCbgpls or FUNCvirNetNB since they are now under USECASE
84
Jon Hall6af749d2018-05-29 12:59:47 -070085 // depends on the first two letters of the test name, it will decide which category to put the test into.
86 def prefixes = [
87 "FU": "FUNC",
88 "HA": "HA",
89 "PL": "USECASE",
90 "SA": "USECASE",
91 "SC": "SCPF",
92 "SR": "SR",
93 "US": "USECASE",
94 "VP": "USECASE"
95 ]
96
97 def testList = tests.tokenize( "\n;, " )
98 for ( String test in testList ){
99 String prefix = ( test == "FUNCbgpls" || test == "FUNCvirNetNB" ) ? "US" : ( test[ 0..1 ] )
100 testcases[ prefixes[ prefix ] ][ "tests" ] += test + ","
101 }
Devin Lim431408d2018-03-23 17:51:31 -0700102 return testcases
103}
Jon Hall6af749d2018-05-29 12:59:47 -0700104
Devin Lim431408d2018-03-23 17:51:31 -0700105def trigger( branch, tests, nodeName, jobOn, manuallyRun, onosTag ){
Devin Limf5175192018-05-14 19:13:22 -0700106 // triggering function that will setup the environment and determine which pipeline to trigger
107
You Wang49461a82018-08-02 13:15:30 -0700108 println "Job name: " + jobOn + "-pipeline-" + ( manuallyRun ? "manually" : branch )
Devin Lim6c77b7c2018-04-06 19:36:56 -0700109 def wiki = branch
You Wangf7a07522018-08-02 14:23:25 -0700110 def onos_branch = funcs.branchWithPrefix( branch )
111 def test_branch = funcs.testBranchWithPrefix( branch )
You Wang49461a82018-08-02 13:15:30 -0700112 println "onos_branch with prefix: " + onos_branch
113 println "test_branch with prefix: " + test_branch
Jon Hall6af749d2018-05-29 12:59:47 -0700114 node( "TestStation-" + nodeName + "s" ) {
You Wang79527502018-08-02 12:18:20 -0700115 envSetup( onos_branch, test_branch, onosTag, jobOn, manuallyRun )
116 exportEnvProperty( onos_branch, test_branch, wiki, tests, post_result, manuallyRun, onosTag, isOldFlow )
Devin Lim431408d2018-03-23 17:51:31 -0700117 }
118
119 jobToRun = jobOn + "-pipeline-" + ( manuallyRun ? "manually" : wiki )
120 build job: jobToRun, propagate: false
121}
Jon Hall6af749d2018-05-29 12:59:47 -0700122
Devin Lim431408d2018-03-23 17:51:31 -0700123def trigger_pipeline( branch, tests, nodeName, jobOn, manuallyRun, onosTag ){
Devin Limf5175192018-05-14 19:13:22 -0700124 // nodeName : "BM" or "VM"
125 // jobOn : "SCPF" or "USECASE" or "FUNC" or "HA"
126 // this will return the function by wrapping them up with return{} to prevent them to be
127 // executed once this function is called to assign to specific variable.
Jon Hall6af749d2018-05-29 12:59:47 -0700128 return {
Devin Lim5b22fbb2018-04-06 15:30:45 -0700129 trigger( branch, tests, nodeName, jobOn, manuallyRun, onosTag )
Devin Lim431408d2018-03-23 17:51:31 -0700130 }
131}
Jon Hall6af749d2018-05-29 12:59:47 -0700132
Devin Lim431408d2018-03-23 17:51:31 -0700133// export Environment properties.
134def exportEnvProperty( onos_branch, test_branch, wiki, tests, postResult, manually_run, onosTag, isOldFlow ){
Devin Limf5175192018-05-14 19:13:22 -0700135 // export environment properties to the machine.
136
Jon Hall6af749d2018-05-29 12:59:47 -0700137 stage( "export Property" ) {
Devin Lim431408d2018-03-23 17:51:31 -0700138 sh '''
Jon Hall6af749d2018-05-29 12:59:47 -0700139 echo "ONOSBranch=''' + onos_branch + '''" > /var/jenkins/TestONOS.property
140 echo "TestONBranch=''' + test_branch + '''" >> /var/jenkins/TestONOS.property
141 echo "ONOSTag=''' + onosTag + '''" >> /var/jenkins/TestONOS.property
142 echo "WikiPrefix=''' + wiki + '''" >> /var/jenkins/TestONOS.property
You Wang8e4f4c02019-01-03 10:49:46 -0800143 echo "ONOSJAVAOPTS=''' + env.ONOSJAVAOPTS + '''" >> /var/jenkins/TestONOS.property
Jon Hall6af749d2018-05-29 12:59:47 -0700144 echo "Tests=''' + tests + '''" >> /var/jenkins/TestONOS.property
145 echo "postResult=''' + postResult + '''" >> /var/jenkins/TestONOS.property
146 echo "manualRun=''' + manually_run + '''" >> /var/jenkins/TestONOS.property
147 echo "isOldFlow=''' + isOldFlow + '''" >> /var/jenkins/TestONOS.property
Devin Lim431408d2018-03-23 17:51:31 -0700148 '''
149 }
150}
Jon Hall6af749d2018-05-29 12:59:47 -0700151
Devin Lim431408d2018-03-23 17:51:31 -0700152// Initialize the environment Setup for the onos and OnosSystemTest
153def envSetup( onos_branch, test_branch, onos_tag, jobOn, manuallyRun ){
Devin Limf5175192018-05-14 19:13:22 -0700154 // to setup the environment using the bash script
You Wang49461a82018-08-02 13:15:30 -0700155 println "onos_branch is set to " + onos_branch
156 println "test_branch is set to " + test_branch
Devin Lim431408d2018-03-23 17:51:31 -0700157 stage( "envSetup" ) {
158 // after env: ''' + borrow_mn( jobOn ) + '''
159 sh '''#!/bin/bash -l
160 set +e
161 . ~/.bashrc
162 env
163 ''' + preSetup( onos_branch, test_branch, onos_tag, manuallyRun ) + '''
164 ''' + oldFlowCheck( jobOn, onos_branch ) + '''
165 ''' + postSetup( onos_branch, test_branch, onos_tag, manuallyRun )
Devin Lim90b6a592018-05-09 13:20:33 -0700166 generateKey()
Devin Lim431408d2018-03-23 17:51:31 -0700167 }
168}
Jon Hall6af749d2018-05-29 12:59:47 -0700169
Devin Lim431408d2018-03-23 17:51:31 -0700170def tagCheck( onos_tag, onos_branch ){
Devin Limf5175192018-05-14 19:13:22 -0700171 // check the tag for onos if it is not empty
172
Devin Lim431408d2018-03-23 17:51:31 -0700173 result = "git checkout "
Jon Hall6af749d2018-05-29 12:59:47 -0700174 if ( onos_tag == "" ){
175 //create new local branch
176 result += onos_branch
177 }
178 else {
179 //checkout the tag
180 result += onos_tag
181 }
Devin Lim431408d2018-03-23 17:51:31 -0700182 return result
183}
Jon Hall6af749d2018-05-29 12:59:47 -0700184
Devin Lim431408d2018-03-23 17:51:31 -0700185def preSetup( onos_branch, test_branch, onos_tag, isManual ){
Devin Limf5175192018-05-14 19:13:22 -0700186 // pre setup part which will clean up and checkout to corresponding branch.
187
Devin Lim431408d2018-03-23 17:51:31 -0700188 result = ""
Jon Hall6af749d2018-05-29 12:59:47 -0700189 if ( !isManual ){
Devin Lim431408d2018-03-23 17:51:31 -0700190 result = '''echo -e "\n##### Set TestON Branch #####"
191 echo "TestON Branch is set on: ''' + test_branch + '''"
192 cd ~/OnosSystemTest/
193 git checkout HEAD~1 # Make sure you aren't pn a branch
194 git branch | grep -v "detached from" | xargs git branch -d # delete all local branches merged with remote
Jon Hall6af749d2018-05-29 12:59:47 -0700195 git branch -D ''' + test_branch + ''' # just in case there are local changes. This will normally result in a branch not found error
Devin Lim431408d2018-03-23 17:51:31 -0700196 git clean -df # clean any local files
197 git fetch --all # update all caches from remotes
Jon Hall6af749d2018-05-29 12:59:47 -0700198 git reset --hard origin/''' + test_branch + ''' # force local index to match remote branch
Devin Lim431408d2018-03-23 17:51:31 -0700199 git clean -df # clean any local files
200 git checkout ''' + test_branch + ''' #create new local branch
201 git branch
202 git log -1 --decorate
203 echo -e "\n##### Set ONOS Branch #####"
204 echo "ONOS Branch is set on: ''' + onos_branch + '''"
205 echo -e "\n #### check karaf version ######"
206 env |grep karaf
207 cd ~/onos
Devin Lim431408d2018-03-23 17:51:31 -0700208 git checkout HEAD~1 # Make sure you aren't pn a branch
209 git branch | grep -v "detached from" | xargs git branch -d # delete all local branches merged with remote
210 git branch -D ''' + onos_branch + ''' # just incase there are local changes. This will normally result in a branch not found error
211 git clean -df # clean any local files
212 git fetch --all # update all caches from remotes
213 git reset --hard origin/''' + onos_branch + ''' # force local index to match remote branch
214 git clean -df # clean any local files
Jon Hall5b056262018-09-25 11:44:41 -0700215 rm -rf buck-out
216 rm -rf bazel-*
Devin Lim431408d2018-03-23 17:51:31 -0700217 ''' + tagCheck( onos_tag, onos_branch ) + '''
218 git branch
219 git log -1 --decorate
220 echo -e "\n##### set jvm heap size to 8G #####"
You Wang8e4f4c02019-01-03 10:49:46 -0800221 echo ${ONOSJAVAOPTS}
222 inserted_line="export JAVA_OPTS=\"\${ONOSJAVAOPTS}\""
Devin Lim431408d2018-03-23 17:51:31 -0700223 sed -i "s/bash/bash\\n$inserted_line/" ~/onos/tools/package/bin/onos-service
224 echo "##### Check onos-service setting..... #####"
225 cat ~/onos/tools/package/bin/onos-service
226 export JAVA_HOME=/usr/lib/jvm/java-8-oracle'''
227 }
228 return result
229}
Jon Hall6af749d2018-05-29 12:59:47 -0700230
Devin Lim431408d2018-03-23 17:51:31 -0700231def oldFlowCheck( jobOn, onos_branch ){
Devin Limf5175192018-05-14 19:13:22 -0700232 // part that will check if it is oldFlow. If so, it will switch to use old flow. Only affected with SCPF.
233
Devin Lim431408d2018-03-23 17:51:31 -0700234 result = ""
Jon Hall6af749d2018-05-29 12:59:47 -0700235 if ( jobOn == "SCPF" && ( onos_branch == "master" || onos_branch == "onos-1.12" ) )
Devin Lim431408d2018-03-23 17:51:31 -0700236 result = '''sed -i -e 's/@Component(immediate = true)/@Component(enabled = false)/g' ~/onos/core/store/dist/src/main/java/org/onosproject/store/flow/impl/''' + ( isOldFlow ? "DistributedFlowRuleStore" : "ECFlowRuleStore" ) + '''.java
237 sed -i -e 's/@Component(enabled = false)/@Component(immediate = true)/g' ~/onos/core/store/dist/src/main/java/org/onosproject/store/flow/impl/''' + ( isOldFlow ? "ECFlowRuleStore" : "DistributedFlowRuleStore" ) + ".java"
238 return result
239}
Jon Hall6af749d2018-05-29 12:59:47 -0700240
Devin Lim431408d2018-03-23 17:51:31 -0700241def postSetup( onos_branch, test_branch, onos_tag, isManual ){
Jon Hall3e6edb32018-08-21 16:20:30 -0700242 // setup that will build ONOS
Devin Limf5175192018-05-14 19:13:22 -0700243
Devin Lim431408d2018-03-23 17:51:31 -0700244 result = ""
Jon Hall6af749d2018-05-29 12:59:47 -0700245 if ( !isManual ){
Devin Lim431408d2018-03-23 17:51:31 -0700246 result = '''echo -e "\n##### build ONOS skip unit tests ######"
Jon Hall3e6edb32018-08-21 16:20:30 -0700247 cd ~/onos
248 . tools/dev/bash_profile
249 op
Devin Lim431408d2018-03-23 17:51:31 -0700250 sleep 30
251 echo -e "\n##### Stop all running instances of Karaf #####"
252 kill $(ps -efw | grep karaf | grep -v grep | awk '{print $2}')
253 sleep 30
Devin Lim2d7371a2018-05-08 18:02:05 -0700254 git branch
Devin Lim2d7371a2018-05-08 18:02:05 -0700255 '''
Devin Lim431408d2018-03-23 17:51:31 -0700256 }
257 return result
258}
Jon Hall6af749d2018-05-29 12:59:47 -0700259
Devin Lim90b6a592018-05-09 13:20:33 -0700260def generateKey(){
Devin Limf5175192018-05-14 19:13:22 -0700261 // generate cluster-key of the onos
262
Jon Hall6af749d2018-05-29 12:59:47 -0700263 try {
Devin Lim018203a2018-05-09 11:33:20 -0700264 sh '''
265 #!/bin/bash -l
266 set +e
267 . ~/.bashrc
268 env
Devin Lim90b6a592018-05-09 13:20:33 -0700269 onos-push-bits-through-proxy
270 onos-gen-cluster-key -f
Devin Lim018203a2018-05-09 11:33:20 -0700271 '''
Jon Hall6af749d2018-05-29 12:59:47 -0700272 } catch ( all ){
273 }
Devin Lim018203a2018-05-09 11:33:20 -0700274}
Devin Lim431408d2018-03-23 17:51:31 -0700275
Jon Hall6af749d2018-05-29 12:59:47 -0700276return this