blob: 96c08557d10933f551af3eb8c398280c4d63969f [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 Lim431408d2018-03-23 17:51:31 -070055 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{
Devin Lim5b22fbb2018-04-06 15:30:45 -070070 trigger( branch, tests, nodeName, jobOn, manuallyRun, onosTag )
Devin Lim431408d2018-03-23 17:51:31 -070071 }
72}
73// export Environment properties.
74def exportEnvProperty( onos_branch, test_branch, wiki, tests, postResult, manually_run, onosTag, isOldFlow ){
75 stage( "export Property" ){
76 sh '''
77 echo "ONOSBranch=''' + onos_branch +'''" > /var/jenkins/TestONOS.property
78 echo "TestONBranch=''' + test_branch +'''" >> /var/jenkins/TestONOS.property
79 echo "ONOSTag='''+ onosTag +'''" >> /var/jenkins/TestONOS.property
80 echo "WikiPrefix=''' + wiki +'''" >> /var/jenkins/TestONOS.property
81 echo "ONOSJVMHeap='''+ env.ONOSJVMHeap +'''" >> /var/jenkins/TestONOS.property
82 echo "Tests=''' + tests +'''" >> /var/jenkins/TestONOS.property
83 echo "postResult=''' + postResult +'''" >> /var/jenkins/TestONOS.property
84 echo "manualRun=''' + manually_run +'''" >> /var/jenkins/TestONOS.property
85 echo "isOldFlow=''' + isOldFlow +'''" >> /var/jenkins/TestONOS.property
86 '''
87 }
88}
89// Initialize the environment Setup for the onos and OnosSystemTest
90def envSetup( onos_branch, test_branch, onos_tag, jobOn, manuallyRun ){
Devin Lim431408d2018-03-23 17:51:31 -070091 stage( "envSetup" ) {
92 // after env: ''' + borrow_mn( jobOn ) + '''
93 sh '''#!/bin/bash -l
94 set +e
95 . ~/.bashrc
96 env
97 ''' + preSetup( onos_branch, test_branch, onos_tag, manuallyRun ) + '''
98 ''' + oldFlowCheck( jobOn, onos_branch ) + '''
99 ''' + postSetup( onos_branch, test_branch, onos_tag, manuallyRun )
Devin Lim90b6a592018-05-09 13:20:33 -0700100 generateKey()
Devin Lim431408d2018-03-23 17:51:31 -0700101 }
102}
103def tagCheck( onos_tag, onos_branch ){
104 result = "git checkout "
105 if ( onos_tag == "" )
106 result += onos_branch //create new local branch
107 else
108 result += onos_tag //checkout the tag
109 return result
110}
111def preSetup( onos_branch, test_branch, onos_tag, isManual ){
112 result = ""
113 if( !isManual ){
114 result = '''echo -e "\n##### Set TestON Branch #####"
115 echo "TestON Branch is set on: ''' + test_branch + '''"
116 cd ~/OnosSystemTest/
117 git checkout HEAD~1 # Make sure you aren't pn a branch
118 git branch | grep -v "detached from" | xargs git branch -d # delete all local branches merged with remote
119 git branch -D ''' + test_branch + ''' # just incase there are local changes. This will normally result in a branch not found error
120 git clean -df # clean any local files
121 git fetch --all # update all caches from remotes
122 git reset --hard origin/''' + test_branch +''' # force local index to match remote branch
123 git clean -df # clean any local files
124 git checkout ''' + test_branch + ''' #create new local branch
125 git branch
126 git log -1 --decorate
127 echo -e "\n##### Set ONOS Branch #####"
128 echo "ONOS Branch is set on: ''' + onos_branch + '''"
129 echo -e "\n #### check karaf version ######"
130 env |grep karaf
131 cd ~/onos
132 rm -rf buck-out/*
133 ~/onos/tools/build/onos-buck clean
134 git checkout HEAD~1 # Make sure you aren't pn a branch
135 git branch | grep -v "detached from" | xargs git branch -d # delete all local branches merged with remote
136 git branch -D ''' + onos_branch + ''' # just incase there are local changes. This will normally result in a branch not found error
137 git clean -df # clean any local files
138 git fetch --all # update all caches from remotes
139 git reset --hard origin/''' + onos_branch + ''' # force local index to match remote branch
140 git clean -df # clean any local files
141 ''' + tagCheck( onos_tag, onos_branch ) + '''
142 git branch
143 git log -1 --decorate
144 echo -e "\n##### set jvm heap size to 8G #####"
145 echo ${ONOSJVMHeap}
146 inserted_line="export JAVA_OPTS=\"\${ONOSJVMHeap}\""
147 sed -i "s/bash/bash\\n$inserted_line/" ~/onos/tools/package/bin/onos-service
148 echo "##### Check onos-service setting..... #####"
149 cat ~/onos/tools/package/bin/onos-service
150 export JAVA_HOME=/usr/lib/jvm/java-8-oracle'''
151 }
152 return result
153}
154def oldFlowCheck( jobOn, onos_branch ){
155 result = ""
156 if( jobOn == "SCPF" && ( onos_branch== "master" || onos_branch=="onos-1.12" ) )
157 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
158 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"
159 return result
160}
161def postSetup( onos_branch, test_branch, onos_tag, isManual ){
162 result = ""
163 if( !isManual ){
164 result = '''echo -e "\n##### build ONOS skip unit tests ######"
165 #mvn clean install -DskipTests
166 # Force buck update
167 rm -f ~/onos/bin/buck
168 ~/onos/tools/build/onos-buck build onos
169 sleep 30
170 echo -e "\n##### Stop all running instances of Karaf #####"
171 kill $(ps -efw | grep karaf | grep -v grep | awk '{print $2}')
172 sleep 30
Devin Lim2d7371a2018-05-08 18:02:05 -0700173 git branch
Devin Lim2d7371a2018-05-08 18:02:05 -0700174 '''
Devin Lim431408d2018-03-23 17:51:31 -0700175 }
176 return result
177}
Devin Lim90b6a592018-05-09 13:20:33 -0700178def generateKey(){
Devin Lim018203a2018-05-09 11:33:20 -0700179 try{
180 sh '''
181 #!/bin/bash -l
182 set +e
183 . ~/.bashrc
184 env
Devin Lim90b6a592018-05-09 13:20:33 -0700185 onos-push-bits-through-proxy
186 onos-gen-cluster-key -f
Devin Lim018203a2018-05-09 11:33:20 -0700187 '''
188 }catch( all ){}
189}
Devin Lim431408d2018-03-23 17:51:31 -0700190def returnCell( nodeName ){
191 node( "TestStation-" + nodeName + "s" ){
192 sh '''#!/bin/bash -l
193 set +e
194 . ~/.bashrc
195 env
196 ~/./return_cell.sh
197 '''
198 }
199}
200
Devin Lim2fdf76a2018-04-06 19:27:54 -0700201return this;