blob: 238d7bcab82d500e92d5d58007ce7672926fc3f4 [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
Devin Lim431408d2018-03-23 17:51:31 -070026def init( commonFuncs ){
27 funcs = commonFuncs
28}
29def lastCommaRemover( str ){
Devin Limf5175192018-05-14 19:13:22 -070030 // function that will remove the last comma from the string
31
Devin Lim431408d2018-03-23 17:51:31 -070032 if ( str.size() > 0 && str[ str.size() - 1 ] == ',' ){
33 str = str.substring( 0,str.size() - 1 )
34 }
35 return str
36}
37def printDaysForTest( AllTheTests ){
Devin Limf5175192018-05-14 19:13:22 -070038 // Print the days for what test has.
39
Devin Lim431408d2018-03-23 17:51:31 -070040 result = ""
41 for ( String test in AllTheTests.keySet() ){
42 result += test + " : \n"
43 for( String each in AllTheTests[ test ].keySet() ){
44 AllTheTests[ test ][ each ][ "day" ] = lastCommaRemover( AllTheTests[ test ][ each ][ "day" ] )
45 result += " " + each + ":[" + AllTheTests[ test ][ each ][ "day" ] + "]\n"
46 }
47 result += "\n"
48 }
49 return result
50}
51def runTestSeq( testList ){
Devin Limf5175192018-05-14 19:13:22 -070052 // Running the test sequentially
Devin Lim431408d2018-03-23 17:51:31 -070053 return{
54 for ( test in testList.keySet() ){
55 testList[ test ].call()
56 }
57 }
58}
59def print_tests( tests ){
Devin Limf5175192018-05-14 19:13:22 -070060 // print the list of the tsets to be run
61
Devin Lim431408d2018-03-23 17:51:31 -070062 for( String test in tests.keySet() ){
63 if( tests[ test ][ "tests" ] != "" ){
64 println test + ":"
65 println tests[ test ][ "tests" ]
66 }
67 }
68}
69def organize_tests( tests, testcases ){
Devin Limf5175192018-05-14 19:13:22 -070070 // organize the test to its category using its name.
71 // most of the time it will use the first two character of the test name
72 // but there are some exceptions like FUNCbgpls or FUNCvirNetNB since they are now under USECASE
73
Devin Lim431408d2018-03-23 17:51:31 -070074 testList = tests.tokenize( "\n;, " )
75 for( String test in testList )
76 testcases [ Prefix_organizer[ ( test == "FUNCbgpls" || test == "FUNCvirNetNB" ? "US" : ( test[ 0 ] + test[ 1 ] ) ) ] ][ "tests" ] += test + ","
77 return testcases
78}
Devin Lim431408d2018-03-23 17:51:31 -070079def trigger( branch, tests, nodeName, jobOn, manuallyRun, onosTag ){
Devin Limf5175192018-05-14 19:13:22 -070080 // triggering function that will setup the environment and determine which pipeline to trigger
81
Devin Lim431408d2018-03-23 17:51:31 -070082 println jobOn + "-pipeline-" + manuallyRun ? "manually" : branch
Devin Lim6c77b7c2018-04-06 19:36:56 -070083 def wiki = branch
Devin Lim431408d2018-03-23 17:51:31 -070084 branch = funcs.branchWithPrefix( branch )
85 test_branch = "master"
86 node( "TestStation-" + nodeName + "s" ){
87 envSetup( branch, test_branch, onosTag, jobOn, manuallyRun )
88
89 exportEnvProperty( branch, test_branch, wiki, tests, post_result, manuallyRun, onosTag, isOldFlow )
90 }
91
92 jobToRun = jobOn + "-pipeline-" + ( manuallyRun ? "manually" : wiki )
93 build job: jobToRun, propagate: false
94}
95def trigger_pipeline( branch, tests, nodeName, jobOn, manuallyRun, onosTag ){
Devin Limf5175192018-05-14 19:13:22 -070096 // nodeName : "BM" or "VM"
97 // jobOn : "SCPF" or "USECASE" or "FUNC" or "HA"
98 // this will return the function by wrapping them up with return{} to prevent them to be
99 // executed once this function is called to assign to specific variable.
Devin Lim431408d2018-03-23 17:51:31 -0700100 return{
Devin Lim5b22fbb2018-04-06 15:30:45 -0700101 trigger( branch, tests, nodeName, jobOn, manuallyRun, onosTag )
Devin Lim431408d2018-03-23 17:51:31 -0700102 }
103}
104// export Environment properties.
105def exportEnvProperty( onos_branch, test_branch, wiki, tests, postResult, manually_run, onosTag, isOldFlow ){
Devin Limf5175192018-05-14 19:13:22 -0700106 // export environment properties to the machine.
107
Devin Lim431408d2018-03-23 17:51:31 -0700108 stage( "export Property" ){
109 sh '''
110 echo "ONOSBranch=''' + onos_branch +'''" > /var/jenkins/TestONOS.property
111 echo "TestONBranch=''' + test_branch +'''" >> /var/jenkins/TestONOS.property
112 echo "ONOSTag='''+ onosTag +'''" >> /var/jenkins/TestONOS.property
113 echo "WikiPrefix=''' + wiki +'''" >> /var/jenkins/TestONOS.property
114 echo "ONOSJVMHeap='''+ env.ONOSJVMHeap +'''" >> /var/jenkins/TestONOS.property
115 echo "Tests=''' + tests +'''" >> /var/jenkins/TestONOS.property
116 echo "postResult=''' + postResult +'''" >> /var/jenkins/TestONOS.property
117 echo "manualRun=''' + manually_run +'''" >> /var/jenkins/TestONOS.property
118 echo "isOldFlow=''' + isOldFlow +'''" >> /var/jenkins/TestONOS.property
119 '''
120 }
121}
122// Initialize the environment Setup for the onos and OnosSystemTest
123def envSetup( onos_branch, test_branch, onos_tag, jobOn, manuallyRun ){
Devin Limf5175192018-05-14 19:13:22 -0700124 // to setup the environment using the bash script
125
Devin Lim431408d2018-03-23 17:51:31 -0700126 stage( "envSetup" ) {
127 // after env: ''' + borrow_mn( jobOn ) + '''
128 sh '''#!/bin/bash -l
129 set +e
130 . ~/.bashrc
131 env
132 ''' + preSetup( onos_branch, test_branch, onos_tag, manuallyRun ) + '''
133 ''' + oldFlowCheck( jobOn, onos_branch ) + '''
134 ''' + postSetup( onos_branch, test_branch, onos_tag, manuallyRun )
Devin Lim90b6a592018-05-09 13:20:33 -0700135 generateKey()
Devin Lim431408d2018-03-23 17:51:31 -0700136 }
137}
138def tagCheck( onos_tag, onos_branch ){
Devin Limf5175192018-05-14 19:13:22 -0700139 // check the tag for onos if it is not empty
140
Devin Lim431408d2018-03-23 17:51:31 -0700141 result = "git checkout "
142 if ( onos_tag == "" )
143 result += onos_branch //create new local branch
144 else
145 result += onos_tag //checkout the tag
146 return result
147}
148def preSetup( onos_branch, test_branch, onos_tag, isManual ){
Devin Limf5175192018-05-14 19:13:22 -0700149 // pre setup part which will clean up and checkout to corresponding branch.
150
Devin Lim431408d2018-03-23 17:51:31 -0700151 result = ""
152 if( !isManual ){
153 result = '''echo -e "\n##### Set TestON Branch #####"
154 echo "TestON Branch is set on: ''' + test_branch + '''"
155 cd ~/OnosSystemTest/
156 git checkout HEAD~1 # Make sure you aren't pn a branch
157 git branch | grep -v "detached from" | xargs git branch -d # delete all local branches merged with remote
158 git branch -D ''' + test_branch + ''' # just incase there are local changes. This will normally result in a branch not found error
159 git clean -df # clean any local files
160 git fetch --all # update all caches from remotes
161 git reset --hard origin/''' + test_branch +''' # force local index to match remote branch
162 git clean -df # clean any local files
163 git checkout ''' + test_branch + ''' #create new local branch
164 git branch
165 git log -1 --decorate
166 echo -e "\n##### Set ONOS Branch #####"
167 echo "ONOS Branch is set on: ''' + onos_branch + '''"
168 echo -e "\n #### check karaf version ######"
169 env |grep karaf
170 cd ~/onos
171 rm -rf buck-out/*
172 ~/onos/tools/build/onos-buck clean
173 git checkout HEAD~1 # Make sure you aren't pn a branch
174 git branch | grep -v "detached from" | xargs git branch -d # delete all local branches merged with remote
175 git branch -D ''' + onos_branch + ''' # just incase there are local changes. This will normally result in a branch not found error
176 git clean -df # clean any local files
177 git fetch --all # update all caches from remotes
178 git reset --hard origin/''' + onos_branch + ''' # force local index to match remote branch
179 git clean -df # clean any local files
180 ''' + tagCheck( onos_tag, onos_branch ) + '''
181 git branch
182 git log -1 --decorate
183 echo -e "\n##### set jvm heap size to 8G #####"
184 echo ${ONOSJVMHeap}
185 inserted_line="export JAVA_OPTS=\"\${ONOSJVMHeap}\""
186 sed -i "s/bash/bash\\n$inserted_line/" ~/onos/tools/package/bin/onos-service
187 echo "##### Check onos-service setting..... #####"
188 cat ~/onos/tools/package/bin/onos-service
189 export JAVA_HOME=/usr/lib/jvm/java-8-oracle'''
190 }
191 return result
192}
193def oldFlowCheck( jobOn, onos_branch ){
Devin Limf5175192018-05-14 19:13:22 -0700194 // part that will check if it is oldFlow. If so, it will switch to use old flow. Only affected with SCPF.
195
Devin Lim431408d2018-03-23 17:51:31 -0700196 result = ""
197 if( jobOn == "SCPF" && ( onos_branch== "master" || onos_branch=="onos-1.12" ) )
198 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
199 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"
200 return result
201}
202def postSetup( onos_branch, test_branch, onos_tag, isManual ){
Devin Limf5175192018-05-14 19:13:22 -0700203 // setup that will build the onos using buck.
204
Devin Lim431408d2018-03-23 17:51:31 -0700205 result = ""
206 if( !isManual ){
207 result = '''echo -e "\n##### build ONOS skip unit tests ######"
208 #mvn clean install -DskipTests
209 # Force buck update
210 rm -f ~/onos/bin/buck
211 ~/onos/tools/build/onos-buck build onos
212 sleep 30
213 echo -e "\n##### Stop all running instances of Karaf #####"
214 kill $(ps -efw | grep karaf | grep -v grep | awk '{print $2}')
215 sleep 30
Devin Lim2d7371a2018-05-08 18:02:05 -0700216 git branch
Devin Lim2d7371a2018-05-08 18:02:05 -0700217 '''
Devin Lim431408d2018-03-23 17:51:31 -0700218 }
219 return result
220}
Devin Lim90b6a592018-05-09 13:20:33 -0700221def generateKey(){
Devin Limf5175192018-05-14 19:13:22 -0700222 // generate cluster-key of the onos
223
Devin Lim018203a2018-05-09 11:33:20 -0700224 try{
225 sh '''
226 #!/bin/bash -l
227 set +e
228 . ~/.bashrc
229 env
Devin Lim90b6a592018-05-09 13:20:33 -0700230 onos-push-bits-through-proxy
231 onos-gen-cluster-key -f
Devin Lim018203a2018-05-09 11:33:20 -0700232 '''
233 }catch( all ){}
234}
Devin Lim431408d2018-03-23 17:51:31 -0700235
Devin Lim2fdf76a2018-04-06 19:27:54 -0700236return this;