blob: 3c78dbe50504910983bcf9033e2bfeaab6f55348 [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"
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -070029graph_generator_file = "~/OnosSystemTest/TestON/JenkinsFile/scripts/testCaseGraphGenerator.R"
Devin Lim90803a82017-08-29 13:41:44 -070030graph_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
Devin Lima0e52eb2017-09-13 18:35:12 -070096 set +e
Devin Lim90803a82017-08-29 13:41:44 -070097 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
Devin Lim90803a82017-08-29 13:41:44 -0700132 export DATE=\$(date +%F_%T)
133 cd ~
134 pwd
135 sed 1d ''' + workSpace + "/" + prop["WikiPrefix"] + "-" + testName + '''.csv | while read line
136 do
137 echo \$line
138 echo ''' + database_command + '''
139
140 done
141 Rscript ''' + graph_generator_file + " " + host + " " + port + " " + user + " " + pass + " " + testName + " " + prop["ONOSBranch"] + " 20 " + graph_saved_directory
142
143 }
144 }
145 // Fetch Logs
146 sh '''#!/bin/bash
Devin Lima0e52eb2017-09-13 18:35:12 -0700147 set +e
Devin Lim90803a82017-08-29 13:41:44 -0700148 cd ~/OnosSystemTest/TestON/logs
149 echo "Job Name is: " + ''' + testName + '''
150 TestONlogDir=$(ls -t | grep ${TEST_NAME}_ |head -1)
151 echo "########################################################################################"
152 echo "##### copying ONOS logs from all nodes to TestON/logs directory: ${TestONlogDir}"
153 echo "########################################################################################"
154 cd $TestONlogDir
155 if [ $? -eq 1 ]
156 then
157 echo "Job name does not match any test suite name to move log!"
158 else
159 pwd
160 for i in $OC{1..7}; do onos-fetch-logs $i || echo log does not exist; done
161 fi
162 cd'''
163 fileContents = readFile workSpace+"/"+USECASE[testName]['wiki_file']
164
165 }
166 }
167 if( prop["manualRun"] == "false" ){
168 def post = build job: "Pipeline_postjob_BM", propagate: false,
169 parameters: [
170 string(name: 'Wiki_Contents', value: fileContents),
171 string(name: 'Wiki_Link', value: USECASE[testName]['wiki_link'])
172 ]
173 }
174 node("TestStation-BMs"){
175 sh '''#!/bin/bash
176
177 if [ -e ''' + workSpace + "/" + testName + "Result.txt ] && grep -q \"1\" " + workSpace + "/" + testName + "Result.txt" + '''
178 then
179 echo ''' + testName + " : All passed." + '''
180 else
181 echo ''' + testName + " : not all passed." + '''
182 DoingThisToSetTheResultFalse
183 fi'''
184 }
185 }
186 }
187 }
188 }
189}