blob: 09ee84a8e3c7ab1466069837d9629f5187881a17 [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
Devin Limf5175192018-05-14 19:13:22 -070029// set the versions of the onos
Devin Limfe9a4cb2018-05-11 17:06:21 -070030fileRelated.init()
You Wang7ca7dc72018-09-05 10:56:24 -070031current_version = "master"
You Wang8f12d7d2018-11-09 13:47:23 -080032previous_version = "1.15"
You Wangf043d0a2019-04-22 16:30:40 -070033before_previous_version = "2.1"
Devin Limf5175192018-05-14 19:13:22 -070034
35// init trend graphs to be on VM.
Devin Lim2edfcec2018-05-09 17:16:21 -070036funcs.initializeTrend( "VM" );
37triggerFuncs.init( funcs )
Devin Limf5175192018-05-14 19:13:22 -070038
39// contents for page https://wiki.onosproject.org/display/ONOS/Automated+Test+Schedule
40// which will demonstrates the list of the scheduled tests on the days.
Devin Lim2edfcec2018-05-09 17:16:21 -070041wikiContents = ""
Devin Limf5175192018-05-14 19:13:22 -070042
43// default FUNC,HA to be VM, SCPF,USECASE to be BM.
44// SR will not be used in here.
Devin Lim2edfcec2018-05-09 17:16:21 -070045testcases = [
Jon Hall6af749d2018-05-29 12:59:47 -070046 "FUNC": [ tests: "", nodeName: "VM", wikiContent: "" ],
47 "HA": [ tests: "", nodeName: "VM", wikiContent: "" ],
48 "SCPF": [ tests: "", nodeName: "BM", wikiContent: "" ],
49 "SR": [ tests: "", nodeName: "Fabric", wikiContent: "" ],
Jon Hall2ee92f82018-06-07 13:07:33 -070050 "SRHA": [ tests: "", nodeName: "Fabric", wikiContent: "" ],
Jon Hall6af749d2018-05-29 12:59:47 -070051 "USECASE": [ tests: "", nodeName: "BM", wikiContent: "" ]
Devin Lim2edfcec2018-05-09 17:16:21 -070052]
53
Devin Limf5175192018-05-14 19:13:22 -070054// read the parameters from the Jenkins
Devin Lim2edfcec2018-05-09 17:16:21 -070055manually_run = params.manual_run
Devin Limf5175192018-05-14 19:13:22 -070056
57// set default onos_b to be current_version.
Devin Lim2edfcec2018-05-09 17:16:21 -070058onos_b = current_version
59test_branch = ""
60onos_tag = params.ONOSTag
61isOldFlow = true
62
63// Set tests based on day of week
64def now = funcs.getCurrentTime()
65print now.toString()
66today = now[ Calendar.DAY_OF_WEEK ]
67
Devin Limf5175192018-05-14 19:13:22 -070068// get branch from parameter if it is manually running
Devin Lim2edfcec2018-05-09 17:16:21 -070069if ( manually_run ){
70 onos_b = params.ONOSVersion
Jon Hall6af749d2018-05-29 12:59:47 -070071}
72else {
Devin Limf5175192018-05-14 19:13:22 -070073 // otherwise, the version would be different over the weekend.
74 // If today is weekdays, it will be default to current_version.
Devin Lim2edfcec2018-05-09 17:16:21 -070075 if ( today == Calendar.SATURDAY ){
76 onos_b = previous_version
Jon Hall6af749d2018-05-29 12:59:47 -070077 }
78 else if ( today == Calendar.SUNDAY ){
Devin Lim2edfcec2018-05-09 17:16:21 -070079 onos_b = before_previous_version
80 }
81}
Devin Limf5175192018-05-14 19:13:22 -070082
Devin Limf5175192018-05-14 19:13:22 -070083// list of the tests to be run will be saved in each choices.
Devin Lim2edfcec2018-05-09 17:16:21 -070084day = ""
85SCPF_choices = ""
86USECASE_choices = ""
87FUNC_choices = ""
88HA_choices = ""
89SR_choices = ""
Jon Hall2ee92f82018-06-07 13:07:33 -070090SRHA_choices = ""
Devin Limf5175192018-05-14 19:13:22 -070091
92// init some paths for the files and directories.
Devin Limfe9a4cb2018-05-11 17:06:21 -070093stat_graph_generator_file = fileRelated.histogramMultiple
94pie_graph_generator_file = fileRelated.pieMultiple
95graph_saved_directory = fileRelated.jenkinsWorkspace + "postjob-VM/"
Devin Lim2edfcec2018-05-09 17:16:21 -070096
Devin Limf5175192018-05-14 19:13:22 -070097// get post result from the params for manually run.
Devin Lim2edfcec2018-05-09 17:16:21 -070098post_result = params.PostResult
Devin Limf5175192018-05-14 19:13:22 -070099
100// if automatically run, it will remove the comma at the end after dividing the tests.
Jon Hall6af749d2018-05-29 12:59:47 -0700101if ( !manually_run ){
Devin Lim2edfcec2018-05-09 17:16:21 -0700102 testDivider( today )
Jon Hall6af749d2018-05-29 12:59:47 -0700103 FUNC_choices = triggerFuncs.lastCommaRemover( FUNC_choices )
104 HA_choices = triggerFuncs.lastCommaRemover( HA_choices )
105 SCPF_choices = triggerFuncs.lastCommaRemover( SCPF_choices )
106 USECASE_choices = triggerFuncs.lastCommaRemover( USECASE_choices )
107 SR_choices = triggerFuncs.lastCommaRemover( SR_choices )
Jon Hall2ee92f82018-06-07 13:07:33 -0700108 SRHA_choices = triggerFuncs.lastCommaRemover( SRHA_choices )
Devin Lim2edfcec2018-05-09 17:16:21 -0700109}
110
Devin Limf5175192018-05-14 19:13:22 -0700111
Devin Lim2edfcec2018-05-09 17:16:21 -0700112if ( manually_run ){
113 testcases = triggerFuncs.organize_tests( params.Tests, testcases )
114
115 isOldFlow = params.isOldFlow
116 println "Tests to be run manually : "
Jon Hall6af749d2018-05-29 12:59:47 -0700117}
118else {
Devin Lim2edfcec2018-05-09 17:16:21 -0700119 testcases[ "SCPF" ][ "tests" ] = SCPF_choices
120 testcases[ "USECASE" ][ "tests" ] = USECASE_choices
121 testcases[ "FUNC" ][ "tests" ] = FUNC_choices
122 testcases[ "HA" ][ "tests" ] = HA_choices
123 testcases[ "SR" ][ "tests" ] = SR_choices
Jon Hall2ee92f82018-06-07 13:07:33 -0700124 testcases[ "SRHA" ][ "tests" ] = SRHA_choices
Devin Lim2edfcec2018-05-09 17:16:21 -0700125 println "Defaulting to " + day + " tests:"
126}
127
128triggerFuncs.print_tests( testcases )
129
130def runTest = [
Jon Hall6af749d2018-05-29 12:59:47 -0700131 "VM": [ : ],
132 "BM": [ : ]
Devin Lim2edfcec2018-05-09 17:16:21 -0700133]
Devin Limf5175192018-05-14 19:13:22 -0700134
135// set the test running function into the dictionary.
Jon Hall6af749d2018-05-29 12:59:47 -0700136for ( String test in testcases.keySet() ){
Devin Lim2edfcec2018-05-09 17:16:21 -0700137 println test
138 if ( testcases[ test ][ "tests" ] != "" ){
Jon Hall6af749d2018-05-29 12:59:47 -0700139 runTest[ testcases[ test ][ "nodeName" ] ][ test ] = triggerFuncs.
140 trigger_pipeline( onos_b, testcases[ test ][ "tests" ], testcases[ test ][ "nodeName" ], test,
141 manually_run, onos_tag )
Devin Lim2edfcec2018-05-09 17:16:21 -0700142 }
143}
Jon Hall6af749d2018-05-29 12:59:47 -0700144def finalList = [ : ]
Devin Limf5175192018-05-14 19:13:22 -0700145
146// get the name of the job.
Devin Limb91bf792018-05-10 15:09:52 -0700147jobName = env.JOB_NAME
Devin Limf5175192018-05-14 19:13:22 -0700148
149// first set the list of the functions to be run.
Devin Lim2edfcec2018-05-09 17:16:21 -0700150finalList[ "VM" ] = triggerFuncs.runTestSeq( runTest[ "VM" ] )
151finalList[ "BM" ] = triggerFuncs.runTestSeq( runTest[ "BM" ] )
Devin Limf5175192018-05-14 19:13:22 -0700152
153// if first two character of the job name is vm, only call VM.
154// else, only on BM
Jon Hall6af749d2018-05-29 12:59:47 -0700155if ( jobName.take( 2 ) == "vm" ){
Devin Limb91bf792018-05-10 15:09:52 -0700156 finalList[ "VM" ].call()
Jon Hall6af749d2018-05-29 12:59:47 -0700157}
158else {
Devin Limb91bf792018-05-10 15:09:52 -0700159 finalList[ "BM" ].call()
Jon Hall6af749d2018-05-29 12:59:47 -0700160}
Devin Lim2edfcec2018-05-09 17:16:21 -0700161
Devin Limf5175192018-05-14 19:13:22 -0700162// If it is automated running, it will generate the stats graph on VM.
Devin Lim2edfcec2018-05-09 17:16:21 -0700163if ( !manually_run ){
164 funcs.generateStatGraph( "TestStation-VMs",
165 funcs.branchWithPrefix( onos_b ),
Devin Lim2edfcec2018-05-09 17:16:21 -0700166 stat_graph_generator_file,
167 pie_graph_generator_file,
168 graph_saved_directory )
169}
170
Devin Limf5175192018-05-14 19:13:22 -0700171// function that will divide tests depends on which day it is.
Devin Lim2edfcec2018-05-09 17:16:21 -0700172def testDivider( today ){
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -0700173 todayStr = today.toString()
174
175 dayMap = [ ( Calendar.MONDAY ) : "mon",
176 ( Calendar.TUESDAY ) : "tue",
177 ( Calendar.WEDNESDAY ) : "wed",
178 ( Calendar.THURSDAY ) : "thu",
179 ( Calendar.FRIDAY ) : "fri",
180 ( Calendar.SATURDAY ) : "sat",
181 ( Calendar.SUNDAY ) : "sun" ]
182 fullDayMap = [ ( Calendar.MONDAY ) : "Monday",
183 ( Calendar.TUESDAY ) : "Tuesday",
184 ( Calendar.WEDNESDAY ) : "Wednesday",
185 ( Calendar.THURSDAY ) : "Thursday",
186 ( Calendar.FRIDAY ) : "Friday",
187 ( Calendar.SATURDAY ) : "Saturday",
188 ( Calendar.SUNDAY ) : "Sunday" ]
189
190 if ( today == Calendar.MONDAY ){
191 initHtmlForWiki()
192 day = fullDayMap[ today ]
193 for ( key in dayMap.keySet() ){
194 buildDay( dayMap[ key ], false )
195 }
196 closeHtmlForWiki()
197 postToWiki( wikiContents )
198 slackSend( color: '#FFD988',
199 message: "Tests to be run this weekdays : \n" +
200 triggerFuncs.printDaysForTest() )
201 } else {
202 day = fullDayMap[ today ]
203 buildDay( dayMap[ today ], true )
Devin Lim2edfcec2018-05-09 17:16:21 -0700204 }
205}
Devin Limf5175192018-05-14 19:13:22 -0700206
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -0700207def buildDay( dayStr, getResult ){
Devin Lim2edfcec2018-05-09 17:16:21 -0700208 addingHeader( "FUNC" )
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -0700209 FUNC_choices += adder( "FUNC", dayStr, getResult )
Devin Lim2edfcec2018-05-09 17:16:21 -0700210 closingHeader( "FUNC" )
211 addingHeader( "HA" )
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -0700212 HA_choices += adder( "HA", dayStr, getResult )
Devin Lim2edfcec2018-05-09 17:16:21 -0700213 closingHeader( "HA" )
214 addingHeader( "SCPF" )
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -0700215 SCPF_choices += adder( "SCPF", dayStr, getResult )
Devin Lim2edfcec2018-05-09 17:16:21 -0700216 closingHeader( "SCPF" )
217 addingHeader( "SR" )
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -0700218 SR_choices += adder( "SR", dayStr, false )
Devin Lim2edfcec2018-05-09 17:16:21 -0700219 closingHeader( "SR" )
Jon Hall2ee92f82018-06-07 13:07:33 -0700220 addingHeader( "SRHA" )
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -0700221 SRHA_choices += adder( "SRHA", dayStr, false )
Jon Hall2ee92f82018-06-07 13:07:33 -0700222 closingHeader( "SRHA" )
Devin Lim2edfcec2018-05-09 17:16:21 -0700223 addingHeader( "USECASE" )
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -0700224 USECASE_choices += adder( "USECASE", dayStr, getResult )
Devin Lim2edfcec2018-05-09 17:16:21 -0700225 closingHeader( "USECASE" )
226}
Devin Limf5175192018-05-14 19:13:22 -0700227
228// adder that will return the list of the tests.
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -0700229def adder( category, day, getResult ){
230 // category : the category of the test which will be either FUNC,HA,SR...
Devin Limf5175192018-05-14 19:13:22 -0700231 // day : the day you are trying to add (m,t,w,th... )
232 // getResult : if want to get the list of the test to be run. False will return empty list.
233 // And once the list is empty, it will not be run.
Jon Hall6af749d2018-05-29 12:59:47 -0700234 def result = ""
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -0700235 selectedTests = getTestsFromCategory( category, getTestsFromDay( day, onos_b ) )
236
237 for ( String test in selectedTests.keySet() ){
238 if ( getResult ){
239 result += test + ","
Devin Lim2edfcec2018-05-09 17:16:21 -0700240 }
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -0700241 // make HTML columns for wiki page on schedule.
242 makeHtmlColList( category, test )
Devin Lim2edfcec2018-05-09 17:16:21 -0700243 }
244 return result
245}
Devin Limf5175192018-05-14 19:13:22 -0700246
247// Initial part of the wiki page.
Devin Lim2edfcec2018-05-09 17:16:21 -0700248def initHtmlForWiki(){
249 wikiContents = '''
250 <table class="wrapped confluenceTable">
251 <colgroup>
252 <col />
253 <col />
254 <col />
255 <col />
256 <col />
257 <col />
258 </colgroup>
259 <tbody>
260 <tr>
261 <th colspan="1" class="confluenceTh">
262 <br />
263 </th>
264 <th class="confluenceTh"><p>Monday</p></th>
265 <th class="confluenceTh"><p>Tuesday</p></th>
266 <th class="confluenceTh"><p>Wednesday</p></th>
267 <th class="confluenceTh"><p>Thursday</p></th>
268 <th class="confluenceTh"><p>Friday</p></th>
269 <th class="confluenceTh"><p>Saturday</p></th>
270 <th class="confluenceTh"><p>Sunday</p></th>
271 </tr>'''
Jon Hall6af749d2018-05-29 12:59:47 -0700272 for ( String test in testcases.keySet() ){
Devin Lim2edfcec2018-05-09 17:16:21 -0700273 testcases[ test ][ 'wikiContent' ] = '''
274 <tr>
275 <th colspan="1" class="confluenceTh">''' + test + '''</th>'''
276 }
277}
Devin Limf5175192018-05-14 19:13:22 -0700278
279// adding header functionality.
Devin Lim2edfcec2018-05-09 17:16:21 -0700280def addingHeader( testCategory ){
281 testcases[ testCategory ][ 'wikiContent' ] += '''
282 <td class="confluenceTd">
283 <ul>'''
284}
Devin Limf5175192018-05-14 19:13:22 -0700285
286// making column list for html
Devin Lim2edfcec2018-05-09 17:16:21 -0700287def makeHtmlColList( testCategory, testName ){
288 testcases[ testCategory ][ 'wikiContent' ] += '''
Jon Hall6af749d2018-05-29 12:59:47 -0700289 <li>''' + testName + '''</li>'''
Devin Lim2edfcec2018-05-09 17:16:21 -0700290
291}
Devin Limf5175192018-05-14 19:13:22 -0700292
293// closing the header for html
Devin Lim2edfcec2018-05-09 17:16:21 -0700294def closingHeader( testCategory ){
295 testcases[ testCategory ][ 'wikiContent' ] += '''
296 </ul>
297 </td>'''
298}
Devin Limf5175192018-05-14 19:13:22 -0700299
300// close the html for the wiki page.
Devin Lim2edfcec2018-05-09 17:16:21 -0700301def closeHtmlForWiki(){
Jon Hall6af749d2018-05-29 12:59:47 -0700302 for ( String test in testcases.keySet() ){
Devin Lim2edfcec2018-05-09 17:16:21 -0700303 wikiContents += testcases[ test ][ 'wikiContent' ]
304 wikiContents += '''
305 </tr>'''
306 }
307 wikiContents += '''
308 </tbody>
309 </table>
310 <p><strong>Everyday</strong>, all SegmentRouting tests are built and run on every supported branch.</p>
311 <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 -0700312 <p>On <strong>Saturdays</strong>, all the other tests are built and run on the ''' +
313 funcs.branchWithPrefix( previous_version ) + ''' branch.</p>
314 <p>On <strong>Sundays</strong>, all the other tests are built and run on the ''' +
315 funcs.branchWithPrefix( before_previous_version ) + ''' branch.</p>'''
Devin Lim2edfcec2018-05-09 17:16:21 -0700316}
Devin Limf5175192018-05-14 19:13:22 -0700317
318// post the result to wiki page using publish to confluence.
Devin Lim2edfcec2018-05-09 17:16:21 -0700319def postToWiki( contents ){
Jon Hall6af749d2018-05-29 12:59:47 -0700320 node( testMachine ) {
Devin Limfe9a4cb2018-05-11 17:06:21 -0700321 workspace = fileRelated.jenkinsWorkspace + "all-pipeline-trigger/"
Devin Lim2edfcec2018-05-09 17:16:21 -0700322 filename = "jenkinsSchedule.txt"
323 writeFile file: workspace + filename, text: contents
324 funcs.publishToConfluence( "false", "true",
325 "Automated Test Schedule",
326 workspace + filename )
327 }
328}