blob: 04a79fd51ba2df740ab78fe3c4e4480defa56752 [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"
Devin Lim4fbf5fc2018-04-06 19:15:34 -070057 print "HERE2:" + branch
Devin Lim431408d2018-03-23 17:51:31 -070058 node( "TestStation-" + nodeName + "s" ){
59 envSetup( branch, test_branch, onosTag, jobOn, manuallyRun )
60
61 exportEnvProperty( branch, test_branch, wiki, tests, post_result, manuallyRun, onosTag, isOldFlow )
62 }
63
64 jobToRun = jobOn + "-pipeline-" + ( manuallyRun ? "manually" : wiki )
65 build job: jobToRun, propagate: false
66}
67def trigger_pipeline( branch, tests, nodeName, jobOn, manuallyRun, onosTag ){
68// nodeName : "BM" or "VM"
69// jobOn : "SCPF" or "USECASE" or "FUNC" or "HA"
70 return{
Devin Lim9d18c972018-04-06 19:09:18 -070071 print "HERE:" + branch
Devin Lim5b22fbb2018-04-06 15:30:45 -070072 trigger( branch, tests, nodeName, jobOn, manuallyRun, onosTag )
Devin Lim431408d2018-03-23 17:51:31 -070073 }
74}
75// export Environment properties.
76def exportEnvProperty( onos_branch, test_branch, wiki, tests, postResult, manually_run, onosTag, isOldFlow ){
77 stage( "export Property" ){
78 sh '''
79 echo "ONOSBranch=''' + onos_branch +'''" > /var/jenkins/TestONOS.property
80 echo "TestONBranch=''' + test_branch +'''" >> /var/jenkins/TestONOS.property
81 echo "ONOSTag='''+ onosTag +'''" >> /var/jenkins/TestONOS.property
82 echo "WikiPrefix=''' + wiki +'''" >> /var/jenkins/TestONOS.property
83 echo "ONOSJVMHeap='''+ env.ONOSJVMHeap +'''" >> /var/jenkins/TestONOS.property
84 echo "Tests=''' + tests +'''" >> /var/jenkins/TestONOS.property
85 echo "postResult=''' + postResult +'''" >> /var/jenkins/TestONOS.property
86 echo "manualRun=''' + manually_run +'''" >> /var/jenkins/TestONOS.property
87 echo "isOldFlow=''' + isOldFlow +'''" >> /var/jenkins/TestONOS.property
88 '''
89 }
90}
91// Initialize the environment Setup for the onos and OnosSystemTest
92def envSetup( onos_branch, test_branch, onos_tag, jobOn, manuallyRun ){
Devin Lim4fbf5fc2018-04-06 19:15:34 -070093 print "HERE3:" + onos_branch
Devin Lim431408d2018-03-23 17:51:31 -070094 stage( "envSetup" ) {
95 // after env: ''' + borrow_mn( jobOn ) + '''
96 sh '''#!/bin/bash -l
97 set +e
98 . ~/.bashrc
99 env
100 ''' + preSetup( onos_branch, test_branch, onos_tag, manuallyRun ) + '''
101 ''' + oldFlowCheck( jobOn, onos_branch ) + '''
102 ''' + postSetup( onos_branch, test_branch, onos_tag, manuallyRun )
103 }
104}
105def tagCheck( onos_tag, onos_branch ){
106 result = "git checkout "
107 if ( onos_tag == "" )
108 result += onos_branch //create new local branch
109 else
110 result += onos_tag //checkout the tag
111 return result
112}
113def preSetup( onos_branch, test_branch, onos_tag, isManual ){
114 result = ""
115 if( !isManual ){
116 result = '''echo -e "\n##### Set TestON Branch #####"
117 echo "TestON Branch is set on: ''' + test_branch + '''"
118 cd ~/OnosSystemTest/
119 git checkout HEAD~1 # Make sure you aren't pn a branch
120 git branch | grep -v "detached from" | xargs git branch -d # delete all local branches merged with remote
121 git branch -D ''' + test_branch + ''' # just incase there are local changes. This will normally result in a branch not found error
122 git clean -df # clean any local files
123 git fetch --all # update all caches from remotes
124 git reset --hard origin/''' + test_branch +''' # force local index to match remote branch
125 git clean -df # clean any local files
126 git checkout ''' + test_branch + ''' #create new local branch
127 git branch
128 git log -1 --decorate
129 echo -e "\n##### Set ONOS Branch #####"
130 echo "ONOS Branch is set on: ''' + onos_branch + '''"
131 echo -e "\n #### check karaf version ######"
132 env |grep karaf
133 cd ~/onos
134 rm -rf buck-out/*
135 ~/onos/tools/build/onos-buck clean
136 git checkout HEAD~1 # Make sure you aren't pn a branch
137 git branch | grep -v "detached from" | xargs git branch -d # delete all local branches merged with remote
138 git branch -D ''' + onos_branch + ''' # just incase there are local changes. This will normally result in a branch not found error
139 git clean -df # clean any local files
140 git fetch --all # update all caches from remotes
141 git reset --hard origin/''' + onos_branch + ''' # force local index to match remote branch
142 git clean -df # clean any local files
143 ''' + tagCheck( onos_tag, onos_branch ) + '''
144 git branch
145 git log -1 --decorate
146 echo -e "\n##### set jvm heap size to 8G #####"
147 echo ${ONOSJVMHeap}
148 inserted_line="export JAVA_OPTS=\"\${ONOSJVMHeap}\""
149 sed -i "s/bash/bash\\n$inserted_line/" ~/onos/tools/package/bin/onos-service
150 echo "##### Check onos-service setting..... #####"
151 cat ~/onos/tools/package/bin/onos-service
152 export JAVA_HOME=/usr/lib/jvm/java-8-oracle'''
153 }
154 return result
155}
156def oldFlowCheck( jobOn, onos_branch ){
157 result = ""
158 if( jobOn == "SCPF" && ( onos_branch== "master" || onos_branch=="onos-1.12" ) )
159 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
160 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"
161 return result
162}
163def postSetup( onos_branch, test_branch, onos_tag, isManual ){
164 result = ""
165 if( !isManual ){
166 result = '''echo -e "\n##### build ONOS skip unit tests ######"
167 #mvn clean install -DskipTests
168 # Force buck update
169 rm -f ~/onos/bin/buck
170 ~/onos/tools/build/onos-buck build onos
171 sleep 30
172 echo -e "\n##### Stop all running instances of Karaf #####"
173 kill $(ps -efw | grep karaf | grep -v grep | awk '{print $2}')
174 sleep 30
175 git branch'''
176 }
177 return result
178}
179def returnCell( nodeName ){
180 node( "TestStation-" + nodeName + "s" ){
181 sh '''#!/bin/bash -l
182 set +e
183 . ~/.bashrc
184 env
185 ~/./return_cell.sh
186 '''
187 }
188}
189
190return this;