Devin Lim | 431408d | 2018-03-23 17:51:31 -0700 | [diff] [blame] | 1 | #!groovy |
| 2 | |
| 3 | def init( commonFuncs ){ |
| 4 | funcs = commonFuncs |
| 5 | } |
| 6 | def lastCommaRemover( str ){ |
| 7 | if ( str.size() > 0 && str[ str.size() - 1 ] == ',' ){ |
| 8 | str = str.substring( 0,str.size() - 1 ) |
| 9 | } |
| 10 | return str |
| 11 | } |
| 12 | def 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 | } |
| 24 | def runTestSeq( testList ){ |
| 25 | return{ |
| 26 | for ( test in testList.keySet() ){ |
| 27 | testList[ test ].call() |
| 28 | } |
| 29 | } |
| 30 | } |
| 31 | def 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 | } |
| 39 | def 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 | } |
| 45 | def borrow_mn( jobOn ){ |
| 46 | result = "" |
| 47 | if( jobOn == "SR" ){ |
| 48 | result = "~/cell_borrow.sh" |
| 49 | } |
| 50 | return result |
| 51 | } |
| 52 | def trigger( branch, tests, nodeName, jobOn, manuallyRun, onosTag ){ |
| 53 | println jobOn + "-pipeline-" + manuallyRun ? "manually" : branch |
Devin Lim | 6c77b7c | 2018-04-06 19:36:56 -0700 | [diff] [blame] | 54 | def wiki = branch |
Devin Lim | 431408d | 2018-03-23 17:51:31 -0700 | [diff] [blame] | 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 | } |
| 66 | def 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 Lim | 5b22fbb | 2018-04-06 15:30:45 -0700 | [diff] [blame] | 70 | trigger( branch, tests, nodeName, jobOn, manuallyRun, onosTag ) |
Devin Lim | 431408d | 2018-03-23 17:51:31 -0700 | [diff] [blame] | 71 | } |
| 72 | } |
| 73 | // export Environment properties. |
| 74 | def 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 |
| 90 | def envSetup( onos_branch, test_branch, onos_tag, jobOn, manuallyRun ){ |
Devin Lim | 431408d | 2018-03-23 17:51:31 -0700 | [diff] [blame] | 91 | 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 ) |
| 100 | } |
| 101 | } |
| 102 | def tagCheck( onos_tag, onos_branch ){ |
| 103 | result = "git checkout " |
| 104 | if ( onos_tag == "" ) |
| 105 | result += onos_branch //create new local branch |
| 106 | else |
| 107 | result += onos_tag //checkout the tag |
| 108 | return result |
| 109 | } |
| 110 | def preSetup( onos_branch, test_branch, onos_tag, isManual ){ |
| 111 | result = "" |
| 112 | if( !isManual ){ |
| 113 | result = '''echo -e "\n##### Set TestON Branch #####" |
| 114 | echo "TestON Branch is set on: ''' + test_branch + '''" |
| 115 | cd ~/OnosSystemTest/ |
| 116 | git checkout HEAD~1 # Make sure you aren't pn a branch |
| 117 | git branch | grep -v "detached from" | xargs git branch -d # delete all local branches merged with remote |
| 118 | git branch -D ''' + test_branch + ''' # just incase there are local changes. This will normally result in a branch not found error |
| 119 | git clean -df # clean any local files |
| 120 | git fetch --all # update all caches from remotes |
| 121 | git reset --hard origin/''' + test_branch +''' # force local index to match remote branch |
| 122 | git clean -df # clean any local files |
| 123 | git checkout ''' + test_branch + ''' #create new local branch |
| 124 | git branch |
| 125 | git log -1 --decorate |
| 126 | echo -e "\n##### Set ONOS Branch #####" |
| 127 | echo "ONOS Branch is set on: ''' + onos_branch + '''" |
| 128 | echo -e "\n #### check karaf version ######" |
| 129 | env |grep karaf |
| 130 | cd ~/onos |
| 131 | rm -rf buck-out/* |
| 132 | ~/onos/tools/build/onos-buck clean |
| 133 | git checkout HEAD~1 # Make sure you aren't pn a branch |
| 134 | git branch | grep -v "detached from" | xargs git branch -d # delete all local branches merged with remote |
| 135 | git branch -D ''' + onos_branch + ''' # just incase there are local changes. This will normally result in a branch not found error |
| 136 | git clean -df # clean any local files |
| 137 | git fetch --all # update all caches from remotes |
| 138 | git reset --hard origin/''' + onos_branch + ''' # force local index to match remote branch |
| 139 | git clean -df # clean any local files |
| 140 | ''' + tagCheck( onos_tag, onos_branch ) + ''' |
| 141 | git branch |
| 142 | git log -1 --decorate |
| 143 | echo -e "\n##### set jvm heap size to 8G #####" |
| 144 | echo ${ONOSJVMHeap} |
| 145 | inserted_line="export JAVA_OPTS=\"\${ONOSJVMHeap}\"" |
| 146 | sed -i "s/bash/bash\\n$inserted_line/" ~/onos/tools/package/bin/onos-service |
| 147 | echo "##### Check onos-service setting..... #####" |
| 148 | cat ~/onos/tools/package/bin/onos-service |
| 149 | export JAVA_HOME=/usr/lib/jvm/java-8-oracle''' |
| 150 | } |
| 151 | return result |
| 152 | } |
| 153 | def oldFlowCheck( jobOn, onos_branch ){ |
| 154 | result = "" |
| 155 | if( jobOn == "SCPF" && ( onos_branch== "master" || onos_branch=="onos-1.12" ) ) |
| 156 | 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 |
| 157 | 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" |
| 158 | return result |
| 159 | } |
| 160 | def postSetup( onos_branch, test_branch, onos_tag, isManual ){ |
| 161 | result = "" |
| 162 | if( !isManual ){ |
| 163 | result = '''echo -e "\n##### build ONOS skip unit tests ######" |
| 164 | #mvn clean install -DskipTests |
| 165 | # Force buck update |
| 166 | rm -f ~/onos/bin/buck |
| 167 | ~/onos/tools/build/onos-buck build onos |
| 168 | sleep 30 |
| 169 | echo -e "\n##### Stop all running instances of Karaf #####" |
| 170 | kill $(ps -efw | grep karaf | grep -v grep | awk '{print $2}') |
| 171 | sleep 30 |
| 172 | git branch''' |
| 173 | } |
| 174 | return result |
| 175 | } |
| 176 | def returnCell( nodeName ){ |
| 177 | node( "TestStation-" + nodeName + "s" ){ |
| 178 | sh '''#!/bin/bash -l |
| 179 | set +e |
| 180 | . ~/.bashrc |
| 181 | env |
| 182 | ~/./return_cell.sh |
| 183 | ''' |
| 184 | } |
| 185 | } |
| 186 | |
Devin Lim | 2fdf76a | 2018-04-06 19:27:54 -0700 | [diff] [blame] | 187 | return this; |