blob: 8493f3c00f45b7b12601d82288e504074cd75e93 [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 HA tests
4
5def prop = null
6node("TestStation-VMs"){
7 prop = readProperties(file:'/var/jenkins/TestONOS.property')
8}
9// TODO: Exception handling around steps
10HA = [
11"HAsanity" : [wiki_link:prop["WikiPrefix"]+"-"+"HA Sanity", wiki_file:"HAsanityWiki.txt"],
12"HAswapNodes" : [wiki_link:prop["WikiPrefix"]+"-"+"HA Swap Nodes", wiki_file:"HAswapNodesWiki.txt"],
13"HAscaling" : [wiki_link:prop["WikiPrefix"]+"-"+"HA Scaling", wiki_file:"HAscalingWiki.txt"],
14"HAclusterRestart" : [wiki_link:prop["WikiPrefix"]+"-"+"HA Cluster Restart", wiki_file:"HAclusterRestartWiki.txt"],
15"HAstopNodes" : [wiki_link:prop["WikiPrefix"]+"-"+"HA Stop Nodes", wiki_file:"HAstopNodes.txt"],
16"HAfullNetPartition" : [wiki_link:prop["WikiPrefix"]+"-"+"HA Full Network Partition", wiki_file:"HAfullNetPartitionWiki.txt"],
17"HAsingleInstanceRestart" : [wiki_link:prop["WikiPrefix"]+"-"+"HA Single Instance Restart", wiki_file:"HAsingleInstanceRestartWiki.txt"],
18"HAkillNodes" : [wiki_link:prop["WikiPrefix"]+"-"+"HA Kill Nodes", wiki_file:"HAkillNodesWiki.txt"] ]
19
20table_name = "executed_test_tests"
21result_name = "executed_test_results"
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -070022graph_generator_file = "~/OnosSystemTest/TestON/JenkinsFile/scripts/testCaseGraphGenerator.R"
Devin Lim90803a82017-08-29 13:41:44 -070023graph_saved_directory = "/var/jenkins/workspace/Pipeline_postjob_VM/"
24
25echo("Testcases:")
26def testsToRun = null
27testsToRun = prop["Tests"].tokenize("\n;, ")
28for ( String test : testsToRun ) {
29 println test
30}
31
32def tests = [:]
33for( String test : HA.keySet() ){
34 toBeRun = testsToRun.contains( test )
35 def stepName = ( toBeRun ? "" : "Not " ) + "Running $test"
36 tests[stepName] = HATest(test, toBeRun, prop)
37}
38
Devin Lim61657e42017-10-09 17:24:40 -070039def now = new Date()
Devin Lim90803a82017-08-29 13:41:44 -070040// run the tests
41for ( test in tests.keySet() ){
42 tests[test].call()
43}
Devin Lim79af50f2017-10-26 14:26:47 -070044try{
45 if( prop["manualRun"] == "false" ){
46 def end = new Date()
47 TimeDuration duration = TimeCategory.minus( end, now )
48 slackSend( color:"#5816EE", message: "HA tests ended at: " + end.toString() + "\nTime took : " + duration )
49 }
Devin Lim61657e42017-10-09 17:24:40 -070050}
Devin Lim79af50f2017-10-26 14:26:47 -070051catch(all){}
52
Devin Lim90803a82017-08-29 13:41:44 -070053// The testName should be the key from the FUNC
54def HATest( testName, toBeRun, prop ) {
55 return {
Devin Lim79af50f2017-10-26 14:26:47 -070056 catchError{
Devin Lim90803a82017-08-29 13:41:44 -070057 stage(testName) {
58 if ( toBeRun ){
59 workSpace = "/var/jenkins/workspace/"+testName
60 def fileContents = ""
61 node("TestStation-VMs"){
62 withEnv(['ONOSBranch='+prop["ONOSBranch"],
63 'ONOSJVMHeap='+prop["ONOSJVMHeap"],
64 'TestONBranch='+prop["TestONBranch"],
65 'ONOSTag='+prop["ONOSTag"],
66 'WikiPrefix='+prop["WikiPrefix"],
67 'WORKSPACE='+workSpace]){
68 sh '''#!/bin/bash -l
69 set -i # interactive
70 set +e
71 shopt -s expand_aliases # expand alias in non-interactive mode
72 export PYTHONUNBUFFERED=1
73
74 ifconfig
75
76 echo "ONOS Branch is: ${ONOSBranch}"
77 echo "TestON Branch is: ${TestONBranch}"
78 echo "Test date: "
79 date
80
81 cd ~
82 export PATH=$PATH:onos/tools/test/bin
83
84 timeout 240 stc shutdown | head -100
85 timeout 240 stc teardown | head -100
86 timeout 240 stc shutdown | head -100
87
88 cd ~/OnosSystemTest/TestON/bin
89 git log |head
90 ./cleanup.sh -f
91 ''' + "./cli.py run " + testName+ '''
92 ./cleanup.sh -f
93 cd'''
94
95 // For the Wiki page
96 sh '''#!/bin/bash -i
97 set +e
98 echo "ONOS Branch is: ${ONOSBranch}"
99 echo "TestON Branch is: ${TestONBranch}"
100
101 echo "Job name is: "''' + testName + '''
102 echo "Workspace is: ${WORKSPACE}/"
103
104 echo "Wiki page to post is: ${WikiPrefix}-"
105
106 # remove any leftover files from previous tests
107 sudo rm ${WORKSPACE}/*Wiki.txt
108 sudo rm ${WORKSPACE}/*Summary.txt
109 sudo rm ${WORKSPACE}/*Result.txt
110 sudo rm ${WORKSPACE}/*.csv
111
112 #copy files to workspace
113 cd `ls -t ~/OnosSystemTest/TestON/logs/*/ | head -1 | sed 's/://'`
114 sudo cp *.txt ${WORKSPACE}/
115 sudo cp *.csv ${WORKSPACE}/
116 cd ${WORKSPACE}/
117 for i in *.csv
118 do mv "$i" "$WikiPrefix"-"$i"
119 done
120 ls -al
121 cd '''
122
Devin Lim61657e42017-10-09 17:24:40 -0700123 if( prop["manualRun"] == "false" || prop["postResult"] == "true" ){
Devin Lim90803a82017-08-29 13:41:44 -0700124 // Post Results
125 withCredentials([
126 string(credentialsId: 'db_pass', variable: 'pass'),
127 string(credentialsId: 'db_user', variable: 'user'),
128 string(credentialsId: 'db_host', variable: 'host'),
129 string(credentialsId: 'db_port', variable: 'port')]) {
130 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);\""
131
132 sh '''#!/bin/bash
Devin Lim90803a82017-08-29 13:41:44 -0700133 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 set +e
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+"/"+HA[testName]['wiki_file']
165 }
166 }
167
Devin Lim61657e42017-10-09 17:24:40 -0700168 if( prop["manualRun"] == "false" || prop["postResult"] == "true" ){
Devin Lim90803a82017-08-29 13:41:44 -0700169 def post = build job: "Pipeline_postjob_VM", propagate: false,
170 parameters: [
171 string(name: 'Wiki_Contents', value: fileContents),
172 string(name: 'Wiki_Link', value: HA[testName]['wiki_link'])
173 ]
174 }
175 node("TestStation-VMs"){
Devin Lim79af50f2017-10-26 14:26:47 -0700176 resultContents = readFile workSpace + "/" + testName + "Result.txt"
177 resultContents = resultContents.split("\n")
178 if( resultContents[ 0 ] == "1" ){
179 print "All passed"
180 }else{
181 print "Failed"
182 if( prop["manualRun"] == "false" )
183 slackSend(color:"FF0000", message: "[" + prop["ONOSBranch"] + "]" + testName + " : Failed!\n"
184 + resultContents[ 1 ] + "\n"
185 + "https://onos-jenkins.onlab.us/blue/organizations/jenkins/${env.JOB_NAME}/detail/${env.JOB_NAME}/${env.BUILD_NUMBER}/pipeline" )
186 Failed
187 }
Devin Lim90803a82017-08-29 13:41:44 -0700188 }
189 }
190 }
Devin Lim90803a82017-08-29 13:41:44 -0700191 }
192 }
193}