blob: f5bef562d34e2d3998f7d48e7305bdc4367c0fcf [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'],
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
25def defaultTests = SCPF.keySet().toArray()
26// Convert to a string with new line deliminators for user input
27StringBuilder sb = new StringBuilder();
28for (String s : defaultTests)
29{
30 sb.append(s);
31 sb.append("\n");
32}
33choices = sb.toString();
34// Define sets of tests
35SCPF_Basic = "SCPFswitchLat\nSCPFportLat\nSCPFintentInstallWithdrawLat\nSCPFintentEventTp\nSCPFflowTp1g\nSCPFcbench\nSCPFbatchFlowResp"
36SCPF_ExtraSetA = "SCPFintentRerouteLat\nSCPFscalingMaxIntents\nSCPFhostLat\nSCPFscaleTopo"
37SCPF_ExtraSetB = "SCPFintentInstallWithdrawLatWithFlowObj\nSCPFintentEventTpWithFlowObj\nSCPFintentRerouteLatWithFlowObj\nSCPFscalingMaxIntentsWithFlowObj"
38
39try {
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 Hallde964e82017-04-18 14:14:22 -070051 case Calendar.MONDAY:
You Wangbfd739c2017-05-01 15:17:06 -070052 choices = SCPF_Basic + "\n" + SCPF_ExtraSetA
Jon Hallde964e82017-04-18 14:14:22 -070053 println "Defaulting to Monday tests:" + choices
54 break
55 case Calendar.TUESDAY:
You Wangbfd739c2017-05-01 15:17:06 -070056 choices = SCPF_Basic + "\n" + SCPF_ExtraSetB
Jon Hallde964e82017-04-18 14:14:22 -070057 println "Defaulting to Tuesday tests:" + choices
58 break
59 case Calendar.WEDNESDAY:
60 choices = SCPF_Basic
61 println "Defaulting to Wednesday tests:" + choices
62 break
63 case Calendar.THURSDAY:
You Wangbfd739c2017-05-01 15:17:06 -070064 choices = SCPF_Basic + "\n" + SCPF_ExtraSetA
Jon Hallde964e82017-04-18 14:14:22 -070065 println "Defaulting to Thursday tests:" + choices
66 break
67 case Calendar.FRIDAY:
You Wangbfd739c2017-05-01 15:17:06 -070068 choices = SCPF_Basic + "\n" + SCPF_ExtraSetA + "\n" + SCPF_ExtraSetB
Jon Hallde964e82017-04-18 14:14:22 -070069 println "Defaulting to Fridat tests:" + choices
70 break
71 case Calendar.SATURDAY:
You Wangbfd739c2017-05-01 15:17:06 -070072 choices = SCPF_Basic + "\n" + SCPF_ExtraSetA + "\n" + SCPF_ExtraSetB
Jon Hallde964e82017-04-18 14:14:22 -070073 println "Defaulting to Saturday tests:" + choices
74 break
75 case Calendar.SUNDAY:
76 choices = SCPF_Basic
77 println "Defaulting to Sunday tests:" + choices
78 break
79 }
80 testcases = choices
81}
82
83echo("Testcases:")
84//println testcases
85// TODO REMOVE AFTER DEBUGGING
86def testsToRun = testcases.tokenize("\n;, ")
87for (String test : testsToRun) {
88 println test
89}
90
91def tests = [:]
92for (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
100parallel tests
101
102// The testName should be the key from the SCPF map
103def 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
129 stc teardown
130
131 cd ~/OnosSystemTest/TestON/bin
132 git log |head
133 ./cleanup.sh
Jon Hall09aced42017-05-01 14:03:22 -0700134 ''' + "./cli.py run " + SCPF[testName]['test']
Jon Hallde964e82017-04-18 14:14:22 -0700135
136 // Post Results
137 withCredentials([
138 string(credentialsId: 'db_pass', variable: 'pass'),
139 string(credentialsId: 'db_user', variable: 'user'),
140 string(credentialsId: 'db_host', variable: 'host'),
141 string(credentialsId: 'db_port', variable: 'port')]) {
You Wang66065662017-05-04 14:35:29 -0700142 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);\""
143 if (testName == "SCPFscaleTopo" || testName == "SCPFswitchLat" || testName == "SCPFportLat") {
144 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');\""
145 }
Jon Hallde964e82017-04-18 14:14:22 -0700146 sh '''#!/bin/bash
147
148 export DATE=\$(date +%F_%T)
149 cd ~
150 pwd
151 cd /tmp
152 while read line
153 do
154
155 echo \$line
You Wang66065662017-05-04 14:35:29 -0700156 echo ''' + database_command + '''
Jon Hallde964e82017-04-18 14:14:22 -0700157
You Wang66065662017-05-04 14:35:29 -0700158 done< ''' + SCPF[testName]['file']
Jon Hallde964e82017-04-18 14:14:22 -0700159 }
160 // Fetch Logs
161 sh '''#!/bin/bash
162
163 cd ~/OnosSystemTest/TestON/logs
164 echo "Job Name is: ${JOB_NAME}"
165 TestONlogDir=$(ls -t | grep ${TEST_NAME}_ |head -1)
166 echo "########################################################################################"
167 echo "##### copying ONOS logs from all nodes to TestON/logs directory: ${TestONlogDir}"
168 echo "########################################################################################"
169 cd $TestONlogDir
170 if [ $? -eq 1 ]
171 then
172 echo "Job name does not match any test suite name to move log!"
173 else
174 pwd
You Wang66065662017-05-04 14:35:29 -0700175 for i in $OC{1..7}; do onos-fetch-logs $i || echo log does not exist; done
Jon Hallde964e82017-04-18 14:14:22 -0700176 fi'''
177 }
178 }
179 }
180 }
181}