blob: b6b3212c98c47bdfbadb3f71634bec64fd1d5e2d [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 Ronquillo6fbfdd52019-07-09 13:49:34 -070026import groovy.time.TimeCategory
27import groovy.time.TimeDuration
28
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -070029test_list = evaluate readTrusted( 'TestON/JenkinsFile/dependencies/JenkinsTestONTests.groovy' )
30test_list.init()
Jon Hall6af749d2018-05-29 12:59:47 -070031
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -070032def printDaysForTest(){
Devin Limf5175192018-05-14 19:13:22 -070033 // Print the days for what test has.
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -070034 AllTheTests = test_list.getAllTests()
Devin Limf5175192018-05-14 19:13:22 -070035
Devin Lim431408d2018-03-23 17:51:31 -070036 result = ""
37 for ( String test in AllTheTests.keySet() ){
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -070038 result += test + ": ["
Jeremy Ronquillo21c29fc2019-06-05 11:15:24 -070039 test_schedule = AllTheTests[ test ][ "schedules" ]
40 for ( String sch_dict in test_schedule ){
41 for ( String day in test_list.convertScheduleKeyToDays( sch_dict[ "branch" ] ) ){
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -070042 result += day + " "
43 }
Devin Lim431408d2018-03-23 17:51:31 -070044 }
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -070045 result += "]\n"
Devin Lim431408d2018-03-23 17:51:31 -070046 }
47 return result
48}
Jon Hall6af749d2018-05-29 12:59:47 -070049
Jeremy Ronquillo6fbfdd52019-07-09 13:49:34 -070050def trigger( branch, tests, nodeLabel, jobOn, manuallyRun, onosTag ){
Devin Limf5175192018-05-14 19:13:22 -070051 // triggering function that will setup the environment and determine which pipeline to trigger
52
You Wang49461a82018-08-02 13:15:30 -070053 println "Job name: " + jobOn + "-pipeline-" + ( manuallyRun ? "manually" : branch )
Devin Lim6c77b7c2018-04-06 19:36:56 -070054 def wiki = branch
Jeremy Ronquillo21c29fc2019-06-05 11:15:24 -070055 def onos_branch = test_list.addPrefixToBranch( branch )
56 def test_branch = test_list.addPrefixToBranch( branch )
You Wang49461a82018-08-02 13:15:30 -070057 println "onos_branch with prefix: " + onos_branch
58 println "test_branch with prefix: " + test_branch
Jeremy Ronquillo6fbfdd52019-07-09 13:49:34 -070059 assignedNode = null
60 node( label: nodeLabel ) {
You Wang79527502018-08-02 12:18:20 -070061 envSetup( onos_branch, test_branch, onosTag, jobOn, manuallyRun )
Jeremy Ronquillo6fbfdd52019-07-09 13:49:34 -070062 exportEnvProperty( onos_branch, test_branch, jobOn, wiki, tests, post_result, manuallyRun, onosTag, isOldFlow, nodeLabel )
63 assignedNode = env.NODE_NAME
Devin Lim431408d2018-03-23 17:51:31 -070064 }
65
66 jobToRun = jobOn + "-pipeline-" + ( manuallyRun ? "manually" : wiki )
Jeremy Ronquillo6fbfdd52019-07-09 13:49:34 -070067 build job: jobToRun, propagate: false, parameters: [ [ $class: 'StringParameterValue', name: 'Category', value: jobOn ],
68 [ $class: 'StringParameterValue', name: 'Branch', value: branch ],
69 [ $class: 'StringParameterValue', name: 'TestStation', value: assignedNode ],
70 [ $class: 'StringParameterValue', name: 'NodeLabel', value: nodeLabel ] ]
Devin Lim431408d2018-03-23 17:51:31 -070071}
Jon Hall6af749d2018-05-29 12:59:47 -070072
Jeremy Ronquillo6fbfdd52019-07-09 13:49:34 -070073def trigger_pipeline( branch, tests, nodeLabel, jobOn, manuallyRun, onosTag ){
74 // nodeLabel : nodeLabel from tests.json
Devin Limf5175192018-05-14 19:13:22 -070075 // jobOn : "SCPF" or "USECASE" or "FUNC" or "HA"
76 // this will return the function by wrapping them up with return{} to prevent them to be
77 // executed once this function is called to assign to specific variable.
Jon Hall6af749d2018-05-29 12:59:47 -070078 return {
Jeremy Ronquillo6fbfdd52019-07-09 13:49:34 -070079 trigger( branch, tests, nodeLabel, jobOn, manuallyRun, onosTag )
Devin Lim431408d2018-03-23 17:51:31 -070080 }
81}
Jon Hall6af749d2018-05-29 12:59:47 -070082
Devin Lim431408d2018-03-23 17:51:31 -070083// export Environment properties.
Jeremy Ronquillo6fbfdd52019-07-09 13:49:34 -070084def exportEnvProperty( onos_branch, test_branch, jobOn, wiki, tests, postResult, manually_run, onosTag, isOldFlow, nodeLabel ){
Devin Limf5175192018-05-14 19:13:22 -070085 // export environment properties to the machine.
86
Jeremy Ronquillo21c29fc2019-06-05 11:15:24 -070087 filePath = "/var/jenkins/TestONOS-" + jobOn + "-" + onos_branch + ".property"
Jeremy Ronquillo259d71f2019-06-07 14:38:46 -070088
Jon Hall6af749d2018-05-29 12:59:47 -070089 stage( "export Property" ) {
Devin Lim431408d2018-03-23 17:51:31 -070090 sh '''
Jeremy Ronquillo259d71f2019-06-07 14:38:46 -070091 echo "ONOSBranch=''' + onos_branch + '''" > ''' + filePath + '''
92 echo "TestONBranch=''' + test_branch + '''" >> ''' + filePath + '''
93 echo "ONOSTag=''' + onosTag + '''" >> ''' + filePath + '''
94 echo "WikiPrefix=''' + wiki + '''" >> ''' + filePath + '''
95 echo "ONOSJAVAOPTS=''' + env.ONOSJAVAOPTS + '''" >> ''' + filePath + '''
96 echo "Tests=''' + tests + '''" >> ''' + filePath + '''
97 echo "postResult=''' + postResult + '''" >> ''' + filePath + '''
98 echo "manualRun=''' + manually_run + '''" >> ''' + filePath + '''
99 echo "isOldFlow=''' + isOldFlow + '''" >> ''' + filePath + '''
Devin Lim431408d2018-03-23 17:51:31 -0700100 '''
101 }
102}
Jon Hall6af749d2018-05-29 12:59:47 -0700103
Devin Lim431408d2018-03-23 17:51:31 -0700104// Initialize the environment Setup for the onos and OnosSystemTest
105def envSetup( onos_branch, test_branch, onos_tag, jobOn, manuallyRun ){
Devin Limf5175192018-05-14 19:13:22 -0700106 // to setup the environment using the bash script
You Wang49461a82018-08-02 13:15:30 -0700107 println "onos_branch is set to " + onos_branch
108 println "test_branch is set to " + test_branch
Devin Lim431408d2018-03-23 17:51:31 -0700109 stage( "envSetup" ) {
110 // after env: ''' + borrow_mn( jobOn ) + '''
111 sh '''#!/bin/bash -l
112 set +e
113 . ~/.bashrc
114 env
115 ''' + preSetup( onos_branch, test_branch, onos_tag, manuallyRun ) + '''
116 ''' + oldFlowCheck( jobOn, onos_branch ) + '''
117 ''' + postSetup( onos_branch, test_branch, onos_tag, manuallyRun )
Devin Lim90b6a592018-05-09 13:20:33 -0700118 generateKey()
Devin Lim431408d2018-03-23 17:51:31 -0700119 }
120}
Jon Hall6af749d2018-05-29 12:59:47 -0700121
Devin Lim431408d2018-03-23 17:51:31 -0700122def tagCheck( onos_tag, onos_branch ){
Devin Limf5175192018-05-14 19:13:22 -0700123 // check the tag for onos if it is not empty
124
Devin Lim431408d2018-03-23 17:51:31 -0700125 result = "git checkout "
Jon Hall6af749d2018-05-29 12:59:47 -0700126 if ( onos_tag == "" ){
127 //create new local branch
128 result += onos_branch
129 }
130 else {
131 //checkout the tag
132 result += onos_tag
133 }
Devin Lim431408d2018-03-23 17:51:31 -0700134 return result
135}
Jon Hall6af749d2018-05-29 12:59:47 -0700136
Devin Lim431408d2018-03-23 17:51:31 -0700137def preSetup( onos_branch, test_branch, onos_tag, isManual ){
Devin Limf5175192018-05-14 19:13:22 -0700138 // pre setup part which will clean up and checkout to corresponding branch.
139
Devin Lim431408d2018-03-23 17:51:31 -0700140 result = ""
Jon Hall6af749d2018-05-29 12:59:47 -0700141 if ( !isManual ){
Devin Lim431408d2018-03-23 17:51:31 -0700142 result = '''echo -e "\n##### Set TestON Branch #####"
143 echo "TestON Branch is set on: ''' + test_branch + '''"
144 cd ~/OnosSystemTest/
145 git checkout HEAD~1 # Make sure you aren't pn a branch
146 git branch | grep -v "detached from" | xargs git branch -d # delete all local branches merged with remote
Jon Hall6af749d2018-05-29 12:59:47 -0700147 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 -0700148 git clean -df # clean any local files
149 git fetch --all # update all caches from remotes
Jon Hall6af749d2018-05-29 12:59:47 -0700150 git reset --hard origin/''' + test_branch + ''' # force local index to match remote branch
Devin Lim431408d2018-03-23 17:51:31 -0700151 git clean -df # clean any local files
152 git checkout ''' + test_branch + ''' #create new local branch
153 git branch
154 git log -1 --decorate
155 echo -e "\n##### Set ONOS Branch #####"
156 echo "ONOS Branch is set on: ''' + onos_branch + '''"
157 echo -e "\n #### check karaf version ######"
158 env |grep karaf
159 cd ~/onos
Devin Lim431408d2018-03-23 17:51:31 -0700160 git checkout HEAD~1 # Make sure you aren't pn a branch
161 git branch | grep -v "detached from" | xargs git branch -d # delete all local branches merged with remote
162 git branch -D ''' + onos_branch + ''' # just incase there are local changes. This will normally result in a branch not found error
163 git clean -df # clean any local files
164 git fetch --all # update all caches from remotes
165 git reset --hard origin/''' + onos_branch + ''' # force local index to match remote branch
166 git clean -df # clean any local files
Jon Hall5b056262018-09-25 11:44:41 -0700167 rm -rf buck-out
168 rm -rf bazel-*
Devin Lim431408d2018-03-23 17:51:31 -0700169 ''' + tagCheck( onos_tag, onos_branch ) + '''
170 git branch
171 git log -1 --decorate
172 echo -e "\n##### set jvm heap size to 8G #####"
You Wang8e4f4c02019-01-03 10:49:46 -0800173 echo ${ONOSJAVAOPTS}
174 inserted_line="export JAVA_OPTS=\"\${ONOSJAVAOPTS}\""
Devin Lim431408d2018-03-23 17:51:31 -0700175 sed -i "s/bash/bash\\n$inserted_line/" ~/onos/tools/package/bin/onos-service
176 echo "##### Check onos-service setting..... #####"
177 cat ~/onos/tools/package/bin/onos-service
178 export JAVA_HOME=/usr/lib/jvm/java-8-oracle'''
179 }
180 return result
181}
Jon Hall6af749d2018-05-29 12:59:47 -0700182
Devin Lim431408d2018-03-23 17:51:31 -0700183def oldFlowCheck( jobOn, onos_branch ){
Devin Limf5175192018-05-14 19:13:22 -0700184 // part that will check if it is oldFlow. If so, it will switch to use old flow. Only affected with SCPF.
185
Devin Lim431408d2018-03-23 17:51:31 -0700186 result = ""
Jon Hall6af749d2018-05-29 12:59:47 -0700187 if ( jobOn == "SCPF" && ( onos_branch == "master" || onos_branch == "onos-1.12" ) )
Devin Lim431408d2018-03-23 17:51:31 -0700188 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
189 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"
190 return result
191}
Jon Hall6af749d2018-05-29 12:59:47 -0700192
Devin Lim431408d2018-03-23 17:51:31 -0700193def postSetup( onos_branch, test_branch, onos_tag, isManual ){
Jon Hall3e6edb32018-08-21 16:20:30 -0700194 // setup that will build ONOS
Devin Limf5175192018-05-14 19:13:22 -0700195
Devin Lim431408d2018-03-23 17:51:31 -0700196 result = ""
Jon Hall6af749d2018-05-29 12:59:47 -0700197 if ( !isManual ){
Jeremy Ronquillo352048b2019-06-20 10:47:47 -0700198 result = '''echo -e "Installing bazel"
199 cd ~
200 rm -rf ci-management
201 git clone https://gerrit.onosproject.org/ci-management
202 cd ci-management/jjb/onos/
203 export GERRIT_BRANCH="''' + onos_branch + '''"
204 chmod +x install-bazel.sh
205 ./install-bazel.sh
206 bazel --version
207
208 echo -e "\n##### build ONOS skip unit tests ######"
Jon Hall3e6edb32018-08-21 16:20:30 -0700209 cd ~/onos
210 . tools/dev/bash_profile
211 op
Devin Lim431408d2018-03-23 17:51:31 -0700212 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}
Jon Hall6af749d2018-05-29 12:59:47 -0700221
Devin Lim90b6a592018-05-09 13:20:33 -0700222def generateKey(){
Devin Limf5175192018-05-14 19:13:22 -0700223 // generate cluster-key of the onos
224
Jon Hall6af749d2018-05-29 12:59:47 -0700225 try {
Devin Lim018203a2018-05-09 11:33:20 -0700226 sh '''
227 #!/bin/bash -l
228 set +e
229 . ~/.bashrc
230 env
Devin Lim90b6a592018-05-09 13:20:33 -0700231 onos-push-bits-through-proxy
232 onos-gen-cluster-key -f
Devin Lim018203a2018-05-09 11:33:20 -0700233 '''
Jon Hall6af749d2018-05-29 12:59:47 -0700234 } catch ( all ){
235 }
Devin Lim018203a2018-05-09 11:33:20 -0700236}
Devin Lim431408d2018-03-23 17:51:31 -0700237
Jon Hall6af749d2018-05-29 12:59:47 -0700238return this