blob: 07ea98b984ac80a4dcdbb55f25796371c5bc5bd4 [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
Jon Hall6af749d2018-05-29 12:59:47 -070026
Devin Lim431408d2018-03-23 17:51:31 -070027def init( commonFuncs ){
28 funcs = commonFuncs
29}
Jon Hall6af749d2018-05-29 12:59:47 -070030
Devin Lim431408d2018-03-23 17:51:31 -070031def lastCommaRemover( str ){
Devin Limf5175192018-05-14 19:13:22 -070032 // function that will remove the last comma from the string
33
Devin Lim431408d2018-03-23 17:51:31 -070034 if ( str.size() > 0 && str[ str.size() - 1 ] == ',' ){
Jon Hall6af749d2018-05-29 12:59:47 -070035 str = str.substring( 0, str.size() - 1 )
Devin Lim431408d2018-03-23 17:51:31 -070036 }
37 return str
38}
Jon Hall6af749d2018-05-29 12:59:47 -070039
Devin Lim431408d2018-03-23 17:51:31 -070040def printDaysForTest( AllTheTests ){
Devin Limf5175192018-05-14 19:13:22 -070041 // Print the days for what test has.
42
Devin Lim431408d2018-03-23 17:51:31 -070043 result = ""
44 for ( String test in AllTheTests.keySet() ){
45 result += test + " : \n"
Jon Hall6af749d2018-05-29 12:59:47 -070046 for ( String each in AllTheTests[ test ].keySet() ){
Devin Lim431408d2018-03-23 17:51:31 -070047 AllTheTests[ test ][ each ][ "day" ] = lastCommaRemover( AllTheTests[ test ][ each ][ "day" ] )
48 result += " " + each + ":[" + AllTheTests[ test ][ each ][ "day" ] + "]\n"
49 }
50 result += "\n"
51 }
52 return result
53}
Jon Hall6af749d2018-05-29 12:59:47 -070054
Devin Lim431408d2018-03-23 17:51:31 -070055def runTestSeq( testList ){
Devin Limf5175192018-05-14 19:13:22 -070056 // Running the test sequentially
Jon Hall6af749d2018-05-29 12:59:47 -070057 return {
Devin Lim431408d2018-03-23 17:51:31 -070058 for ( test in testList.keySet() ){
59 testList[ test ].call()
60 }
61 }
62}
Jon Hall6af749d2018-05-29 12:59:47 -070063
Devin Lim431408d2018-03-23 17:51:31 -070064def print_tests( tests ){
Devin Limf5175192018-05-14 19:13:22 -070065 // print the list of the tsets to be run
66
Jon Hall6af749d2018-05-29 12:59:47 -070067 for ( String test in tests.keySet() ){
68 if ( tests[ test ][ "tests" ] != "" ){
Devin Lim431408d2018-03-23 17:51:31 -070069 println test + ":"
70 println tests[ test ][ "tests" ]
71 }
72 }
73}
Jon Hall6af749d2018-05-29 12:59:47 -070074
Devin Lim431408d2018-03-23 17:51:31 -070075def organize_tests( tests, testcases ){
Devin Limf5175192018-05-14 19:13:22 -070076 // organize the test to its category using its name.
77 // most of the time it will use the first two character of the test name
78 // but there are some exceptions like FUNCbgpls or FUNCvirNetNB since they are now under USECASE
79
Jon Hall6af749d2018-05-29 12:59:47 -070080 // depends on the first two letters of the test name, it will decide which category to put the test into.
81 def prefixes = [
82 "FU": "FUNC",
83 "HA": "HA",
84 "PL": "USECASE",
85 "SA": "USECASE",
86 "SC": "SCPF",
87 "SR": "SR",
88 "US": "USECASE",
89 "VP": "USECASE"
90 ]
91
92 def testList = tests.tokenize( "\n;, " )
93 for ( String test in testList ){
94 String prefix = ( test == "FUNCbgpls" || test == "FUNCvirNetNB" ) ? "US" : ( test[ 0..1 ] )
95 testcases[ prefixes[ prefix ] ][ "tests" ] += test + ","
96 }
Devin Lim431408d2018-03-23 17:51:31 -070097 return testcases
98}
Jon Hall6af749d2018-05-29 12:59:47 -070099
Devin Lim431408d2018-03-23 17:51:31 -0700100def trigger( branch, tests, nodeName, jobOn, manuallyRun, onosTag ){
Devin Limf5175192018-05-14 19:13:22 -0700101 // triggering function that will setup the environment and determine which pipeline to trigger
102
Devin Lim431408d2018-03-23 17:51:31 -0700103 println jobOn + "-pipeline-" + manuallyRun ? "manually" : branch
Devin Lim6c77b7c2018-04-06 19:36:56 -0700104 def wiki = branch
Devin Lim431408d2018-03-23 17:51:31 -0700105 branch = funcs.branchWithPrefix( branch )
106 test_branch = "master"
Jon Hall6af749d2018-05-29 12:59:47 -0700107 node( "TestStation-" + nodeName + "s" ) {
Devin Lim431408d2018-03-23 17:51:31 -0700108 envSetup( branch, test_branch, onosTag, jobOn, manuallyRun )
109
110 exportEnvProperty( branch, test_branch, wiki, tests, post_result, manuallyRun, onosTag, isOldFlow )
111 }
112
113 jobToRun = jobOn + "-pipeline-" + ( manuallyRun ? "manually" : wiki )
114 build job: jobToRun, propagate: false
115}
Jon Hall6af749d2018-05-29 12:59:47 -0700116
Devin Lim431408d2018-03-23 17:51:31 -0700117def trigger_pipeline( branch, tests, nodeName, jobOn, manuallyRun, onosTag ){
Devin Limf5175192018-05-14 19:13:22 -0700118 // nodeName : "BM" or "VM"
119 // jobOn : "SCPF" or "USECASE" or "FUNC" or "HA"
120 // this will return the function by wrapping them up with return{} to prevent them to be
121 // executed once this function is called to assign to specific variable.
Jon Hall6af749d2018-05-29 12:59:47 -0700122 return {
Devin Lim5b22fbb2018-04-06 15:30:45 -0700123 trigger( branch, tests, nodeName, jobOn, manuallyRun, onosTag )
Devin Lim431408d2018-03-23 17:51:31 -0700124 }
125}
Jon Hall6af749d2018-05-29 12:59:47 -0700126
Devin Lim431408d2018-03-23 17:51:31 -0700127// export Environment properties.
128def exportEnvProperty( onos_branch, test_branch, wiki, tests, postResult, manually_run, onosTag, isOldFlow ){
Devin Limf5175192018-05-14 19:13:22 -0700129 // export environment properties to the machine.
130
Jon Hall6af749d2018-05-29 12:59:47 -0700131 stage( "export Property" ) {
Devin Lim431408d2018-03-23 17:51:31 -0700132 sh '''
Jon Hall6af749d2018-05-29 12:59:47 -0700133 echo "ONOSBranch=''' + onos_branch + '''" > /var/jenkins/TestONOS.property
134 echo "TestONBranch=''' + test_branch + '''" >> /var/jenkins/TestONOS.property
135 echo "ONOSTag=''' + onosTag + '''" >> /var/jenkins/TestONOS.property
136 echo "WikiPrefix=''' + wiki + '''" >> /var/jenkins/TestONOS.property
137 echo "ONOSJVMHeap=''' + env.ONOSJVMHeap + '''" >> /var/jenkins/TestONOS.property
138 echo "Tests=''' + tests + '''" >> /var/jenkins/TestONOS.property
139 echo "postResult=''' + postResult + '''" >> /var/jenkins/TestONOS.property
140 echo "manualRun=''' + manually_run + '''" >> /var/jenkins/TestONOS.property
141 echo "isOldFlow=''' + isOldFlow + '''" >> /var/jenkins/TestONOS.property
Devin Lim431408d2018-03-23 17:51:31 -0700142 '''
143 }
144}
Jon Hall6af749d2018-05-29 12:59:47 -0700145
Devin Lim431408d2018-03-23 17:51:31 -0700146// Initialize the environment Setup for the onos and OnosSystemTest
147def envSetup( onos_branch, test_branch, onos_tag, jobOn, manuallyRun ){
Devin Limf5175192018-05-14 19:13:22 -0700148 // to setup the environment using the bash script
149
Devin Lim431408d2018-03-23 17:51:31 -0700150 stage( "envSetup" ) {
151 // after env: ''' + borrow_mn( jobOn ) + '''
152 sh '''#!/bin/bash -l
153 set +e
154 . ~/.bashrc
155 env
156 ''' + preSetup( onos_branch, test_branch, onos_tag, manuallyRun ) + '''
157 ''' + oldFlowCheck( jobOn, onos_branch ) + '''
158 ''' + postSetup( onos_branch, test_branch, onos_tag, manuallyRun )
Devin Lim90b6a592018-05-09 13:20:33 -0700159 generateKey()
Devin Lim431408d2018-03-23 17:51:31 -0700160 }
161}
Jon Hall6af749d2018-05-29 12:59:47 -0700162
Devin Lim431408d2018-03-23 17:51:31 -0700163def tagCheck( onos_tag, onos_branch ){
Devin Limf5175192018-05-14 19:13:22 -0700164 // check the tag for onos if it is not empty
165
Devin Lim431408d2018-03-23 17:51:31 -0700166 result = "git checkout "
Jon Hall6af749d2018-05-29 12:59:47 -0700167 if ( onos_tag == "" ){
168 //create new local branch
169 result += onos_branch
170 }
171 else {
172 //checkout the tag
173 result += onos_tag
174 }
Devin Lim431408d2018-03-23 17:51:31 -0700175 return result
176}
Jon Hall6af749d2018-05-29 12:59:47 -0700177
Devin Lim431408d2018-03-23 17:51:31 -0700178def preSetup( onos_branch, test_branch, onos_tag, isManual ){
Devin Limf5175192018-05-14 19:13:22 -0700179 // pre setup part which will clean up and checkout to corresponding branch.
180
Devin Lim431408d2018-03-23 17:51:31 -0700181 result = ""
Jon Hall6af749d2018-05-29 12:59:47 -0700182 if ( !isManual ){
Devin Lim431408d2018-03-23 17:51:31 -0700183 result = '''echo -e "\n##### Set TestON Branch #####"
184 echo "TestON Branch is set on: ''' + test_branch + '''"
185 cd ~/OnosSystemTest/
186 git checkout HEAD~1 # Make sure you aren't pn a branch
187 git branch | grep -v "detached from" | xargs git branch -d # delete all local branches merged with remote
Jon Hall6af749d2018-05-29 12:59:47 -0700188 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 -0700189 git clean -df # clean any local files
190 git fetch --all # update all caches from remotes
Jon Hall6af749d2018-05-29 12:59:47 -0700191 git reset --hard origin/''' + test_branch + ''' # force local index to match remote branch
Devin Lim431408d2018-03-23 17:51:31 -0700192 git clean -df # clean any local files
193 git checkout ''' + test_branch + ''' #create new local branch
194 git branch
195 git log -1 --decorate
196 echo -e "\n##### Set ONOS Branch #####"
197 echo "ONOS Branch is set on: ''' + onos_branch + '''"
198 echo -e "\n #### check karaf version ######"
199 env |grep karaf
200 cd ~/onos
201 rm -rf buck-out/*
202 ~/onos/tools/build/onos-buck clean
203 git checkout HEAD~1 # Make sure you aren't pn a branch
204 git branch | grep -v "detached from" | xargs git branch -d # delete all local branches merged with remote
205 git branch -D ''' + onos_branch + ''' # just incase there are local changes. This will normally result in a branch not found error
206 git clean -df # clean any local files
207 git fetch --all # update all caches from remotes
208 git reset --hard origin/''' + onos_branch + ''' # force local index to match remote branch
209 git clean -df # clean any local files
210 ''' + tagCheck( onos_tag, onos_branch ) + '''
211 git branch
212 git log -1 --decorate
213 echo -e "\n##### set jvm heap size to 8G #####"
214 echo ${ONOSJVMHeap}
215 inserted_line="export JAVA_OPTS=\"\${ONOSJVMHeap}\""
216 sed -i "s/bash/bash\\n$inserted_line/" ~/onos/tools/package/bin/onos-service
217 echo "##### Check onos-service setting..... #####"
218 cat ~/onos/tools/package/bin/onos-service
219 export JAVA_HOME=/usr/lib/jvm/java-8-oracle'''
220 }
221 return result
222}
Jon Hall6af749d2018-05-29 12:59:47 -0700223
Devin Lim431408d2018-03-23 17:51:31 -0700224def oldFlowCheck( jobOn, onos_branch ){
Devin Limf5175192018-05-14 19:13:22 -0700225 // part that will check if it is oldFlow. If so, it will switch to use old flow. Only affected with SCPF.
226
Devin Lim431408d2018-03-23 17:51:31 -0700227 result = ""
Jon Hall6af749d2018-05-29 12:59:47 -0700228 if ( jobOn == "SCPF" && ( onos_branch == "master" || onos_branch == "onos-1.12" ) )
Devin Lim431408d2018-03-23 17:51:31 -0700229 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
230 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"
231 return result
232}
Jon Hall6af749d2018-05-29 12:59:47 -0700233
Devin Lim431408d2018-03-23 17:51:31 -0700234def postSetup( onos_branch, test_branch, onos_tag, isManual ){
Devin Limf5175192018-05-14 19:13:22 -0700235 // setup that will build the onos using buck.
236
Devin Lim431408d2018-03-23 17:51:31 -0700237 result = ""
Jon Hall6af749d2018-05-29 12:59:47 -0700238 if ( !isManual ){
Devin Lim431408d2018-03-23 17:51:31 -0700239 result = '''echo -e "\n##### build ONOS skip unit tests ######"
240 #mvn clean install -DskipTests
241 # Force buck update
242 rm -f ~/onos/bin/buck
243 ~/onos/tools/build/onos-buck build onos
244 sleep 30
245 echo -e "\n##### Stop all running instances of Karaf #####"
246 kill $(ps -efw | grep karaf | grep -v grep | awk '{print $2}')
247 sleep 30
Devin Lim2d7371a2018-05-08 18:02:05 -0700248 git branch
Devin Lim2d7371a2018-05-08 18:02:05 -0700249 '''
Devin Lim431408d2018-03-23 17:51:31 -0700250 }
251 return result
252}
Jon Hall6af749d2018-05-29 12:59:47 -0700253
Devin Lim90b6a592018-05-09 13:20:33 -0700254def generateKey(){
Devin Limf5175192018-05-14 19:13:22 -0700255 // generate cluster-key of the onos
256
Jon Hall6af749d2018-05-29 12:59:47 -0700257 try {
Devin Lim018203a2018-05-09 11:33:20 -0700258 sh '''
259 #!/bin/bash -l
260 set +e
261 . ~/.bashrc
262 env
Devin Lim90b6a592018-05-09 13:20:33 -0700263 onos-push-bits-through-proxy
264 onos-gen-cluster-key -f
Devin Lim018203a2018-05-09 11:33:20 -0700265 '''
Jon Hall6af749d2018-05-29 12:59:47 -0700266 } catch ( all ){
267 }
Devin Lim018203a2018-05-09 11:33:20 -0700268}
Devin Lim431408d2018-03-23 17:51:31 -0700269
Jon Hall6af749d2018-05-29 12:59:47 -0700270return this