Jon Hall | de964e8 | 2017-04-18 14:14:22 -0700 | [diff] [blame] | 1 | #!groovy |
| 2 | // This is a Jenkinsfile for a scripted pipeline for the SCPF tests |
| 3 | properties([pipelineTriggers([cron('30 19 * * *')])]) |
| 4 | |
| 5 | // TODO: Exception handling around steps |
| 6 | SCPF = [ |
| 7 | SCPFcbench: [ test:'SCPFcbench', table:'cbench_bm_tests', results:'cbench_bm_results', file:'CbenchDB'], |
| 8 | SCPFhostLat: [ test:'SCPFhostLat', table:'host_latency_results', results:'host_latency_results', file:'HostAddLatency'], |
| 9 | SCPFportLat: [ test:'SCPFportLat', table:'port_latency_details', results:'port_latency_results', file:'/tmp/portEventResultDb'], |
| 10 | SCPFflowTp1g: [ test:'SCPFflowTp1g', table:'flow_tp_tests', results:'flow_tp_results', file:'flowTP1gDB'], |
| 11 | SCPFscaleTopo: [ test:'SCPFscaleTopo', table:'scale_topo_latency_details', results:'scale_topo_latency_results', file:'/tmp/scaleTopoResultDb'], |
| 12 | SCPFswitchLat: [ test:'SCPFswitchLat', table:'switch_latency_details', results:'switch_latency_results', file:'/tmp/switchEventResultDb'], |
| 13 | SCPFbatchFlowResp: [ test:'SCPFbatchFlowResp', table:'batch_flow_tests', results:'batch_flow_results', file:'SCPFbatchFlowRespData'], |
| 14 | SCPFintentEventTp: [ test:'SCPFintentEventTp', table:'intent_tp_tests', results:'intent_tp_results', file:'IntentEventTPDB'], |
| 15 | SCPFintentRerouteLat: [ test:'SCPFintentRerouteLat', table:'intent_reroute_latency_tests', results:'intent_reroute_latency_results', file:'IntentRerouteLatDB'], |
| 16 | SCPFscalingMaxIntents: [ test:'SCPFscalingMaxIntents', table:'max_intents_tests', results:'max_intents_results', file:'ScalingMaxIntentDB'], |
| 17 | SCPFintentEventTpWithFlowObj: [ test:'SCPFintentEventTp --params TEST/flowObj=True', table:'intent_tp_fobj_tests', results:'intent_tp_fobj_results', file:'IntentEventTPflowObjDB'], |
| 18 | SCPFintentInstallWithdrawLat: [ test:'SCPFintentInstallWithdrawLat', table:'intent_latency_tests', results:'intent_latency_results', file:'IntentInstallWithdrawLatDB'], |
| 19 | SCPFintentRerouteLatWithFlowObj: [ test:'SCPFintentRerouteLat --params TEST/flowObj=True', table:'intent_reroute_latency_fobj_tests', results:'intent_reroute_latency_fobj_results', file:'IntentRerouteLatDBWithFlowObj'], |
| 20 | SCPFscalingMaxIntentsWithFlowObj: [ test:'SCPFscalingMaxIntents --params TEST/flowObj=True', table:'max_intents_fobj_tests', results:'max_intents_fobj_results', file:'ScalingMaxIntentDBWFO'], |
| 21 | SCPFintentInstallWithdrawLatWithFlowObj: [ test:'SCPFintentInstallWithdrawLat --params TEST/flowObj=True', table:'intent_latency_fobj_tests', results:'intent_latency_fobj_results', file:'IntentInstallWithdrawLatDBWFO'] |
| 22 | ] |
| 23 | |
| 24 | // Get just the test names |
| 25 | def defaultTests = SCPF.keySet().toArray() |
| 26 | // Convert to a string with new line deliminators for user input |
| 27 | StringBuilder sb = new StringBuilder(); |
| 28 | for (String s : defaultTests) |
| 29 | { |
| 30 | sb.append(s); |
| 31 | sb.append("\n"); |
| 32 | } |
| 33 | choices = sb.toString(); |
| 34 | // Define sets of tests |
| 35 | SCPF_Basic = "SCPFswitchLat\nSCPFportLat\nSCPFintentInstallWithdrawLat\nSCPFintentEventTp\nSCPFflowTp1g\nSCPFcbench\nSCPFbatchFlowResp" |
| 36 | SCPF_ExtraSetA = "SCPFintentRerouteLat\nSCPFscalingMaxIntents\nSCPFhostLat\nSCPFscaleTopo" |
| 37 | SCPF_ExtraSetB = "SCPFintentInstallWithdrawLatWithFlowObj\nSCPFintentEventTpWithFlowObj\nSCPFintentRerouteLatWithFlowObj\nSCPFscalingMaxIntentsWithFlowObj" |
| 38 | |
| 39 | try { |
| 40 | timeout(time: 120, unit: 'SECONDS') { |
| 41 | // This is kind of hacky, I can't seem to find the correct way to get a "build with parameters" button |
| 42 | testcases = input message: 'Tests to run?', parameters:[[$class:'TextParameterDefinition', defaultValue: choices, description:'', name: 'Run these tests']] |
| 43 | } |
| 44 | } catch(org.jenkinsci.plugins.workflow.steps.FlowInterruptedException Err) { |
| 45 | echo("Input timed out or cancled, using default values") |
| 46 | // Set tests based on day of week |
| 47 | def now = new Date() |
| 48 | echo(now.toString()) |
| 49 | today = now[Calendar.DAY_OF_WEEK] |
| 50 | switch (today) { |
| 51 | // TODO Choose which tests to run based on day of the week for nightly run? |
| 52 | // TODO Maybe define different subsets of tests above then just add them here |
| 53 | case Calendar.MONDAY: |
| 54 | choices = SCPF_Basic + SCPF_ExtraSetA |
| 55 | println "Defaulting to Monday tests:" + choices |
| 56 | break |
| 57 | case Calendar.TUESDAY: |
| 58 | choices = SCPF_Basic + SCPF_ExtraSetB |
| 59 | println "Defaulting to Tuesday tests:" + choices |
| 60 | break |
| 61 | case Calendar.WEDNESDAY: |
| 62 | choices = SCPF_Basic |
| 63 | println "Defaulting to Wednesday tests:" + choices |
| 64 | break |
| 65 | case Calendar.THURSDAY: |
| 66 | choices = SCPF_Basic + SCPF_ExtraSetA |
| 67 | println "Defaulting to Thursday tests:" + choices |
| 68 | break |
| 69 | case Calendar.FRIDAY: |
| 70 | choices = SCPF_Basic + SCPF_ExtraSetA + SCPF_ExtraSetB |
| 71 | println "Defaulting to Fridat tests:" + choices |
| 72 | break |
| 73 | case Calendar.SATURDAY: |
| 74 | choices = SCPF_Basic + SCPF_ExtraSetA + SCPF_ExtraSetB |
| 75 | println "Defaulting to Saturday tests:" + choices |
| 76 | break |
| 77 | case Calendar.SUNDAY: |
| 78 | choices = SCPF_Basic |
| 79 | println "Defaulting to Sunday tests:" + choices |
| 80 | break |
| 81 | } |
| 82 | testcases = choices |
| 83 | } |
| 84 | |
| 85 | echo("Testcases:") |
| 86 | //println testcases |
| 87 | // TODO REMOVE AFTER DEBUGGING |
| 88 | def testsToRun = testcases.tokenize("\n;, ") |
| 89 | for (String test : testsToRun) { |
| 90 | println test |
| 91 | } |
| 92 | |
| 93 | def tests = [:] |
| 94 | for (int i = 0; i < testsToRun.size(); i++) { |
| 95 | // Get the actual string here. |
| 96 | def testName = testsToRun[i] |
| 97 | def stepName = "Running ${testName}" |
| 98 | tests[stepName] = SCPFTest(testName) |
| 99 | } |
| 100 | |
| 101 | // run the tests |
| 102 | parallel tests |
| 103 | |
| 104 | // The testName should be the key from the SCPF map |
| 105 | def SCPFTest( testName ) { |
| 106 | return { |
| 107 | node ("TestStation-BMs"){ // only run SCPF tests on the BM cluster |
| 108 | def prop = readProperties(file:'/var/jenkins/TestONOS.property') // TODO set defaults |
| 109 | |
| 110 | withEnv(['ONOSBranch='+prop["ONOSBranch"], |
| 111 | 'ONOSJVMHeap='+prop["ONOSJVMHeap"], |
| 112 | 'TestONBranch='+prop["TestONBranch"], |
| 113 | 'ONOSTag='+prop["ONOSTag"], |
| 114 | 'WikiPrefix='+prop["WikiPrefix"]]){ |
| 115 | stage(testName) { |
| 116 | sh '''#!/bin/bash -l |
| 117 | set -i # interactive |
| 118 | shopt -s expand_aliases # expand alias in non-interactive mode |
| 119 | export PYTHONUNBUFFERED=1 |
| 120 | |
| 121 | ifconfig |
| 122 | |
| 123 | echo "ONOS Branch is: $ONOSBranch" |
| 124 | echo "TestON Branch is: $TestONBranch" |
| 125 | echo "Test date: " |
| 126 | date |
| 127 | |
| 128 | cd ~ |
| 129 | export PATH=$PATH:onos/tools/test/bin |
| 130 | |
| 131 | stc teardown |
| 132 | |
| 133 | cd ~/OnosSystemTest/TestON/bin |
| 134 | git log |head |
| 135 | ./cleanup.sh |
| 136 | ''' |
| 137 | sh "./cli.py run " + SCPF[testName]['test'] |
| 138 | |
| 139 | // Post Results |
| 140 | withCredentials([ |
| 141 | string(credentialsId: 'db_pass', variable: 'pass'), |
| 142 | string(credentialsId: 'db_user', variable: 'user'), |
| 143 | string(credentialsId: 'db_host', variable: 'host'), |
| 144 | string(credentialsId: 'db_port', variable: 'port')]) { |
| 145 | sh '''#!/bin/bash |
| 146 | |
| 147 | export DATE=\$(date +%F_%T) |
| 148 | cd ~ |
| 149 | pwd |
| 150 | cd /tmp |
| 151 | while read line |
| 152 | do |
| 153 | |
| 154 | echo \$line |
| 155 | echo ''' + pass + "|psql --host=" + host + " --port=" + port + " --username=" + user + " --password --dbname onostest -c \"INSERT INTO " + SCPF[testName]['table'] + " VALUES('\$DATE','" + SCPF[testName]['results'] + '''','\$BUILD_NUMBER', '\$ONOSBranch', \$line );\" |
| 156 | |
| 157 | done< ''' + SCPF[testName]['file'] + ''' |
| 158 | echo 'Done' |
| 159 | ''' |
| 160 | } |
| 161 | // Fetch Logs |
| 162 | sh '''#!/bin/bash |
| 163 | |
| 164 | cd ~/OnosSystemTest/TestON/logs |
| 165 | echo "Job Name is: ${JOB_NAME}" |
| 166 | TestONlogDir=$(ls -t | grep ${TEST_NAME}_ |head -1) |
| 167 | echo "########################################################################################" |
| 168 | echo "##### copying ONOS logs from all nodes to TestON/logs directory: ${TestONlogDir}" |
| 169 | echo "########################################################################################" |
| 170 | cd $TestONlogDir |
| 171 | if [ $? -eq 1 ] |
| 172 | then |
| 173 | echo "Job name does not match any test suite name to move log!" |
| 174 | else |
| 175 | pwd |
| 176 | for i in $OC{1..7}; do onos-fetch-logs $i; done |
| 177 | fi''' |
| 178 | } |
| 179 | } |
| 180 | } |
| 181 | } |
| 182 | } |