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