blob: bdcdc89ed5bfb18e4bb17631f8996ed76ff70c40 [file] [log] [blame]
Jon Hallde964e82017-04-18 14:14:22 -07001#!groovy
2// This is a Jenkinsfile for a scripted pipeline for the SCPF tests
You Wang66065662017-05-04 14:35:29 -07003// properties([pipelineTriggers([cron('30 19 * * *')])])
Jon Hallde964e82017-04-18 14:14:22 -07004
5// TODO: Exception handling around steps
6SCPF = [
7 SCPFcbench: [ test:'SCPFcbench', table:'cbench_bm_tests', results:'cbench_bm_results', file:'CbenchDB'],
You Wang66065662017-05-04 14:35:29 -07008 SCPFhostLat: [ test:'SCPFhostLat', table:'host_latency_tests', results:'host_latency_results', file:'HostAddLatency'],
Jon Hallde964e82017-04-18 14:14:22 -07009 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 Limccce5c82017-08-17 17:34:12 -070011 SCPFflowTp1gWithFlowObj: [ test:'SCPFflowTp1g --params TEST/flowObj=True', table:'flow_tp_fobj_tests', results:'flow_tp_fobj_results', file:'flowTP1gDBFlowObj'],
Jon Hallde964e82017-04-18 14:14:22 -070012 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
26def defaultTests = SCPF.keySet().toArray()
27// Convert to a string with new line deliminators for user input
28StringBuilder sb = new StringBuilder();
29for (String s : defaultTests)
30{
31 sb.append(s);
32 sb.append("\n");
33}
34choices = sb.toString();
35// Define sets of tests
36SCPF_Basic = "SCPFswitchLat\nSCPFportLat\nSCPFintentInstallWithdrawLat\nSCPFintentEventTp\nSCPFflowTp1g\nSCPFcbench\nSCPFbatchFlowResp"
37SCPF_ExtraSetA = "SCPFintentRerouteLat\nSCPFscalingMaxIntents\nSCPFhostLat\nSCPFscaleTopo"
Devin Limccce5c82017-08-17 17:34:12 -070038SCPF_ExtraSetB = "SCPFintentInstallWithdrawLatWithFlowObj\nSCPFintentEventTpWithFlowObj\nSCPFintentRerouteLatWithFlowObj\nSCPFscalingMaxIntentsWithFlowObj\nSCPFflowTp1gWithFlowObj"
Jon Hallde964e82017-04-18 14:14:22 -070039
40try {
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 Hallde964e82017-04-18 14:14:22 -070052 case Calendar.MONDAY:
You Wang122e3192017-05-05 15:28:33 -070053 choices = SCPF_Basic + "\n" + SCPF_ExtraSetB
Jon Hallde964e82017-04-18 14:14:22 -070054 println "Defaulting to Monday tests:" + choices
55 break
56 case Calendar.TUESDAY:
You Wang122e3192017-05-05 15:28:33 -070057 choices = SCPF_Basic
Jon Hallde964e82017-04-18 14:14:22 -070058 println "Defaulting to Tuesday tests:" + choices
59 break
60 case Calendar.WEDNESDAY:
You Wang122e3192017-05-05 15:28:33 -070061 choices = SCPF_Basic + "\n" + SCPF_ExtraSetA
Jon Hallde964e82017-04-18 14:14:22 -070062 println "Defaulting to Wednesday tests:" + choices
63 break
64 case Calendar.THURSDAY:
You Wang122e3192017-05-05 15:28:33 -070065 choices = SCPF_Basic + "\n" + SCPF_ExtraSetB
Jon Hallde964e82017-04-18 14:14:22 -070066 println "Defaulting to Thursday tests:" + choices
67 break
68 case Calendar.FRIDAY:
You Wangbfd739c2017-05-01 15:17:06 -070069 choices = SCPF_Basic + "\n" + SCPF_ExtraSetA + "\n" + SCPF_ExtraSetB
Jon Hallde964e82017-04-18 14:14:22 -070070 println "Defaulting to Fridat tests:" + choices
71 break
72 case Calendar.SATURDAY:
You Wangbfd739c2017-05-01 15:17:06 -070073 choices = SCPF_Basic + "\n" + SCPF_ExtraSetA + "\n" + SCPF_ExtraSetB
Jon Hallde964e82017-04-18 14:14:22 -070074 println "Defaulting to Saturday tests:" + choices
75 break
76 case Calendar.SUNDAY:
You Wang122e3192017-05-05 15:28:33 -070077 choices = SCPF_Basic + "\n" + SCPF_ExtraSetA
Jon Hallde964e82017-04-18 14:14:22 -070078 println "Defaulting to Sunday tests:" + choices
79 break
80 }
81 testcases = choices
82}
83
84echo("Testcases:")
85//println testcases
86// TODO REMOVE AFTER DEBUGGING
87def testsToRun = testcases.tokenize("\n;, ")
88for (String test : testsToRun) {
89 println test
90}
91
92def tests = [:]
93for (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
101parallel tests
102
103// The testName should be the key from the SCPF map
104def 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 Hall554d42a2017-07-06 10:15:30 -0700130 timeout 240 stc shutdown
131 timeout 240 stc teardown
132 timeout 240 stc shutdown
Jon Hallde964e82017-04-18 14:14:22 -0700133
134 cd ~/OnosSystemTest/TestON/bin
135 git log |head
136 ./cleanup.sh
Jon Hall09aced42017-05-01 14:03:22 -0700137 ''' + "./cli.py run " + SCPF[testName]['test']
Jon Hallde964e82017-04-18 14:14:22 -0700138
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 Wang66065662017-05-04 14:35:29 -0700145 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 Hallde964e82017-04-18 14:14:22 -0700149 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 Wang66065662017-05-04 14:35:29 -0700159 echo ''' + database_command + '''
Jon Hallde964e82017-04-18 14:14:22 -0700160
You Wang66065662017-05-04 14:35:29 -0700161 done< ''' + SCPF[testName]['file']
Jon Hallde964e82017-04-18 14:14:22 -0700162 }
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 Wang66065662017-05-04 14:35:29 -0700178 for i in $OC{1..7}; do onos-fetch-logs $i || echo log does not exist; done
Jon Hallde964e82017-04-18 14:14:22 -0700179 fi'''
180 }
181 }
182 }
183 }
184}