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 | |
Jeremy Ronquillo | 6fbfdd5 | 2019-07-09 13:49:34 -0700 | [diff] [blame] | 26 | import groovy.time.TimeCategory |
| 27 | import groovy.time.TimeDuration |
| 28 | |
Jeremy Ronquillo | 64eeeb1 | 2019-05-13 11:19:46 -0700 | [diff] [blame] | 29 | test_list = evaluate readTrusted( 'TestON/JenkinsFile/dependencies/JenkinsTestONTests.groovy' ) |
| 30 | test_list.init() |
Jon Hall | 6af749d | 2018-05-29 12:59:47 -0700 | [diff] [blame] | 31 | |
Jeremy Ronquillo | 64eeeb1 | 2019-05-13 11:19:46 -0700 | [diff] [blame] | 32 | def printDaysForTest(){ |
Devin Lim | f517519 | 2018-05-14 19:13:22 -0700 | [diff] [blame] | 33 | // Print the days for what test has. |
Jeremy Ronquillo | 64eeeb1 | 2019-05-13 11:19:46 -0700 | [diff] [blame] | 34 | AllTheTests = test_list.getAllTests() |
Devin Lim | f517519 | 2018-05-14 19:13:22 -0700 | [diff] [blame] | 35 | |
Devin Lim | 431408d | 2018-03-23 17:51:31 -0700 | [diff] [blame] | 36 | result = "" |
| 37 | for ( String test in AllTheTests.keySet() ){ |
Jeremy Ronquillo | 64eeeb1 | 2019-05-13 11:19:46 -0700 | [diff] [blame] | 38 | result += test + ": [" |
Jeremy Ronquillo | 21c29fc | 2019-06-05 11:15:24 -0700 | [diff] [blame] | 39 | test_schedule = AllTheTests[ test ][ "schedules" ] |
| 40 | for ( String sch_dict in test_schedule ){ |
| 41 | for ( String day in test_list.convertScheduleKeyToDays( sch_dict[ "branch" ] ) ){ |
Jeremy Ronquillo | 64eeeb1 | 2019-05-13 11:19:46 -0700 | [diff] [blame] | 42 | result += day + " " |
| 43 | } |
Devin Lim | 431408d | 2018-03-23 17:51:31 -0700 | [diff] [blame] | 44 | } |
Jeremy Ronquillo | 64eeeb1 | 2019-05-13 11:19:46 -0700 | [diff] [blame] | 45 | result += "]\n" |
Devin Lim | 431408d | 2018-03-23 17:51:31 -0700 | [diff] [blame] | 46 | } |
| 47 | return result |
| 48 | } |
Jon Hall | 6af749d | 2018-05-29 12:59:47 -0700 | [diff] [blame] | 49 | |
Jeremy Ronquillo | 6fbfdd5 | 2019-07-09 13:49:34 -0700 | [diff] [blame] | 50 | def trigger( branch, tests, nodeLabel, jobOn, manuallyRun, onosTag ){ |
Devin Lim | f517519 | 2018-05-14 19:13:22 -0700 | [diff] [blame] | 51 | // triggering function that will setup the environment and determine which pipeline to trigger |
| 52 | |
You Wang | 49461a8 | 2018-08-02 13:15:30 -0700 | [diff] [blame] | 53 | println "Job name: " + jobOn + "-pipeline-" + ( manuallyRun ? "manually" : branch ) |
Devin Lim | 6c77b7c | 2018-04-06 19:36:56 -0700 | [diff] [blame] | 54 | def wiki = branch |
Jeremy Ronquillo | 21c29fc | 2019-06-05 11:15:24 -0700 | [diff] [blame] | 55 | def onos_branch = test_list.addPrefixToBranch( branch ) |
| 56 | def test_branch = test_list.addPrefixToBranch( branch ) |
You Wang | 49461a8 | 2018-08-02 13:15:30 -0700 | [diff] [blame] | 57 | println "onos_branch with prefix: " + onos_branch |
| 58 | println "test_branch with prefix: " + test_branch |
Jeremy Ronquillo | 6fbfdd5 | 2019-07-09 13:49:34 -0700 | [diff] [blame] | 59 | assignedNode = null |
| 60 | node( label: nodeLabel ) { |
You Wang | 7952750 | 2018-08-02 12:18:20 -0700 | [diff] [blame] | 61 | envSetup( onos_branch, test_branch, onosTag, jobOn, manuallyRun ) |
Jeremy Ronquillo | 6fbfdd5 | 2019-07-09 13:49:34 -0700 | [diff] [blame] | 62 | exportEnvProperty( onos_branch, test_branch, jobOn, wiki, tests, post_result, manuallyRun, onosTag, isOldFlow, nodeLabel ) |
| 63 | assignedNode = env.NODE_NAME |
Devin Lim | 431408d | 2018-03-23 17:51:31 -0700 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | jobToRun = jobOn + "-pipeline-" + ( manuallyRun ? "manually" : wiki ) |
Jeremy Ronquillo | 6fbfdd5 | 2019-07-09 13:49:34 -0700 | [diff] [blame] | 67 | build job: jobToRun, propagate: false, parameters: [ [ $class: 'StringParameterValue', name: 'Category', value: jobOn ], |
| 68 | [ $class: 'StringParameterValue', name: 'Branch', value: branch ], |
| 69 | [ $class: 'StringParameterValue', name: 'TestStation', value: assignedNode ], |
| 70 | [ $class: 'StringParameterValue', name: 'NodeLabel', value: nodeLabel ] ] |
Devin Lim | 431408d | 2018-03-23 17:51:31 -0700 | [diff] [blame] | 71 | } |
Jon Hall | 6af749d | 2018-05-29 12:59:47 -0700 | [diff] [blame] | 72 | |
Jeremy Ronquillo | 6fbfdd5 | 2019-07-09 13:49:34 -0700 | [diff] [blame] | 73 | def trigger_pipeline( branch, tests, nodeLabel, jobOn, manuallyRun, onosTag ){ |
| 74 | // nodeLabel : nodeLabel from tests.json |
Devin Lim | f517519 | 2018-05-14 19:13:22 -0700 | [diff] [blame] | 75 | // jobOn : "SCPF" or "USECASE" or "FUNC" or "HA" |
| 76 | // this will return the function by wrapping them up with return{} to prevent them to be |
| 77 | // executed once this function is called to assign to specific variable. |
Jon Hall | 6af749d | 2018-05-29 12:59:47 -0700 | [diff] [blame] | 78 | return { |
Jeremy Ronquillo | 6fbfdd5 | 2019-07-09 13:49:34 -0700 | [diff] [blame] | 79 | trigger( branch, tests, nodeLabel, jobOn, manuallyRun, onosTag ) |
Devin Lim | 431408d | 2018-03-23 17:51:31 -0700 | [diff] [blame] | 80 | } |
| 81 | } |
Jon Hall | 6af749d | 2018-05-29 12:59:47 -0700 | [diff] [blame] | 82 | |
Devin Lim | 431408d | 2018-03-23 17:51:31 -0700 | [diff] [blame] | 83 | // export Environment properties. |
Jeremy Ronquillo | 6fbfdd5 | 2019-07-09 13:49:34 -0700 | [diff] [blame] | 84 | def exportEnvProperty( onos_branch, test_branch, jobOn, wiki, tests, postResult, manually_run, onosTag, isOldFlow, nodeLabel ){ |
Devin Lim | f517519 | 2018-05-14 19:13:22 -0700 | [diff] [blame] | 85 | // export environment properties to the machine. |
| 86 | |
Jeremy Ronquillo | 21c29fc | 2019-06-05 11:15:24 -0700 | [diff] [blame] | 87 | filePath = "/var/jenkins/TestONOS-" + jobOn + "-" + onos_branch + ".property" |
Jeremy Ronquillo | 259d71f | 2019-06-07 14:38:46 -0700 | [diff] [blame] | 88 | |
Jon Hall | 6af749d | 2018-05-29 12:59:47 -0700 | [diff] [blame] | 89 | stage( "export Property" ) { |
Devin Lim | 431408d | 2018-03-23 17:51:31 -0700 | [diff] [blame] | 90 | sh ''' |
Jeremy Ronquillo | 259d71f | 2019-06-07 14:38:46 -0700 | [diff] [blame] | 91 | echo "ONOSBranch=''' + onos_branch + '''" > ''' + filePath + ''' |
| 92 | echo "TestONBranch=''' + test_branch + '''" >> ''' + filePath + ''' |
| 93 | echo "ONOSTag=''' + onosTag + '''" >> ''' + filePath + ''' |
| 94 | echo "WikiPrefix=''' + wiki + '''" >> ''' + filePath + ''' |
| 95 | echo "ONOSJAVAOPTS=''' + env.ONOSJAVAOPTS + '''" >> ''' + filePath + ''' |
| 96 | echo "Tests=''' + tests + '''" >> ''' + filePath + ''' |
| 97 | echo "postResult=''' + postResult + '''" >> ''' + filePath + ''' |
| 98 | echo "manualRun=''' + manually_run + '''" >> ''' + filePath + ''' |
| 99 | echo "isOldFlow=''' + isOldFlow + '''" >> ''' + filePath + ''' |
Devin Lim | 431408d | 2018-03-23 17:51:31 -0700 | [diff] [blame] | 100 | ''' |
| 101 | } |
| 102 | } |
Jon Hall | 6af749d | 2018-05-29 12:59:47 -0700 | [diff] [blame] | 103 | |
Devin Lim | 431408d | 2018-03-23 17:51:31 -0700 | [diff] [blame] | 104 | // Initialize the environment Setup for the onos and OnosSystemTest |
| 105 | def envSetup( onos_branch, test_branch, onos_tag, jobOn, manuallyRun ){ |
Devin Lim | f517519 | 2018-05-14 19:13:22 -0700 | [diff] [blame] | 106 | // to setup the environment using the bash script |
You Wang | 49461a8 | 2018-08-02 13:15:30 -0700 | [diff] [blame] | 107 | println "onos_branch is set to " + onos_branch |
| 108 | println "test_branch is set to " + test_branch |
Devin Lim | 431408d | 2018-03-23 17:51:31 -0700 | [diff] [blame] | 109 | stage( "envSetup" ) { |
| 110 | // after env: ''' + borrow_mn( jobOn ) + ''' |
| 111 | sh '''#!/bin/bash -l |
| 112 | set +e |
| 113 | . ~/.bashrc |
| 114 | env |
| 115 | ''' + preSetup( onos_branch, test_branch, onos_tag, manuallyRun ) + ''' |
| 116 | ''' + oldFlowCheck( jobOn, onos_branch ) + ''' |
| 117 | ''' + postSetup( onos_branch, test_branch, onos_tag, manuallyRun ) |
Devin Lim | 90b6a59 | 2018-05-09 13:20:33 -0700 | [diff] [blame] | 118 | generateKey() |
Devin Lim | 431408d | 2018-03-23 17:51:31 -0700 | [diff] [blame] | 119 | } |
| 120 | } |
Jon Hall | 6af749d | 2018-05-29 12:59:47 -0700 | [diff] [blame] | 121 | |
Devin Lim | 431408d | 2018-03-23 17:51:31 -0700 | [diff] [blame] | 122 | def tagCheck( onos_tag, onos_branch ){ |
Devin Lim | f517519 | 2018-05-14 19:13:22 -0700 | [diff] [blame] | 123 | // check the tag for onos if it is not empty |
| 124 | |
Devin Lim | 431408d | 2018-03-23 17:51:31 -0700 | [diff] [blame] | 125 | result = "git checkout " |
Jon Hall | 6af749d | 2018-05-29 12:59:47 -0700 | [diff] [blame] | 126 | if ( onos_tag == "" ){ |
| 127 | //create new local branch |
| 128 | result += onos_branch |
| 129 | } |
| 130 | else { |
| 131 | //checkout the tag |
| 132 | result += onos_tag |
| 133 | } |
Devin Lim | 431408d | 2018-03-23 17:51:31 -0700 | [diff] [blame] | 134 | return result |
| 135 | } |
Jon Hall | 6af749d | 2018-05-29 12:59:47 -0700 | [diff] [blame] | 136 | |
Devin Lim | 431408d | 2018-03-23 17:51:31 -0700 | [diff] [blame] | 137 | def preSetup( onos_branch, test_branch, onos_tag, isManual ){ |
Devin Lim | f517519 | 2018-05-14 19:13:22 -0700 | [diff] [blame] | 138 | // pre setup part which will clean up and checkout to corresponding branch. |
| 139 | |
Devin Lim | 431408d | 2018-03-23 17:51:31 -0700 | [diff] [blame] | 140 | result = "" |
Jon Hall | 6af749d | 2018-05-29 12:59:47 -0700 | [diff] [blame] | 141 | if ( !isManual ){ |
Devin Lim | 431408d | 2018-03-23 17:51:31 -0700 | [diff] [blame] | 142 | result = '''echo -e "\n##### Set TestON Branch #####" |
| 143 | echo "TestON Branch is set on: ''' + test_branch + '''" |
| 144 | cd ~/OnosSystemTest/ |
| 145 | git checkout HEAD~1 # Make sure you aren't pn a branch |
| 146 | git branch | grep -v "detached from" | xargs git branch -d # delete all local branches merged with remote |
Jon Hall | 6af749d | 2018-05-29 12:59:47 -0700 | [diff] [blame] | 147 | git branch -D ''' + test_branch + ''' # just in case there are local changes. This will normally result in a branch not found error |
Devin Lim | 431408d | 2018-03-23 17:51:31 -0700 | [diff] [blame] | 148 | git clean -df # clean any local files |
| 149 | git fetch --all # update all caches from remotes |
Jon Hall | 6af749d | 2018-05-29 12:59:47 -0700 | [diff] [blame] | 150 | git reset --hard origin/''' + test_branch + ''' # force local index to match remote branch |
Devin Lim | 431408d | 2018-03-23 17:51:31 -0700 | [diff] [blame] | 151 | git clean -df # clean any local files |
| 152 | git checkout ''' + test_branch + ''' #create new local branch |
| 153 | git branch |
| 154 | git log -1 --decorate |
| 155 | echo -e "\n##### Set ONOS Branch #####" |
| 156 | echo "ONOS Branch is set on: ''' + onos_branch + '''" |
| 157 | echo -e "\n #### check karaf version ######" |
| 158 | env |grep karaf |
| 159 | cd ~/onos |
Devin Lim | 431408d | 2018-03-23 17:51:31 -0700 | [diff] [blame] | 160 | git checkout HEAD~1 # Make sure you aren't pn a branch |
| 161 | git branch | grep -v "detached from" | xargs git branch -d # delete all local branches merged with remote |
| 162 | git branch -D ''' + onos_branch + ''' # just incase there are local changes. This will normally result in a branch not found error |
| 163 | git clean -df # clean any local files |
| 164 | git fetch --all # update all caches from remotes |
| 165 | git reset --hard origin/''' + onos_branch + ''' # force local index to match remote branch |
| 166 | git clean -df # clean any local files |
Jon Hall | 5b05626 | 2018-09-25 11:44:41 -0700 | [diff] [blame] | 167 | rm -rf buck-out |
| 168 | rm -rf bazel-* |
Devin Lim | 431408d | 2018-03-23 17:51:31 -0700 | [diff] [blame] | 169 | ''' + tagCheck( onos_tag, onos_branch ) + ''' |
| 170 | git branch |
| 171 | git log -1 --decorate |
| 172 | echo -e "\n##### set jvm heap size to 8G #####" |
You Wang | 8e4f4c0 | 2019-01-03 10:49:46 -0800 | [diff] [blame] | 173 | echo ${ONOSJAVAOPTS} |
| 174 | inserted_line="export JAVA_OPTS=\"\${ONOSJAVAOPTS}\"" |
Devin Lim | 431408d | 2018-03-23 17:51:31 -0700 | [diff] [blame] | 175 | sed -i "s/bash/bash\\n$inserted_line/" ~/onos/tools/package/bin/onos-service |
| 176 | echo "##### Check onos-service setting..... #####" |
| 177 | cat ~/onos/tools/package/bin/onos-service |
| 178 | export JAVA_HOME=/usr/lib/jvm/java-8-oracle''' |
| 179 | } |
| 180 | return result |
| 181 | } |
Jon Hall | 6af749d | 2018-05-29 12:59:47 -0700 | [diff] [blame] | 182 | |
Devin Lim | 431408d | 2018-03-23 17:51:31 -0700 | [diff] [blame] | 183 | def oldFlowCheck( jobOn, onos_branch ){ |
Devin Lim | f517519 | 2018-05-14 19:13:22 -0700 | [diff] [blame] | 184 | // part that will check if it is oldFlow. If so, it will switch to use old flow. Only affected with SCPF. |
| 185 | |
Devin Lim | 431408d | 2018-03-23 17:51:31 -0700 | [diff] [blame] | 186 | result = "" |
Jon Hall | 6af749d | 2018-05-29 12:59:47 -0700 | [diff] [blame] | 187 | if ( jobOn == "SCPF" && ( onos_branch == "master" || onos_branch == "onos-1.12" ) ) |
Devin Lim | 431408d | 2018-03-23 17:51:31 -0700 | [diff] [blame] | 188 | 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 |
| 189 | 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" |
| 190 | return result |
| 191 | } |
Jon Hall | 6af749d | 2018-05-29 12:59:47 -0700 | [diff] [blame] | 192 | |
Devin Lim | 431408d | 2018-03-23 17:51:31 -0700 | [diff] [blame] | 193 | def postSetup( onos_branch, test_branch, onos_tag, isManual ){ |
Jon Hall | 3e6edb3 | 2018-08-21 16:20:30 -0700 | [diff] [blame] | 194 | // setup that will build ONOS |
Devin Lim | f517519 | 2018-05-14 19:13:22 -0700 | [diff] [blame] | 195 | |
Devin Lim | 431408d | 2018-03-23 17:51:31 -0700 | [diff] [blame] | 196 | result = "" |
Jon Hall | 6af749d | 2018-05-29 12:59:47 -0700 | [diff] [blame] | 197 | if ( !isManual ){ |
Jeremy Ronquillo | 352048b | 2019-06-20 10:47:47 -0700 | [diff] [blame] | 198 | result = '''echo -e "Installing bazel" |
| 199 | cd ~ |
| 200 | rm -rf ci-management |
| 201 | git clone https://gerrit.onosproject.org/ci-management |
| 202 | cd ci-management/jjb/onos/ |
| 203 | export GERRIT_BRANCH="''' + onos_branch + '''" |
| 204 | chmod +x install-bazel.sh |
| 205 | ./install-bazel.sh |
| 206 | bazel --version |
| 207 | |
| 208 | echo -e "\n##### build ONOS skip unit tests ######" |
Jon Hall | 3e6edb3 | 2018-08-21 16:20:30 -0700 | [diff] [blame] | 209 | cd ~/onos |
| 210 | . tools/dev/bash_profile |
| 211 | op |
Devin Lim | 431408d | 2018-03-23 17:51:31 -0700 | [diff] [blame] | 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 | } |
Jon Hall | 6af749d | 2018-05-29 12:59:47 -0700 | [diff] [blame] | 221 | |
Devin Lim | 90b6a59 | 2018-05-09 13:20:33 -0700 | [diff] [blame] | 222 | def generateKey(){ |
Devin Lim | f517519 | 2018-05-14 19:13:22 -0700 | [diff] [blame] | 223 | // generate cluster-key of the onos |
| 224 | |
Jon Hall | 6af749d | 2018-05-29 12:59:47 -0700 | [diff] [blame] | 225 | try { |
Devin Lim | 018203a | 2018-05-09 11:33:20 -0700 | [diff] [blame] | 226 | sh ''' |
| 227 | #!/bin/bash -l |
| 228 | set +e |
| 229 | . ~/.bashrc |
| 230 | env |
Devin Lim | 90b6a59 | 2018-05-09 13:20:33 -0700 | [diff] [blame] | 231 | onos-push-bits-through-proxy |
| 232 | onos-gen-cluster-key -f |
Devin Lim | 018203a | 2018-05-09 11:33:20 -0700 | [diff] [blame] | 233 | ''' |
Jon Hall | 6af749d | 2018-05-29 12:59:47 -0700 | [diff] [blame] | 234 | } catch ( all ){ |
| 235 | } |
Devin Lim | 018203a | 2018-05-09 11:33:20 -0700 | [diff] [blame] | 236 | } |
Devin Lim | 431408d | 2018-03-23 17:51:31 -0700 | [diff] [blame] | 237 | |
Jon Hall | 6af749d | 2018-05-29 12:59:47 -0700 | [diff] [blame] | 238 | return this |