blob: fe066972694e6f34e7d1a25f7a64d20d3b6663bf [file] [log] [blame]
Devin Lime1346f42018-05-15 15:41:36 -07001#!groovy
Devin Limf5175192018-05-14 19:13:22 -07002// Copyright 2017 Open Networking Foundation (ONF)
3//
4// Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>,
5// the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>,
6// or the System Testing Guide page at <https://wiki.onosproject.org/x/WYQg>
7//
8// TestON is free software: you can redistribute it and/or modify
9// it under the terms of the GNU General Public License as published by
10// the Free Software Foundation, either version 2 of the License, or
11// (at your option) any later version.
12//
13// TestON is distributed in the hope that it will be useful,
14// but WITHOUT ANY WARRANTY; without even the implied warranty of
15// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16// GNU General Public License for more details.
17//
18// You should have received a copy of the GNU General Public License
19// along with TestON. If not, see <http://www.gnu.org/licenses/>.
20
21// This is the Jenkins script for vm-pipeline-trigger or bm-pipeline-trigger
22
Devin Limf5175192018-05-14 19:13:22 -070023// set the functions of the dependencies.
Devin Limb734ea52018-05-14 14:13:05 -070024funcs = evaluate readTrusted( 'TestON/JenkinsFile/dependencies/JenkinsCommonFuncs.groovy' )
Devin Limb734ea52018-05-14 14:13:05 -070025triggerFuncs = evaluate readTrusted( 'TestON/JenkinsFile/dependencies/TriggerFuncs.groovy' )
26fileRelated = evaluate readTrusted( 'TestON/JenkinsFile/dependencies/JenkinsPathAndFiles.groovy' )
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -070027test_list = evaluate readTrusted( 'TestON/JenkinsFile/dependencies/JenkinsTestONTests.groovy' )
Devin Lim2edfcec2018-05-09 17:16:21 -070028
Jeremy Ronquillo4fd82442019-05-21 20:56:58 -070029test_list.init()
30
Devin Limf5175192018-05-14 19:13:22 -070031// set the versions of the onos
Devin Limfe9a4cb2018-05-11 17:06:21 -070032fileRelated.init()
You Wang7ca7dc72018-09-05 10:56:24 -070033current_version = "master"
You Wang8f12d7d2018-11-09 13:47:23 -080034previous_version = "1.15"
You Wangf043d0a2019-04-22 16:30:40 -070035before_previous_version = "2.1"
Devin Limf5175192018-05-14 19:13:22 -070036
37// init trend graphs to be on VM.
Devin Lim2edfcec2018-05-09 17:16:21 -070038funcs.initializeTrend( "VM" );
39triggerFuncs.init( funcs )
Devin Limf5175192018-05-14 19:13:22 -070040
41// contents for page https://wiki.onosproject.org/display/ONOS/Automated+Test+Schedule
42// which will demonstrates the list of the scheduled tests on the days.
Devin Lim2edfcec2018-05-09 17:16:21 -070043wikiContents = ""
Devin Limf5175192018-05-14 19:13:22 -070044
45// default FUNC,HA to be VM, SCPF,USECASE to be BM.
46// SR will not be used in here.
Devin Lim2edfcec2018-05-09 17:16:21 -070047testcases = [
Jon Hall6af749d2018-05-29 12:59:47 -070048 "FUNC": [ tests: "", nodeName: "VM", wikiContent: "" ],
49 "HA": [ tests: "", nodeName: "VM", wikiContent: "" ],
50 "SCPF": [ tests: "", nodeName: "BM", wikiContent: "" ],
51 "SR": [ tests: "", nodeName: "Fabric", wikiContent: "" ],
Jon Hall2ee92f82018-06-07 13:07:33 -070052 "SRHA": [ tests: "", nodeName: "Fabric", wikiContent: "" ],
Jon Hall6af749d2018-05-29 12:59:47 -070053 "USECASE": [ tests: "", nodeName: "BM", wikiContent: "" ]
Devin Lim2edfcec2018-05-09 17:16:21 -070054]
55
Devin Limf5175192018-05-14 19:13:22 -070056// read the parameters from the Jenkins
Devin Lim2edfcec2018-05-09 17:16:21 -070057manually_run = params.manual_run
Devin Limf5175192018-05-14 19:13:22 -070058
59// set default onos_b to be current_version.
Devin Lim2edfcec2018-05-09 17:16:21 -070060onos_b = current_version
61test_branch = ""
62onos_tag = params.ONOSTag
63isOldFlow = true
64
65// Set tests based on day of week
66def now = funcs.getCurrentTime()
67print now.toString()
68today = now[ Calendar.DAY_OF_WEEK ]
69
Devin Limf5175192018-05-14 19:13:22 -070070// get branch from parameter if it is manually running
Devin Lim2edfcec2018-05-09 17:16:21 -070071if ( manually_run ){
72 onos_b = params.ONOSVersion
Jon Hall6af749d2018-05-29 12:59:47 -070073}
74else {
Devin Limf5175192018-05-14 19:13:22 -070075 // otherwise, the version would be different over the weekend.
76 // If today is weekdays, it will be default to current_version.
Devin Lim2edfcec2018-05-09 17:16:21 -070077 if ( today == Calendar.SATURDAY ){
78 onos_b = previous_version
Jon Hall6af749d2018-05-29 12:59:47 -070079 }
80 else if ( today == Calendar.SUNDAY ){
Devin Lim2edfcec2018-05-09 17:16:21 -070081 onos_b = before_previous_version
82 }
83}
Devin Limf5175192018-05-14 19:13:22 -070084
Devin Limf5175192018-05-14 19:13:22 -070085// list of the tests to be run will be saved in each choices.
Devin Lim2edfcec2018-05-09 17:16:21 -070086day = ""
87SCPF_choices = ""
88USECASE_choices = ""
89FUNC_choices = ""
90HA_choices = ""
91SR_choices = ""
Jon Hall2ee92f82018-06-07 13:07:33 -070092SRHA_choices = ""
Devin Limf5175192018-05-14 19:13:22 -070093
94// init some paths for the files and directories.
Devin Limfe9a4cb2018-05-11 17:06:21 -070095stat_graph_generator_file = fileRelated.histogramMultiple
96pie_graph_generator_file = fileRelated.pieMultiple
97graph_saved_directory = fileRelated.jenkinsWorkspace + "postjob-VM/"
Devin Lim2edfcec2018-05-09 17:16:21 -070098
Devin Limf5175192018-05-14 19:13:22 -070099// get post result from the params for manually run.
Devin Lim2edfcec2018-05-09 17:16:21 -0700100post_result = params.PostResult
Devin Limf5175192018-05-14 19:13:22 -0700101
102// if automatically run, it will remove the comma at the end after dividing the tests.
Jon Hall6af749d2018-05-29 12:59:47 -0700103if ( !manually_run ){
Devin Lim2edfcec2018-05-09 17:16:21 -0700104 testDivider( today )
Jon Hall6af749d2018-05-29 12:59:47 -0700105 FUNC_choices = triggerFuncs.lastCommaRemover( FUNC_choices )
106 HA_choices = triggerFuncs.lastCommaRemover( HA_choices )
107 SCPF_choices = triggerFuncs.lastCommaRemover( SCPF_choices )
108 USECASE_choices = triggerFuncs.lastCommaRemover( USECASE_choices )
109 SR_choices = triggerFuncs.lastCommaRemover( SR_choices )
Jon Hall2ee92f82018-06-07 13:07:33 -0700110 SRHA_choices = triggerFuncs.lastCommaRemover( SRHA_choices )
Devin Lim2edfcec2018-05-09 17:16:21 -0700111}
112
Devin Limf5175192018-05-14 19:13:22 -0700113
Devin Lim2edfcec2018-05-09 17:16:21 -0700114if ( manually_run ){
115 testcases = triggerFuncs.organize_tests( params.Tests, testcases )
116
117 isOldFlow = params.isOldFlow
118 println "Tests to be run manually : "
Jon Hall6af749d2018-05-29 12:59:47 -0700119}
120else {
Devin Lim2edfcec2018-05-09 17:16:21 -0700121 testcases[ "SCPF" ][ "tests" ] = SCPF_choices
122 testcases[ "USECASE" ][ "tests" ] = USECASE_choices
123 testcases[ "FUNC" ][ "tests" ] = FUNC_choices
124 testcases[ "HA" ][ "tests" ] = HA_choices
125 testcases[ "SR" ][ "tests" ] = SR_choices
Jon Hall2ee92f82018-06-07 13:07:33 -0700126 testcases[ "SRHA" ][ "tests" ] = SRHA_choices
Devin Lim2edfcec2018-05-09 17:16:21 -0700127 println "Defaulting to " + day + " tests:"
128}
129
130triggerFuncs.print_tests( testcases )
131
132def runTest = [
Jon Hall6af749d2018-05-29 12:59:47 -0700133 "VM": [ : ],
134 "BM": [ : ]
Devin Lim2edfcec2018-05-09 17:16:21 -0700135]
Devin Limf5175192018-05-14 19:13:22 -0700136
137// set the test running function into the dictionary.
Jon Hall6af749d2018-05-29 12:59:47 -0700138for ( String test in testcases.keySet() ){
Devin Lim2edfcec2018-05-09 17:16:21 -0700139 println test
140 if ( testcases[ test ][ "tests" ] != "" ){
Jon Hall6af749d2018-05-29 12:59:47 -0700141 runTest[ testcases[ test ][ "nodeName" ] ][ test ] = triggerFuncs.
142 trigger_pipeline( onos_b, testcases[ test ][ "tests" ], testcases[ test ][ "nodeName" ], test,
143 manually_run, onos_tag )
Devin Lim2edfcec2018-05-09 17:16:21 -0700144 }
145}
Jon Hall6af749d2018-05-29 12:59:47 -0700146def finalList = [ : ]
Devin Limf5175192018-05-14 19:13:22 -0700147
148// get the name of the job.
Devin Limb91bf792018-05-10 15:09:52 -0700149jobName = env.JOB_NAME
Devin Limf5175192018-05-14 19:13:22 -0700150
151// first set the list of the functions to be run.
Devin Lim2edfcec2018-05-09 17:16:21 -0700152finalList[ "VM" ] = triggerFuncs.runTestSeq( runTest[ "VM" ] )
153finalList[ "BM" ] = triggerFuncs.runTestSeq( runTest[ "BM" ] )
Devin Limf5175192018-05-14 19:13:22 -0700154
155// if first two character of the job name is vm, only call VM.
156// else, only on BM
Jon Hall6af749d2018-05-29 12:59:47 -0700157if ( jobName.take( 2 ) == "vm" ){
Devin Limb91bf792018-05-10 15:09:52 -0700158 finalList[ "VM" ].call()
Jon Hall6af749d2018-05-29 12:59:47 -0700159}
160else {
Devin Limb91bf792018-05-10 15:09:52 -0700161 finalList[ "BM" ].call()
Jon Hall6af749d2018-05-29 12:59:47 -0700162}
Devin Lim2edfcec2018-05-09 17:16:21 -0700163
Devin Limf5175192018-05-14 19:13:22 -0700164// If it is automated running, it will generate the stats graph on VM.
Devin Lim2edfcec2018-05-09 17:16:21 -0700165if ( !manually_run ){
166 funcs.generateStatGraph( "TestStation-VMs",
167 funcs.branchWithPrefix( onos_b ),
Devin Lim2edfcec2018-05-09 17:16:21 -0700168 stat_graph_generator_file,
169 pie_graph_generator_file,
170 graph_saved_directory )
171}
172
Devin Limf5175192018-05-14 19:13:22 -0700173// function that will divide tests depends on which day it is.
Devin Lim2edfcec2018-05-09 17:16:21 -0700174def testDivider( today ){
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -0700175 todayStr = today.toString()
176
177 dayMap = [ ( Calendar.MONDAY ) : "mon",
178 ( Calendar.TUESDAY ) : "tue",
179 ( Calendar.WEDNESDAY ) : "wed",
180 ( Calendar.THURSDAY ) : "thu",
181 ( Calendar.FRIDAY ) : "fri",
182 ( Calendar.SATURDAY ) : "sat",
183 ( Calendar.SUNDAY ) : "sun" ]
184 fullDayMap = [ ( Calendar.MONDAY ) : "Monday",
185 ( Calendar.TUESDAY ) : "Tuesday",
186 ( Calendar.WEDNESDAY ) : "Wednesday",
187 ( Calendar.THURSDAY ) : "Thursday",
188 ( Calendar.FRIDAY ) : "Friday",
189 ( Calendar.SATURDAY ) : "Saturday",
190 ( Calendar.SUNDAY ) : "Sunday" ]
191
192 if ( today == Calendar.MONDAY ){
193 initHtmlForWiki()
194 day = fullDayMap[ today ]
195 for ( key in dayMap.keySet() ){
196 buildDay( dayMap[ key ], false )
197 }
198 closeHtmlForWiki()
199 postToWiki( wikiContents )
200 slackSend( color: '#FFD988',
201 message: "Tests to be run this weekdays : \n" +
202 triggerFuncs.printDaysForTest() )
203 } else {
204 day = fullDayMap[ today ]
205 buildDay( dayMap[ today ], true )
Devin Lim2edfcec2018-05-09 17:16:21 -0700206 }
207}
Devin Limf5175192018-05-14 19:13:22 -0700208
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -0700209def buildDay( dayStr, getResult ){
Devin Lim2edfcec2018-05-09 17:16:21 -0700210 addingHeader( "FUNC" )
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -0700211 FUNC_choices += adder( "FUNC", dayStr, getResult )
Devin Lim2edfcec2018-05-09 17:16:21 -0700212 closingHeader( "FUNC" )
213 addingHeader( "HA" )
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -0700214 HA_choices += adder( "HA", dayStr, getResult )
Devin Lim2edfcec2018-05-09 17:16:21 -0700215 closingHeader( "HA" )
216 addingHeader( "SCPF" )
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -0700217 SCPF_choices += adder( "SCPF", dayStr, getResult )
Devin Lim2edfcec2018-05-09 17:16:21 -0700218 closingHeader( "SCPF" )
219 addingHeader( "SR" )
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -0700220 SR_choices += adder( "SR", dayStr, false )
Devin Lim2edfcec2018-05-09 17:16:21 -0700221 closingHeader( "SR" )
Jon Hall2ee92f82018-06-07 13:07:33 -0700222 addingHeader( "SRHA" )
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -0700223 SRHA_choices += adder( "SRHA", dayStr, false )
Jon Hall2ee92f82018-06-07 13:07:33 -0700224 closingHeader( "SRHA" )
Devin Lim2edfcec2018-05-09 17:16:21 -0700225 addingHeader( "USECASE" )
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -0700226 USECASE_choices += adder( "USECASE", dayStr, getResult )
Devin Lim2edfcec2018-05-09 17:16:21 -0700227 closingHeader( "USECASE" )
228}
Devin Limf5175192018-05-14 19:13:22 -0700229
230// adder that will return the list of the tests.
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -0700231def adder( category, day, getResult ){
232 // category : the category of the test which will be either FUNC,HA,SR...
Devin Limf5175192018-05-14 19:13:22 -0700233 // day : the day you are trying to add (m,t,w,th... )
234 // getResult : if want to get the list of the test to be run. False will return empty list.
235 // And once the list is empty, it will not be run.
Jon Hall6af749d2018-05-29 12:59:47 -0700236 def result = ""
Jeremy Ronquillo4fd82442019-05-21 20:56:58 -0700237 selectedTests = test_list.getTestsFromCategory( category, test_list.getTestsFromDay( day, onos_b ) )
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -0700238
239 for ( String test in selectedTests.keySet() ){
240 if ( getResult ){
241 result += test + ","
Devin Lim2edfcec2018-05-09 17:16:21 -0700242 }
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -0700243 // make HTML columns for wiki page on schedule.
244 makeHtmlColList( category, test )
Devin Lim2edfcec2018-05-09 17:16:21 -0700245 }
246 return result
247}
Devin Limf5175192018-05-14 19:13:22 -0700248
249// Initial part of the wiki page.
Devin Lim2edfcec2018-05-09 17:16:21 -0700250def initHtmlForWiki(){
251 wikiContents = '''
252 <table class="wrapped confluenceTable">
253 <colgroup>
254 <col />
255 <col />
256 <col />
257 <col />
258 <col />
259 <col />
260 </colgroup>
261 <tbody>
262 <tr>
263 <th colspan="1" class="confluenceTh">
264 <br />
265 </th>
266 <th class="confluenceTh"><p>Monday</p></th>
267 <th class="confluenceTh"><p>Tuesday</p></th>
268 <th class="confluenceTh"><p>Wednesday</p></th>
269 <th class="confluenceTh"><p>Thursday</p></th>
270 <th class="confluenceTh"><p>Friday</p></th>
271 <th class="confluenceTh"><p>Saturday</p></th>
272 <th class="confluenceTh"><p>Sunday</p></th>
273 </tr>'''
Jon Hall6af749d2018-05-29 12:59:47 -0700274 for ( String test in testcases.keySet() ){
Devin Lim2edfcec2018-05-09 17:16:21 -0700275 testcases[ test ][ 'wikiContent' ] = '''
276 <tr>
277 <th colspan="1" class="confluenceTh">''' + test + '''</th>'''
278 }
279}
Devin Limf5175192018-05-14 19:13:22 -0700280
281// adding header functionality.
Devin Lim2edfcec2018-05-09 17:16:21 -0700282def addingHeader( testCategory ){
283 testcases[ testCategory ][ 'wikiContent' ] += '''
284 <td class="confluenceTd">
285 <ul>'''
286}
Devin Limf5175192018-05-14 19:13:22 -0700287
288// making column list for html
Devin Lim2edfcec2018-05-09 17:16:21 -0700289def makeHtmlColList( testCategory, testName ){
290 testcases[ testCategory ][ 'wikiContent' ] += '''
Jon Hall6af749d2018-05-29 12:59:47 -0700291 <li>''' + testName + '''</li>'''
Devin Lim2edfcec2018-05-09 17:16:21 -0700292
293}
Devin Limf5175192018-05-14 19:13:22 -0700294
295// closing the header for html
Devin Lim2edfcec2018-05-09 17:16:21 -0700296def closingHeader( testCategory ){
297 testcases[ testCategory ][ 'wikiContent' ] += '''
298 </ul>
299 </td>'''
300}
Devin Limf5175192018-05-14 19:13:22 -0700301
302// close the html for the wiki page.
Devin Lim2edfcec2018-05-09 17:16:21 -0700303def closeHtmlForWiki(){
Jon Hall6af749d2018-05-29 12:59:47 -0700304 for ( String test in testcases.keySet() ){
Devin Lim2edfcec2018-05-09 17:16:21 -0700305 wikiContents += testcases[ test ][ 'wikiContent' ]
306 wikiContents += '''
307 </tr>'''
308 }
309 wikiContents += '''
310 </tbody>
311 </table>
312 <p><strong>Everyday</strong>, all SegmentRouting tests are built and run on every supported branch.</p>
313 <p>On <strong>Weekdays</strong>, all the other tests are built and run on the master branch.</p>
Jon Hall6af749d2018-05-29 12:59:47 -0700314 <p>On <strong>Saturdays</strong>, all the other tests are built and run on the ''' +
315 funcs.branchWithPrefix( previous_version ) + ''' branch.</p>
316 <p>On <strong>Sundays</strong>, all the other tests are built and run on the ''' +
317 funcs.branchWithPrefix( before_previous_version ) + ''' branch.</p>'''
Devin Lim2edfcec2018-05-09 17:16:21 -0700318}
Devin Limf5175192018-05-14 19:13:22 -0700319
320// post the result to wiki page using publish to confluence.
Devin Lim2edfcec2018-05-09 17:16:21 -0700321def postToWiki( contents ){
Jon Hall6af749d2018-05-29 12:59:47 -0700322 node( testMachine ) {
Devin Limfe9a4cb2018-05-11 17:06:21 -0700323 workspace = fileRelated.jenkinsWorkspace + "all-pipeline-trigger/"
Devin Lim2edfcec2018-05-09 17:16:21 -0700324 filename = "jenkinsSchedule.txt"
325 writeFile file: workspace + filename, text: contents
326 funcs.publishToConfluence( "false", "true",
327 "Automated Test Schedule",
328 workspace + filename )
329 }
330}