blob: c6fa9cad11ef97346f5ea73c40559dada7d89ae6 [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
54 wiki = branch
55 branch = funcs.branchWithPrefix( branch )
56 test_branch = "master"
57 node( "TestStation-" + nodeName + "s" ){
58 envSetup( branch, test_branch, onosTag, jobOn, manuallyRun )
59
60 exportEnvProperty( branch, test_branch, wiki, tests, post_result, manuallyRun, onosTag, isOldFlow )
61 }
62
63 jobToRun = jobOn + "-pipeline-" + ( manuallyRun ? "manually" : wiki )
64 build job: jobToRun, propagate: false
65}
66def trigger_pipeline( branch, tests, nodeName, jobOn, manuallyRun, onosTag ){
67// nodeName : "BM" or "VM"
68// jobOn : "SCPF" or "USECASE" or "FUNC" or "HA"
69 return{
70 if( jobOn == "SR" ){
71 trigger( "1.11", tests, nodeName, jobOn, manuallyRun, onosTag )
72 trigger( "1.12", tests, nodeName, jobOn, manuallyRun, onosTag )
73 trigger( "master", tests, nodeName, jobOn, manuallyRun, onosTag )
74 // returnCell( nodeName )
75 }else{
76 trigger( branch, tests, nodeName, jobOn, manuallyRun, onosTag )
77 }
78 }
79}
80// export Environment properties.
81def exportEnvProperty( onos_branch, test_branch, wiki, tests, postResult, manually_run, onosTag, isOldFlow ){
82 stage( "export Property" ){
83 sh '''
84 echo "ONOSBranch=''' + onos_branch +'''" > /var/jenkins/TestONOS.property
85 echo "TestONBranch=''' + test_branch +'''" >> /var/jenkins/TestONOS.property
86 echo "ONOSTag='''+ onosTag +'''" >> /var/jenkins/TestONOS.property
87 echo "WikiPrefix=''' + wiki +'''" >> /var/jenkins/TestONOS.property
88 echo "ONOSJVMHeap='''+ env.ONOSJVMHeap +'''" >> /var/jenkins/TestONOS.property
89 echo "Tests=''' + tests +'''" >> /var/jenkins/TestONOS.property
90 echo "postResult=''' + postResult +'''" >> /var/jenkins/TestONOS.property
91 echo "manualRun=''' + manually_run +'''" >> /var/jenkins/TestONOS.property
92 echo "isOldFlow=''' + isOldFlow +'''" >> /var/jenkins/TestONOS.property
93 '''
94 }
95}
96// Initialize the environment Setup for the onos and OnosSystemTest
97def envSetup( onos_branch, test_branch, onos_tag, jobOn, manuallyRun ){
98 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
194return this;