blob: b0cd74399e76147bffa1bc9540f2d0ce15d87aec [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()
Devin Limf5175192018-05-14 19:13:22 -070033
34// init trend graphs to be on VM.
Devin Lim2edfcec2018-05-09 17:16:21 -070035funcs.initializeTrend( "VM" );
36triggerFuncs.init( funcs )
Devin Limf5175192018-05-14 19:13:22 -070037
38// contents for page https://wiki.onosproject.org/display/ONOS/Automated+Test+Schedule
39// which will demonstrates the list of the scheduled tests on the days.
Devin Lim2edfcec2018-05-09 17:16:21 -070040wikiContents = ""
Devin Limf5175192018-05-14 19:13:22 -070041
Jeremy Ronquilloa37920b2019-05-23 14:34:25 -070042all_testcases = [:]
Devin Lim2edfcec2018-05-09 17:16:21 -070043
Devin Limf5175192018-05-14 19:13:22 -070044// read the parameters from the Jenkins
Devin Lim2edfcec2018-05-09 17:16:21 -070045manually_run = params.manual_run
Devin Limf5175192018-05-14 19:13:22 -070046
Devin Lim2edfcec2018-05-09 17:16:21 -070047onos_tag = params.ONOSTag
48isOldFlow = true
49
50// Set tests based on day of week
51def now = funcs.getCurrentTime()
52print now.toString()
53today = now[ Calendar.DAY_OF_WEEK ]
54
Jeremy Ronquilloa37920b2019-05-23 14:34:25 -070055dayMap = [ ( Calendar.MONDAY ) : "mon",
56 ( Calendar.TUESDAY ) : "tue",
57 ( Calendar.WEDNESDAY ) : "wed",
58 ( Calendar.THURSDAY ) : "thu",
59 ( Calendar.FRIDAY ) : "fri",
60 ( Calendar.SATURDAY ) : "sat",
61 ( Calendar.SUNDAY ) : "sun" ]
62fullDayMap = [ ( Calendar.MONDAY ) : "Monday",
63 ( Calendar.TUESDAY ) : "Tuesday",
64 ( Calendar.WEDNESDAY ) : "Wednesday",
65 ( Calendar.THURSDAY ) : "Thursday",
66 ( Calendar.FRIDAY ) : "Friday",
67 ( Calendar.SATURDAY ) : "Saturday",
68 ( Calendar.SUNDAY ) : "Sunday" ]
69
Devin Lim2edfcec2018-05-09 17:16:21 -070070if ( manually_run ){
Jeremy Ronquilloa37920b2019-05-23 14:34:25 -070071 onos_branches = params.branches.tokenize( "\n;, " )
72} else {
73 onos_branches = getBranchesFromDay( dayMap[ today ] )
Jon Hall6af749d2018-05-29 12:59:47 -070074}
Jeremy Ronquilloa37920b2019-05-23 14:34:25 -070075
76// default FUNC,HA to be VM, SCPF,USECASE to be BM.
77// SR will not be used in here.
78testcases_template = [
79 "FUNC": [ tests: "", nodeName: "VM", wikiContent: "" ],
80 "HA": [ tests: "", nodeName: "VM", wikiContent: "" ],
81 "SCPF": [ tests: "", nodeName: "BM", wikiContent: "" ],
82 "SR": [ tests: "", nodeName: "Fabric", wikiContent: "" ],
83 "SRHA": [ tests: "", nodeName: "Fabric", wikiContent: "" ],
84 "USECASE": [ tests: "", nodeName: "BM", wikiContent: "" ]
85]
86
87for ( String b in onos_branches ){
88 all_testcases.put( b, testcases_template )
Devin Lim2edfcec2018-05-09 17:16:21 -070089}
Devin Limf5175192018-05-14 19:13:22 -070090
Devin Limf5175192018-05-14 19:13:22 -070091// list of the tests to be run will be saved in each choices.
Devin Lim2edfcec2018-05-09 17:16:21 -070092day = ""
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.
Devin Lim2edfcec2018-05-09 17:16:21 -0700103if ( manually_run ){
Jeremy Ronquilloa37920b2019-05-23 14:34:25 -0700104 for ( String b in onos_branches ){
105 all_testcases[ b ] = triggerFuncs.organize_tests( params.Tests, all_testcases[ b ] )
106 }
Devin Lim2edfcec2018-05-09 17:16:21 -0700107 isOldFlow = params.isOldFlow
Jeremy Ronquilloa37920b2019-05-23 14:34:25 -0700108 println "Tests to be run manually:"
109} else {
110 testDivider( today )
Devin Lim2edfcec2018-05-09 17:16:21 -0700111 println "Defaulting to " + day + " tests:"
112}
113
Jeremy Ronquilloa37920b2019-05-23 14:34:25 -0700114
115for ( String b in onos_branches ){
116 triggerFuncs.print_tests( all_testcases[ b ] )
117}
Devin Lim2edfcec2018-05-09 17:16:21 -0700118
119def runTest = [
Jon Hall6af749d2018-05-29 12:59:47 -0700120 "VM": [ : ],
121 "BM": [ : ]
Devin Lim2edfcec2018-05-09 17:16:21 -0700122]
Devin Limf5175192018-05-14 19:13:22 -0700123
Jon Hall6af749d2018-05-29 12:59:47 -0700124def finalList = [ : ]
Devin Limf5175192018-05-14 19:13:22 -0700125
Jeremy Ronquilloa37920b2019-05-23 14:34:25 -0700126finalList[ "VM" ] = [ : ]
127finalList[ "BM" ] = [ : ]
128
Devin Limf5175192018-05-14 19:13:22 -0700129// get the name of the job.
Devin Limb91bf792018-05-10 15:09:52 -0700130jobName = env.JOB_NAME
Devin Limf5175192018-05-14 19:13:22 -0700131
Jeremy Ronquilloa37920b2019-05-23 14:34:25 -0700132// set the test running function into the dictionary.
133for ( String b in onos_branches ){
134 for ( String test in all_testcases[ b ].keySet() ){
135 if ( all_testcases[ b ][ test ][ "tests" ] != "" ){
136 runTest[ all_testcases[ b ][ test ][ "nodeName" ] ][ test ] = triggerFuncs.
137 trigger_pipeline( b, all_testcases[ b ][ test ][ "tests" ], all_testcases[ b ][ test ][ "nodeName" ], test,
138 manually_run, onos_tag )
139 }
140 }
141
142 // first set the list of the functions to be run.
143 finalList[ "VM" ][ b ] = triggerFuncs.runTestSeq( runTest[ "VM" ] )
144 finalList[ "BM" ][ b ] = triggerFuncs.runTestSeq( runTest[ "BM" ] )
145}
Devin Limf5175192018-05-14 19:13:22 -0700146
147// if first two character of the job name is vm, only call VM.
148// else, only on BM
Jeremy Ronquilloa37920b2019-05-23 14:34:25 -0700149
Jon Hall6af749d2018-05-29 12:59:47 -0700150if ( jobName.take( 2 ) == "vm" ){
Jeremy Ronquilloa37920b2019-05-23 14:34:25 -0700151 parallel finalList[ "VM" ]
Jon Hall6af749d2018-05-29 12:59:47 -0700152}
153else {
Jeremy Ronquilloa37920b2019-05-23 14:34:25 -0700154 parallel finalList[ "BM" ]
Jon Hall6af749d2018-05-29 12:59:47 -0700155}
Devin Lim2edfcec2018-05-09 17:16:21 -0700156
Jeremy Ronquilloa37920b2019-05-23 14:34:25 -0700157
Devin Limf5175192018-05-14 19:13:22 -0700158// If it is automated running, it will generate the stats graph on VM.
Devin Lim2edfcec2018-05-09 17:16:21 -0700159if ( !manually_run ){
Jeremy Ronquilloa37920b2019-05-23 14:34:25 -0700160 for ( String b in onos_branches ){
161 funcs.generateStatGraph( "TestStation-VMs",
162 funcs.branchWithPrefix( b ),
163 stat_graph_generator_file,
164 pie_graph_generator_file,
165 graph_saved_directory )
166 }
Devin Lim2edfcec2018-05-09 17:16:21 -0700167}
168
Devin Limf5175192018-05-14 19:13:22 -0700169// function that will divide tests depends on which day it is.
Devin Lim2edfcec2018-05-09 17:16:21 -0700170def testDivider( today ){
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -0700171 todayStr = today.toString()
172
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -0700173 if ( today == Calendar.MONDAY ){
174 initHtmlForWiki()
175 day = fullDayMap[ today ]
176 for ( key in dayMap.keySet() ){
177 buildDay( dayMap[ key ], false )
178 }
179 closeHtmlForWiki()
180 postToWiki( wikiContents )
181 slackSend( color: '#FFD988',
182 message: "Tests to be run this weekdays : \n" +
183 triggerFuncs.printDaysForTest() )
184 } else {
185 day = fullDayMap[ today ]
186 buildDay( dayMap[ today ], true )
Devin Lim2edfcec2018-05-09 17:16:21 -0700187 }
188}
Devin Limf5175192018-05-14 19:13:22 -0700189
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -0700190def buildDay( dayStr, getResult ){
Jeremy Ronquilloa37920b2019-05-23 14:34:25 -0700191 for ( String b in onos_branches ){
192 addingHeader( "FUNC", b )
193 all_testcases[ b ][ "FUNC" ][ "tests" ] += adder( "FUNC", dayStr, getResult, b )
194 closingHeader( "FUNC", b )
195 addingHeader( "HA", b )
196 all_testcases[ b ][ "HA" ][ "tests" ] += adder( "HA", dayStr, getResult, b )
197 closingHeader( "HA", b )
198 addingHeader( "SCPF", b )
199 all_testcases[ b ][ "SCPF" ][ "tests" ] += adder( "SCPF", dayStr, getResult, b )
200 closingHeader( "SCPF", b )
201 addingHeader( "SR", b )
202 all_testcases[ b ][ "SR" ][ "tests" ] += adder( "SR", dayStr, false, b )
203 closingHeader( "SR", b )
204 addingHeader( "SRHA", b )
205 all_testcases[ b ][ "SRHA" ][ "tests" ] += adder( "SRHA", dayStr, false, b )
206 closingHeader( "SRHA", b )
207 addingHeader( "USECASE", b )
208 all_testcases[ b ][ "USECASE" ][ "tests" ] += adder( "USECASE", dayStr, getResult, b )
209 closingHeader( "USECASE", b )
210 }
Devin Lim2edfcec2018-05-09 17:16:21 -0700211}
Devin Limf5175192018-05-14 19:13:22 -0700212
213// adder that will return the list of the tests.
Jeremy Ronquilloa37920b2019-05-23 14:34:25 -0700214def adder( category, day, getResult, branch ){
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -0700215 // category : the category of the test which will be either FUNC,HA,SR...
Devin Limf5175192018-05-14 19:13:22 -0700216 // day : the day you are trying to add (m,t,w,th... )
217 // getResult : if want to get the list of the test to be run. False will return empty list.
218 // And once the list is empty, it will not be run.
Jon Hall6af749d2018-05-29 12:59:47 -0700219 def result = ""
Jeremy Ronquilloa37920b2019-05-23 14:34:25 -0700220 selectedTests = test_list.getTestsFromCategory( category, test_list.getTestsFromDay( day, branch ) )
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -0700221
222 for ( String test in selectedTests.keySet() ){
223 if ( getResult ){
224 result += test + ","
Devin Lim2edfcec2018-05-09 17:16:21 -0700225 }
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -0700226 // make HTML columns for wiki page on schedule.
Jeremy Ronquilloa37920b2019-05-23 14:34:25 -0700227 makeHtmlColList( category, test, branch )
Devin Lim2edfcec2018-05-09 17:16:21 -0700228 }
229 return result
230}
Devin Limf5175192018-05-14 19:13:22 -0700231
232// Initial part of the wiki page.
Devin Lim2edfcec2018-05-09 17:16:21 -0700233def initHtmlForWiki(){
234 wikiContents = '''
235 <table class="wrapped confluenceTable">
236 <colgroup>
237 <col />
238 <col />
239 <col />
240 <col />
241 <col />
242 <col />
243 </colgroup>
244 <tbody>
245 <tr>
246 <th colspan="1" class="confluenceTh">
247 <br />
248 </th>
249 <th class="confluenceTh"><p>Monday</p></th>
250 <th class="confluenceTh"><p>Tuesday</p></th>
251 <th class="confluenceTh"><p>Wednesday</p></th>
252 <th class="confluenceTh"><p>Thursday</p></th>
253 <th class="confluenceTh"><p>Friday</p></th>
254 <th class="confluenceTh"><p>Saturday</p></th>
255 <th class="confluenceTh"><p>Sunday</p></th>
256 </tr>'''
Jeremy Ronquilloa37920b2019-05-23 14:34:25 -0700257 for ( String b in onos_branches ){
258 for ( String test in all_testcases[ b ].keySet() ){
259 all_testcases[ b ][ test ][ 'wikiContent' ] = '''
260 <tr>
261 <th colspan="1" class="confluenceTh">''' + test + '''</th>'''
262 }
Devin Lim2edfcec2018-05-09 17:16:21 -0700263 }
264}
Devin Limf5175192018-05-14 19:13:22 -0700265
266// adding header functionality.
Jeremy Ronquilloa37920b2019-05-23 14:34:25 -0700267def addingHeader( testCategory, branch ){
268 all_testcases[ branch ][ testCategory ][ 'wikiContent' ] += '''
Devin Lim2edfcec2018-05-09 17:16:21 -0700269 <td class="confluenceTd">
270 <ul>'''
271}
Devin Limf5175192018-05-14 19:13:22 -0700272
273// making column list for html
Jeremy Ronquilloa37920b2019-05-23 14:34:25 -0700274def makeHtmlColList( testCategory, testName, branch ){
275 all_testcases[ branch ][ testCategory ][ 'wikiContent' ] += '''
Jon Hall6af749d2018-05-29 12:59:47 -0700276 <li>''' + testName + '''</li>'''
Devin Lim2edfcec2018-05-09 17:16:21 -0700277
278}
Devin Limf5175192018-05-14 19:13:22 -0700279
280// closing the header for html
Jeremy Ronquilloa37920b2019-05-23 14:34:25 -0700281def closingHeader( testCategory, branch ){
282 all_testcases[ branch ][ testCategory ][ 'wikiContent' ] += '''
Devin Lim2edfcec2018-05-09 17:16:21 -0700283 </ul>
284 </td>'''
285}
Devin Limf5175192018-05-14 19:13:22 -0700286
287// close the html for the wiki page.
Devin Lim2edfcec2018-05-09 17:16:21 -0700288def closeHtmlForWiki(){
Jeremy Ronquilloa37920b2019-05-23 14:34:25 -0700289 for ( String b in onos_branches ){
290 for ( String test in all_testcases[ b ].keySet() ){
291 wikiContents += all_testcases[ b ][ test ][ 'wikiContent' ]
292 wikiContents += '''
293 </tr>'''
294 }
Devin Lim2edfcec2018-05-09 17:16:21 -0700295 }
296 wikiContents += '''
297 </tbody>
298 </table>
299 <p><strong>Everyday</strong>, all SegmentRouting tests are built and run on every supported branch.</p>
300 <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 -0700301 <p>On <strong>Saturdays</strong>, all the other tests are built and run on the ''' +
Jeremy Ronquilloa37920b2019-05-23 14:34:25 -0700302 test_list.convertBranchCodeToBranch( "onos-2.x" ) + ''' branch.</p>
Jon Hall6af749d2018-05-29 12:59:47 -0700303 <p>On <strong>Sundays</strong>, all the other tests are built and run on the ''' +
Jeremy Ronquilloa37920b2019-05-23 14:34:25 -0700304 test_list.convertBranchCodeToBranch( "onos-1.x" ) + ''' branch.</p>'''
Devin Lim2edfcec2018-05-09 17:16:21 -0700305}
Devin Limf5175192018-05-14 19:13:22 -0700306
307// post the result to wiki page using publish to confluence.
Devin Lim2edfcec2018-05-09 17:16:21 -0700308def postToWiki( contents ){
Jon Hall6af749d2018-05-29 12:59:47 -0700309 node( testMachine ) {
Devin Limfe9a4cb2018-05-11 17:06:21 -0700310 workspace = fileRelated.jenkinsWorkspace + "all-pipeline-trigger/"
Devin Lim2edfcec2018-05-09 17:16:21 -0700311 filename = "jenkinsSchedule.txt"
312 writeFile file: workspace + filename, text: contents
313 funcs.publishToConfluence( "false", "true",
314 "Automated Test Schedule",
315 workspace + filename )
316 }
317}