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