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