[ONOS-8015]: Utilize node labels in Jenkins pipelines

Change-Id: I6599f0f1fea4199a31fb2fbca10ef64188c07de1
diff --git a/TestON/JenkinsFile/dependencies/JenkinsCommonFuncs.groovy b/TestON/JenkinsFile/dependencies/JenkinsCommonFuncs.groovy
index eddb588..9656e71 100644
--- a/TestON/JenkinsFile/dependencies/JenkinsCommonFuncs.groovy
+++ b/TestON/JenkinsFile/dependencies/JenkinsCommonFuncs.groovy
@@ -31,23 +31,28 @@
 fileRelated.init()
 test_list.init()
 
+nodeLabel = null
+testStation = null
+
 def initializeTrend( machine ){
     // For initializing any trend graph jobs
     // machine : Either VM,BM, or Fabric#
 
     table_name = "executed_test_tests"
     result_name = "executed_test_results"
-    testMachine = "TestStation-" + machine + "s"
+    testStation = "TestStation-" + machine + "s"
     this.machine = machine
     isSCPF = false
     isTrend = true
 }
 
-def initialize( type, SCPFfuncs=null ){
+def initialize( type, testS, nodeL, SCPFfuncs=null ){
     // initializing for FUNC,HA,SR, and USECASE
     // type : type of the test ( SR,FUNC,SCPF... )
 
-    init( type )
+    testStation = testS
+    testType = type
+    nodeLabel = nodeL
     isSCPF = ( type == "SCPF" )
     SCPFfunc = SCPFfuncs
 
@@ -55,58 +60,15 @@
     result_name = "executed_test_results"
     trend_generator_file = fileRelated.trendMultiple
     build_stats_generator_file = fileRelated.histogramMultiple
-}
-
-def init( type ){
-    // type : type of the test ( SR,FUNC,SCPF... )
-
-    machineType = [ "FUNC": "VM",
-                    "HA": "VM",
-                    "SR": "Fabric",
-                    "SCPF": "BM",
-                    "USECASE": "BM" ]
-    testType = type
-    testMachine = "TestStation-" + machineType[ type ] + "s"
     isTrend = false
 }
 
-def additionalInitForSR( branch ){
-    // additional setup for SegmentRouting tests to determine the machine depends on the branch it is running.
-    // branch : branch of the onos. ( master, 2.1, 1.15... )
-
-    testMachine = ( ( new StringBuilder( testMachine ) ).insert( testMachine.size() - 1, fabricOn( branch ) ) ).
-            toString()
-    if ( isTrend ){
-        machine += fabricOn( branch )
-    }
-    else {
-        machineType[ testType ] += fabricOn( branch )
-    }
-    print testMachine
-}
-
-def fabricOn( branch ){
-    // gets the fabric machines with the branch of onos.
-    // branch : master, 2.1, 1.15...
-    // branch.reverse().take(4).reverse() will get last 4 characters of the string.
-    switch ( branch.reverse().take( 3 ).reverse() ){
-        case "ter": return "4"
-        case "2.1": return "3"
-        case "2.0": return "3"
-        case ".15": return "2"
-        case ".14": return "3"
-        case ".13": return "2"
-        case ".12": return "3"
-        default: return "4"
-    }
-}
-
 def getProperties( category, branchWithPrefix ){
     // get the properties of the test by reading the TestONOS.property
 
     filePath = '''/var/jenkins/TestONOS-''' + category + '''-''' + branchWithPrefix + '''.property'''
 
-    node( testMachine ) {
+    node( testStation ) {
         return readProperties( file: filePath )
     }
 }
@@ -172,7 +134,7 @@
         ./cleanup.sh -f
         ''' + "./cli.py run " +
           testName +
-           " --params GRAPH/nodeCluster=" + machineType[ testType ] + '''
+           " --params GRAPH/nodeCluster=" + nodeLabel + '''
         ./cleanup.sh -f
         # cleanup config changes
         cd ~/onos/tools/package/config
@@ -262,13 +224,8 @@
     // prop : property dictionary that was read from the machine.
     // graphOnly : if it is graph generating job
 
-    if ( graphOnly ){
-        if ( machine == null ){
-            machine = machineType[ testType ]
-        }
-        def post = build job: "postjob-" + machine, propagate: false
-    } else if ( isPostingResult( prop[ "manualRun" ], prop[ "postResult" ] ) ){
-        def post = build job: "postjob-" + machineType[ testType ], propagate: false
+    if ( graphOnly || isPostingResult( prop[ "manualRun" ], prop[ "postResult" ] ) ){
+        def post = build job: "postjob-" + nodeLabel, propagate: false
     }
 }
 
@@ -304,7 +261,7 @@
     // wikiLink : link of the wiki page where the result was posted
     // isSCPF : Check if it is SCPF. If so, it won't post the wiki link.
 
-    node( testMachine ) {
+    node( testStation ) {
         def alarmFile = workSpace + "/" + pureTestName + "Alarm.txt"
         if ( fileExists( alarmFile ) ) {
             def alarmContents = readFile( alarmFile )
@@ -362,7 +319,7 @@
                 if ( toBeRun ){
                     def workSpace = "/var/jenkins/workspace/" + testName
                     def fileContents = ""
-                    node( testMachine ) {
+                    node( testStation ) {
                         withEnv( [ 'ONOSBranch=' + prop[ "ONOSBranch" ],
                                    'ONOSJAVAOPTS=' + prop[ "ONOSJAVAOPTS" ],
                                    'TestONBranch=' + prop[ "TestONBranch" ],
@@ -474,7 +431,7 @@
     // generate the overall graph for the test
 
     if ( isPostingResult( prop[ "manualRun" ], prop[ "postResult" ] ) ){
-        node( testMachine ) {
+        node( testStation ) {
 
             withCredentials( [
                     string( credentialsId: 'db_pass', variable: 'pass' ),
diff --git a/TestON/JenkinsFile/dependencies/TriggerFuncs.groovy b/TestON/JenkinsFile/dependencies/TriggerFuncs.groovy
index 2aba5d2..b6b3212 100644
--- a/TestON/JenkinsFile/dependencies/TriggerFuncs.groovy
+++ b/TestON/JenkinsFile/dependencies/TriggerFuncs.groovy
@@ -23,13 +23,12 @@
 // This will provide the portion that will set up the environment of the machine
 //      and trigger the corresponding jobs.
 
+import groovy.time.TimeCategory
+import groovy.time.TimeDuration
+
 test_list = evaluate readTrusted( 'TestON/JenkinsFile/dependencies/JenkinsTestONTests.groovy' )
 test_list.init()
 
-def init( commonFuncs ){
-    funcs = commonFuncs
-}
-
 def printDaysForTest(){
     // Print the days for what test has.
     AllTheTests = test_list.getAllTests()
@@ -48,7 +47,7 @@
     return result
 }
 
-def trigger( branch, tests, nodeName, jobOn, manuallyRun, onosTag ){
+def trigger( branch, tests, nodeLabel, jobOn, manuallyRun, onosTag ){
     // triggering function that will setup the environment and determine which pipeline to trigger
 
     println "Job name: " + jobOn + "-pipeline-" + ( manuallyRun ? "manually" : branch )
@@ -57,27 +56,32 @@
     def test_branch = test_list.addPrefixToBranch( branch )
     println "onos_branch with prefix: " + onos_branch
     println "test_branch with prefix: " + test_branch
-    node( "TestStation-" + nodeName + "s" ) {
+    assignedNode = null
+    node( label: nodeLabel ) {
         envSetup( onos_branch, test_branch, onosTag, jobOn, manuallyRun )
-        exportEnvProperty( onos_branch, test_branch, jobOn, wiki, tests, post_result, manuallyRun, onosTag, isOldFlow )
+        exportEnvProperty( onos_branch, test_branch, jobOn, wiki, tests, post_result, manuallyRun, onosTag, isOldFlow, nodeLabel )
+        assignedNode = env.NODE_NAME
     }
 
     jobToRun = jobOn + "-pipeline-" + ( manuallyRun ? "manually" : wiki )
-    build job: jobToRun, propagate: false, parameters: [ [ $class: 'StringParameterValue', name: 'Category', value: jobOn ], [ $class: 'StringParameterValue', name: 'Branch', value: branch ] ]
+    build job: jobToRun, propagate: false, parameters: [ [ $class: 'StringParameterValue', name: 'Category', value: jobOn ],
+                                                         [ $class: 'StringParameterValue', name: 'Branch', value: branch ],
+                                                         [ $class: 'StringParameterValue', name: 'TestStation', value: assignedNode ],
+                                                         [ $class: 'StringParameterValue', name: 'NodeLabel', value: nodeLabel ] ]
 }
 
-def trigger_pipeline( branch, tests, nodeName, jobOn, manuallyRun, onosTag ){
-    // nodeName : "BM" or "VM"
+def trigger_pipeline( branch, tests, nodeLabel, jobOn, manuallyRun, onosTag ){
+    // nodeLabel : nodeLabel from tests.json
     // jobOn : "SCPF" or "USECASE" or "FUNC" or "HA"
     // this will return the function by wrapping them up with return{} to prevent them to be
     // executed once this function is called to assign to specific variable.
     return {
-        trigger( branch, tests, nodeName, jobOn, manuallyRun, onosTag )
+        trigger( branch, tests, nodeLabel, jobOn, manuallyRun, onosTag )
     }
 }
 
 // export Environment properties.
-def exportEnvProperty( onos_branch, test_branch, jobOn, wiki, tests, postResult, manually_run, onosTag, isOldFlow ){
+def exportEnvProperty( onos_branch, test_branch, jobOn, wiki, tests, postResult, manually_run, onosTag, isOldFlow, nodeLabel ){
     // export environment properties to the machine.
 
     filePath = "/var/jenkins/TestONOS-" + jobOn + "-" + onos_branch + ".property"
diff --git a/TestON/JenkinsFile/dependencies/tests.json b/TestON/JenkinsFile/dependencies/tests.json
index 5a26f08..51fdb04 100644
--- a/TestON/JenkinsFile/dependencies/tests.json
+++ b/TestON/JenkinsFile/dependencies/tests.json
@@ -786,17 +786,17 @@
             {
                 "branch": "master",
                 "day": "everyday",
-                "nodeLabel": "Fabric4"
+                "nodeLabel": "Fabric-master"
             },
             {
                 "branch": "onos-1.x",
                 "day": "everyday",
-                "nodeLabel": "Fabric2"
+                "nodeLabel": "Fabric-1.x"
             },
             {
                 "branch": "onos-2.x",
                 "day": "everyday",
-                "nodeLabel": "Fabric3"
+                "nodeLabel": "Fabric-2.x"
             }
         ],
         "category": "SR",
@@ -809,17 +809,17 @@
             {
                 "branch": "master",
                 "day": "everyday",
-                "nodeLabel": "Fabric4"
+                "nodeLabel": "Fabric-master"
             },
             {
                 "branch": "onos-1.x",
                 "day": "everyday",
-                "nodeLabel": "Fabric2"
+                "nodeLabel": "Fabric-1.x"
             },
             {
                 "branch": "onos-2.x",
                 "day": "everyday",
-                "nodeLabel": "Fabric3"
+                "nodeLabel": "Fabric-2.x"
             }
         ],
         "category": "SR",
@@ -832,17 +832,17 @@
             {
                 "branch": "master",
                 "day": "everyday",
-                "nodeLabel": "Fabric4"
+                "nodeLabel": "Fabric-master"
             },
             {
                 "branch": "onos-1.x",
                 "day": "everyday",
-                "nodeLabel": "Fabric2"
+                "nodeLabel": "Fabric-1.x"
             },
             {
                 "branch": "onos-2.x",
                 "day": "everyday",
-                "nodeLabel": "Fabric3"
+                "nodeLabel": "Fabric-2.x"
             }
         ],
         "category": "SR",
@@ -855,17 +855,17 @@
             {
                 "branch": "master",
                 "day": "everyday",
-                "nodeLabel": "Fabric4"
+                "nodeLabel": "Fabric-master"
             },
             {
                 "branch": "onos-1.x",
                 "day": "everyday",
-                "nodeLabel": "Fabric2"
+                "nodeLabel": "Fabric-1.x"
             },
             {
                 "branch": "onos-2.x",
                 "day": "everyday",
-                "nodeLabel": "Fabric3"
+                "nodeLabel": "Fabric-2.x"
             }
         ],
         "category": "SR",
@@ -878,17 +878,17 @@
             {
                 "branch": "master",
                 "day": "everyday",
-                "nodeLabel": "Fabric4"
+                "nodeLabel": "Fabric-master"
             },
             {
                 "branch": "onos-1.x",
                 "day": "everyday",
-                "nodeLabel": "Fabric2"
+                "nodeLabel": "Fabric-1.x"
             },
             {
                 "branch": "onos-2.x",
                 "day": "everyday",
-                "nodeLabel": "Fabric3"
+                "nodeLabel": "Fabric-2.x"
             }
         ],
         "category": "SR",
@@ -901,17 +901,17 @@
             {
                 "branch": "master",
                 "day": "fri",
-                "nodeLabel": "Fabric4"
+                "nodeLabel": "Fabric-master"
             },
             {
                 "branch": "onos-1.x",
                 "day": "fri",
-                "nodeLabel": "Fabric2"
+                "nodeLabel": "Fabric-1.x"
             },
             {
                 "branch": "onos-2.x",
                 "day": "fri",
-                "nodeLabel": "Fabric3"
+                "nodeLabel": "Fabric-2.x"
             }
         ],
         "category": "SR",
@@ -924,17 +924,17 @@
             {
                 "branch": "master",
                 "day": "fri",
-                "nodeLabel": "Fabric4"
+                "nodeLabel": "Fabric-master"
             },
             {
                 "branch": "onos-1.x",
                 "day": "fri",
-                "nodeLabel": "Fabric2"
+                "nodeLabel": "Fabric-1.x"
             },
             {
                 "branch": "onos-2.x",
                 "day": "fri",
-                "nodeLabel": "Fabric3"
+                "nodeLabel": "Fabric-2.x"
             }
         ],
         "category": "SR",
@@ -947,17 +947,17 @@
             {
                 "branch": "master",
                 "day": "fri",
-                "nodeLabel": "Fabric4"
+                "nodeLabel": "Fabric-master"
             },
             {
                 "branch": "onos-1.x",
                 "day": "fri",
-                "nodeLabel": "Fabric2"
+                "nodeLabel": "Fabric-1.x"
             },
             {
                 "branch": "onos-2.x",
                 "day": "fri",
-                "nodeLabel": "Fabric3"
+                "nodeLabel": "Fabric-2.x"
             }
         ],
         "category": "SR",
@@ -970,17 +970,17 @@
             {
                 "branch": "master",
                 "day": "fri",
-                "nodeLabel": "Fabric4"
+                "nodeLabel": "Fabric-master"
             },
             {
                 "branch": "onos-1.x",
                 "day": "fri",
-                "nodeLabel": "Fabric2"
+                "nodeLabel": "Fabric-1.x"
             },
             {
                 "branch": "onos-2.x",
                 "day": "fri",
-                "nodeLabel": "Fabric3"
+                "nodeLabel": "Fabric-2.x"
             }
         ],
         "category": "SR",
@@ -993,17 +993,17 @@
             {
                 "branch": "master",
                 "day": "sat",
-                "nodeLabel": "Fabric4"
+                "nodeLabel": "Fabric-master"
             },
             {
                 "branch": "onos-1.x",
                 "day": "sat",
-                "nodeLabel": "Fabric2"
+                "nodeLabel": "Fabric-1.x"
             },
             {
                 "branch": "onos-2.x",
                 "day": "sat",
-                "nodeLabel": "Fabric3"
+                "nodeLabel": "Fabric-2.x"
             }
         ],
         "category": "SR",
@@ -1016,17 +1016,17 @@
             {
                 "branch": "master",
                 "day": "sat",
-                "nodeLabel": "Fabric4"
+                "nodeLabel": "Fabric-master"
             },
             {
                 "branch": "onos-1.x",
                 "day": "sat",
-                "nodeLabel": "Fabric2"
+                "nodeLabel": "Fabric-1.x"
             },
             {
                 "branch": "onos-2.x",
                 "day": "sat",
-                "nodeLabel": "Fabric3"
+                "nodeLabel": "Fabric-2.x"
             }
         ],
         "category": "SR",
@@ -1039,17 +1039,17 @@
             {
                 "branch": "master",
                 "day": "sat",
-                "nodeLabel": "Fabric4"
+                "nodeLabel": "Fabric-master"
             },
             {
                 "branch": "onos-1.x",
                 "day": "sat",
-                "nodeLabel": "Fabric2"
+                "nodeLabel": "Fabric-1.x"
             },
             {
                 "branch": "onos-2.x",
                 "day": "sat",
-                "nodeLabel": "Fabric3"
+                "nodeLabel": "Fabric-2.x"
             }
         ],
         "category": "SR",
@@ -1063,17 +1063,17 @@
             {
                 "branch": "master",
                 "day": "everyday",
-                "nodeLabel": "Fabric4"
+                "nodeLabel": "Fabric-master"
             },
             {
                 "branch": "onos-1.x",
                 "day": "everyday",
-                "nodeLabel": "Fabric2"
+                "nodeLabel": "Fabric-1.x"
             },
             {
                 "branch": "onos-2.x",
                 "day": "everyday",
-                "nodeLabel": "Fabric3"
+                "nodeLabel": "Fabric-2.x"
             }
         ],
         "category": "SR",
@@ -1085,17 +1085,17 @@
             {
                 "branch": "master",
                 "day": "everyday",
-                "nodeLabel": "Fabric4"
+                "nodeLabel": "Fabric-master"
             },
             {
                 "branch": "onos-1.x",
                 "day": "everyday",
-                "nodeLabel": "Fabric2"
+                "nodeLabel": "Fabric-1.x"
             },
             {
                 "branch": "onos-2.x",
                 "day": "everyday",
-                "nodeLabel": "Fabric3"
+                "nodeLabel": "Fabric-2.x"
             }
         ],
         "category": "SR",
@@ -1109,17 +1109,17 @@
             {
                 "branch": "master",
                 "day": "everyday",
-                "nodeLabel": "Fabric4"
+                "nodeLabel": "Fabric-master"
             },
             {
                 "branch": "onos-1.x",
                 "day": "everyday",
-                "nodeLabel": "Fabric2"
+                "nodeLabel": "Fabric-1.x"
             },
             {
                 "branch": "onos-2.x",
                 "day": "everyday",
-                "nodeLabel": "Fabric3"
+                "nodeLabel": "Fabric-2.x"
             }
         ],
         "category": "SR",
@@ -1133,17 +1133,17 @@
             {
                 "branch": "master",
                 "day": "everyday",
-                "nodeLabel": "Fabric4"
+                "nodeLabel": "Fabric-master"
             },
             {
                 "branch": "onos-1.x",
                 "day": "everyday",
-                "nodeLabel": "Fabric2"
+                "nodeLabel": "Fabric-1.x"
             },
             {
                 "branch": "onos-2.x",
                 "day": "everyday",
-                "nodeLabel": "Fabric3"
+                "nodeLabel": "Fabric-2.x"
             }
         ],
         "category": "SR",
@@ -1157,17 +1157,17 @@
             {
                 "branch": "master",
                 "day": "fri",
-                "nodeLabel": "Fabric4"
+                "nodeLabel": "Fabric-master"
             },
             {
                 "branch": "onos-1.x",
                 "day": "fri",
-                "nodeLabel": "Fabric2"
+                "nodeLabel": "Fabric-1.x"
             },
             {
                 "branch": "onos-2.x",
                 "day": "fri",
-                "nodeLabel": "Fabric3"
+                "nodeLabel": "Fabric-2.x"
             }
         ],
         "category": "SR",
@@ -1181,17 +1181,17 @@
             {
                 "branch": "master",
                 "day": "sat",
-                "nodeLabel": "Fabric4"
+                "nodeLabel": "Fabric-master"
             },
             {
                 "branch": "onos-1.x",
                 "day": "sat",
-                "nodeLabel": "Fabric2"
+                "nodeLabel": "Fabric-1.x"
             },
             {
                 "branch": "onos-2.x",
                 "day": "sat",
-                "nodeLabel": "Fabric3"
+                "nodeLabel": "Fabric-2.x"
             }
         ],
         "category": "SR",
@@ -1205,17 +1205,17 @@
             {
                 "branch": "master",
                 "day": "sat",
-                "nodeLabel": "Fabric4"
+                "nodeLabel": "Fabric-master"
             },
             {
                 "branch": "onos-1.x",
                 "day": "sat",
-                "nodeLabel": "Fabric2"
+                "nodeLabel": "Fabric-1.x"
             },
             {
                 "branch": "onos-2.x",
                 "day": "sat",
-                "nodeLabel": "Fabric3"
+                "nodeLabel": "Fabric-2.x"
             }
         ],
         "category": "SR",
@@ -1229,17 +1229,17 @@
             {
                 "branch": "master",
                 "day": "everyday",
-                "nodeLabel": "Fabric4"
+                "nodeLabel": "Fabric-master"
             },
             {
                 "branch": "onos-1.x",
                 "day": "everyday",
-                "nodeLabel": "Fabric2"
+                "nodeLabel": "Fabric-1.x"
             },
             {
                 "branch": "onos-2.x",
                 "day": "everyday",
-                "nodeLabel": "Fabric3"
+                "nodeLabel": "Fabric-2.x"
             }
         ],
         "category": "SR",
@@ -1253,17 +1253,17 @@
             {
                 "branch": "master",
                 "day": "everyday",
-                "nodeLabel": "Fabric4"
+                "nodeLabel": "Fabric-master"
             },
             {
                 "branch": "onos-1.x",
                 "day": "everyday",
-                "nodeLabel": "Fabric2"
+                "nodeLabel": "Fabric-1.x"
             },
             {
                 "branch": "onos-2.x",
                 "day": "everyday",
-                "nodeLabel": "Fabric3"
+                "nodeLabel": "Fabric-2.x"
             }
         ],
         "category": "SR",