Add more support for Jenkins test names being different from TestON names

Example SRHAsanity is HAsanity with a different paramd file

Change-Id: Ibfdcbdbea83ef5017074e0e24677ed17f39e28f6
diff --git a/TestON/JenkinsFile/FUNCJenkinsFile b/TestON/JenkinsFile/FUNCJenkinsFile
index 419f35d..d7d237d 100644
--- a/TestON/JenkinsFile/FUNCJenkinsFile
+++ b/TestON/JenkinsFile/FUNCJenkinsFile
@@ -54,7 +54,8 @@
 for ( String test : FUNC.keySet() ){
     def toBeRun = testsToRun.contains( test )
     def stepName = ( toBeRun ? "" : "Not " ) + "Running $test"
-    tests[ stepName ] = funcs.runTest( test, toBeRun, prop, test, false,
+    def pureTestName = FUNC[ test ][ "test" ].split().head()
+    tests[ stepName ] = funcs.runTest( test, toBeRun, prop, pureTestName, false,
                                        FUNC, graph_generator_file, graph_saved_directory )
 }
 
diff --git a/TestON/JenkinsFile/HAJenkinsFile b/TestON/JenkinsFile/HAJenkinsFile
index cb407ab..1eae790 100644
--- a/TestON/JenkinsFile/HAJenkinsFile
+++ b/TestON/JenkinsFile/HAJenkinsFile
@@ -54,7 +54,8 @@
 for ( String test : HA.keySet() ){
     toBeRun = testsToRun.contains( test )
     def stepName = ( toBeRun ? "" : "Not " ) + "Running $test"
-    tests[ stepName ] = funcs.runTest( test, toBeRun, prop, test, false,
+    def pureTestName = HA[ test ][ "test" ].split().head()
+    tests[ stepName ] = funcs.runTest( test, toBeRun, prop, pureTestName, false,
                                        HA, graph_generator_file, graph_saved_directory )
 }
 
diff --git a/TestON/JenkinsFile/JenkinsfileTrigger b/TestON/JenkinsFile/JenkinsfileTrigger
index 0836a97..9d4e420 100644
--- a/TestON/JenkinsFile/JenkinsfileTrigger
+++ b/TestON/JenkinsFile/JenkinsfileTrigger
@@ -26,7 +26,6 @@
 // get current time and send the notification of starting the test.
 def now = funcs.getCurrentTime()
 print now.toString()
-today = now[ Calendar.DAY_OF_WEEK ]
 
 // read the passed parameters from the Jenkins.
 machines = params.machines
diff --git a/TestON/JenkinsFile/SCPFJenkinsFile b/TestON/JenkinsFile/SCPFJenkinsFile
index 9d1122e..cf31c9d 100644
--- a/TestON/JenkinsFile/SCPFJenkinsFile
+++ b/TestON/JenkinsFile/SCPFJenkinsFile
@@ -48,7 +48,7 @@
     toBeRun = testsToRun.contains( test )
     def stepName = ( toBeRun ? "" : "Not " ) + "Running $test"
 
-    pureTestName = test.replaceAll( "WithFlowObj", "" )
+    def pureTestName = test.replaceAll( "WithFlowObj", "" )
     tests[ stepName ] = funcs.runTest( test, toBeRun, prop, pureTestName, false, SCPFfuncs.SCPF, "", "" )
 }
 
diff --git a/TestON/JenkinsFile/SRHAJenkinsFile b/TestON/JenkinsFile/SRHAJenkinsFile
index 2d3b2e1..cbef08e 100644
--- a/TestON/JenkinsFile/SRHAJenkinsFile
+++ b/TestON/JenkinsFile/SRHAJenkinsFile
@@ -35,9 +35,6 @@
 // get the name of the Jenkins job.
 jobName = env.JOB_NAME
 
-// SRHA has it's own test machine
-// testmachine = "Fabrics"
-
 // read the TestON.property depends on which branch it is running.
 // ( currently master on Fabric4, 1.13 on Fabric2 and 1.12 on Fabric3 )
 def prop = null
@@ -60,8 +57,8 @@
     toBeRun = testsToRun.contains( test )
     def stepName = ( toBeRun ? "" : "Not " ) + "Running $test"
     def pureTestName = SRHA[ test ][ "test" ].split().head()
-    tests[stepName] = funcs.runTest( test, toBeRun, prop, pureTestName, false,
-                                     SRHA, graph_generator_file, graph_saved_directory )
+    tests[ stepName ] = funcs.runTest( test, toBeRun, prop, pureTestName, false,
+                                       SRHA, graph_generator_file, graph_saved_directory )
 }
 
 // get start time
