blob: b0cd74399e76147bffa1bc9540f2d0ce15d87aec [file] [log] [blame]
#!groovy
// Copyright 2017 Open Networking Foundation (ONF)
//
// Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>,
// the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>,
// or the System Testing Guide page at <https://wiki.onosproject.org/x/WYQg>
//
// TestON is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 2 of the License, or
// (at your option) any later version.
//
// TestON is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with TestON. If not, see <http://www.gnu.org/licenses/>.
// This is the Jenkins script for vm-pipeline-trigger or bm-pipeline-trigger
// set the functions of the dependencies.
funcs = evaluate readTrusted( 'TestON/JenkinsFile/dependencies/JenkinsCommonFuncs.groovy' )
triggerFuncs = evaluate readTrusted( 'TestON/JenkinsFile/dependencies/TriggerFuncs.groovy' )
fileRelated = evaluate readTrusted( 'TestON/JenkinsFile/dependencies/JenkinsPathAndFiles.groovy' )
test_list = evaluate readTrusted( 'TestON/JenkinsFile/dependencies/JenkinsTestONTests.groovy' )
test_list.init()
// set the versions of the onos
fileRelated.init()
// init trend graphs to be on VM.
funcs.initializeTrend( "VM" );
triggerFuncs.init( funcs )
// contents for page https://wiki.onosproject.org/display/ONOS/Automated+Test+Schedule
// which will demonstrates the list of the scheduled tests on the days.
wikiContents = ""
all_testcases = [:]
// read the parameters from the Jenkins
manually_run = params.manual_run
onos_tag = params.ONOSTag
isOldFlow = true
// Set tests based on day of week
def now = funcs.getCurrentTime()
print now.toString()
today = now[ Calendar.DAY_OF_WEEK ]
dayMap = [ ( Calendar.MONDAY ) : "mon",
( Calendar.TUESDAY ) : "tue",
( Calendar.WEDNESDAY ) : "wed",
( Calendar.THURSDAY ) : "thu",
( Calendar.FRIDAY ) : "fri",
( Calendar.SATURDAY ) : "sat",
( Calendar.SUNDAY ) : "sun" ]
fullDayMap = [ ( Calendar.MONDAY ) : "Monday",
( Calendar.TUESDAY ) : "Tuesday",
( Calendar.WEDNESDAY ) : "Wednesday",
( Calendar.THURSDAY ) : "Thursday",
( Calendar.FRIDAY ) : "Friday",
( Calendar.SATURDAY ) : "Saturday",
( Calendar.SUNDAY ) : "Sunday" ]
if ( manually_run ){
onos_branches = params.branches.tokenize( "\n;, " )
} else {
onos_branches = getBranchesFromDay( dayMap[ today ] )
}
// default FUNC,HA to be VM, SCPF,USECASE to be BM.
// SR will not be used in here.
testcases_template = [
"FUNC": [ tests: "", nodeName: "VM", wikiContent: "" ],
"HA": [ tests: "", nodeName: "VM", wikiContent: "" ],
"SCPF": [ tests: "", nodeName: "BM", wikiContent: "" ],
"SR": [ tests: "", nodeName: "Fabric", wikiContent: "" ],
"SRHA": [ tests: "", nodeName: "Fabric", wikiContent: "" ],
"USECASE": [ tests: "", nodeName: "BM", wikiContent: "" ]
]
for ( String b in onos_branches ){
all_testcases.put( b, testcases_template )
}
// list of the tests to be run will be saved in each choices.
day = ""
// init some paths for the files and directories.
stat_graph_generator_file = fileRelated.histogramMultiple
pie_graph_generator_file = fileRelated.pieMultiple
graph_saved_directory = fileRelated.jenkinsWorkspace + "postjob-VM/"
// get post result from the params for manually run.
post_result = params.PostResult
// if automatically run, it will remove the comma at the end after dividing the tests.
if ( manually_run ){
for ( String b in onos_branches ){
all_testcases[ b ] = triggerFuncs.organize_tests( params.Tests, all_testcases[ b ] )
}
isOldFlow = params.isOldFlow
println "Tests to be run manually:"
} else {
testDivider( today )
println "Defaulting to " + day + " tests:"
}
for ( String b in onos_branches ){
triggerFuncs.print_tests( all_testcases[ b ] )
}
def runTest = [
"VM": [ : ],
"BM": [ : ]
]
def finalList = [ : ]
finalList[ "VM" ] = [ : ]
finalList[ "BM" ] = [ : ]
// get the name of the job.
jobName = env.JOB_NAME
// set the test running function into the dictionary.
for ( String b in onos_branches ){
for ( String test in all_testcases[ b ].keySet() ){
if ( all_testcases[ b ][ test ][ "tests" ] != "" ){
runTest[ all_testcases[ b ][ test ][ "nodeName" ] ][ test ] = triggerFuncs.
trigger_pipeline( b, all_testcases[ b ][ test ][ "tests" ], all_testcases[ b ][ test ][ "nodeName" ], test,
manually_run, onos_tag )
}
}
// first set the list of the functions to be run.
finalList[ "VM" ][ b ] = triggerFuncs.runTestSeq( runTest[ "VM" ] )
finalList[ "BM" ][ b ] = triggerFuncs.runTestSeq( runTest[ "BM" ] )
}
// if first two character of the job name is vm, only call VM.
// else, only on BM
if ( jobName.take( 2 ) == "vm" ){
parallel finalList[ "VM" ]
}
else {
parallel finalList[ "BM" ]
}
// If it is automated running, it will generate the stats graph on VM.
if ( !manually_run ){
for ( String b in onos_branches ){
funcs.generateStatGraph( "TestStation-VMs",
funcs.branchWithPrefix( b ),
stat_graph_generator_file,
pie_graph_generator_file,
graph_saved_directory )
}
}
// function that will divide tests depends on which day it is.
def testDivider( today ){
todayStr = today.toString()
if ( today == Calendar.MONDAY ){
initHtmlForWiki()
day = fullDayMap[ today ]
for ( key in dayMap.keySet() ){
buildDay( dayMap[ key ], false )
}
closeHtmlForWiki()
postToWiki( wikiContents )
slackSend( color: '#FFD988',
message: "Tests to be run this weekdays : \n" +
triggerFuncs.printDaysForTest() )
} else {
day = fullDayMap[ today ]
buildDay( dayMap[ today ], true )
}
}
def buildDay( dayStr, getResult ){
for ( String b in onos_branches ){
addingHeader( "FUNC", b )
all_testcases[ b ][ "FUNC" ][ "tests" ] += adder( "FUNC", dayStr, getResult, b )
closingHeader( "FUNC", b )
addingHeader( "HA", b )
all_testcases[ b ][ "HA" ][ "tests" ] += adder( "HA", dayStr, getResult, b )
closingHeader( "HA", b )
addingHeader( "SCPF", b )
all_testcases[ b ][ "SCPF" ][ "tests" ] += adder( "SCPF", dayStr, getResult, b )
closingHeader( "SCPF", b )
addingHeader( "SR", b )
all_testcases[ b ][ "SR" ][ "tests" ] += adder( "SR", dayStr, false, b )
closingHeader( "SR", b )
addingHeader( "SRHA", b )
all_testcases[ b ][ "SRHA" ][ "tests" ] += adder( "SRHA", dayStr, false, b )
closingHeader( "SRHA", b )
addingHeader( "USECASE", b )
all_testcases[ b ][ "USECASE" ][ "tests" ] += adder( "USECASE", dayStr, getResult, b )
closingHeader( "USECASE", b )
}
}
// adder that will return the list of the tests.
def adder( category, day, getResult, branch ){
// category : the category of the test which will be either FUNC,HA,SR...
// day : the day you are trying to add (m,t,w,th... )
// getResult : if want to get the list of the test to be run. False will return empty list.
// And once the list is empty, it will not be run.
def result = ""
selectedTests = test_list.getTestsFromCategory( category, test_list.getTestsFromDay( day, branch ) )
for ( String test in selectedTests.keySet() ){
if ( getResult ){
result += test + ","
}
// make HTML columns for wiki page on schedule.
makeHtmlColList( category, test, branch )
}
return result
}
// Initial part of the wiki page.
def initHtmlForWiki(){
wikiContents = '''
<table class="wrapped confluenceTable">
<colgroup>
<col />
<col />
<col />
<col />
<col />
<col />
</colgroup>
<tbody>
<tr>
<th colspan="1" class="confluenceTh">
<br />
</th>
<th class="confluenceTh"><p>Monday</p></th>
<th class="confluenceTh"><p>Tuesday</p></th>
<th class="confluenceTh"><p>Wednesday</p></th>
<th class="confluenceTh"><p>Thursday</p></th>
<th class="confluenceTh"><p>Friday</p></th>
<th class="confluenceTh"><p>Saturday</p></th>
<th class="confluenceTh"><p>Sunday</p></th>
</tr>'''
for ( String b in onos_branches ){
for ( String test in all_testcases[ b ].keySet() ){
all_testcases[ b ][ test ][ 'wikiContent' ] = '''
<tr>
<th colspan="1" class="confluenceTh">''' + test + '''</th>'''
}
}
}
// adding header functionality.
def addingHeader( testCategory, branch ){
all_testcases[ branch ][ testCategory ][ 'wikiContent' ] += '''
<td class="confluenceTd">
<ul>'''
}
// making column list for html
def makeHtmlColList( testCategory, testName, branch ){
all_testcases[ branch ][ testCategory ][ 'wikiContent' ] += '''
<li>''' + testName + '''</li>'''
}
// closing the header for html
def closingHeader( testCategory, branch ){
all_testcases[ branch ][ testCategory ][ 'wikiContent' ] += '''
</ul>
</td>'''
}
// close the html for the wiki page.
def closeHtmlForWiki(){
for ( String b in onos_branches ){
for ( String test in all_testcases[ b ].keySet() ){
wikiContents += all_testcases[ b ][ test ][ 'wikiContent' ]
wikiContents += '''
</tr>'''
}
}
wikiContents += '''
</tbody>
</table>
<p><strong>Everyday</strong>, all SegmentRouting tests are built and run on every supported branch.</p>
<p>On <strong>Weekdays</strong>, all the other tests are built and run on the master branch.</p>
<p>On <strong>Saturdays</strong>, all the other tests are built and run on the ''' +
test_list.convertBranchCodeToBranch( "onos-2.x" ) + ''' branch.</p>
<p>On <strong>Sundays</strong>, all the other tests are built and run on the ''' +
test_list.convertBranchCodeToBranch( "onos-1.x" ) + ''' branch.</p>'''
}
// post the result to wiki page using publish to confluence.
def postToWiki( contents ){
node( testMachine ) {
workspace = fileRelated.jenkinsWorkspace + "all-pipeline-trigger/"
filename = "jenkinsSchedule.txt"
writeFile file: workspace + filename, text: contents
funcs.publishToConfluence( "false", "true",
"Automated Test Schedule",
workspace + filename )
}
}