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