blob: 2aba5d2ffd2529131aa0576744e98a4b83cb77ab [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
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -070033def printDaysForTest(){
Devin Limf5175192018-05-14 19:13:22 -070034 // Print the days for what test has.
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -070035 AllTheTests = test_list.getAllTests()
Devin Limf5175192018-05-14 19:13:22 -070036
Devin Lim431408d2018-03-23 17:51:31 -070037 result = ""
38 for ( String test in AllTheTests.keySet() ){
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -070039 result += test + ": ["
Jeremy Ronquillo21c29fc2019-06-05 11:15:24 -070040 test_schedule = AllTheTests[ test ][ "schedules" ]
41 for ( String sch_dict in test_schedule ){
42 for ( String day in test_list.convertScheduleKeyToDays( sch_dict[ "branch" ] ) ){
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -070043 result += day + " "
44 }
Devin Lim431408d2018-03-23 17:51:31 -070045 }
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -070046 result += "]\n"
Devin Lim431408d2018-03-23 17:51:31 -070047 }
48 return result
49}
Jon Hall6af749d2018-05-29 12:59:47 -070050
Devin Lim431408d2018-03-23 17:51:31 -070051def trigger( branch, tests, nodeName, jobOn, manuallyRun, onosTag ){
Devin Limf5175192018-05-14 19:13:22 -070052 // triggering function that will setup the environment and determine which pipeline to trigger
53
You Wang49461a82018-08-02 13:15:30 -070054 println "Job name: " + jobOn + "-pipeline-" + ( manuallyRun ? "manually" : branch )
Devin Lim6c77b7c2018-04-06 19:36:56 -070055 def wiki = branch
Jeremy Ronquillo21c29fc2019-06-05 11:15:24 -070056 def onos_branch = test_list.addPrefixToBranch( branch )
57 def test_branch = test_list.addPrefixToBranch( branch )
You Wang49461a82018-08-02 13:15:30 -070058 println "onos_branch with prefix: " + onos_branch
59 println "test_branch with prefix: " + test_branch
Jon Hall6af749d2018-05-29 12:59:47 -070060 node( "TestStation-" + nodeName + "s" ) {
You Wang79527502018-08-02 12:18:20 -070061 envSetup( onos_branch, test_branch, onosTag, jobOn, manuallyRun )
Jeremy Ronquillo259d71f2019-06-07 14:38:46 -070062 exportEnvProperty( onos_branch, test_branch, jobOn, wiki, tests, post_result, manuallyRun, onosTag, isOldFlow )
Devin Lim431408d2018-03-23 17:51:31 -070063 }
64
65 jobToRun = jobOn + "-pipeline-" + ( manuallyRun ? "manually" : wiki )
Jeremy Ronquillo21c29fc2019-06-05 11:15:24 -070066 build job: jobToRun, propagate: false, parameters: [ [ $class: 'StringParameterValue', name: 'Category', value: jobOn ], [ $class: 'StringParameterValue', name: 'Branch', value: branch ] ]
Devin Lim431408d2018-03-23 17:51:31 -070067}
Jon Hall6af749d2018-05-29 12:59:47 -070068
Devin Lim431408d2018-03-23 17:51:31 -070069def trigger_pipeline( branch, tests, nodeName, jobOn, manuallyRun, onosTag ){
Devin Limf5175192018-05-14 19:13:22 -070070 // nodeName : "BM" or "VM"
71 // jobOn : "SCPF" or "USECASE" or "FUNC" or "HA"
72 // this will return the function by wrapping them up with return{} to prevent them to be
73 // executed once this function is called to assign to specific variable.
Jon Hall6af749d2018-05-29 12:59:47 -070074 return {
Devin Lim5b22fbb2018-04-06 15:30:45 -070075 trigger( branch, tests, nodeName, jobOn, manuallyRun, onosTag )
Devin Lim431408d2018-03-23 17:51:31 -070076 }
77}
Jon Hall6af749d2018-05-29 12:59:47 -070078
Devin Lim431408d2018-03-23 17:51:31 -070079// export Environment properties.
Jeremy Ronquillo259d71f2019-06-07 14:38:46 -070080def exportEnvProperty( onos_branch, test_branch, jobOn, wiki, tests, postResult, manually_run, onosTag, isOldFlow ){
Devin Limf5175192018-05-14 19:13:22 -070081 // export environment properties to the machine.
82
Jeremy Ronquillo21c29fc2019-06-05 11:15:24 -070083 filePath = "/var/jenkins/TestONOS-" + jobOn + "-" + onos_branch + ".property"
Jeremy Ronquillo259d71f2019-06-07 14:38:46 -070084
Jon Hall6af749d2018-05-29 12:59:47 -070085 stage( "export Property" ) {
Devin Lim431408d2018-03-23 17:51:31 -070086 sh '''
Jeremy Ronquillo259d71f2019-06-07 14:38:46 -070087 echo "ONOSBranch=''' + onos_branch + '''" > ''' + filePath + '''
88 echo "TestONBranch=''' + test_branch + '''" >> ''' + filePath + '''
89 echo "ONOSTag=''' + onosTag + '''" >> ''' + filePath + '''
90 echo "WikiPrefix=''' + wiki + '''" >> ''' + filePath + '''
91 echo "ONOSJAVAOPTS=''' + env.ONOSJAVAOPTS + '''" >> ''' + filePath + '''
92 echo "Tests=''' + tests + '''" >> ''' + filePath + '''
93 echo "postResult=''' + postResult + '''" >> ''' + filePath + '''
94 echo "manualRun=''' + manually_run + '''" >> ''' + filePath + '''
95 echo "isOldFlow=''' + isOldFlow + '''" >> ''' + filePath + '''
Devin Lim431408d2018-03-23 17:51:31 -070096 '''
97 }
98}
Jon Hall6af749d2018-05-29 12:59:47 -070099
Devin Lim431408d2018-03-23 17:51:31 -0700100// Initialize the environment Setup for the onos and OnosSystemTest
101def envSetup( onos_branch, test_branch, onos_tag, jobOn, manuallyRun ){
Devin Limf5175192018-05-14 19:13:22 -0700102 // to setup the environment using the bash script
You Wang49461a82018-08-02 13:15:30 -0700103 println "onos_branch is set to " + onos_branch
104 println "test_branch is set to " + test_branch
Devin Lim431408d2018-03-23 17:51:31 -0700105 stage( "envSetup" ) {
106 // after env: ''' + borrow_mn( jobOn ) + '''
107 sh '''#!/bin/bash -l
108 set +e
109 . ~/.bashrc
110 env
111 ''' + preSetup( onos_branch, test_branch, onos_tag, manuallyRun ) + '''
112 ''' + oldFlowCheck( jobOn, onos_branch ) + '''
113 ''' + postSetup( onos_branch, test_branch, onos_tag, manuallyRun )
Devin Lim90b6a592018-05-09 13:20:33 -0700114 generateKey()
Devin Lim431408d2018-03-23 17:51:31 -0700115 }
116}
Jon Hall6af749d2018-05-29 12:59:47 -0700117
Devin Lim431408d2018-03-23 17:51:31 -0700118def tagCheck( onos_tag, onos_branch ){
Devin Limf5175192018-05-14 19:13:22 -0700119 // check the tag for onos if it is not empty
120
Devin Lim431408d2018-03-23 17:51:31 -0700121 result = "git checkout "
Jon Hall6af749d2018-05-29 12:59:47 -0700122 if ( onos_tag == "" ){
123 //create new local branch
124 result += onos_branch
125 }
126 else {
127 //checkout the tag
128 result += onos_tag
129 }
Devin Lim431408d2018-03-23 17:51:31 -0700130 return result
131}
Jon Hall6af749d2018-05-29 12:59:47 -0700132
Devin Lim431408d2018-03-23 17:51:31 -0700133def preSetup( onos_branch, test_branch, onos_tag, isManual ){
Devin Limf5175192018-05-14 19:13:22 -0700134 // pre setup part which will clean up and checkout to corresponding branch.
135
Devin Lim431408d2018-03-23 17:51:31 -0700136 result = ""
Jon Hall6af749d2018-05-29 12:59:47 -0700137 if ( !isManual ){
Devin Lim431408d2018-03-23 17:51:31 -0700138 result = '''echo -e "\n##### Set TestON Branch #####"
139 echo "TestON Branch is set on: ''' + test_branch + '''"
140 cd ~/OnosSystemTest/
141 git checkout HEAD~1 # Make sure you aren't pn a branch
142 git branch | grep -v "detached from" | xargs git branch -d # delete all local branches merged with remote
Jon Hall6af749d2018-05-29 12:59:47 -0700143 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 -0700144 git clean -df # clean any local files
145 git fetch --all # update all caches from remotes
Jon Hall6af749d2018-05-29 12:59:47 -0700146 git reset --hard origin/''' + test_branch + ''' # force local index to match remote branch
Devin Lim431408d2018-03-23 17:51:31 -0700147 git clean -df # clean any local files
148 git checkout ''' + test_branch + ''' #create new local branch
149 git branch
150 git log -1 --decorate
151 echo -e "\n##### Set ONOS Branch #####"
152 echo "ONOS Branch is set on: ''' + onos_branch + '''"
153 echo -e "\n #### check karaf version ######"
154 env |grep karaf
155 cd ~/onos
Devin Lim431408d2018-03-23 17:51:31 -0700156 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 ''' + onos_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/''' + onos_branch + ''' # force local index to match remote branch
162 git clean -df # clean any local files
Jon Hall5b056262018-09-25 11:44:41 -0700163 rm -rf buck-out
164 rm -rf bazel-*
Devin Lim431408d2018-03-23 17:51:31 -0700165 ''' + tagCheck( onos_tag, onos_branch ) + '''
166 git branch
167 git log -1 --decorate
168 echo -e "\n##### set jvm heap size to 8G #####"
You Wang8e4f4c02019-01-03 10:49:46 -0800169 echo ${ONOSJAVAOPTS}
170 inserted_line="export JAVA_OPTS=\"\${ONOSJAVAOPTS}\""
Devin Lim431408d2018-03-23 17:51:31 -0700171 sed -i "s/bash/bash\\n$inserted_line/" ~/onos/tools/package/bin/onos-service
172 echo "##### Check onos-service setting..... #####"
173 cat ~/onos/tools/package/bin/onos-service
174 export JAVA_HOME=/usr/lib/jvm/java-8-oracle'''
175 }
176 return result
177}
Jon Hall6af749d2018-05-29 12:59:47 -0700178
Devin Lim431408d2018-03-23 17:51:31 -0700179def oldFlowCheck( jobOn, onos_branch ){
Devin Limf5175192018-05-14 19:13:22 -0700180 // part that will check if it is oldFlow. If so, it will switch to use old flow. Only affected with SCPF.
181
Devin Lim431408d2018-03-23 17:51:31 -0700182 result = ""
Jon Hall6af749d2018-05-29 12:59:47 -0700183 if ( jobOn == "SCPF" && ( onos_branch == "master" || onos_branch == "onos-1.12" ) )
Devin Lim431408d2018-03-23 17:51:31 -0700184 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
185 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"
186 return result
187}
Jon Hall6af749d2018-05-29 12:59:47 -0700188
Devin Lim431408d2018-03-23 17:51:31 -0700189def postSetup( onos_branch, test_branch, onos_tag, isManual ){
Jon Hall3e6edb32018-08-21 16:20:30 -0700190 // setup that will build ONOS
Devin Limf5175192018-05-14 19:13:22 -0700191
Devin Lim431408d2018-03-23 17:51:31 -0700192 result = ""
Jon Hall6af749d2018-05-29 12:59:47 -0700193 if ( !isManual ){
Jeremy Ronquillo352048b2019-06-20 10:47:47 -0700194 result = '''echo -e "Installing bazel"
195 cd ~
196 rm -rf ci-management
197 git clone https://gerrit.onosproject.org/ci-management
198 cd ci-management/jjb/onos/
199 export GERRIT_BRANCH="''' + onos_branch + '''"
200 chmod +x install-bazel.sh
201 ./install-bazel.sh
202 bazel --version
203
204 echo -e "\n##### build ONOS skip unit tests ######"
Jon Hall3e6edb32018-08-21 16:20:30 -0700205 cd ~/onos
206 . tools/dev/bash_profile
207 op
Devin Lim431408d2018-03-23 17:51:31 -0700208 sleep 30
209 echo -e "\n##### Stop all running instances of Karaf #####"
210 kill $(ps -efw | grep karaf | grep -v grep | awk '{print $2}')
211 sleep 30
Devin Lim2d7371a2018-05-08 18:02:05 -0700212 git branch
Devin Lim2d7371a2018-05-08 18:02:05 -0700213 '''
Devin Lim431408d2018-03-23 17:51:31 -0700214 }
215 return result
216}
Jon Hall6af749d2018-05-29 12:59:47 -0700217
Devin Lim90b6a592018-05-09 13:20:33 -0700218def generateKey(){
Devin Limf5175192018-05-14 19:13:22 -0700219 // generate cluster-key of the onos
220
Jon Hall6af749d2018-05-29 12:59:47 -0700221 try {
Devin Lim018203a2018-05-09 11:33:20 -0700222 sh '''
223 #!/bin/bash -l
224 set +e
225 . ~/.bashrc
226 env
Devin Lim90b6a592018-05-09 13:20:33 -0700227 onos-push-bits-through-proxy
228 onos-gen-cluster-key -f
Devin Lim018203a2018-05-09 11:33:20 -0700229 '''
Jon Hall6af749d2018-05-29 12:59:47 -0700230 } catch ( all ){
231 }
Devin Lim018203a2018-05-09 11:33:20 -0700232}
Devin Lim431408d2018-03-23 17:51:31 -0700233
Jon Hall6af749d2018-05-29 12:59:47 -0700234return this