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'], |
| 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) { |
Jon Hall | de964e8 | 2017-04-18 14:14:22 -0700 | [diff] [blame] | 51 | case Calendar.MONDAY: |
You Wang | 122e319 | 2017-05-05 15:28:33 -0700 | [diff] [blame] | 52 | choices = SCPF_Basic + "\n" + SCPF_ExtraSetB |
Jon Hall | de964e8 | 2017-04-18 14:14:22 -0700 | [diff] [blame] | 53 | println "Defaulting to Monday tests:" + choices |
| 54 | break |
| 55 | case Calendar.TUESDAY: |
You Wang | 122e319 | 2017-05-05 15:28:33 -0700 | [diff] [blame] | 56 | choices = SCPF_Basic |
Jon Hall | de964e8 | 2017-04-18 14:14:22 -0700 | [diff] [blame] | 57 | println "Defaulting to Tuesday tests:" + choices |
| 58 | break |
| 59 | case Calendar.WEDNESDAY: |
You Wang | 122e319 | 2017-05-05 15:28:33 -0700 | [diff] [blame] | 60 | choices = SCPF_Basic + "\n" + SCPF_ExtraSetA |
Jon Hall | de964e8 | 2017-04-18 14:14:22 -0700 | [diff] [blame] | 61 | println "Defaulting to Wednesday tests:" + choices |
| 62 | break |
| 63 | case Calendar.THURSDAY: |
You Wang | 122e319 | 2017-05-05 15:28:33 -0700 | [diff] [blame] | 64 | choices = SCPF_Basic + "\n" + SCPF_ExtraSetB |
Jon Hall | de964e8 | 2017-04-18 14:14:22 -0700 | [diff] [blame] | 65 | println "Defaulting to Thursday tests:" + choices |
| 66 | break |
| 67 | case Calendar.FRIDAY: |
You Wang | bfd739c | 2017-05-01 15:17:06 -0700 | [diff] [blame] | 68 | choices = SCPF_Basic + "\n" + SCPF_ExtraSetA + "\n" + SCPF_ExtraSetB |
Jon Hall | de964e8 | 2017-04-18 14:14:22 -0700 | [diff] [blame] | 69 | println "Defaulting to Fridat tests:" + choices |
| 70 | break |
| 71 | case Calendar.SATURDAY: |
You Wang | bfd739c | 2017-05-01 15:17:06 -0700 | [diff] [blame] | 72 | choices = SCPF_Basic + "\n" + SCPF_ExtraSetA + "\n" + SCPF_ExtraSetB |
Jon Hall | de964e8 | 2017-04-18 14:14:22 -0700 | [diff] [blame] | 73 | println "Defaulting to Saturday tests:" + choices |
| 74 | break |
| 75 | case Calendar.SUNDAY: |
You Wang | 122e319 | 2017-05-05 15:28:33 -0700 | [diff] [blame] | 76 | choices = SCPF_Basic + "\n" + SCPF_ExtraSetA |
Jon Hall | de964e8 | 2017-04-18 14:14:22 -0700 | [diff] [blame] | 77 | println "Defaulting to Sunday tests:" + choices |
| 78 | break |
| 79 | } |
| 80 | testcases = choices |
| 81 | } |
| 82 | |
| 83 | echo("Testcases:") |
| 84 | //println testcases |
| 85 | // TODO REMOVE AFTER DEBUGGING |
| 86 | def testsToRun = testcases.tokenize("\n;, ") |
| 87 | for (String test : testsToRun) { |
| 88 | println test |
| 89 | } |
| 90 | |
| 91 | def tests = [:] |
| 92 | for (int i = 0; i < testsToRun.size(); i++) { |
| 93 | // Get the actual string here. |
| 94 | def testName = testsToRun[i] |
| 95 | def stepName = "Running ${testName}" |
| 96 | tests[stepName] = SCPFTest(testName) |
| 97 | } |
| 98 | |
| 99 | // run the tests |
| 100 | parallel tests |
| 101 | |
| 102 | // The testName should be the key from the SCPF map |
| 103 | def SCPFTest( testName ) { |
| 104 | return { |
| 105 | node ("TestStation-BMs"){ // only run SCPF tests on the BM cluster |
| 106 | def prop = readProperties(file:'/var/jenkins/TestONOS.property') // TODO set defaults |
| 107 | |
| 108 | withEnv(['ONOSBranch='+prop["ONOSBranch"], |
| 109 | 'ONOSJVMHeap='+prop["ONOSJVMHeap"], |
| 110 | 'TestONBranch='+prop["TestONBranch"], |
| 111 | 'ONOSTag='+prop["ONOSTag"], |
| 112 | 'WikiPrefix='+prop["WikiPrefix"]]){ |
| 113 | stage(testName) { |
| 114 | sh '''#!/bin/bash -l |
| 115 | set -i # interactive |
| 116 | shopt -s expand_aliases # expand alias in non-interactive mode |
| 117 | export PYTHONUNBUFFERED=1 |
| 118 | |
| 119 | ifconfig |
| 120 | |
| 121 | echo "ONOS Branch is: $ONOSBranch" |
| 122 | echo "TestON Branch is: $TestONBranch" |
| 123 | echo "Test date: " |
| 124 | date |
| 125 | |
| 126 | cd ~ |
| 127 | export PATH=$PATH:onos/tools/test/bin |
| 128 | |
Jon Hall | 554d42a | 2017-07-06 10:15:30 -0700 | [diff] [blame] | 129 | timeout 240 stc shutdown |
| 130 | timeout 240 stc teardown |
| 131 | timeout 240 stc shutdown |
Jon Hall | de964e8 | 2017-04-18 14:14:22 -0700 | [diff] [blame] | 132 | |
| 133 | cd ~/OnosSystemTest/TestON/bin |
| 134 | git log |head |
| 135 | ./cleanup.sh |
Jon Hall | 09aced4 | 2017-05-01 14:03:22 -0700 | [diff] [blame] | 136 | ''' + "./cli.py run " + SCPF[testName]['test'] |
Jon Hall | de964e8 | 2017-04-18 14:14:22 -0700 | [diff] [blame] | 137 | |
| 138 | // Post Results |
| 139 | withCredentials([ |
| 140 | string(credentialsId: 'db_pass', variable: 'pass'), |
| 141 | string(credentialsId: 'db_user', variable: 'user'), |
| 142 | string(credentialsId: 'db_host', variable: 'host'), |
| 143 | string(credentialsId: 'db_port', variable: 'port')]) { |
You Wang | 6606566 | 2017-05-04 14:35:29 -0700 | [diff] [blame] | 144 | 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);\"" |
| 145 | if (testName == "SCPFscaleTopo" || testName == "SCPFswitchLat" || testName == "SCPFportLat") { |
| 146 | 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');\"" |
| 147 | } |
Jon Hall | de964e8 | 2017-04-18 14:14:22 -0700 | [diff] [blame] | 148 | sh '''#!/bin/bash |
| 149 | |
| 150 | export DATE=\$(date +%F_%T) |
| 151 | cd ~ |
| 152 | pwd |
| 153 | cd /tmp |
| 154 | while read line |
| 155 | do |
| 156 | |
| 157 | echo \$line |
You Wang | 6606566 | 2017-05-04 14:35:29 -0700 | [diff] [blame] | 158 | echo ''' + database_command + ''' |
Jon Hall | de964e8 | 2017-04-18 14:14:22 -0700 | [diff] [blame] | 159 | |
You Wang | 6606566 | 2017-05-04 14:35:29 -0700 | [diff] [blame] | 160 | done< ''' + SCPF[testName]['file'] |
Jon Hall | de964e8 | 2017-04-18 14:14:22 -0700 | [diff] [blame] | 161 | } |
| 162 | // Fetch Logs |
| 163 | sh '''#!/bin/bash |
| 164 | |
| 165 | cd ~/OnosSystemTest/TestON/logs |
| 166 | echo "Job Name is: ${JOB_NAME}" |
| 167 | TestONlogDir=$(ls -t | grep ${TEST_NAME}_ |head -1) |
| 168 | echo "########################################################################################" |
| 169 | echo "##### copying ONOS logs from all nodes to TestON/logs directory: ${TestONlogDir}" |
| 170 | echo "########################################################################################" |
| 171 | cd $TestONlogDir |
| 172 | if [ $? -eq 1 ] |
| 173 | then |
| 174 | echo "Job name does not match any test suite name to move log!" |
| 175 | else |
| 176 | pwd |
You Wang | 6606566 | 2017-05-04 14:35:29 -0700 | [diff] [blame] | 177 | 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] | 178 | fi''' |
| 179 | } |
| 180 | } |
| 181 | } |
| 182 | } |
| 183 | } |