blob: 84577a2797396125159c8b5f8ccbfc4e6189260a [file] [log] [blame]
Devin Lim90803a82017-08-29 13:41:44 -07001#!groovy
2// This is a Jenkinsfile for a scripted pipeline for the USECASETest tests
3
4// TODO: Exception handling around steps
5
6def prop = null
7node("TestStation-BMs"){
8 prop = readProperties(file:'/var/jenkins/TestONOS.property')
9}
10USECASE = [
11 "FUNCvirNetNB" : [wiki_link:prop["WikiPrefix"]+"-"+"FUNCvirNetNB", wiki_file:"FUNCvirNetNBWiki.txt"],
12 "FUNCbgpls" : [wiki_link:prop["WikiPrefix"]+"-"+"FUNCbgpls", wiki_file:"FUNCbgplsWiki.txt"],
13 "VPLSBasic" : [wiki_link:prop["WikiPrefix"]+"-"+"VPLSBasic", wiki_file:"VPLSBasicWiki.txt"],
14 "VPLSfailsafe" : [wiki_link:prop["WikiPrefix"]+"-"+"VPLSfailsafe", wiki_file:"VPLSfailsafeWiki.txt"],
15 "PLATdockertest": [wiki_link:"Docker Images sanity test", wiki_file:"PLATdockertestTableWiki.txt"],
16 "SRSanity": [wiki_link:prop["WikiPrefix"]+"-"+"SR Sanity", wiki_file:"SRSanityWiki.txt"],
17 "SRSwitchFailure": [wiki_link:prop["WikiPrefix"]+"-"+"SR Switch Failure", wiki_file:"SRSwitchFailureWiki.txt"],
18 "SRLinkFailure": [wiki_link:prop["WikiPrefix"]+"-"+"SR Link Failure", wiki_file:"SRLinkFailureWiki.txt"],
19 "SROnosFailure": [wiki_link:prop["WikiPrefix"]+"-"+"SR Onos node Failure", wiki_file:"SROnosFailureWiki.txt"],
20 "SRClusterRestart": [wiki_link:prop["WikiPrefix"]+"-"+"SR Cluster Restart", wiki_file:"SRClusterRestartWiki.txt"],
21 "SRDynamic": [wiki_link:prop["WikiPrefix"]+"-"+"SR Dynamic Config", wiki_file:"SRDynamicWiki.txt"],
22 "SRHA": [wiki_link:prop["WikiPrefix"]+"-"+"SR High Availability", wiki_file:"SRHighAvailabilityWiki.txt"],
23 "USECASE_SdnipFunction": [wiki_link:prop["WikiPrefix"]+"-"+"SDNIP Function", wiki_file:"USECASE_SdnipFunctionWiki.txt"],
24 "USECASE_SdnipFunctionCluster": [wiki_link:prop["WikiPrefix"]+"-"+"SDNIP Function Cluster", wiki_file:"USECASE_SdnipFunctionClusterWiki.txt"]
25]
26
27table_name = "executed_test_tests"
28result_name = "executed_test_results"
29graph_generator_file = "~/OnosSystemTest/TestON/JenkinsFile/testCaseGraphGenerator.R"
30graph_saved_directory = "/var/jenkins/workspace/Pipeline_postjob_BM/"
31
32echo("Testcases:")
33testsToRun = prop["Tests"].tokenize("\n;, ")
34for ( String test : testsToRun ) {
35 println test
36}
37
38def tests = [:]
39for( String test : USECASE.keySet() ){
40 toBeRun = testsToRun.contains( test )
41 def stepName = ( toBeRun ? "" : "Not " ) + "Running $test"
42 tests[stepName] = USECASETest(test, toBeRun, prop)
43}
44
45// run the tests
46for ( test in tests.keySet() ){
47 tests[test].call()
48}
49
50// The testName should be the key from the FUNC
51def USECASETest( testName, toBeRun, prop ) {
52 return {
53 catchError{
54 stage(testName) {
55 if ( toBeRun ){
56 workSpace = "/var/jenkins/workspace/"+testName
57 def fileContents = ""
58 node("TestStation-BMs"){
59 withEnv(['ONOSBranch='+prop["ONOSBranch"],
60 'ONOSJVMHeap='+prop["ONOSJVMHeap"],
61 'TestONBranch='+prop["TestONBranch"],
62 'ONOSTag='+prop["ONOSTag"],
63 'WikiPrefix='+prop["WikiPrefix"],
64 'WORKSPACE='+workSpace]){
65 sh '''#!/bin/bash -l
66 set -i # interactive
67 set +e
68 shopt -s expand_aliases # expand alias in non-interactive mode
69 export PYTHONUNBUFFERED=1
70
71 ifconfig
72
73 echo "ONOS Branch is: $ONOSBranch"
74 echo "TestON Branch is: $TestONBranch"
75 echo "Test date: "
76 date
77
78 cd ~
79 export PATH=$PATH:onos/tools/test/bin
80
81 . .bash_killcmd
82 killTestONall
83 onos-group uninstall
84 timeout 240 stc teardown | head -100
85
86 cd ~/OnosSystemTest/TestON/bin
87 git log |head
88 ./cleanup.sh -f
89 ''' + "./cli.py run " + testName + '''
90 ./cleanup.sh -f
91 cd ~/onos/tools/package/config
92 git clean -df'''
93
94 // For the Wiki page
95 sh '''#!/bin/bash -i
96
97 echo "ONOS Branch is: ${ONOSBranch}"
98 echo "TestON Branch is: ${TestONBranch}"
99
100 echo "Job name is: "''' + testName + '''
101 echo "Workspace is: ${WORKSPACE}/"
102
103 echo "Wiki page to post is: ${WikiPrefix}-"
104
105 # remove any leftover files from previous tests
106 sudo rm ${WORKSPACE}/*Wiki.txt
107 sudo rm ${WORKSPACE}/*Summary.txt
108 sudo rm ${WORKSPACE}/*Result.txt
109 sudo rm ${WORKSPACE}/*.csv
110
111 #copy files to workspace
112 cd `ls -t ~/OnosSystemTest/TestON/logs/*/ | head -1 | sed 's/://'`
113 sudo cp *.txt ${WORKSPACE}/
114 sudo cp *.csv ${WORKSPACE}/
115 cd ${WORKSPACE}/
116 for i in *.csv
117 do mv "$i" "$WikiPrefix"-"$i"
118 done
119 ls -al
120 cd '''
121
122 if( prop["manualRun"] == "false" ){
123 // Post Results
124 withCredentials([
125 string(credentialsId: 'db_pass', variable: 'pass'),
126 string(credentialsId: 'db_user', variable: 'user'),
127 string(credentialsId: 'db_host', variable: 'host'),
128 string(credentialsId: 'db_port', variable: 'port')]) {
129 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);\""
130
131 sh '''#!/bin/bash
132 set +e
133 export DATE=\$(date +%F_%T)
134 cd ~
135 pwd
136 sed 1d ''' + workSpace + "/" + prop["WikiPrefix"] + "-" + testName + '''.csv | while read line
137 do
138 echo \$line
139 echo ''' + database_command + '''
140
141 done
142 Rscript ''' + graph_generator_file + " " + host + " " + port + " " + user + " " + pass + " " + testName + " " + prop["ONOSBranch"] + " 20 " + graph_saved_directory
143
144 }
145 }
146 // Fetch Logs
147 sh '''#!/bin/bash
148
149 cd ~/OnosSystemTest/TestON/logs
150 echo "Job Name is: " + ''' + testName + '''
151 TestONlogDir=$(ls -t | grep ${TEST_NAME}_ |head -1)
152 echo "########################################################################################"
153 echo "##### copying ONOS logs from all nodes to TestON/logs directory: ${TestONlogDir}"
154 echo "########################################################################################"
155 cd $TestONlogDir
156 if [ $? -eq 1 ]
157 then
158 echo "Job name does not match any test suite name to move log!"
159 else
160 pwd
161 for i in $OC{1..7}; do onos-fetch-logs $i || echo log does not exist; done
162 fi
163 cd'''
164 fileContents = readFile workSpace+"/"+USECASE[testName]['wiki_file']
165
166 }
167 }
168 if( prop["manualRun"] == "false" ){
169 def post = build job: "Pipeline_postjob_BM", propagate: false,
170 parameters: [
171 string(name: 'Wiki_Contents', value: fileContents),
172 string(name: 'Wiki_Link', value: USECASE[testName]['wiki_link'])
173 ]
174 }
175 node("TestStation-BMs"){
176 sh '''#!/bin/bash
177
178 if [ -e ''' + workSpace + "/" + testName + "Result.txt ] && grep -q \"1\" " + workSpace + "/" + testName + "Result.txt" + '''
179 then
180 echo ''' + testName + " : All passed." + '''
181 else
182 echo ''' + testName + " : not all passed." + '''
183 DoingThisToSetTheResultFalse
184 fi'''
185 }
186 }
187 }
188 }
189 }
190}