blob: 3952183f8b53542f7a59e62fa377b8d0c86df07e [file] [log] [blame]
Devin Lim431408d2018-03-23 17:51:31 -07001#!groovy
2
3def init( commonFuncs ){
4 funcs = commonFuncs
5}
6def lastCommaRemover( str ){
7 if ( str.size() > 0 && str[ str.size() - 1 ] == ',' ){
8 str = str.substring( 0,str.size() - 1 )
9 }
10 return str
11}
12def printDaysForTest( AllTheTests ){
13 result = ""
14 for ( String test in AllTheTests.keySet() ){
15 result += test + " : \n"
16 for( String each in AllTheTests[ test ].keySet() ){
17 AllTheTests[ test ][ each ][ "day" ] = lastCommaRemover( AllTheTests[ test ][ each ][ "day" ] )
18 result += " " + each + ":[" + AllTheTests[ test ][ each ][ "day" ] + "]\n"
19 }
20 result += "\n"
21 }
22 return result
23}
24def runTestSeq( testList ){
25 return{
26 for ( test in testList.keySet() ){
27 testList[ test ].call()
28 }
29 }
30}
31def print_tests( tests ){
32 for( String test in tests.keySet() ){
33 if( tests[ test ][ "tests" ] != "" ){
34 println test + ":"
35 println tests[ test ][ "tests" ]
36 }
37 }
38}
39def organize_tests( tests, testcases ){
40 testList = tests.tokenize( "\n;, " )
41 for( String test in testList )
42 testcases [ Prefix_organizer[ ( test == "FUNCbgpls" || test == "FUNCvirNetNB" ? "US" : ( test[ 0 ] + test[ 1 ] ) ) ] ][ "tests" ] += test + ","
43 return testcases
44}
45def borrow_mn( jobOn ){
46 result = ""
47 if( jobOn == "SR" ){
48 result = "~/cell_borrow.sh"
49 }
50 return result
51}
52def trigger( branch, tests, nodeName, jobOn, manuallyRun, onosTag ){
53 println jobOn + "-pipeline-" + manuallyRun ? "manually" : branch
Devin Lim6c77b7c2018-04-06 19:36:56 -070054 def wiki = branch
Devin Lim2fdf76a2018-04-06 19:27:54 -070055 print "HERE2.5:" + branch
56 print "HERE4:" + wiki
Devin Lim431408d2018-03-23 17:51:31 -070057 branch = funcs.branchWithPrefix( branch )
58 test_branch = "master"
Devin Lim4fbf5fc2018-04-06 19:15:34 -070059 print "HERE2:" + branch
Devin Lim431408d2018-03-23 17:51:31 -070060 node( "TestStation-" + nodeName + "s" ){
61 envSetup( branch, test_branch, onosTag, jobOn, manuallyRun )
62
63 exportEnvProperty( branch, test_branch, wiki, tests, post_result, manuallyRun, onosTag, isOldFlow )
64 }
65
Devin Lim2fdf76a2018-04-06 19:27:54 -070066 print "HERE5:" + wiki
Devin Lim431408d2018-03-23 17:51:31 -070067 jobToRun = jobOn + "-pipeline-" + ( manuallyRun ? "manually" : wiki )
68 build job: jobToRun, propagate: false
69}
70def trigger_pipeline( branch, tests, nodeName, jobOn, manuallyRun, onosTag ){
71// nodeName : "BM" or "VM"
72// jobOn : "SCPF" or "USECASE" or "FUNC" or "HA"
73 return{
Devin Lim9d18c972018-04-06 19:09:18 -070074 print "HERE:" + branch
Devin Lim5b22fbb2018-04-06 15:30:45 -070075 trigger( branch, tests, nodeName, jobOn, manuallyRun, onosTag )
Devin Lim431408d2018-03-23 17:51:31 -070076 }
77}
78// export Environment properties.
79def exportEnvProperty( onos_branch, test_branch, wiki, tests, postResult, manually_run, onosTag, isOldFlow ){
Devin Lim2fdf76a2018-04-06 19:27:54 -070080 print "HERE6:" + wiki
Devin Lim431408d2018-03-23 17:51:31 -070081 stage( "export Property" ){
82 sh '''
83 echo "ONOSBranch=''' + onos_branch +'''" > /var/jenkins/TestONOS.property
84 echo "TestONBranch=''' + test_branch +'''" >> /var/jenkins/TestONOS.property
85 echo "ONOSTag='''+ onosTag +'''" >> /var/jenkins/TestONOS.property
86 echo "WikiPrefix=''' + wiki +'''" >> /var/jenkins/TestONOS.property
87 echo "ONOSJVMHeap='''+ env.ONOSJVMHeap +'''" >> /var/jenkins/TestONOS.property
88 echo "Tests=''' + tests +'''" >> /var/jenkins/TestONOS.property
89 echo "postResult=''' + postResult +'''" >> /var/jenkins/TestONOS.property
90 echo "manualRun=''' + manually_run +'''" >> /var/jenkins/TestONOS.property
91 echo "isOldFlow=''' + isOldFlow +'''" >> /var/jenkins/TestONOS.property
92 '''
93 }
94}
95// Initialize the environment Setup for the onos and OnosSystemTest
96def envSetup( onos_branch, test_branch, onos_tag, jobOn, manuallyRun ){
Devin Lim4fbf5fc2018-04-06 19:15:34 -070097 print "HERE3:" + onos_branch
Devin Lim431408d2018-03-23 17:51:31 -070098 stage( "envSetup" ) {
99 // after env: ''' + borrow_mn( jobOn ) + '''
100 sh '''#!/bin/bash -l
101 set +e
102 . ~/.bashrc
103 env
104 ''' + preSetup( onos_branch, test_branch, onos_tag, manuallyRun ) + '''
105 ''' + oldFlowCheck( jobOn, onos_branch ) + '''
106 ''' + postSetup( onos_branch, test_branch, onos_tag, manuallyRun )
107 }
108}
109def tagCheck( onos_tag, onos_branch ){
110 result = "git checkout "
111 if ( onos_tag == "" )
112 result += onos_branch //create new local branch
113 else
114 result += onos_tag //checkout the tag
115 return result
116}
117def preSetup( onos_branch, test_branch, onos_tag, isManual ){
118 result = ""
119 if( !isManual ){
120 result = '''echo -e "\n##### Set TestON Branch #####"
121 echo "TestON Branch is set on: ''' + test_branch + '''"
122 cd ~/OnosSystemTest/
123 git checkout HEAD~1 # Make sure you aren't pn a branch
124 git branch | grep -v "detached from" | xargs git branch -d # delete all local branches merged with remote
125 git branch -D ''' + test_branch + ''' # just incase there are local changes. This will normally result in a branch not found error
126 git clean -df # clean any local files
127 git fetch --all # update all caches from remotes
128 git reset --hard origin/''' + test_branch +''' # force local index to match remote branch
129 git clean -df # clean any local files
130 git checkout ''' + test_branch + ''' #create new local branch
131 git branch
132 git log -1 --decorate
133 echo -e "\n##### Set ONOS Branch #####"
134 echo "ONOS Branch is set on: ''' + onos_branch + '''"
135 echo -e "\n #### check karaf version ######"
136 env |grep karaf
137 cd ~/onos
138 rm -rf buck-out/*
139 ~/onos/tools/build/onos-buck clean
140 git checkout HEAD~1 # Make sure you aren't pn a branch
141 git branch | grep -v "detached from" | xargs git branch -d # delete all local branches merged with remote
142 git branch -D ''' + onos_branch + ''' # just incase there are local changes. This will normally result in a branch not found error
143 git clean -df # clean any local files
144 git fetch --all # update all caches from remotes
145 git reset --hard origin/''' + onos_branch + ''' # force local index to match remote branch
146 git clean -df # clean any local files
147 ''' + tagCheck( onos_tag, onos_branch ) + '''
148 git branch
149 git log -1 --decorate
150 echo -e "\n##### set jvm heap size to 8G #####"
151 echo ${ONOSJVMHeap}
152 inserted_line="export JAVA_OPTS=\"\${ONOSJVMHeap}\""
153 sed -i "s/bash/bash\\n$inserted_line/" ~/onos/tools/package/bin/onos-service
154 echo "##### Check onos-service setting..... #####"
155 cat ~/onos/tools/package/bin/onos-service
156 export JAVA_HOME=/usr/lib/jvm/java-8-oracle'''
157 }
158 return result
159}
160def oldFlowCheck( jobOn, onos_branch ){
161 result = ""
162 if( jobOn == "SCPF" && ( onos_branch== "master" || onos_branch=="onos-1.12" ) )
163 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
164 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"
165 return result
166}
167def postSetup( onos_branch, test_branch, onos_tag, isManual ){
168 result = ""
169 if( !isManual ){
170 result = '''echo -e "\n##### build ONOS skip unit tests ######"
171 #mvn clean install -DskipTests
172 # Force buck update
173 rm -f ~/onos/bin/buck
174 ~/onos/tools/build/onos-buck build onos
175 sleep 30
176 echo -e "\n##### Stop all running instances of Karaf #####"
177 kill $(ps -efw | grep karaf | grep -v grep | awk '{print $2}')
178 sleep 30
179 git branch'''
180 }
181 return result
182}
183def returnCell( nodeName ){
184 node( "TestStation-" + nodeName + "s" ){
185 sh '''#!/bin/bash -l
186 set +e
187 . ~/.bashrc
188 env
189 ~/./return_cell.sh
190 '''
191 }
192}
193
Devin Lim2fdf76a2018-04-06 19:27:54 -0700194return this;