[ONOS-7994]: Combine TestON Pipeline Scripts Containing Similar Code
Change-Id: I1727233b87ca957c8e23c6c839232b22121847dd
diff --git a/TestON/JenkinsFile/CommonJenkinsFile.groovy b/TestON/JenkinsFile/CommonJenkinsFile.groovy
new file mode 100644
index 0000000..eb7557c
--- /dev/null
+++ b/TestON/JenkinsFile/CommonJenkinsFile.groovy
@@ -0,0 +1,115 @@
+#!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/>.
+
+// read the dependency files
+funcs = evaluate readTrusted( 'TestON/JenkinsFile/dependencies/JenkinsCommonFuncs.groovy' )
+test_list = evaluate readTrusted( 'TestON/JenkinsFile/dependencies/JenkinsTestONTests.groovy' )
+fileRelated = evaluate readTrusted( 'TestON/JenkinsFile/dependencies/JenkinsPathAndFiles.groovy' )
+SCPFfuncs = evaluate readTrusted( 'TestON/JenkinsFile/dependencies/PerformanceFuncs.groovy' )
+
+category = null
+prop = null
+testsToRun = null
+branch = null
+testsFromList = [:]
+graphPaths = [:]
+pipeline = [:]
+
+main()
+
+def main(){
+ init()
+ runTests()
+}
+
+def init(){
+ fileRelated.init()
+ test_list.init()
+ readParams()
+
+ if ( category == "SCPF" ){
+ SCPFfuncs.init()
+ isOldFlow = prop[ "isOldFlow" ] == "true"
+ SCPFfuncs.oldFlowRuleCheck( isOldFlow, prop[ "ONOSBranch" ]
+ } else if ( category == "SR" ){
+ // get the name of the Jenkins job.
+ jobName = env.JOB_NAME
+
+ // additional setup for Segment routing because it is running multiple branch concurrently on different machines.
+ funcs.additionalInitForSR( jobName )
+ }
+
+ funcs.initialize( category );
+
+ // Read the TestONOS.property from the VM
+ prop = funcs.getProperties( category, test_list.addPrefixToBranch( branch ) )
+
+ // get the list of the test and init branch to it.
+ testsFromList = test_list.getTestsFromCategory( category )
+
+ initGraphPaths()
+
+ testsToRun = funcs.getTestsToRun( prop[ "Tests" ] )
+}
+
+def readParams(){
+ category = params.Category // "FUNC", "HA", "USECASE", etc.
+ branch = params.Branch
+}
+
+def initGraphPaths(){
+ graphPaths.put( "trendIndividual", fileRelated.trendIndividual )
+ if ( catetgory == "SR" ){
+ graphPaths.put( "saveDirectory", fileRelated.jenkinsWorkspace + "postjob-Fabric" + funcs.fabricOn( prop[ "ONOSBranch" ] ) + "/" )
+ } else if ( category == "SRHA" ) {
+ graphPaths.put( "saveDirectory", fileRelated.jenkinsWorkspace + "postjob-Fabric" + "/" )
+ } else {
+ graphPaths.put( "saveDirectory", fileRelated.jenkinsWorkspace + "postjob-VM/" )
+ }
+}
+
+def runTests(){
+ // run the test sequentially and save the function into the dictionary.
+ for ( String test : testsToRun.keySet() ){
+ def toBeRun = testsToRun.contains( test )
+ def stepName = ( toBeRun ? "" : "Not " ) + "Running $test"
+ def pureTestName = ( testsToRun[ test ].containsKey( "test" ) ? testsToRun[ test ][ "test" ].split().head() : test )
+ pipeline[ stepName ] = funcs.runTest( test, toBeRun, prop, pureTestName, false,
+ testsToRun, graphPaths[ "trendIndividual" ], graphPaths[ "saveDirectory" ] )
+ }
+
+ // get the start time of the test.
+ start = funcs.getCurrentTime()
+
+ // run the tests sequentially.
+ for ( test in pipeline.keySet() ){
+ pipeline[ test ].call()
+ }
+}
+
+def generateGraphs(){
+ // generate the overall graph of the FUNC tests.
+ funcs.generateOverallGraph( prop, testsToRun, graphPaths[ "saveDirectory" ] )
+}
+
+def sendToSlack(){
+ // send the notification to Slack that running FUNC tests was ended.
+ funcs.sendResultToSlack( start, prop[ "manualRun" ], prop[ "WikiPrefix" ] )
+}