blob: 578b2d85627374461bd2f54e68e77744d7c5bfde [file] [log] [blame]
Devin Lim61643762017-12-07 15:55:38 -08001#!groovy
2import groovy.time.*
Devin Lim81ab48b2018-02-09 14:24:57 -08003generalFuncs = evaluate readTrusted( 'TestON/JenkinsFile/GeneralFuncs.groovy' )
Jeremy Ronquillo14ecc172018-03-05 09:57:17 -08004
Devin Lim61643762017-12-07 15:55:38 -08005def initializeTrend( machine ){
6 table_name = "executed_test_tests"
7 result_name = "executed_test_results"
8 testMachine = "TestStation-" + machine + "s";
9 this.machine = machine
10 isSCPF = false
Devin Lim981f80b2018-04-09 11:25:59 -070011 isTrend = true
Devin Lim61643762017-12-07 15:55:38 -080012 generalFuncs.initBasicVars();
13}
14def initialize( type, SCPFfuncs ){
15 init( type )
16 SCPFfunc = SCPFfuncs
17 isSCPF = true
18 machine = machineType[ type ]
19}
20def initialize( type ){
21 init( type )
22 SCPFfunc = null
23 table_name = "executed_test_tests"
24 result_name = "executed_test_results"
25 trend_generator_file = generalFuncs.rScriptLocation + "testCategoryTrend.R"
26 build_stats_generator_file = generalFuncs.rScriptLocation + "testCategoryBuildStats.R"
27 isSCPF = false
28}
29def init( type ){
30 machineType = [ "FUNC" : "VM",
31 "HA" : "VM",
Devin Lim431408d2018-03-23 17:51:31 -070032 "SR" : "Fabric",
Devin Lim61643762017-12-07 15:55:38 -080033 "SCPF" : "BM",
34 "USECASE" : "BM" ]
35 testType = type;
36 testMachine = "TestStation-" + machineType[ type ] + "s";
Devin Lim981f80b2018-04-09 11:25:59 -070037 isTrend = false
Devin Lim61643762017-12-07 15:55:38 -080038 generalFuncs.initBasicVars();
39}
Devin Lim86e40532018-04-06 12:44:06 -070040def additionalInitForSR( branch ){
Devin Limc38e6932018-04-06 18:04:33 -070041 testMachine = ( ( new StringBuilder( testMachine ) ).insert( testMachine.size()-1, fabricOn( branch ) ) ).toString()
Devin Lim6cccad52018-04-09 11:32:19 -070042 if( isTrend )
43 machine += fabricOn( branch )
44 else
45 machineType[ testType ] += fabricOn( branch )
Devin Lim86e40532018-04-06 12:44:06 -070046 print testMachine
47}
48def fabricOn( branch ){
Devin Limc4054d52018-04-13 18:58:33 -070049 return branch.reverse().take(4).reverse() == "1.13" ? '2' : '3'
50// Temp Fix return branch.reverse().take(6).reverse() == "master" ? '2' : '3'
Devin Lim86e40532018-04-06 12:44:06 -070051}
Devin Lim61643762017-12-07 15:55:38 -080052def printType(){
53 echo testType;
54 echo testMachine;
55}
56def getProperties(){
57 node( testMachine ){
58 return readProperties( file:'/var/jenkins/TestONOS.property' );
59 }
60}
61def getTestsToRun( testList ){
62 testList.tokenize("\n;, ")
63}
64def getCurrentTime(){
Devin Limd1fb8e92018-02-28 16:29:33 -080065 TimeZone.setDefault( TimeZone.getTimeZone('PST') )
Devin Lim61643762017-12-07 15:55:38 -080066 return new Date();
67}
68def getTotalTime( start, end ){
69 return TimeCategory.minus( end, start );
70}
71def printTestToRun( testList ){
72 for ( String test : testList ) {
73 println test;
74 }
75}
76def sendResultToSlack( start, isManualRun, branch ){
77 try{
78 if( isManualRun == "false" ){
79 end = getCurrentTime();
80 TimeDuration duration = TimeCategory.minus( end , start );
81 slackSend( color:"#5816EE",
82 message: testType + "-" + branch + " tests ended at: " + end.toString() + "\nTime took : " + duration )
83 }
84 }
85 catch( all ){}
86}
87def initAndRunTest( testName, testCategory ){
Devin Limf5bf9b52018-02-28 18:16:21 -080088 // after ifconfig : ''' + borrowCell( testName ) + '''
Devin Lim61643762017-12-07 15:55:38 -080089 return '''#!/bin/bash -l
90 set -i # interactive
91 set +e
92 shopt -s expand_aliases # expand alias in non-interactive mode
93 export PYTHONUNBUFFERED=1
94 ifconfig
Devin Lim61643762017-12-07 15:55:38 -080095 echo "ONOS Branch is: $ONOSBranch"
96 echo "TestON Branch is: $TestONBranch"
97 echo "Test date: "
98 date
99 cd ~
100 export PATH=$PATH:onos/tools/test/bin
101 timeout 240 stc shutdown | head -100
102 timeout 240 stc teardown | head -100
103 timeout 240 stc shutdown | head -100
104 cd ~/OnosSystemTest/TestON/bin
105 git log |head
106 ./cleanup.sh -f
Devin Lima7b97a42018-04-09 14:26:38 -0700107 ''' + "./cli.py run " + ( !isSCPF ? testName : testCategory[ testName ][ 'test' ] ) + " --params GRAPH/nodeCluster=" + machineType[ testType ] + '''
Devin Lim61643762017-12-07 15:55:38 -0800108 ./cleanup.sh -f
109 # cleanup config changes
110 cd ~/onos/tools/package/config
111 git clean -df'''
112}
113def copyLogs( testName ){
114 result = ""
115 if( testType == "SR" ){
116 result = '''
117 sudo rm /var/jenkins/workspace/SR-log-${WikiPrefix}/*
118 sudo cp *karaf.log.* /var/jenkins/workspace/SR-log-${WikiPrefix}/
119 sudo cp *Flows* /var/jenkins/workspace/SR-log-${WikiPrefix}/
120 sudo cp *Groups* /var/jenkins/workspace/SR-log-${WikiPrefix}/
Devin Lima7b97a42018-04-09 14:26:38 -0700121 sudo cp *.tar.gz /var/jenkins/workspace/SR-log-${WikiPrefix}/
Devin Lim61643762017-12-07 15:55:38 -0800122 '''
123 }
124 return result
125}
126def cleanAndCopyFiles( testName ){
127 return '''#!/bin/bash -i
128 set +e
129 echo "ONOS Branch is: ${ONOSBranch}"
130 echo "TestON Branch is: ${TestONBranch}"
131 echo "Job name is: "''' + testName + '''
132 echo "Workspace is: ${WORKSPACE}/"
133 echo "Wiki page to post is: ${WikiPrefix}-"
134 # remove any leftover files from previous tests
135 sudo rm ${WORKSPACE}/*Wiki.txt
136 sudo rm ${WORKSPACE}/*Summary.txt
137 sudo rm ${WORKSPACE}/*Result.txt
138 sudo rm ${WORKSPACE}/*.csv
139 #copy files to workspace
140 cd `ls -t ~/OnosSystemTest/TestON/logs/*/ | head -1 | sed 's/://'`
141 ''' + copyLogs( testName ) + '''
142 sudo cp *.txt ${WORKSPACE}/
143 sudo cp *.csv ${WORKSPACE}/
144 cd ${WORKSPACE}/
145 for i in *.csv
146 do mv "$i" "$WikiPrefix"-"$i"
147 done
148 ls -al
149 cd '''
150}
151def fetchLogs( testName ){
152 return '''#!/bin/bash
153 set +e
154 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}
170def isPostingResult( manual, postresult ){
171 return manual == "false" || postresult == "true"
172}
173def postResult( prop, graphOnly ){
174 if( graphOnly || isPostingResult( prop[ "manualRun" ], prop[ "postResult" ] ) ){
175 def post = build job: "postjob-" + ( graphOnly ? machine : machineType[ testType ] ), propagate: false
176 }
177}
178def postLogs( testName, prefix ){
179 resultURL = ""
180 if( testType == "SR" ){
181 def post = build job: "SR-log-" + prefix, propagate: false
182 resultURL = post.getAbsoluteUrl()
183 }
184 return resultURL
185}
186def getSlackChannel(){
187 return "#" + ( testType == "SR" ? "sr-failures" : "jenkins-related" )
188}
189def analyzeResult( prop, workSpace, testName, otherTestName, resultURL, wikiLink, isSCPF ){
190 node( testMachine ){
191 resultContents = readFile workSpace + "/" + testName + "Result.txt"
192 resultContents = resultContents.split("\n")
193 if( resultContents[ 0 ] == "1" ){
194 print "All passed"
195 }else{
196 print "Failed"
197 if( prop[ "manualRun" ] == "false" ){
198 slackSend( channel:getSlackChannel(), color:"FF0000", message: "[" + prop[ "ONOSBranch" ] + "]"
199 + otherTestName + " : Failed!\n" + resultContents[ 1 ] + "\n"
200 + "[TestON log] : \n"
Devin Limd1fb8e92018-02-28 16:29:33 -0800201 + "https://jenkins.onosproject.org/blue/organizations/jenkins/${env.JOB_NAME}/detail/${env.JOB_NAME}/${env.BUILD_NUMBER}/pipeline"
Devin Lim61643762017-12-07 15:55:38 -0800202 + ( isSCPF ? "" : ( "\n[Result on Wiki] : \n" + "https://wiki.onosproject.org/display/ONOS/" + wikiLink.replaceAll( "\\s","+" ) ) )
203 + ( resultURL != "" ? ( "\n[Karaf log] : \n" + resultURL + "artifact/" ) : "" ),
204 teamDomain: 'onosproject' )
205 }
206 Failed
207 }
208 }
209}
Devin Lime89761a2018-03-16 17:52:57 -0700210def publishToConfluence( isManualRun, isPostResult, wikiLink, file ){
211 if( isPostingResult( isManualRun, isPostResult ) ){
Devin Lim61643762017-12-07 15:55:38 -0800212 publishConfluence siteName: 'wiki.onosproject.org', pageName: wikiLink, spaceName: 'ONOS',
Devin Lim1253ae82018-02-26 11:13:36 -0800213 attachArchivedArtifacts: true, buildIfUnstable: true,
Devin Lim61643762017-12-07 15:55:38 -0800214 editorList: [
215 confluenceWritePage( confluenceFile( file ) )
216 ]
217 }
218
219}
220def runTest( testName, toBeRun, prop, pureTestName, graphOnly, testCategory, graph_generator_file, graph_saved_directory ) {
221 return {
222 catchError{
223 stage( testName ) {
224 if ( toBeRun ){
225 workSpace = "/var/jenkins/workspace/" + testName
226 def fileContents = ""
227 node( testMachine ){
228 withEnv( [ 'ONOSBranch=' + prop[ "ONOSBranch" ],
229 'ONOSJVMHeap=' + prop[ "ONOSJVMHeap" ],
230 'TestONBranch=' + prop[ "TestONBranch" ],
231 'ONOSTag=' + prop[ "ONOSTag" ],
232 'WikiPrefix=' + prop[ "WikiPrefix" ],
233 'WORKSPACE=' + workSpace ] ){
234 if( ! graphOnly ){
235 sh initAndRunTest( testName, testCategory )
236 // For the Wiki page
237 sh cleanAndCopyFiles( pureTestName )
238 }
239 databaseAndGraph( prop, testName, graphOnly, graph_generator_file, graph_saved_directory )
240 if( ! graphOnly ){
241 sh fetchLogs( pureTestName )
242 if( !isSCPF )
Devin Lime89761a2018-03-16 17:52:57 -0700243 publishToConfluence( prop[ "manualRun" ], prop[ "postResult" ],
244 testCategory[ testName ][ 'wiki_link' ],
245 workSpace + "/" + testCategory[ testName ][ 'wiki_file' ] )
Devin Lim61643762017-12-07 15:55:38 -0800246 }
247 }
248
249
250 }
251 postResult( prop, graphOnly )
252 if( ! graphOnly ){
253 resultURL = postLogs( testName, prop[ "WikiPrefix" ] )
254 analyzeResult( prop, workSpace, pureTestName, testName, resultURL, isSCPF ? "" : testCategory[ testName ][ 'wiki_link' ], isSCPF )
255 }
256 }
257 }
258 }
259 }
260}
261def borrowCell( testName ){
262 result = ""
263 if( testType == "SR" ){
264 result = '''
265 cd
266 source ~/borrow.cell
267 '''
268 }
269 return result
270}
271def databaseAndGraph( prop, testName, graphOnly, graph_generator_file, graph_saved_directory ){
272 if( graphOnly || isPostingResult( prop[ "manualRun" ], prop[ "postResult" ] ) ){
273 // Post Results
274 withCredentials( [
275 string( credentialsId: 'db_pass', variable: 'pass' ),
276 string( credentialsId: 'db_user', variable: 'user' ),
277 string( credentialsId: 'db_host', variable: 'host' ),
278 string( credentialsId: 'db_port', variable: 'port' ) ] ) {
279 def database_command = generalFuncs.database_command_create( pass, host, port, user ) + ( !isSCPF ? sqlCommand( testName ) : SCPFfunc.sqlCommand( testName ) )
280 sh '''#!/bin/bash
281 export DATE=\$(date +%F_%T)
282 cd ~
283 pwd ''' + ( graphOnly ? "" : ( !isSCPF ? databasePart( prop[ "WikiPrefix" ], testName, database_command ) :
284 SCPFfunc.databasePart( testName, database_command ) ) ) + '''
285 ''' + ( !isSCPF ? graphGenerating( host, port, user, pass, testName, prop, graph_saved_directory, graph_generator_file ) : SCPFfunc.getGraphGeneratingCommand( host, port, user, pass, testName, prop ) )
286 }
287 }
288}
Devin Lim86e40532018-04-06 12:44:06 -0700289def generateCategoryStatsGraph( testMachineOn, manualRun, postresult, stat_file, pie_file, type, branch, testListPart, save_path, pieTestListPart ){
Devin Lim61643762017-12-07 15:55:38 -0800290
291 if( isPostingResult( manualRun, postresult ) ){
Devin Lim86e40532018-04-06 12:44:06 -0700292 node( testMachineOn ){
Devin Lim61643762017-12-07 15:55:38 -0800293
294 withCredentials( [
295 string( credentialsId: 'db_pass', variable: 'pass' ),
296 string( credentialsId: 'db_user', variable: 'user' ),
297 string( credentialsId: 'db_host', variable: 'host' ),
298 string( credentialsId: 'db_port', variable: 'port' ) ] ) {
299 sh '''#!/bin/bash
300 ''' + generalFuncs.basicGraphPart( generalFuncs.rScriptLocation + stat_file, host, port, user, pass, type, branch ) + " \"" + testListPart + "\" latest " + save_path + '''
301 ''' + getOverallPieGraph( generalFuncs.rScriptLocation + pie_file, host, port, user, pass, branch, type, pieTestListPart, 'y', save_path ) + '''
302 ''' + getOverallPieGraph( generalFuncs.rScriptLocation + pie_file, host, port, user, pass, branch, type, pieTestListPart, 'n', save_path )
303 }
304 }
305 postResult( [], true )
306 }
307}
308def makeTestList( list, commaNeeded ){
309 return generalFuncs.getTestList( list ) + ( commaNeeded ? "," : "" )
310}
311def createStatsList( testCategory, list, semiNeeded ){
312 return testCategory + "-" + generalFuncs.getTestList( list ) + ( semiNeeded ? ";" : "" )
313}
314def generateOverallGraph( prop, testCategory, graph_saved_directory ){
315
316 if( isPostingResult( prop[ "manualRun" ], prop[ "postResult" ] ) ){
317 node( testMachine ){
318
319 withCredentials( [
320 string( credentialsId: 'db_pass', variable: 'pass' ),
321 string( credentialsId: 'db_user', variable: 'user' ),
322 string( credentialsId: 'db_host', variable: 'host' ),
323 string( credentialsId: 'db_port', variable: 'port' ) ] ) {
324 testList = generalFuncs.getTestList( testCategory )
325 sh '''#!/bin/bash
326 ''' + generalFuncs.basicGraphPart( trend_generator_file, host, port, user, pass, testType, prop[ "ONOSBranch" ] ) + " " + testList + " 20 " + graph_saved_directory
327 }
328 }
329 postResult( prop, false )
330 }
331}
332def getOverallPieGraph( file, host, port, user, pass, branch, type, testList, yOrN, path ){
333 return generalFuncs.basicGraphPart( file, host, port, user, pass, type, branch ) + " \"" + testList + "\" latest " + yOrN + " " + path
334}
335def sqlCommand( testName ){
336 return "\"INSERT INTO " + table_name + " VALUES('\$DATE','" + result_name + "','" + testName + "',\$BUILD_NUMBER, '\$ONOSBranch', \$line);\" "
337}
338def graphGenerating( host, port, user, pass, testName, prop, graph_saved_directory, graph_generator_file ){
339 return generalFuncs.basicGraphPart( graph_generator_file, host, port, user, pass, testName, prop[ "ONOSBranch" ] ) + " 20 " + graph_saved_directory
340}
341def databasePart( wikiPrefix, testName, database_command ){
342 return '''
343 sed 1d ''' + workSpace + "/" + wikiPrefix + "-" + testName + '''.csv | while read line
344 do
345 echo \$line
346 echo ''' + database_command + '''
347 done '''
348}
Devin Lim86e40532018-04-06 12:44:06 -0700349def generateStatGraph( testMachineOn, onos_branch, AllTheTests, stat_graph_generator_file, pie_graph_generator_file, graph_saved_directory ){
Jeremy Ronquillo14ecc172018-03-05 09:57:17 -0800350 testListPart = createStatsList( "FUNC", AllTheTests[ "FUNC" ], true ) +
351 createStatsList( "HA", AllTheTests[ "HA" ], true ) +
352 createStatsList( "USECASE", AllTheTests[ "USECASE" ], false )
353 pieTestList = makeTestList( AllTheTests[ "FUNC" ], true ) +
354 makeTestList( AllTheTests[ "HA" ], true ) +
355 makeTestList( AllTheTests[ "USECASE" ], false )
Devin Lim86e40532018-04-06 12:44:06 -0700356 generateCategoryStatsGraph( testMachineOn, "false", "true", stat_graph_generator_file, pie_graph_generator_file, "ALL", onos_branch, testListPart, graph_saved_directory, pieTestList )
Jeremy Ronquillo14ecc172018-03-05 09:57:17 -0800357}
Jeremy Ronquillof78a6ca2018-03-12 09:20:57 -0700358def branchWithPrefix( branch ){
359 return ( ( branch != "master" ) ? "onos-" : "" ) + branch
360}
Devin Lim1253ae82018-02-26 11:13:36 -0800361return this;