Devin Lim | 90803a8 | 2017-08-29 13:41:44 -0700 | [diff] [blame] | 1 | #!groovy |
| 2 | // This is a Jenkinsfile for a scripted pipeline for the SCPF tests |
| 3 | // Define sets of tests |
| 4 | SCPF_Basic = "SCPFswitchLat,SCPFportLat,SCPFintentInstallWithdrawLat,SCPFintentEventTp,SCPFflowTp1g,SCPFcbench,SCPFbatchFlowResp" |
| 5 | SCPF_ExtraSetA = "SCPFintentRerouteLat,SCPFscalingMaxIntents,SCPFhostLat,SCPFscaleTopo,SCPFmastershipFailoverLat" |
| 6 | SCPF_NEW_TEST = "SCPFmastershipFailoverLat" |
| 7 | SCPF_ExtraSetB = "SCPFintentInstallWithdrawLatWithFlowObj,SCPFintentEventTpWithFlowObj,SCPFintentRerouteLatWithFlowObj,SCPFscalingMaxIntentsWithFlowObj,SCPFflowTp1gWithFlowObj" |
| 8 | FUNC_Basic = "FUNCipv6Intent,FUNCoptical,FUNCflow,FUNCnetCfg,FUNCovsdbtest,FUNCnetconf" |
| 9 | FUNC_ExtraSetA = "FUNCgroup,FUNCintent" |
| 10 | FUNC_ExtraSetB = "FUNCintentRest" |
| 11 | HA_Basic = "HAsanity,HAsingleInstanceRestart,HAclusterRestart" |
| 12 | HA_ExtraSetA = "HAstopNodes,HAfullNetPartition" |
| 13 | HA_ExtraSetB = "HAkillNodes,HAswapNodes,HAscaling" |
| 14 | USECASE_Basic = "FUNCvirNetNB,FUNCbgpls,VPLSBasic,PLATdockertest,SRSanity,SRSwitchFailure,SRLinkFailure,SROnosFailure,SRClusterRestart,SRDynamic,SRHA,USECASE_SdnipFunction,USECASE_SdnipFunctionCluster" |
| 15 | USECASE_NEW_TEST = "VPLSfailsafe" |
| 16 | testcases = [ |
| 17 | "FUNC" : [ tests : "" , nodeName : "VM"], |
| 18 | "HA" : [ tests : "" , nodeName : "VM"], |
| 19 | "SCPF" : [ tests : "" , nodeName : "BM"], |
| 20 | "USECASE" : [ tests : "" , nodeName : "BM"] |
| 21 | ] |
| 22 | Prefix_organizer = [ |
| 23 | "FU" : "FUNC", |
| 24 | "HA" : "HA", |
| 25 | "PL" : "USECASE", |
| 26 | "SA" : "USECASE", |
| 27 | "SC" : "SCPF", |
| 28 | "SR" : "USECASE", |
| 29 | "US" : "USECASE", |
| 30 | "VP" : "USECASE" |
| 31 | ] |
| 32 | |
| 33 | onos_branch = "1.11" |
| 34 | // Set tests based on day of week |
| 35 | def now = new Date() |
| 36 | echo(now.toString()) |
| 37 | today = now[Calendar.DAY_OF_WEEK] |
| 38 | day = "" |
| 39 | SCPF_choices = SCPF_Basic |
| 40 | USECASE_choices = "" |
| 41 | FUNC_choices = FUNC_Basic |
| 42 | HA_choices = HA_Basic |
| 43 | |
| 44 | switch (today) { |
| 45 | case Calendar.MONDAY: |
| 46 | SCPF_choices += "," + SCPF_ExtraSetB |
| 47 | FUNC_choices += "," + FUNC_ExtraSetA |
| 48 | HA_choices += "," + HA_ExtraSetA |
| 49 | day = "Monday" |
| 50 | break |
| 51 | case Calendar.TUESDAY: |
| 52 | day = "Tuesday" |
| 53 | USECASE_choices = USECASE_Basic + "," + USECASE_NEW_TEST |
| 54 | FUNC_choices += "," + FUNC_ExtraSetB |
| 55 | HA_choices += "," + HA_ExtraSetB |
| 56 | break |
| 57 | case Calendar.WEDNESDAY: |
| 58 | SCPF_choices += "," + SCPF_ExtraSetA + "," + SCPF_NEW_TEST |
| 59 | FUNC_choices += "," + FUNC_ExtraSetA |
| 60 | HA_choices += "," + HA_ExtraSetA |
| 61 | day = "Wednesday" |
| 62 | break |
| 63 | case Calendar.THURSDAY: |
| 64 | SCPF_choices += "," + SCPF_ExtraSetB |
| 65 | FUNC_choices += "," + FUNC_ExtraSetB |
| 66 | HA_choices += "," + HA_ExtraSetB |
| 67 | day = "Thursday" |
| 68 | break |
| 69 | case Calendar.FRIDAY: |
| 70 | SCPF_choices += "," + SCPF_ExtraSetA + "," + SCPF_NEW_TEST + "," + SCPF_ExtraSetB |
| 71 | FUNC_choices += "," + FUNC_ExtraSetA |
| 72 | HA_choices += "," + HA_ExtraSetA |
| 73 | day = "Friday" |
| 74 | break |
| 75 | case Calendar.SATURDAY: |
| 76 | SCPF_choices += "," + SCPF_ExtraSetA + "," + SCPF_ExtraSetB |
| 77 | USECASE_choices = USECASE_Basic |
| 78 | FUNC_choices += "," + FUNC_ExtraSetA + "," + FUNC_ExtraSetB |
| 79 | HA_choices += "," + HA_ExtraSetA + "," + HA_ExtraSetB |
| 80 | onos_branch= "1.10" |
| 81 | day = "Saturday" |
| 82 | break |
| 83 | case Calendar.SUNDAY: |
| 84 | SCPF_choices += "," + SCPF_ExtraSetA + "," + SCPF_NEW_TEST + "," + SCPF_ExtraSetB |
| 85 | USECASE_choices = USECASE_Basic + "," + USECASE_NEW_TEST |
| 86 | FUNC_choices += "," + FUNC_ExtraSetA + "," + FUNC_ExtraSetB |
| 87 | HA_choices += "," + HA_ExtraSetA + "," + HA_ExtraSetB |
| 88 | onos_branch= "master" |
| 89 | day = "Sunday" |
| 90 | break |
| 91 | } |
| 92 | |
| 93 | manually_run = params.manual_run |
| 94 | post_result = params.PostResult |
| 95 | if ( manually_run ){ |
| 96 | organize_tests( params.Tests ) |
| 97 | onos_branch = params.ONOSVersion |
| 98 | test_branch = params.TestONBranch |
| 99 | println "Tests to be run manually : " |
| 100 | }else{ |
| 101 | testcases["SCPF"]["tests"] = SCPF_choices |
| 102 | testcases["USECASE"]["tests"] = USECASE_choices |
| 103 | testcases["FUNC"]["tests"] = FUNC_choices |
| 104 | testcases["HA"]["tests"] = HA_choices |
| 105 | println "Defaulting to " + day + " tests:" |
| 106 | } |
| 107 | print_tests( testcases ) |
| 108 | |
| 109 | def runTest = [ |
| 110 | "VM" : [:], |
| 111 | "BM" : [:] |
| 112 | ] |
| 113 | for( String test in testcases.keySet() ){ |
| 114 | println test |
| 115 | if (testcases[test]["tests"] != ""){ |
| 116 | runTest[testcases[test]["nodeName"]][test] = trigger_pipeline( onos_branch, testcases[test]["tests"], testcases[test]["nodeName"], test, manually_run ) |
| 117 | } |
| 118 | } |
| 119 | def finalList = [:] |
| 120 | finalList["VM"] = runTestSeq( runTest["VM"] ) |
| 121 | finalList["BM"] = runTestSeq( runTest["BM"] ) |
| 122 | parallel finalList |
| 123 | |
| 124 | def runTestSeq( testList ){ |
| 125 | return{ |
| 126 | for ( test in testList.keySet() ){ |
| 127 | testList[test].call() |
| 128 | } |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | def print_tests( tests ){ |
| 133 | for( String test in tests.keySet() ){ |
| 134 | if( tests[test]["tests"] != "" ){ |
| 135 | println test + ":" |
| 136 | println tests[test]["tests"] |
| 137 | } |
| 138 | } |
| 139 | } |
| 140 | def organize_tests( tests ){ |
| 141 | testList = tests.tokenize("\n;, ") |
| 142 | for( String test in testList ) |
| 143 | testcases [ Prefix_organizer[ ( test == "FUNCbgpls" || test == "FUNCvirNetNB" ? "US" : ( test[ 0 ] + test[ 1 ] ) ) ] ][ "tests" ] += test + "," |
| 144 | } |
| 145 | def trigger_pipeline( branch, tests, nodeName, jobOn, manuallyRun ){ |
| 146 | // nodeName : "BM" or "VM" |
| 147 | // jobOn : "SCPF" or "USECASE" or "FUNC" or "HA" |
| 148 | return{ |
| 149 | if (branch == "master"){ |
| 150 | onos_branch = branch |
| 151 | }else{ |
| 152 | onos_branch = "onos-" + branch |
| 153 | } |
| 154 | wiki = branch |
| 155 | if ( !manuallyRun ) |
| 156 | test_branch = onos_branch |
| 157 | if (onos_branch == "onos-1.11") |
| 158 | test_branch = "master" |
| 159 | println jobOn + "_Pipeline_" + manuallyRun ? "manually" : branch |
| 160 | node("TestStation-" + nodeName + "s"){ |
| 161 | if (!manuallyRun) |
| 162 | envSetup(onos_branch, test_branch) |
| 163 | |
| 164 | exportEnvProperty( onos_branch, test_branch, wiki, tests, post_result, manuallyRun ) |
| 165 | } |
| 166 | |
| 167 | jobToRun = jobOn + "_Pipeline_" + ( manuallyRun ? "manually" : branch ) |
| 168 | build job: jobToRun, propagate: false |
| 169 | } |
| 170 | } |
| 171 | |
| 172 | // export Environment properties. |
| 173 | def exportEnvProperty( onos_branch, test_branch, wiki, tests, postResult, manually_run ){ |
| 174 | stage("export Property"){ |
| 175 | sh ''' |
| 176 | echo "ONOSBranch=''' + onos_branch +'''" > /var/jenkins/TestONOS.property |
| 177 | echo "TestONBranch=''' + test_branch +'''" >> /var/jenkins/TestONOS.property |
| 178 | echo "ONOSTag='''+ env.ONOSTag +'''" >> /var/jenkins/TestONOS.property |
| 179 | echo "WikiPrefix=''' + wiki +'''" >> /var/jenkins/TestONOS.property |
| 180 | echo "ONOSJVMHeap='''+ env.ONOSJVMHeap +'''" >> /var/jenkins/TestONOS.property |
| 181 | echo "Tests=''' + tests +'''" >> /var/jenkins/TestONOS.property |
| 182 | echo "postResult=''' + postResult +'''" >> /var/jenkins/TestONOS.property |
| 183 | echo "manualRun=''' + manually_run +'''" >> /var/jenkins/TestONOS.property |
| 184 | ''' |
| 185 | } |
| 186 | } |
| 187 | // Initialize the environment Setup for the onos and OnosSystemTest |
| 188 | def envSetup( onos_branch, test_branch ){ |
| 189 | stage("envSetup") { |
| 190 | sh ''' |
| 191 | #!/bin/bash |
| 192 | set +e |
| 193 | . ~/.bashrc |
| 194 | env |
| 195 | |
| 196 | echo -e "\n##### Set TestON Branch #####" |
| 197 | echo "TestON Branch is set on: " + test_branch |
| 198 | |
| 199 | cd ~/OnosSystemTest/ |
| 200 | git checkout HEAD~1 # Make sure you aren't pn a branch |
| 201 | git branch | grep -v "detached from" | xargs git branch -d # delete all local branches merged with remote |
| 202 | git branch -D $TestONBranch # just incase there are local changes. This will normally result in a branch not found error |
| 203 | git clean -df # clean any local files |
| 204 | git fetch --all # update all caches from remotes |
| 205 | git reset --hard origin/$TestONBranch # force local index to match remote branch |
| 206 | git clean -df # clean any local files |
| 207 | git checkout $TestONBranch #create new local branch |
| 208 | git branch |
| 209 | git log -1 --decorate |
| 210 | |
| 211 | |
| 212 | echo -e "\n##### Set ONOS Branch #####" |
| 213 | echo "ONOS Branch is set on: + onos_branch |
| 214 | |
| 215 | echo -e "\n #### check karaf version ######" |
| 216 | env |grep karaf |
| 217 | |
| 218 | cd ~/onos |
| 219 | rm -rf buck-out/* |
| 220 | ~/onos/tools/build/onos-buck clean |
| 221 | git checkout HEAD~1 # Make sure you aren't pn a branch |
| 222 | git branch | grep -v "detached from" | xargs git branch -d # delete all local branches merged with remote |
| 223 | git branch -D $ONOSBranch # just incase there are local changes. This will normally result in a branch not found error |
| 224 | git clean -df # clean any local files |
| 225 | git fetch --all # update all caches from remotes |
| 226 | git reset --hard origin/$ONOSBranch # force local index to match remote branch |
| 227 | git clean -df # clean any local files |
| 228 | if [ -z "$ONOSTag" ] #if tag is not specified |
| 229 | then |
| 230 | git checkout $ONOSBranch #create new local branch |
| 231 | else |
| 232 | git checkout $ONOSTag #checkout the tag |
| 233 | fi |
| 234 | git branch |
| 235 | git log -1 --decorate |
| 236 | |
| 237 | |
| 238 | echo -e "\n##### set jvm heap size to 8G #####" |
| 239 | echo ${ONOSJVMHeap} |
| 240 | |
| 241 | inserted_line="export JAVA_OPTS="${ONOSJVMHeap}"" |
| 242 | sed -i "s/bash/bash\n$inserted_line/" ~/onos/tools/package/bin/onos-service |
| 243 | |
| 244 | echo "##### Check onos-service setting..... #####" |
| 245 | cat ~/onos/tools/package/bin/onos-service |
| 246 | |
| 247 | export JAVA_HOME=/usr/lib/jvm/java-8-oracle |
| 248 | |
| 249 | echo -e "\n##### build ONOS skip unit tests ######" |
| 250 | #mvn clean install -DskipTests |
| 251 | # Force buck update |
| 252 | rm -f ~/onos/bin/buck |
| 253 | ~/onos/tools/build/onos-buck build onos |
| 254 | |
| 255 | git branch''' |
| 256 | } |
| 257 | } |