blob: 63551b9c4021526df07a0dff148dcb558d64128b [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 Lim61657e42017-10-09 17:24:40 -070051if( prop["manualRun"] == "false" ){
52 def end = new Date()
53 TimeDuration duration = TimeCategory.minus( end, now )
54 slackSend( color:"#5816EE", message: "USECASE tests ended at: " + end.toString() + "\nTime took : " + duration )
55}
Devin Lim90803a82017-08-29 13:41:44 -070056// The testName should be the key from the FUNC
57def USECASETest( testName, toBeRun, prop ) {
58 return {
Devin Lim61657e42017-10-09 17:24:40 -070059 try{
Devin Lim90803a82017-08-29 13:41:44 -070060 stage(testName) {
61 if ( toBeRun ){
62 workSpace = "/var/jenkins/workspace/"+testName
63 def fileContents = ""
64 node("TestStation-BMs"){
65 withEnv(['ONOSBranch='+prop["ONOSBranch"],
66 'ONOSJVMHeap='+prop["ONOSJVMHeap"],
67 'TestONBranch='+prop["TestONBranch"],
68 'ONOSTag='+prop["ONOSTag"],
69 'WikiPrefix='+prop["WikiPrefix"],
70 'WORKSPACE='+workSpace]){
71 sh '''#!/bin/bash -l
72 set -i # interactive
73 set +e
74 shopt -s expand_aliases # expand alias in non-interactive mode
75 export PYTHONUNBUFFERED=1
76
77 ifconfig
78
79 echo "ONOS Branch is: $ONOSBranch"
80 echo "TestON Branch is: $TestONBranch"
81 echo "Test date: "
82 date
83
84 cd ~
85 export PATH=$PATH:onos/tools/test/bin
86
87 . .bash_killcmd
88 killTestONall
89 onos-group uninstall
90 timeout 240 stc teardown | head -100
91
92 cd ~/OnosSystemTest/TestON/bin
93 git log |head
94 ./cleanup.sh -f
95 ''' + "./cli.py run " + testName + '''
96 ./cleanup.sh -f
97 cd ~/onos/tools/package/config
98 git clean -df'''
99
100 // For the Wiki page
101 sh '''#!/bin/bash -i
Devin Lima0e52eb2017-09-13 18:35:12 -0700102 set +e
Devin Lim90803a82017-08-29 13:41:44 -0700103 echo "ONOS Branch is: ${ONOSBranch}"
104 echo "TestON Branch is: ${TestONBranch}"
105
106 echo "Job name is: "''' + testName + '''
107 echo "Workspace is: ${WORKSPACE}/"
108
109 echo "Wiki page to post is: ${WikiPrefix}-"
110
111 # remove any leftover files from previous tests
112 sudo rm ${WORKSPACE}/*Wiki.txt
113 sudo rm ${WORKSPACE}/*Summary.txt
114 sudo rm ${WORKSPACE}/*Result.txt
115 sudo rm ${WORKSPACE}/*.csv
116
117 #copy files to workspace
118 cd `ls -t ~/OnosSystemTest/TestON/logs/*/ | head -1 | sed 's/://'`
119 sudo cp *.txt ${WORKSPACE}/
120 sudo cp *.csv ${WORKSPACE}/
121 cd ${WORKSPACE}/
122 for i in *.csv
123 do mv "$i" "$WikiPrefix"-"$i"
124 done
125 ls -al
126 cd '''
127
Devin Lim61657e42017-10-09 17:24:40 -0700128 if( prop["manualRun"] == "false" || prop["postResult"] == "true" ){
Devin Lim90803a82017-08-29 13:41:44 -0700129 // Post Results
130 withCredentials([
131 string(credentialsId: 'db_pass', variable: 'pass'),
132 string(credentialsId: 'db_user', variable: 'user'),
133 string(credentialsId: 'db_host', variable: 'host'),
134 string(credentialsId: 'db_port', variable: 'port')]) {
135 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);\""
136
137 sh '''#!/bin/bash
Devin Lim90803a82017-08-29 13:41:44 -0700138 export DATE=\$(date +%F_%T)
139 cd ~
140 pwd
141 sed 1d ''' + workSpace + "/" + prop["WikiPrefix"] + "-" + testName + '''.csv | while read line
142 do
143 echo \$line
144 echo ''' + database_command + '''
145
146 done
147 Rscript ''' + graph_generator_file + " " + host + " " + port + " " + user + " " + pass + " " + testName + " " + prop["ONOSBranch"] + " 20 " + graph_saved_directory
148
149 }
150 }
151 // Fetch Logs
152 sh '''#!/bin/bash
Devin Lima0e52eb2017-09-13 18:35:12 -0700153 set +e
Devin Lim90803a82017-08-29 13:41:44 -0700154 cd ~/OnosSystemTest/TestON/logs
155 echo "Job Name is: " + ''' + testName + '''
156 TestONlogDir=$(ls -t | grep ${TEST_NAME}_ |head -1)
157 echo "########################################################################################"
158 echo "##### copying ONOS logs from all nodes to TestON/logs directory: ${TestONlogDir}"
159 echo "########################################################################################"
160 cd $TestONlogDir
161 if [ $? -eq 1 ]
162 then
163 echo "Job name does not match any test suite name to move log!"
164 else
165 pwd
166 for i in $OC{1..7}; do onos-fetch-logs $i || echo log does not exist; done
167 fi
168 cd'''
169 fileContents = readFile workSpace+"/"+USECASE[testName]['wiki_file']
170
171 }
172 }
Devin Lim61657e42017-10-09 17:24:40 -0700173 if( prop["manualRun"] == "false" || prop["postResult"] == "true" ){
Devin Lim90803a82017-08-29 13:41:44 -0700174 def post = build job: "Pipeline_postjob_BM", propagate: false,
175 parameters: [
176 string(name: 'Wiki_Contents', value: fileContents),
177 string(name: 'Wiki_Link', value: USECASE[testName]['wiki_link'])
178 ]
179 }
180 node("TestStation-BMs"){
181 sh '''#!/bin/bash
182
183 if [ -e ''' + workSpace + "/" + testName + "Result.txt ] && grep -q \"1\" " + workSpace + "/" + testName + "Result.txt" + '''
184 then
185 echo ''' + testName + " : All passed." + '''
186 else
187 echo ''' + testName + " : not all passed." + '''
188 DoingThisToSetTheResultFalse
189 fi'''
190 }
191 }
192 }
Devin Lim61657e42017-10-09 17:24:40 -0700193 }catch (all) {
194 catchError{
195 if( prop["manualRun"] == "false" )
Devin Lim4d57f7e2017-10-16 14:01:09 -0700196 slackSend(color:"FF0000", message: "[" + prop["ONOSBranch"] + "]" + testName + " : Failed!\n"
197 + "https://onos-jenkins.onlab.us/blue/organizations/jenkins/${env.JOB_NAME}/detail/${env.JOB_NAME}/${env.BUILD_NUMBER}/pipeline" )
Devin Lim61657e42017-10-09 17:24:40 -0700198 Failed
199 }
Devin Lim90803a82017-08-29 13:41:44 -0700200 }
201 }
202}