blob: 4828143ad2e237ed461a6b26db759a18dfe0f2a1 [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 ){
49 return branch == "master" ? '2' : '3'
50}
Devin Lim61643762017-12-07 15:55:38 -080051def printType(){
52 echo testType;
53 echo testMachine;
54}
55def getProperties(){
56 node( testMachine ){
57 return readProperties( file:'/var/jenkins/TestONOS.property' );
58 }
59}
60def getTestsToRun( testList ){
61 testList.tokenize("\n;, ")
62}
63def getCurrentTime(){
Devin Limd1fb8e92018-02-28 16:29:33 -080064 TimeZone.setDefault( TimeZone.getTimeZone('PST') )
Devin Lim61643762017-12-07 15:55:38 -080065 return new Date();
66}
67def getTotalTime( start, end ){
68 return TimeCategory.minus( end, start );
69}
70def printTestToRun( testList ){
71 for ( String test : testList ) {
72 println test;
73 }
74}
75def sendResultToSlack( start, isManualRun, branch ){
76 try{
77 if( isManualRun == "false" ){
78 end = getCurrentTime();
79 TimeDuration duration = TimeCategory.minus( end , start );
80 slackSend( color:"#5816EE",
81 message: testType + "-" + branch + " tests ended at: " + end.toString() + "\nTime took : " + duration )
82 }
83 }
84 catch( all ){}
85}
86def initAndRunTest( testName, testCategory ){
Devin Limf5bf9b52018-02-28 18:16:21 -080087 // after ifconfig : ''' + borrowCell( testName ) + '''
Devin Lim61643762017-12-07 15:55:38 -080088 return '''#!/bin/bash -l
89 set -i # interactive
90 set +e
91 shopt -s expand_aliases # expand alias in non-interactive mode
92 export PYTHONUNBUFFERED=1
93 ifconfig
Devin Lim61643762017-12-07 15:55:38 -080094 echo "ONOS Branch is: $ONOSBranch"
95 echo "TestON Branch is: $TestONBranch"
96 echo "Test date: "
97 date
98 cd ~
99 export PATH=$PATH:onos/tools/test/bin
100 timeout 240 stc shutdown | head -100
101 timeout 240 stc teardown | head -100
102 timeout 240 stc shutdown | head -100
103 cd ~/OnosSystemTest/TestON/bin
104 git log |head
105 ./cleanup.sh -f
106 ''' + "./cli.py run " + ( !isSCPF ? testName : testCategory[ testName ][ 'test' ] ) + '''
107 ./cleanup.sh -f
108 # cleanup config changes
109 cd ~/onos/tools/package/config
110 git clean -df'''
111}
112def copyLogs( testName ){
113 result = ""
114 if( testType == "SR" ){
115 result = '''
116 sudo rm /var/jenkins/workspace/SR-log-${WikiPrefix}/*
117 sudo cp *karaf.log.* /var/jenkins/workspace/SR-log-${WikiPrefix}/
118 sudo cp *Flows* /var/jenkins/workspace/SR-log-${WikiPrefix}/
119 sudo cp *Groups* /var/jenkins/workspace/SR-log-${WikiPrefix}/
120 '''
121 }
122 return result
123}
124def cleanAndCopyFiles( testName ){
125 return '''#!/bin/bash -i
126 set +e
127 echo "ONOS Branch is: ${ONOSBranch}"
128 echo "TestON Branch is: ${TestONBranch}"
129 echo "Job name is: "''' + testName + '''
130 echo "Workspace is: ${WORKSPACE}/"
131 echo "Wiki page to post is: ${WikiPrefix}-"
132 # remove any leftover files from previous tests
133 sudo rm ${WORKSPACE}/*Wiki.txt
134 sudo rm ${WORKSPACE}/*Summary.txt
135 sudo rm ${WORKSPACE}/*Result.txt
136 sudo rm ${WORKSPACE}/*.csv
137 #copy files to workspace
138 cd `ls -t ~/OnosSystemTest/TestON/logs/*/ | head -1 | sed 's/://'`
139 ''' + copyLogs( testName ) + '''
140 sudo cp *.txt ${WORKSPACE}/
141 sudo cp *.csv ${WORKSPACE}/
142 cd ${WORKSPACE}/
143 for i in *.csv
144 do mv "$i" "$WikiPrefix"-"$i"
145 done
146 ls -al
147 cd '''
148}
149def fetchLogs( testName ){
150 return '''#!/bin/bash
151 set +e
152 cd ~/OnosSystemTest/TestON/logs
153 echo "Job Name is: " + ''' + testName + '''
154 TestONlogDir=$(ls -t | grep ${TEST_NAME}_ |head -1)
155 echo "########################################################################################"
156 echo "##### copying ONOS logs from all nodes to TestON/logs directory: ${TestONlogDir}"
157 echo "########################################################################################"
158 cd $TestONlogDir
159 if [ $? -eq 1 ]
160 then
161 echo "Job name does not match any test suite name to move log!"
162 else
163 pwd
164 for i in $OC{1..7}; do onos-fetch-logs $i || echo log does not exist; done
165 fi
166 cd'''
167}
168def isPostingResult( manual, postresult ){
169 return manual == "false" || postresult == "true"
170}
171def postResult( prop, graphOnly ){
172 if( graphOnly || isPostingResult( prop[ "manualRun" ], prop[ "postResult" ] ) ){
173 def post = build job: "postjob-" + ( graphOnly ? machine : machineType[ testType ] ), propagate: false
174 }
175}
176def postLogs( testName, prefix ){
177 resultURL = ""
178 if( testType == "SR" ){
179 def post = build job: "SR-log-" + prefix, propagate: false
180 resultURL = post.getAbsoluteUrl()
181 }
182 return resultURL
183}
184def getSlackChannel(){
185 return "#" + ( testType == "SR" ? "sr-failures" : "jenkins-related" )
186}
187def analyzeResult( prop, workSpace, testName, otherTestName, resultURL, wikiLink, isSCPF ){
188 node( testMachine ){
189 resultContents = readFile workSpace + "/" + testName + "Result.txt"
190 resultContents = resultContents.split("\n")
191 if( resultContents[ 0 ] == "1" ){
192 print "All passed"
193 }else{
194 print "Failed"
195 if( prop[ "manualRun" ] == "false" ){
196 slackSend( channel:getSlackChannel(), color:"FF0000", message: "[" + prop[ "ONOSBranch" ] + "]"
197 + otherTestName + " : Failed!\n" + resultContents[ 1 ] + "\n"
198 + "[TestON log] : \n"
Devin Limd1fb8e92018-02-28 16:29:33 -0800199 + "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 -0800200 + ( isSCPF ? "" : ( "\n[Result on Wiki] : \n" + "https://wiki.onosproject.org/display/ONOS/" + wikiLink.replaceAll( "\\s","+" ) ) )
201 + ( resultURL != "" ? ( "\n[Karaf log] : \n" + resultURL + "artifact/" ) : "" ),
202 teamDomain: 'onosproject' )
203 }
204 Failed
205 }
206 }
207}
Devin Lime89761a2018-03-16 17:52:57 -0700208def publishToConfluence( isManualRun, isPostResult, wikiLink, file ){
209 if( isPostingResult( isManualRun, isPostResult ) ){
Devin Lim61643762017-12-07 15:55:38 -0800210 publishConfluence siteName: 'wiki.onosproject.org', pageName: wikiLink, spaceName: 'ONOS',
Devin Lim1253ae82018-02-26 11:13:36 -0800211 attachArchivedArtifacts: true, buildIfUnstable: true,
Devin Lim61643762017-12-07 15:55:38 -0800212 editorList: [
213 confluenceWritePage( confluenceFile( file ) )
214 ]
215 }
216
217}
218def runTest( testName, toBeRun, prop, pureTestName, graphOnly, testCategory, graph_generator_file, graph_saved_directory ) {
219 return {
220 catchError{
221 stage( testName ) {
222 if ( toBeRun ){
223 workSpace = "/var/jenkins/workspace/" + testName
224 def fileContents = ""
225 node( testMachine ){
226 withEnv( [ 'ONOSBranch=' + prop[ "ONOSBranch" ],
227 'ONOSJVMHeap=' + prop[ "ONOSJVMHeap" ],
228 'TestONBranch=' + prop[ "TestONBranch" ],
229 'ONOSTag=' + prop[ "ONOSTag" ],
230 'WikiPrefix=' + prop[ "WikiPrefix" ],
231 'WORKSPACE=' + workSpace ] ){
232 if( ! graphOnly ){
233 sh initAndRunTest( testName, testCategory )
234 // For the Wiki page
235 sh cleanAndCopyFiles( pureTestName )
236 }
237 databaseAndGraph( prop, testName, graphOnly, graph_generator_file, graph_saved_directory )
238 if( ! graphOnly ){
239 sh fetchLogs( pureTestName )
240 if( !isSCPF )
Devin Lime89761a2018-03-16 17:52:57 -0700241 publishToConfluence( prop[ "manualRun" ], prop[ "postResult" ],
242 testCategory[ testName ][ 'wiki_link' ],
243 workSpace + "/" + testCategory[ testName ][ 'wiki_file' ] )
Devin Lim61643762017-12-07 15:55:38 -0800244 }
245 }
246
247
248 }
249 postResult( prop, graphOnly )
250 if( ! graphOnly ){
251 resultURL = postLogs( testName, prop[ "WikiPrefix" ] )
252 analyzeResult( prop, workSpace, pureTestName, testName, resultURL, isSCPF ? "" : testCategory[ testName ][ 'wiki_link' ], isSCPF )
253 }
254 }
255 }
256 }
257 }
258}
259def borrowCell( testName ){
260 result = ""
261 if( testType == "SR" ){
262 result = '''
263 cd
264 source ~/borrow.cell
265 '''
266 }
267 return result
268}
269def databaseAndGraph( prop, testName, graphOnly, graph_generator_file, graph_saved_directory ){
270 if( graphOnly || isPostingResult( prop[ "manualRun" ], prop[ "postResult" ] ) ){
271 // Post Results
272 withCredentials( [
273 string( credentialsId: 'db_pass', variable: 'pass' ),
274 string( credentialsId: 'db_user', variable: 'user' ),
275 string( credentialsId: 'db_host', variable: 'host' ),
276 string( credentialsId: 'db_port', variable: 'port' ) ] ) {
277 def database_command = generalFuncs.database_command_create( pass, host, port, user ) + ( !isSCPF ? sqlCommand( testName ) : SCPFfunc.sqlCommand( testName ) )
278 sh '''#!/bin/bash
279 export DATE=\$(date +%F_%T)
280 cd ~
281 pwd ''' + ( graphOnly ? "" : ( !isSCPF ? databasePart( prop[ "WikiPrefix" ], testName, database_command ) :
282 SCPFfunc.databasePart( testName, database_command ) ) ) + '''
283 ''' + ( !isSCPF ? graphGenerating( host, port, user, pass, testName, prop, graph_saved_directory, graph_generator_file ) : SCPFfunc.getGraphGeneratingCommand( host, port, user, pass, testName, prop ) )
284 }
285 }
286}
Devin Lim86e40532018-04-06 12:44:06 -0700287def generateCategoryStatsGraph( testMachineOn, manualRun, postresult, stat_file, pie_file, type, branch, testListPart, save_path, pieTestListPart ){
Devin Lim61643762017-12-07 15:55:38 -0800288
289 if( isPostingResult( manualRun, postresult ) ){
Devin Lim86e40532018-04-06 12:44:06 -0700290 node( testMachineOn ){
Devin Lim61643762017-12-07 15:55:38 -0800291
292 withCredentials( [
293 string( credentialsId: 'db_pass', variable: 'pass' ),
294 string( credentialsId: 'db_user', variable: 'user' ),
295 string( credentialsId: 'db_host', variable: 'host' ),
296 string( credentialsId: 'db_port', variable: 'port' ) ] ) {
297 sh '''#!/bin/bash
298 ''' + generalFuncs.basicGraphPart( generalFuncs.rScriptLocation + stat_file, host, port, user, pass, type, branch ) + " \"" + testListPart + "\" latest " + save_path + '''
299 ''' + getOverallPieGraph( generalFuncs.rScriptLocation + pie_file, host, port, user, pass, branch, type, pieTestListPart, 'y', save_path ) + '''
300 ''' + getOverallPieGraph( generalFuncs.rScriptLocation + pie_file, host, port, user, pass, branch, type, pieTestListPart, 'n', save_path )
301 }
302 }
303 postResult( [], true )
304 }
305}
306def makeTestList( list, commaNeeded ){
307 return generalFuncs.getTestList( list ) + ( commaNeeded ? "," : "" )
308}
309def createStatsList( testCategory, list, semiNeeded ){
310 return testCategory + "-" + generalFuncs.getTestList( list ) + ( semiNeeded ? ";" : "" )
311}
312def generateOverallGraph( prop, testCategory, graph_saved_directory ){
313
314 if( isPostingResult( prop[ "manualRun" ], prop[ "postResult" ] ) ){
315 node( testMachine ){
316
317 withCredentials( [
318 string( credentialsId: 'db_pass', variable: 'pass' ),
319 string( credentialsId: 'db_user', variable: 'user' ),
320 string( credentialsId: 'db_host', variable: 'host' ),
321 string( credentialsId: 'db_port', variable: 'port' ) ] ) {
322 testList = generalFuncs.getTestList( testCategory )
323 sh '''#!/bin/bash
324 ''' + generalFuncs.basicGraphPart( trend_generator_file, host, port, user, pass, testType, prop[ "ONOSBranch" ] ) + " " + testList + " 20 " + graph_saved_directory
325 }
326 }
327 postResult( prop, false )
328 }
329}
330def getOverallPieGraph( file, host, port, user, pass, branch, type, testList, yOrN, path ){
331 return generalFuncs.basicGraphPart( file, host, port, user, pass, type, branch ) + " \"" + testList + "\" latest " + yOrN + " " + path
332}
333def sqlCommand( testName ){
334 return "\"INSERT INTO " + table_name + " VALUES('\$DATE','" + result_name + "','" + testName + "',\$BUILD_NUMBER, '\$ONOSBranch', \$line);\" "
335}
336def graphGenerating( host, port, user, pass, testName, prop, graph_saved_directory, graph_generator_file ){
337 return generalFuncs.basicGraphPart( graph_generator_file, host, port, user, pass, testName, prop[ "ONOSBranch" ] ) + " 20 " + graph_saved_directory
338}
339def databasePart( wikiPrefix, testName, database_command ){
340 return '''
341 sed 1d ''' + workSpace + "/" + wikiPrefix + "-" + testName + '''.csv | while read line
342 do
343 echo \$line
344 echo ''' + database_command + '''
345 done '''
346}
Devin Lim86e40532018-04-06 12:44:06 -0700347def generateStatGraph( testMachineOn, onos_branch, AllTheTests, stat_graph_generator_file, pie_graph_generator_file, graph_saved_directory ){
Jeremy Ronquillo14ecc172018-03-05 09:57:17 -0800348 testListPart = createStatsList( "FUNC", AllTheTests[ "FUNC" ], true ) +
349 createStatsList( "HA", AllTheTests[ "HA" ], true ) +
350 createStatsList( "USECASE", AllTheTests[ "USECASE" ], false )
351 pieTestList = makeTestList( AllTheTests[ "FUNC" ], true ) +
352 makeTestList( AllTheTests[ "HA" ], true ) +
353 makeTestList( AllTheTests[ "USECASE" ], false )
Devin Lim86e40532018-04-06 12:44:06 -0700354 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 -0800355}
Jeremy Ronquillof78a6ca2018-03-12 09:20:57 -0700356def branchWithPrefix( branch ){
357 return ( ( branch != "master" ) ? "onos-" : "" ) + branch
358}
Devin Lim1253ae82018-02-26 11:13:36 -0800359return this;