Devin Lim | e1346f4 | 2018-05-15 15:41:36 -0700 | [diff] [blame] | 1 | #!groovy |
| 2 | |
Devin Lim | f517519 | 2018-05-14 19:13:22 -0700 | [diff] [blame] | 3 | // Copyright 2017 Open Networking Foundation (ONF) |
| 4 | // |
| 5 | // Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>, |
| 6 | // the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>, |
| 7 | // or the System Testing Guide page at <https://wiki.onosproject.org/x/WYQg> |
| 8 | // |
| 9 | // TestON is free software: you can redistribute it and/or modify |
| 10 | // it under the terms of the GNU General Public License as published by |
| 11 | // the Free Software Foundation, either version 2 of the License, or |
| 12 | // (at your option) any later version. |
| 13 | // |
| 14 | // TestON is distributed in the hope that it will be useful, |
| 15 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | // GNU General Public License for more details. |
| 18 | // |
| 19 | // You should have received a copy of the GNU General Public License |
| 20 | // along with TestON. If not, see <http://www.gnu.org/licenses/>. |
| 21 | |
| 22 | // This is the dependency Jenkins script. |
| 23 | // This will provide the portion that will set up the environment of the machine |
| 24 | // and trigger the corresponding jobs. |
| 25 | |
Devin Lim | 431408d | 2018-03-23 17:51:31 -0700 | [diff] [blame] | 26 | def init( commonFuncs ){ |
| 27 | funcs = commonFuncs |
| 28 | } |
| 29 | def lastCommaRemover( str ){ |
Devin Lim | f517519 | 2018-05-14 19:13:22 -0700 | [diff] [blame] | 30 | // function that will remove the last comma from the string |
| 31 | |
Devin Lim | 431408d | 2018-03-23 17:51:31 -0700 | [diff] [blame] | 32 | if ( str.size() > 0 && str[ str.size() - 1 ] == ',' ){ |
| 33 | str = str.substring( 0,str.size() - 1 ) |
| 34 | } |
| 35 | return str |
| 36 | } |
| 37 | def printDaysForTest( AllTheTests ){ |
Devin Lim | f517519 | 2018-05-14 19:13:22 -0700 | [diff] [blame] | 38 | // Print the days for what test has. |
| 39 | |
Devin Lim | 431408d | 2018-03-23 17:51:31 -0700 | [diff] [blame] | 40 | result = "" |
| 41 | for ( String test in AllTheTests.keySet() ){ |
| 42 | result += test + " : \n" |
| 43 | for( String each in AllTheTests[ test ].keySet() ){ |
| 44 | AllTheTests[ test ][ each ][ "day" ] = lastCommaRemover( AllTheTests[ test ][ each ][ "day" ] ) |
| 45 | result += " " + each + ":[" + AllTheTests[ test ][ each ][ "day" ] + "]\n" |
| 46 | } |
| 47 | result += "\n" |
| 48 | } |
| 49 | return result |
| 50 | } |
| 51 | def runTestSeq( testList ){ |
Devin Lim | f517519 | 2018-05-14 19:13:22 -0700 | [diff] [blame] | 52 | // Running the test sequentially |
Devin Lim | 431408d | 2018-03-23 17:51:31 -0700 | [diff] [blame] | 53 | return{ |
| 54 | for ( test in testList.keySet() ){ |
| 55 | testList[ test ].call() |
| 56 | } |
| 57 | } |
| 58 | } |
| 59 | def print_tests( tests ){ |
Devin Lim | f517519 | 2018-05-14 19:13:22 -0700 | [diff] [blame] | 60 | // print the list of the tsets to be run |
| 61 | |
Devin Lim | 431408d | 2018-03-23 17:51:31 -0700 | [diff] [blame] | 62 | for( String test in tests.keySet() ){ |
| 63 | if( tests[ test ][ "tests" ] != "" ){ |
| 64 | println test + ":" |
| 65 | println tests[ test ][ "tests" ] |
| 66 | } |
| 67 | } |
| 68 | } |
| 69 | def organize_tests( tests, testcases ){ |
Devin Lim | f517519 | 2018-05-14 19:13:22 -0700 | [diff] [blame] | 70 | // organize the test to its category using its name. |
| 71 | // most of the time it will use the first two character of the test name |
| 72 | // but there are some exceptions like FUNCbgpls or FUNCvirNetNB since they are now under USECASE |
| 73 | |
Devin Lim | 431408d | 2018-03-23 17:51:31 -0700 | [diff] [blame] | 74 | testList = tests.tokenize( "\n;, " ) |
| 75 | for( String test in testList ) |
| 76 | testcases [ Prefix_organizer[ ( test == "FUNCbgpls" || test == "FUNCvirNetNB" ? "US" : ( test[ 0 ] + test[ 1 ] ) ) ] ][ "tests" ] += test + "," |
| 77 | return testcases |
| 78 | } |
Devin Lim | 431408d | 2018-03-23 17:51:31 -0700 | [diff] [blame] | 79 | def trigger( branch, tests, nodeName, jobOn, manuallyRun, onosTag ){ |
Devin Lim | f517519 | 2018-05-14 19:13:22 -0700 | [diff] [blame] | 80 | // triggering function that will setup the environment and determine which pipeline to trigger |
| 81 | |
Devin Lim | 431408d | 2018-03-23 17:51:31 -0700 | [diff] [blame] | 82 | println jobOn + "-pipeline-" + manuallyRun ? "manually" : branch |
Devin Lim | 6c77b7c | 2018-04-06 19:36:56 -0700 | [diff] [blame] | 83 | def wiki = branch |
Devin Lim | 431408d | 2018-03-23 17:51:31 -0700 | [diff] [blame] | 84 | branch = funcs.branchWithPrefix( branch ) |
| 85 | test_branch = "master" |
| 86 | node( "TestStation-" + nodeName + "s" ){ |
| 87 | envSetup( branch, test_branch, onosTag, jobOn, manuallyRun ) |
| 88 | |
| 89 | exportEnvProperty( branch, test_branch, wiki, tests, post_result, manuallyRun, onosTag, isOldFlow ) |
| 90 | } |
| 91 | |
| 92 | jobToRun = jobOn + "-pipeline-" + ( manuallyRun ? "manually" : wiki ) |
| 93 | build job: jobToRun, propagate: false |
| 94 | } |
| 95 | def trigger_pipeline( branch, tests, nodeName, jobOn, manuallyRun, onosTag ){ |
Devin Lim | f517519 | 2018-05-14 19:13:22 -0700 | [diff] [blame] | 96 | // nodeName : "BM" or "VM" |
| 97 | // jobOn : "SCPF" or "USECASE" or "FUNC" or "HA" |
| 98 | // this will return the function by wrapping them up with return{} to prevent them to be |
| 99 | // executed once this function is called to assign to specific variable. |
Devin Lim | 431408d | 2018-03-23 17:51:31 -0700 | [diff] [blame] | 100 | return{ |
Devin Lim | 5b22fbb | 2018-04-06 15:30:45 -0700 | [diff] [blame] | 101 | trigger( branch, tests, nodeName, jobOn, manuallyRun, onosTag ) |
Devin Lim | 431408d | 2018-03-23 17:51:31 -0700 | [diff] [blame] | 102 | } |
| 103 | } |
| 104 | // export Environment properties. |
| 105 | def exportEnvProperty( onos_branch, test_branch, wiki, tests, postResult, manually_run, onosTag, isOldFlow ){ |
Devin Lim | f517519 | 2018-05-14 19:13:22 -0700 | [diff] [blame] | 106 | // export environment properties to the machine. |
| 107 | |
Devin Lim | 431408d | 2018-03-23 17:51:31 -0700 | [diff] [blame] | 108 | stage( "export Property" ){ |
| 109 | sh ''' |
| 110 | echo "ONOSBranch=''' + onos_branch +'''" > /var/jenkins/TestONOS.property |
| 111 | echo "TestONBranch=''' + test_branch +'''" >> /var/jenkins/TestONOS.property |
| 112 | echo "ONOSTag='''+ onosTag +'''" >> /var/jenkins/TestONOS.property |
| 113 | echo "WikiPrefix=''' + wiki +'''" >> /var/jenkins/TestONOS.property |
| 114 | echo "ONOSJVMHeap='''+ env.ONOSJVMHeap +'''" >> /var/jenkins/TestONOS.property |
| 115 | echo "Tests=''' + tests +'''" >> /var/jenkins/TestONOS.property |
| 116 | echo "postResult=''' + postResult +'''" >> /var/jenkins/TestONOS.property |
| 117 | echo "manualRun=''' + manually_run +'''" >> /var/jenkins/TestONOS.property |
| 118 | echo "isOldFlow=''' + isOldFlow +'''" >> /var/jenkins/TestONOS.property |
| 119 | ''' |
| 120 | } |
| 121 | } |
| 122 | // Initialize the environment Setup for the onos and OnosSystemTest |
| 123 | def envSetup( onos_branch, test_branch, onos_tag, jobOn, manuallyRun ){ |
Devin Lim | f517519 | 2018-05-14 19:13:22 -0700 | [diff] [blame] | 124 | // to setup the environment using the bash script |
| 125 | |
Devin Lim | 431408d | 2018-03-23 17:51:31 -0700 | [diff] [blame] | 126 | stage( "envSetup" ) { |
| 127 | // after env: ''' + borrow_mn( jobOn ) + ''' |
| 128 | sh '''#!/bin/bash -l |
| 129 | set +e |
| 130 | . ~/.bashrc |
| 131 | env |
| 132 | ''' + preSetup( onos_branch, test_branch, onos_tag, manuallyRun ) + ''' |
| 133 | ''' + oldFlowCheck( jobOn, onos_branch ) + ''' |
| 134 | ''' + postSetup( onos_branch, test_branch, onos_tag, manuallyRun ) |
Devin Lim | 90b6a59 | 2018-05-09 13:20:33 -0700 | [diff] [blame] | 135 | generateKey() |
Devin Lim | 431408d | 2018-03-23 17:51:31 -0700 | [diff] [blame] | 136 | } |
| 137 | } |
| 138 | def tagCheck( onos_tag, onos_branch ){ |
Devin Lim | f517519 | 2018-05-14 19:13:22 -0700 | [diff] [blame] | 139 | // check the tag for onos if it is not empty |
| 140 | |
Devin Lim | 431408d | 2018-03-23 17:51:31 -0700 | [diff] [blame] | 141 | result = "git checkout " |
| 142 | if ( onos_tag == "" ) |
| 143 | result += onos_branch //create new local branch |
| 144 | else |
| 145 | result += onos_tag //checkout the tag |
| 146 | return result |
| 147 | } |
| 148 | def preSetup( onos_branch, test_branch, onos_tag, isManual ){ |
Devin Lim | f517519 | 2018-05-14 19:13:22 -0700 | [diff] [blame] | 149 | // pre setup part which will clean up and checkout to corresponding branch. |
| 150 | |
Devin Lim | 431408d | 2018-03-23 17:51:31 -0700 | [diff] [blame] | 151 | result = "" |
| 152 | if( !isManual ){ |
| 153 | result = '''echo -e "\n##### Set TestON Branch #####" |
| 154 | echo "TestON Branch is set on: ''' + test_branch + '''" |
| 155 | cd ~/OnosSystemTest/ |
| 156 | git checkout HEAD~1 # Make sure you aren't pn a branch |
| 157 | git branch | grep -v "detached from" | xargs git branch -d # delete all local branches merged with remote |
| 158 | git branch -D ''' + test_branch + ''' # just incase there are local changes. This will normally result in a branch not found error |
| 159 | git clean -df # clean any local files |
| 160 | git fetch --all # update all caches from remotes |
| 161 | git reset --hard origin/''' + test_branch +''' # force local index to match remote branch |
| 162 | git clean -df # clean any local files |
| 163 | git checkout ''' + test_branch + ''' #create new local branch |
| 164 | git branch |
| 165 | git log -1 --decorate |
| 166 | echo -e "\n##### Set ONOS Branch #####" |
| 167 | echo "ONOS Branch is set on: ''' + onos_branch + '''" |
| 168 | echo -e "\n #### check karaf version ######" |
| 169 | env |grep karaf |
| 170 | cd ~/onos |
| 171 | rm -rf buck-out/* |
| 172 | ~/onos/tools/build/onos-buck clean |
| 173 | git checkout HEAD~1 # Make sure you aren't pn a branch |
| 174 | git branch | grep -v "detached from" | xargs git branch -d # delete all local branches merged with remote |
| 175 | git branch -D ''' + onos_branch + ''' # just incase there are local changes. This will normally result in a branch not found error |
| 176 | git clean -df # clean any local files |
| 177 | git fetch --all # update all caches from remotes |
| 178 | git reset --hard origin/''' + onos_branch + ''' # force local index to match remote branch |
| 179 | git clean -df # clean any local files |
| 180 | ''' + tagCheck( onos_tag, onos_branch ) + ''' |
| 181 | git branch |
| 182 | git log -1 --decorate |
| 183 | echo -e "\n##### set jvm heap size to 8G #####" |
| 184 | echo ${ONOSJVMHeap} |
| 185 | inserted_line="export JAVA_OPTS=\"\${ONOSJVMHeap}\"" |
| 186 | sed -i "s/bash/bash\\n$inserted_line/" ~/onos/tools/package/bin/onos-service |
| 187 | echo "##### Check onos-service setting..... #####" |
| 188 | cat ~/onos/tools/package/bin/onos-service |
| 189 | export JAVA_HOME=/usr/lib/jvm/java-8-oracle''' |
| 190 | } |
| 191 | return result |
| 192 | } |
| 193 | def oldFlowCheck( jobOn, onos_branch ){ |
Devin Lim | f517519 | 2018-05-14 19:13:22 -0700 | [diff] [blame] | 194 | // part that will check if it is oldFlow. If so, it will switch to use old flow. Only affected with SCPF. |
| 195 | |
Devin Lim | 431408d | 2018-03-23 17:51:31 -0700 | [diff] [blame] | 196 | result = "" |
| 197 | if( jobOn == "SCPF" && ( onos_branch== "master" || onos_branch=="onos-1.12" ) ) |
| 198 | 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 |
| 199 | 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" |
| 200 | return result |
| 201 | } |
| 202 | def postSetup( onos_branch, test_branch, onos_tag, isManual ){ |
Devin Lim | f517519 | 2018-05-14 19:13:22 -0700 | [diff] [blame] | 203 | // setup that will build the onos using buck. |
| 204 | |
Devin Lim | 431408d | 2018-03-23 17:51:31 -0700 | [diff] [blame] | 205 | result = "" |
| 206 | if( !isManual ){ |
| 207 | result = '''echo -e "\n##### build ONOS skip unit tests ######" |
| 208 | #mvn clean install -DskipTests |
| 209 | # Force buck update |
| 210 | rm -f ~/onos/bin/buck |
| 211 | ~/onos/tools/build/onos-buck build onos |
| 212 | sleep 30 |
| 213 | echo -e "\n##### Stop all running instances of Karaf #####" |
| 214 | kill $(ps -efw | grep karaf | grep -v grep | awk '{print $2}') |
| 215 | sleep 30 |
Devin Lim | 2d7371a | 2018-05-08 18:02:05 -0700 | [diff] [blame] | 216 | git branch |
Devin Lim | 2d7371a | 2018-05-08 18:02:05 -0700 | [diff] [blame] | 217 | ''' |
Devin Lim | 431408d | 2018-03-23 17:51:31 -0700 | [diff] [blame] | 218 | } |
| 219 | return result |
| 220 | } |
Devin Lim | 90b6a59 | 2018-05-09 13:20:33 -0700 | [diff] [blame] | 221 | def generateKey(){ |
Devin Lim | f517519 | 2018-05-14 19:13:22 -0700 | [diff] [blame] | 222 | // generate cluster-key of the onos |
| 223 | |
Devin Lim | 018203a | 2018-05-09 11:33:20 -0700 | [diff] [blame] | 224 | try{ |
| 225 | sh ''' |
| 226 | #!/bin/bash -l |
| 227 | set +e |
| 228 | . ~/.bashrc |
| 229 | env |
Devin Lim | 90b6a59 | 2018-05-09 13:20:33 -0700 | [diff] [blame] | 230 | onos-push-bits-through-proxy |
| 231 | onos-gen-cluster-key -f |
Devin Lim | 018203a | 2018-05-09 11:33:20 -0700 | [diff] [blame] | 232 | ''' |
| 233 | }catch( all ){} |
| 234 | } |
Devin Lim | 431408d | 2018-03-23 17:51:31 -0700 | [diff] [blame] | 235 | |
Devin Lim | 2fdf76a | 2018-04-06 19:27:54 -0700 | [diff] [blame] | 236 | return this; |