diff --git a/TestON/JenkinsFile/SRJenkinsFile b/TestON/JenkinsFile/SRJenkinsFile
index 18958e3..1832b6c 100644
--- a/TestON/JenkinsFile/SRJenkinsFile
+++ b/TestON/JenkinsFile/SRJenkinsFile
@@ -56,7 +56,8 @@
 for ( String test : SR.keySet() ){
     toBeRun = testsToRun.contains( test )
     def stepName = ( toBeRun ? "" : "Not " ) + "Running $test"
-    tests[stepName] = funcs.runTest( test, toBeRun, prop, test, false,
+    def pureTestName = SR[ test ][ "test" ].split().head()
+    tests[stepName] = funcs.runTest( test, toBeRun, prop, pureTestName, false,
                                      SR, graph_generator_file, graph_saved_directory )
 }
 
diff --git a/TestON/JenkinsFile/Trend_Graph_Generator b/TestON/JenkinsFile/Trend_Graph_Generator
index 4c51964..2779d9b 100644
--- a/TestON/JenkinsFile/Trend_Graph_Generator
+++ b/TestON/JenkinsFile/Trend_Graph_Generator
@@ -54,7 +54,8 @@
 def tests = [ : ]
 for ( String test : testsToRun ){
     println test
-    tests[ test ] = funcs.runTest( test, true, prop, test, true, [ ], graph_generator_file, graph_saved_directory )
+    def pureTestName = test.split().head()
+    tests[ test ] = funcs.runTest( test, true, prop, pureTestName, true, [ ], graph_generator_file, graph_saved_directory )
 }
 
 for ( test in tests.keySet() ){
diff --git a/TestON/JenkinsFile/USECASEJenkinsFile b/TestON/JenkinsFile/USECASEJenkinsFile
index 7d55330..8a3e995 100644
--- a/TestON/JenkinsFile/USECASEJenkinsFile
+++ b/TestON/JenkinsFile/USECASEJenkinsFile
@@ -49,7 +49,8 @@
 for ( String test : USECASE.keySet() ){
     toBeRun = testsToRun.contains( test )
     def stepName = ( toBeRun ? "" : "Not " ) + "Running $test"
-    tests[ stepName ] = funcs.runTest( test, toBeRun, prop, test, false,
+    def pureTestName = USECASE[ test ][ "test" ].split().head()
+    tests[ stepName ] = funcs.runTest( test, toBeRun, prop, pureTestName, false,
                                        USECASE, graph_generator_file, graph_saved_directory )
 }
 
diff --git a/TestON/JenkinsFile/dependencies/JenkinsCommonFuncs.groovy b/TestON/JenkinsFile/dependencies/JenkinsCommonFuncs.groovy
index 7a0fd9a..01bec60 100644
--- a/TestON/JenkinsFile/dependencies/JenkinsCommonFuncs.groovy
+++ b/TestON/JenkinsFile/dependencies/JenkinsCommonFuncs.groovy
@@ -202,9 +202,8 @@
         git clean -df'''
 }
 
-def copyLogs( testName ){
-    // bash script part for copy the logs and other neccessary element for SR tests.
-    // testName : name of the test.
+def copyLogs(){
+    // bash script to copy the logs and other necessary element for SR tests.
 
     result = ""
     if ( testType == "SR" ){
@@ -238,7 +237,7 @@
         sudo rm ${WORKSPACE}/*.csv
         #copy files to workspace
         cd `ls -t ~/OnosSystemTest/TestON/logs/*/ | head -1 | sed 's/://'`
-        ''' + copyLogs( testName ) + '''
+        ''' + copyLogs() + '''
         sudo cp *.txt ${WORKSPACE}/
         sudo cp *.csv ${WORKSPACE}/
         cd ${WORKSPACE}/
@@ -256,7 +255,7 @@
     return '''#!/bin/bash
   set +e
   cd ~/OnosSystemTest/TestON/logs
-  echo "Job Name is: " + ''' + testName + '''
+  echo "TestON test name is: "''' + testName + '''
   TestONlogDir=$(ls -t | grep ${TEST_NAME}_  |head -1)
   echo "########################################################################################"
   echo "#####  copying ONOS logs from all nodes to TestON/logs directory: ${TestONlogDir}"
@@ -309,18 +308,18 @@
     return "#" + ( testType == "SR" ? "sr-failures" : "jenkins-related" )
 }
 
-def analyzeResult( prop, workSpace, testName, otherTestName, resultURL, wikiLink, isSCPF ){
+def analyzeResult( prop, workSpace, pureTestName, testName, resultURL, wikiLink, isSCPF ){
     // analyzing the result of the test and send to slack if the test was failed.
     // prop : property dictionary
     // workSpace : workSpace where the result file is saved
-    // testName : real name of the test
-    // otherTestName : other name of the test for SCPF tests ( SCPFflowTPFobj )
+    // pureTestName : TestON name of the test
+    // testName : Jenkins name of the test. Example: SCPFflowTPFobj
     // resultURL : url for the logs for SR tests. Will not be posted if it is empty
     // 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 ) {
-        def resultContents = readFile( workSpace + "/" + testName + "Result.txt" )
+        def resultContents = readFile( workSpace + "/" + pureTestName + "Result.txt" )
         resultContents = resultContents.split( "\n" )
         if ( resultContents[ 0 ] == "1" ){
             print "All passed"
@@ -330,7 +329,7 @@
             if ( prop[ "manualRun" ] == "false" ){
                 slackSend( channel: getSlackChannel(),
                            color: "FF0000",
-                           message: "[" + prop[ "ONOSBranch" ] + "]" + otherTestName + " : Failed!\n" +
+                           message: "[" + prop[ "ONOSBranch" ] + "]" + testName + " : Failed!\n" +
                                     resultContents[ 1 ] + "\n" +
                                     "[TestON log] : \n" +
                                     "https://jenkins.onosproject.org/blue/organizations/jenkins/${ env.JOB_NAME }/detail/${ env.JOB_NAME }/${ env.BUILD_NUMBER }/pipeline" +
@@ -364,7 +363,7 @@
 def runTest( testName, toBeRun, prop, pureTestName, graphOnly, testCategory, graph_generator_file,
              graph_saved_directory ){
     // run the test on the machine that contains all the steps : init and run test, copy files, publish result ...
-    // testName : name of the test
+    // testName : name of the test in Jenkins
     // toBeRun : boolean value whether the test will be run or not. If not, it won't be run but shows up with empty
     //           result on pipeline view
     // prop : dictionary property on the machine
@@ -392,7 +391,8 @@
                                 // For the Wiki page
                                 sh cleanAndCopyFiles( pureTestName )
                             }
-                            databaseAndGraph( prop, testName, graphOnly, graph_generator_file, graph_saved_directory )
+                            databaseAndGraph( prop, testName, pureTestName, graphOnly,
+                                              graph_generator_file, graph_saved_directory )
                             if ( !graphOnly ){
                                 sh fetchLogs( pureTestName )
                                 if ( !isSCPF ){
@@ -405,7 +405,7 @@
                     }
                     postResult( prop, graphOnly )
                     if ( !graphOnly ){
-                        resultURL = postLogs( testName, prop[ "WikiPrefix" ] )
+                        def resultURL = postLogs( testName, prop[ "WikiPrefix" ] )
                         analyzeResult( prop, workSpace, pureTestName, testName, resultURL,
                                        isSCPF ? "" : testCategory[ testName ][ 'wiki_link' ],
                                        isSCPF )
@@ -416,15 +416,15 @@
     }
 }
 
-def databaseAndGraph( prop, testName, graphOnly, graph_generator_file, graph_saved_directory ){
+def databaseAndGraph( prop, testName, pureTestName, graphOnly, graph_generator_file, graph_saved_directory ){
     // part where it insert the data into the database.
     // It will use the predefined encrypted variables from the Jenkins.
     // prop : property dictionary that was read from the machine
-    // testName : name of the test
+    // testName : Jenkins name for the test
+    // pureTestName : TestON name for the test
     // graphOnly : boolean whether it is graph only or not
     // graph_generator_file : Rscript file with the full path.
     // graph_saved_directory : where the generated graph will be saved to.
-
     if ( graphOnly || isPostingResult( prop[ "manualRun" ], prop[ "postResult" ] ) ){
         // Post Results
         withCredentials( [
@@ -438,7 +438,7 @@
               export DATE=\$(date +%F_%T)
               cd ~
               pwd ''' + ( graphOnly ? "" :
-                          ( !isSCPF ? databasePart( prop[ "WikiPrefix" ], testName, database_command ) :
+                          ( !isSCPF ? databasePart( prop[ "WikiPrefix" ], pureTestName, database_command ) :
                             SCPFfunc.databasePart( testName, database_command ) ) ) + '''
               ''' + ( !isSCPF ? graphGenerating( host, port, user, pass, testName, prop, graph_saved_directory,
                                                  graph_generator_file ) :