blob: bfae6c1ba3e723d89e46291a50e931ada2766cbf [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 USECASETest tests
4
5// TODO: Exception handling around steps
6
7def prop = null
8node("TestStation-BMs"){
9 prop = readProperties(file:'/var/jenkins/TestONOS.property')
10}
11USECASE = [
12 "FUNCvirNetNB" : [wiki_link:prop["WikiPrefix"]+"-"+"FUNCvirNetNB", wiki_file:"FUNCvirNetNBWiki.txt"],
13 "FUNCbgpls" : [wiki_link:prop["WikiPrefix"]+"-"+"FUNCbgpls", wiki_file:"FUNCbgplsWiki.txt"],
14 "VPLSBasic" : [wiki_link:prop["WikiPrefix"]+"-"+"VPLSBasic", wiki_file:"VPLSBasicWiki.txt"],
15 "VPLSfailsafe" : [wiki_link:prop["WikiPrefix"]+"-"+"VPLSfailsafe", wiki_file:"VPLSfailsafeWiki.txt"],
16 "PLATdockertest": [wiki_link:"Docker Images sanity test", wiki_file:"PLATdockertestTableWiki.txt"],
17 "SRSanity": [wiki_link:prop["WikiPrefix"]+"-"+"SR Sanity", wiki_file:"SRSanityWiki.txt"],
18 "SRSwitchFailure": [wiki_link:prop["WikiPrefix"]+"-"+"SR Switch Failure", wiki_file:"SRSwitchFailureWiki.txt"],
19 "SRLinkFailure": [wiki_link:prop["WikiPrefix"]+"-"+"SR Link Failure", wiki_file:"SRLinkFailureWiki.txt"],
20 "SROnosFailure": [wiki_link:prop["WikiPrefix"]+"-"+"SR Onos node Failure", wiki_file:"SROnosFailureWiki.txt"],
21 "SRClusterRestart": [wiki_link:prop["WikiPrefix"]+"-"+"SR Cluster Restart", wiki_file:"SRClusterRestartWiki.txt"],
22 "SRDynamic": [wiki_link:prop["WikiPrefix"]+"-"+"SR Dynamic Config", wiki_file:"SRDynamicWiki.txt"],
Devin Lim61657e42017-10-09 17:24:40 -070023 "SRHighAvailability": [wiki_link:prop["WikiPrefix"]+"-"+"SR High Availability", wiki_file:"SRHighAvailabilityWiki.txt"],
Devin Lim90803a82017-08-29 13:41:44 -070024 "USECASE_SdnipFunction": [wiki_link:prop["WikiPrefix"]+"-"+"SDNIP Function", wiki_file:"USECASE_SdnipFunctionWiki.txt"],
25 "USECASE_SdnipFunctionCluster": [wiki_link:prop["WikiPrefix"]+"-"+"SDNIP Function Cluster", wiki_file:"USECASE_SdnipFunctionClusterWiki.txt"]
26]
27
28table_name = "executed_test_tests"
29result_name = "executed_test_results"
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -070030graph_generator_file = "~/OnosSystemTest/TestON/JenkinsFile/scripts/testCaseGraphGenerator.R"
Devin Lim90803a82017-08-29 13:41:44 -070031graph_saved_directory = "/var/jenkins/workspace/Pipeline_postjob_BM/"
32
33echo("Testcases:")
34testsToRun = prop["Tests"].tokenize("\n;, ")
35for ( String test : testsToRun ) {
36 println test
37}
38
39def tests = [:]
40for( String test : USECASE.keySet() ){
41 toBeRun = testsToRun.contains( test )
42 def stepName = ( toBeRun ? "" : "Not " ) + "Running $test"
43 tests[stepName] = USECASETest(test, toBeRun, prop)
44}
45
Devin Lim61657e42017-10-09 17:24:40 -070046def now = new Date()
Devin Lim90803a82017-08-29 13:41:44 -070047// run the tests
48for ( test in tests.keySet() ){
49 tests[test].call()
50}
Devin Lim79af50f2017-10-26 14:26:47 -070051try{
52 if( prop["manualRun"] == "false" ){
53 def end = new Date()
54 TimeDuration duration = TimeCategory.minus( end, now )
55 slackSend( color:"#5816EE", message: "USECASE tests ended at: " + end.toString() + "\nTime took : " + duration )
56 }
Devin Lim61657e42017-10-09 17:24:40 -070057}
Devin Lim79af50f2017-10-26 14:26:47 -070058catch(all){}
59
Devin Lim90803a82017-08-29 13:41:44 -070060// The testName should be the key from the FUNC
61def USECASETest( testName, toBeRun, prop ) {
62 return {
Devin Lim79af50f2017-10-26 14:26:47 -070063 catchError{
Devin Lim90803a82017-08-29 13:41:44 -070064 stage(testName) {
65 if ( toBeRun ){
66 workSpace = "/var/jenkins/workspace/"+testName
67 def fileContents = ""
68 node("TestStation-BMs"){
69 withEnv(['ONOSBranch='+prop["ONOSBranch"],
70 'ONOSJVMHeap='+prop["ONOSJVMHeap"],
71 'TestONBranch='+prop["TestONBranch"],
72 'ONOSTag='+prop["ONOSTag"],
73 'WikiPrefix='+prop["WikiPrefix"],
74 'WORKSPACE='+workSpace]){
75 sh '''#!/bin/bash -l
76 set -i # interactive
77 set +e
78 shopt -s expand_aliases # expand alias in non-interactive mode
79 export PYTHONUNBUFFERED=1
80
81 ifconfig
82
83 echo "ONOS Branch is: $ONOSBranch"
84 echo "TestON Branch is: $TestONBranch"
85 echo "Test date: "
86 date
87
88 cd ~
89 export PATH=$PATH:onos/tools/test/bin
90
91 . .bash_killcmd
92 killTestONall
93 onos-group uninstall
94 timeout 240 stc teardown | head -100
95
96 cd ~/OnosSystemTest/TestON/bin
97 git log |head
98 ./cleanup.sh -f
99 ''' + "./cli.py run " + testName + '''
100 ./cleanup.sh -f
101 cd ~/onos/tools/package/config
102 git clean -df'''
103
104 // For the Wiki page
105 sh '''#!/bin/bash -i
Devin Lima0e52eb2017-09-13 18:35:12 -0700106 set +e
Devin Lim90803a82017-08-29 13:41:44 -0700107 echo "ONOS Branch is: ${ONOSBranch}"
108 echo "TestON Branch is: ${TestONBranch}"
109
110 echo "Job name is: "''' + testName + '''
111 echo "Workspace is: ${WORKSPACE}/"
112
113 echo "Wiki page to post is: ${WikiPrefix}-"
114
115 # remove any leftover files from previous tests
116 sudo rm ${WORKSPACE}/*Wiki.txt
117 sudo rm ${WORKSPACE}/*Summary.txt
118 sudo rm ${WORKSPACE}/*Result.txt
119 sudo rm ${WORKSPACE}/*.csv
120
121 #copy files to workspace
122 cd `ls -t ~/OnosSystemTest/TestON/logs/*/ | head -1 | sed 's/://'`
123 sudo cp *.txt ${WORKSPACE}/
124 sudo cp *.csv ${WORKSPACE}/
125 cd ${WORKSPACE}/
126 for i in *.csv
127 do mv "$i" "$WikiPrefix"-"$i"
128 done
129 ls -al
130 cd '''
131
Devin Lim61657e42017-10-09 17:24:40 -0700132 if( prop["manualRun"] == "false" || prop["postResult"] == "true" ){
Devin Lim90803a82017-08-29 13:41:44 -0700133 // Post Results
134 withCredentials([
135 string(credentialsId: 'db_pass', variable: 'pass'),
136 string(credentialsId: 'db_user', variable: 'user'),
137 string(credentialsId: 'db_host', variable: 'host'),
138 string(credentialsId: 'db_port', variable: 'port')]) {
139 def database_command = pass + "|psql --host=" + host + " --port=" + port + " --username=" + user + " --password --dbname onostest -c \"INSERT INTO " + table_name + " VALUES('\$DATE','" + result_name + "','" + testName + "',\$BUILD_NUMBER, '\$ONOSBranch', \$line);\""
140
141 sh '''#!/bin/bash
Devin Lim90803a82017-08-29 13:41:44 -0700142 export DATE=\$(date +%F_%T)
143 cd ~
144 pwd
145 sed 1d ''' + workSpace + "/" + prop["WikiPrefix"] + "-" + testName + '''.csv | while read line
146 do
147 echo \$line
148 echo ''' + database_command + '''
149
150 done
151 Rscript ''' + graph_generator_file + " " + host + " " + port + " " + user + " " + pass + " " + testName + " " + prop["ONOSBranch"] + " 20 " + graph_saved_directory
152
153 }
154 }
155 // Fetch Logs
156 sh '''#!/bin/bash
Devin Lima0e52eb2017-09-13 18:35:12 -0700157 set +e
Devin Lim90803a82017-08-29 13:41:44 -0700158 cd ~/OnosSystemTest/TestON/logs
159 echo "Job Name is: " + ''' + testName + '''
160 TestONlogDir=$(ls -t | grep ${TEST_NAME}_ |head -1)
161 echo "########################################################################################"
162 echo "##### copying ONOS logs from all nodes to TestON/logs directory: ${TestONlogDir}"
163 echo "########################################################################################"
164 cd $TestONlogDir
165 if [ $? -eq 1 ]
166 then
167 echo "Job name does not match any test suite name to move log!"
168 else
169 pwd
170 for i in $OC{1..7}; do onos-fetch-logs $i || echo log does not exist; done
171 fi
172 cd'''
173 fileContents = readFile workSpace+"/"+USECASE[testName]['wiki_file']
174
175 }
176 }
Devin Lim61657e42017-10-09 17:24:40 -0700177 if( prop["manualRun"] == "false" || prop["postResult"] == "true" ){
Devin Lim90803a82017-08-29 13:41:44 -0700178 def post = build job: "Pipeline_postjob_BM", propagate: false,
179 parameters: [
180 string(name: 'Wiki_Contents', value: fileContents),
181 string(name: 'Wiki_Link', value: USECASE[testName]['wiki_link'])
182 ]
183 }
184 node("TestStation-BMs"){
Devin Lim79af50f2017-10-26 14:26:47 -0700185 resultContents = readFile workSpace + "/" + testName + "Result.txt"
186 resultContents = resultContents.split("\n")
187 if( resultContents[ 0 ] == "1" ){
188 print "All passed"
189 }else{
190 print "Failed"
191 if( prop["manualRun"] == "false" )
192 slackSend(color:"FF0000", message: "[" + prop["ONOSBranch"] + "]" + testName + " : Failed!\n"
193 + resultContents[ 1 ] + "\n"
194 + "https://onos-jenkins.onlab.us/blue/organizations/jenkins/${env.JOB_NAME}/detail/${env.JOB_NAME}/${env.BUILD_NUMBER}/pipeline" )
195 Failed
196 }
Devin Lim90803a82017-08-29 13:41:44 -0700197 }
198 }
199 }
Devin Lim90803a82017-08-29 13:41:44 -0700200 }
201 }
202}