blob: fa75de20d9889e9aaf31aef42e8e70af9597b928 [file] [log] [blame]
Devin Lim90803a82017-08-29 13:41:44 -07001#!groovy
Devin Lim61657e42017-10-09 17:24:40 -07002import groovy.time.*
Devin Lim90803a82017-08-29 13:41:44 -07003// This is a Jenkinsfile for a scripted pipeline for the SCPF tests
4// properties([pipelineTriggers([cron('30 19 * * *')])])
5
6// TODO: Exception handling around steps
7
8none = [ "" ]
9batches = [1,100,1000]
10neighbors = ['y', 'n']
Devin Lim61657e42017-10-09 17:24:40 -070011times = [ 'y', 'n' ]
Devin Lim90803a82017-08-29 13:41:44 -070012SCPF = [
13 SCPFcbench: [ test:'SCPFcbench', table:'cbench_bm_tests', results:'cbench_bm_results', file:'CbenchDB', rFile:'SCPFcbench.R', extra:none, finalResult:1, graphTitle:['Cbench Test'], dbCols:'avg', dbWhere:'', y_axis:'Throughput (Responses/sec)'],
14 SCPFhostLat: [ test:'SCPFhostLat', table:'host_latency_tests', results:'host_latency_results', file:'HostAddLatency', rFile:'SCPFhostLat.R', extra:none,finalResult:1, graphTitle:['Host Latency Test'], dbCols:'avg', dbWhere:'AND scale=5', y_axis:'Latency (ms)'],
15 SCPFportLat: [ test:'SCPFportLat', table:'port_latency_details', results:'port_latency_results', file:'/tmp/portEventResultDb', rFile:'SCPFportLat.R', extra:none, finalResult:1, graphTitle:['Port Latency Test - Port Up','Port Latency Test - Port Down'], dbCols:[ 'up_ofp_to_dev_avg,up_dev_to_link_avg,up_link_to_graph_avg', 'down_ofp_to_dev_avg,down_dev_to_link_avg,down_link_to_graph_avg' ], dbWhere:'AND scale=5', y_axis:'Latency (ms)' ],
Devin Lim79af50f2017-10-26 14:26:47 -070016 SCPFflowTp1g: [ test:'SCPFflowTp1g', table:'flow_tp_tests', results:'flow_tp_results', file:'flowTP1gDB', rFile:'SCPFflowTp1g.R n', extra:neighbors,finalResult:1, graphTitle:['Flow Throughput Test - neighbors=0','Flow Throughput Test - neighbors=4'], dbCols:'avg', dbWhere:[ 'AND scale=5 AND neighbors=0 ','AND scale=5 AND NOT neighbors=0' ], y_axis:'Throughput (,000 Flows/sec)' ],
Devin Lima0e52eb2017-09-13 18:35:12 -070017 SCPFflowTp1gWithFlowObj: [ test:'SCPFflowTp1g --params TEST/flowObj=True', table:'flow_tp_fobj_tests', results:'flow_tp_fobj_results', file:'flowTP1gDBFlowObj', rFile:'SCPFflowTp1g.R y', extra:neighbors, finalResult:0],
Devin Lim90803a82017-08-29 13:41:44 -070018 SCPFscaleTopo: [ test:'SCPFscaleTopo', table:'scale_topo_latency_details', results:'scale_topo_latency_results', file:'/tmp/scaleTopoResultDb', rFile:'SCPFscaleTopo.R', extra:none, finalResult:1, graphTitle:['Scale Topology Test'], dbCols:[ 'first_connection_to_last_connection, last_connection_to_last_role_request, last_role_request_to_last_topology' ], dbWhere:'AND scale=20' , y_axis:'Latency (s)'],
19 SCPFswitchLat: [ test:'SCPFswitchLat', table:'switch_latency_details', results:'switch_latency_results', file:'/tmp/switchEventResultDb', rFile:'SCPFswitchLat.R', extra:none, finalResult:1, graphTitle:['Switch Latency Test - Switch Up','Switch Latency Test - Switch Down'], dbCols:[ 'tcp_to_feature_reply_avg,feature_reply_to_role_request_avg,role_request_to_role_reply_avg,role_reply_to_device_avg,up_device_to_graph_avg', 'fin_ack_to_ack_avg,ack_to_device_avg,down_device_to_graph_avg' ], dbWhere:'AND scale=5', y_axis:'Latency (ms)' ],
Devin Lima0e52eb2017-09-13 18:35:12 -070020 SCPFbatchFlowResp: [ test:'SCPFbatchFlowResp', table:'batch_flow_tests', results:'batch_flow_results', file:'SCPFbatchFlowRespData', rFile:'SCPFbatchFlowResp.R', extra:none, finalResult:1, graphTitle:['Batch Flow Test - Post', 'Batch Flow Test - Del'], dbCols:[ 'elapsepost, posttoconfrm', 'elapsedel, deltoconfrm' ], dbWhere:'', y_axis:'Latency (ms)'],
21 SCPFintentEventTp: [ test:'SCPFintentEventTp', table:'intent_tp_tests', results:'intent_tp_results', file:'IntentEventTPDB', rFile:'SCPFintentEventTp.R n', extra:neighbors, finalResult:1, graphTitle:['Intent Throughput Test - neighbors=0','Intent Throughput Test - neighbors=4'], dbCols:'SUM( avg ) as avg', dbWhere:[ 'AND scale=5 AND neighbors=0 GROUP BY date','AND scale=5 AND NOT neighbors=0 GROUP BY date' ], y_axis:'Throughput (Ops/sec)'],
Devin Lim90803a82017-08-29 13:41:44 -070022 SCPFintentRerouteLat: [ test:'SCPFintentRerouteLat', table:'intent_reroute_latency_tests', results:'intent_reroute_latency_results', file:'IntentRerouteLatDB', rFile:'SCPFIntentInstallWithdrawRerouteLat.R n', extra:batches, finalResult:1, graphTitle:['Intent Reroute Test'], dbCols:'avg', dbWhere:'AND scale=5 AND batch_size=100', y_axis:'Latency (ms)'],
Devin Lim61657e42017-10-09 17:24:40 -070023 SCPFscalingMaxIntents: [ test:'SCPFscalingMaxIntents', table:'max_intents_tests', results:'max_intents_results', file:'ScalingMaxIntentDB', rFile:'SCPFscalingMaxIntents.R n', extra:times, finalResult:0],
Devin Lima0e52eb2017-09-13 18:35:12 -070024 SCPFintentEventTpWithFlowObj: [ test:'SCPFintentEventTp --params TEST/flowObj=True', table:'intent_tp_fobj_tests', results:'intent_tp_fobj_results', file:'IntentEventTPflowObjDB', rFile:'SCPFintentEventTp.R y', extra:neighbors,finalResult:0],
Devin Lim90803a82017-08-29 13:41:44 -070025 SCPFintentInstallWithdrawLat: [ test:'SCPFintentInstallWithdrawLat', table:'intent_latency_tests', results:'intent_latency_results', file:'IntentInstallWithdrawLatDB', rFile:'SCPFIntentInstallWithdrawRerouteLat.R n', extra:batches,finalResult:1, graphTitle:['Intent Installation Test','Intent Withdrawal Test'], dbCols:[ 'install_avg','withdraw_avg' ], dbWhere:'AND scale=5 AND batch_size=100', y_axis:'Latency (ms)'],
Devin Lima0e52eb2017-09-13 18:35:12 -070026 SCPFintentRerouteLatWithFlowObj: [ test:'SCPFintentRerouteLat --params TEST/flowObj=True', table:'intent_reroute_latency_fobj_tests', results:'intent_reroute_latency_fobj_results', file:'IntentRerouteLatDBWithFlowObj', rFile:'SCPFIntentInstallWithdrawRerouteLat.R y', extra:batches, finalResult:0],
Devin Lim61657e42017-10-09 17:24:40 -070027 SCPFscalingMaxIntentsWithFlowObj: [ test:'SCPFscalingMaxIntents --params TEST/flowObj=True', table:'max_intents_fobj_tests', results:'max_intents_fobj_results', file:'ScalingMaxIntentDBWFO', rFile:'SCPFscalingMaxIntents.R y', extra:times, finalResult:0],
Devin Lima0e52eb2017-09-13 18:35:12 -070028 SCPFintentInstallWithdrawLatWithFlowObj: [ test:'SCPFintentInstallWithdrawLat --params TEST/flowObj=True', table:'intent_latency_fobj_tests', results:'intent_latency_fobj_results', file:'IntentInstallWithdrawLatDBWFO', rFile:'SCPFIntentInstallWithdrawRerouteLat.R y', extra:batches, finalResult:0],
Devin Lim90803a82017-08-29 13:41:44 -070029 SCPFmastershipFailoverLat: [test:'SCPFmastershipFailoverLat', table:'mastership_failover_tests', results:'mastership_failover_results', file:'mastershipFailoverLatDB', rFile:'SCPFmastershipFailoverLat.R', extra:none, finalResult:1, graphTitle:['Mastership Failover Test'], dbCols:[ 'kill_deact_avg,deact_role_avg' ], dbWhere:'AND scale=5', y_axis:'Latency (ms)' ]
30]
31
32echo("Testcases:")
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -070033graph_generator_directory = "~/OnosSystemTest/TestON/JenkinsFile/scripts/"
Devin Lim90803a82017-08-29 13:41:44 -070034graph_saved_directory = "/var/jenkins/workspace/Pipeline_postjob_BM/"
35def testsToRun = null
36def prop = null
37node("TestStation-BMs"){
38 prop = readProperties(file:'/var/jenkins/TestONOS.property') // TODO set defaults
39 testsToRun = prop["Tests"].tokenize("\n;, ")
40 for ( String test : testsToRun ) {
41 println test
42 }
43}
44
45def tests = [:]
46for( String test : SCPF.keySet() ){
47 toBeRun = testsToRun.contains( test )
48 def stepName = ( toBeRun ? "" : "Not " ) + "Running $test"
49 tests[stepName] = SCPFTest(test, toBeRun, prop)
50}
51
Devin Lim61657e42017-10-09 17:24:40 -070052def now = new Date()
Devin Lim90803a82017-08-29 13:41:44 -070053// run the tests
54for ( test in tests.keySet() ){
55 tests[test].call()
56}
Devin Lim79af50f2017-10-26 14:26:47 -070057try{
58 if( prop["manualRun"] == "false" ){
59 def end = new Date()
60 TimeDuration duration = TimeCategory.minus( end, now )
61 slackSend( color:"#5816EE", message: "SCPF tests ended at: " + end.toString() + "\nTime took : " + duration )
62 }
Devin Lim61657e42017-10-09 17:24:40 -070063}
Devin Lim79af50f2017-10-26 14:26:47 -070064catch(all){}
65
Devin Lim90803a82017-08-29 13:41:44 -070066// The testName should be the key from the SCPF map
67def SCPFTest( testName, toBeRun, prop ) {
68 return {
Devin Lim79af50f2017-10-26 14:26:47 -070069 catchError{
Devin Lim90803a82017-08-29 13:41:44 -070070 stage(testName) {
71 if ( toBeRun ){
72 workSpace = "/var/jenkins/workspace/"+testName
73 node("TestStation-BMs"){
74 withEnv(['ONOSBranch='+prop["ONOSBranch"],
75 'ONOSJVMHeap='+prop["ONOSJVMHeap"],
76 'TestONBranch='+prop["TestONBranch"],
77 'ONOSTag='+prop["ONOSTag"],
78 'WikiPrefix='+prop["WikiPrefix"],
79 'WORKSPACE='+workSpace]){
80 sh '''#!/bin/bash -l
81 set -i # interactive
Devin Lima0e52eb2017-09-13 18:35:12 -070082 set +e
Devin Lim90803a82017-08-29 13:41:44 -070083 shopt -s expand_aliases # expand alias in non-interactive mode
84 export PYTHONUNBUFFERED=1
85
86 ifconfig
87
88 echo "ONOS Branch is: $ONOSBranch"
89 echo "TestON Branch is: $TestONBranch"
90 echo "Test date: "
91 date
92
93 cd ~
94 export PATH=$PATH:onos/tools/test/bin
95
96 timeout 240 stc shutdown | head -100
97 timeout 240 stc teardown | head -100
98 timeout 240 stc shutdown | head -100
99
100 cd ~/OnosSystemTest/TestON/bin
101 git log |head
102 ./cleanup.sh
103 ''' + "./cli.py run " + SCPF[testName]['test']
104
105 // For moving results
106 sh '''#!/bin/bash -i
Devin Lima0e52eb2017-09-13 18:35:12 -0700107 set +e
Devin Lim90803a82017-08-29 13:41:44 -0700108 # remove any leftover files from previous tests
109 sudo rm ${WORKSPACE}/*Result.txt
110
111 #copy files to workspace
112 cd `ls -t ~/OnosSystemTest/TestON/logs/*/ | head -1 | sed 's/://'`
113 sudo cp *Result.txt ${WORKSPACE}/
114 cd ${WORKSPACE}/
115 ls -al
116 cd '''
117 // Post Results
Devin Lim61657e42017-10-09 17:24:40 -0700118 if( prop["manualRun"] == "false" || prop["postResult"] == "true" ){
119 withCredentials([
120 string(credentialsId: 'db_pass', variable: 'pass'),
121 string(credentialsId: 'db_user', variable: 'user'),
122 string(credentialsId: 'db_host', variable: 'host'),
123 string(credentialsId: 'db_port', variable: 'port')]) {
124 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);\""
125 if (testName == "SCPFscaleTopo" || testName == "SCPFswitchLat" || testName == "SCPFportLat") {
126 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');\""
127 }
128 sh '''#!/bin/bash
Devin Lim90803a82017-08-29 13:41:44 -0700129
Devin Lim61657e42017-10-09 17:24:40 -0700130 export DATE=\$(date +%F_%T)
131 cd ~
132 pwd
133 cd /tmp
134 while read line
135 do
Devin Lim90803a82017-08-29 13:41:44 -0700136
Devin Lim61657e42017-10-09 17:24:40 -0700137 echo \$line
138 echo ''' + database_command + '''
Devin Lim90803a82017-08-29 13:41:44 -0700139
Devin Lim61657e42017-10-09 17:24:40 -0700140 done< ''' + SCPF[testName]['file'] + '''
141 ''' + getGraphCommand( SCPF[testName]['rFile'], SCPF[testName]['extra'], host, port, user, pass, testName, prop["ONOSBranch"] ) + '''
142 ''' + ( SCPF[testName]['finalResult'] ? generateCombinedResultGraph( host,port, user, pass, testName, prop["ONOSBranch"] ) : "" )
143 }
Devin Lim90803a82017-08-29 13:41:44 -0700144 }
145 // Fetch Logs
146 sh '''#!/bin/bash
Devin Lima0e52eb2017-09-13 18:35:12 -0700147 set +e
Devin Lim90803a82017-08-29 13:41:44 -0700148 cd ~/OnosSystemTest/TestON/logs
149 echo "Job Name is: ${JOB_NAME}"
150 TestONlogDir=$(ls -t | grep ${TEST_NAME}_ |head -1)
151 echo "########################################################################################"
152 echo "##### copying ONOS logs from all nodes to TestON/logs directory: ${TestONlogDir}"
153 echo "########################################################################################"
154 cd $TestONlogDir
155 if [ $? -eq 1 ]
156 then
157 echo "Job name does not match any test suite name to move log!"
158 else
159 pwd
160 for i in $OC{1..7}; do onos-fetch-logs $i || echo log does not exist; done
161 fi'''
162 }
163 }
Devin Lim61657e42017-10-09 17:24:40 -0700164 if( prop["manualRun"] == "false" || prop["postResult"] == "true" ){
Devin Lim90803a82017-08-29 13:41:44 -0700165 def post = build job: "Pipeline_postjob_BM", propagate: false
166 }
167 node("TestStation-BMs"){
Devin Lim79af50f2017-10-26 14:26:47 -0700168 resultContents = readFile workSpace + "/" + testName + "Result.txt"
169 resultContents = resultContents.split("\n")
170 if( resultContents[ 0 ] == "1" ){
171 print "All passed"
172 }else{
173 print "Failed"
174 if( prop["manualRun"] == "false" )
175 slackSend(color:"FF0000", message: "[" + prop["ONOSBranch"] + "]" + testName + " : Failed!\n"
176 + resultContents[ 1 ] + "\n"
177 + "https://onos-jenkins.onlab.us/blue/organizations/jenkins/${env.JOB_NAME}/detail/${env.JOB_NAME}/${env.BUILD_NUMBER}/pipeline" )
178 Failed
179 }
Devin Lim90803a82017-08-29 13:41:44 -0700180 }
181 }
182 }
183 }
184 }
185}
186def getGraphCommand( rFileName, extras, host, port, user, pass, testName, branchName ){
187 result = ""
188 for( extra in extras ){
189 result += generateGraph( rFileName, " " + extra, host, port, user, pass, testName, branchName ) + ";"
190 }
191 return result
192}
193def generateGraph( rFileName, batch, host, port, user, pass, testName, branchName){
194 return "Rscript " + graph_generator_directory + rFileName + " " + host + " " + port + " " + user + " " + pass + " " + testName + " " + branchName + " " + batch + " " + graph_saved_directory
195}
196def generateCombinedResultGraph( host, port, user, pass, testName, branchName ){
197 result = ""
198 for ( int i=0; i< SCPF[testName]['graphTitle'].size(); i++){
Jeremy Ronquilloe9063762017-10-17 15:36:09 -0700199 result += "Rscript " + graph_generator_directory + "SCPFLineGraph.R " + host + " " + port + " " + user + " " + pass + " \"" + SCPF[testName]['graphTitle'][i] + "\" " + branchName + " " + 50 + " \"SELECT " +
Devin Lima0e52eb2017-09-13 18:35:12 -0700200 checkIfList( testName, 'dbCols', i ) + " FROM " + SCPF[testName]['table'] + " WHERE branch=\'" + branchName + "\' " + checkIfList( testName, 'dbWhere', i ) +
Jeremy Ronquilloe9063762017-10-17 15:36:09 -0700201 " ORDER BY date DESC LIMIT 50\" \"" + SCPF[testName]['y_axis'] + "\" " + graph_saved_directory + ";"
Devin Lim90803a82017-08-29 13:41:44 -0700202 }
203 return result
204}
205def checkIfList( testName, forWhich, pos ){
Devin Lima5a41002017-09-19 13:05:04 -0700206 return SCPF[testName][forWhich].getClass().getName() != "java.lang.String" ? SCPF[testName][forWhich][pos] : SCPF[testName][forWhich]
Devin Lim90803a82017-08-29 13:41:44 -0700207}