Enforce code style for groovy files

Change-Id: I7d8bd721c0e5b744777a5ad92386d36a524f93ec
diff --git a/TestON/JenkinsFile/dependencies/JenkinsCommonFuncs.groovy b/TestON/JenkinsFile/dependencies/JenkinsCommonFuncs.groovy
index b7c9c2e..9cf5e7b 100644
--- a/TestON/JenkinsFile/dependencies/JenkinsCommonFuncs.groovy
+++ b/TestON/JenkinsFile/dependencies/JenkinsCommonFuncs.groovy
@@ -21,138 +21,158 @@
 // This is the dependency Jenkins script.
 // it has some common functions that runs test and generate graph.
 
-import groovy.time.*
+import groovy.time.TimeCategory
+import groovy.time.TimeDuration
+
 generalFuncs = evaluate readTrusted( 'TestON/JenkinsFile/dependencies/GeneralFuncs.groovy' )
 fileRelated = evaluate readTrusted( 'TestON/JenkinsFile/dependencies/JenkinsPathAndFiles.groovy' )
 
 fileRelated.init()
 
 def initializeTrend( machine ){
-  // For initializing any trend graph jobs
-  // machine : Either VM,BM, or Fabric#
+    // 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";
-  this.machine = machine
-  isSCPF = false
-  isTrend = true
+    table_name = "executed_test_tests"
+    result_name = "executed_test_results"
+    testMachine = "TestStation-" + machine + "s"
+    this.machine = machine
+    isSCPF = false
+    isTrend = true
 }
+
 def initialize( type, SCPFfuncs ){
-  // Initializing for SCPF tests
-  // type : type of the test ( SR,FUNC,SCPF... )
-  // Passing the SCPFfunction which will be PerformanceFuncs.groovy
+    // Initializing for SCPF tests
+    // type : type of the test ( SR,FUNC,SCPF... )
+    // Passing the SCPFfunction which will be PerformanceFuncs.groovy
 
-  init( type )
-  SCPFfunc = SCPFfuncs
-  isSCPF = true
-  machine = machineType[ type ]
+    init( type )
+    SCPFfunc = SCPFfuncs
+    isSCPF = true
+    machine = machineType[ type ]
 }
+
 def initialize( type ){
-  // initializing for FUNC,HA,SR, and USECASE
-  // type : type of the test ( SR,FUNC,SCPF... )
+    // initializing for FUNC,HA,SR, and USECASE
+    // type : type of the test ( SR,FUNC,SCPF... )
 
-  init( type )
-  SCPFfunc = null
-  table_name = "executed_test_tests"
-  result_name = "executed_test_results"
-  trend_generator_file = fileRelated.trendMultiple
-  build_stats_generator_file = fileRelated.histogramMultiple
-  isSCPF = false
+    init( type )
+    SCPFfunc = null
+    table_name = "executed_test_tests"
+    result_name = "executed_test_results"
+    trend_generator_file = fileRelated.trendMultiple
+    build_stats_generator_file = fileRelated.histogramMultiple
+    isSCPF = false
 }
+
 def init( type ){
-  // type : type of the test ( SR,FUNC,SCPF... )
+    // 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
+    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, 1.12, 1.13... )
+    // additional setup for SegmentRouting tests to determine the machine depends on the branch it is running.
+    // branch : branch of the onos. ( master, 1.12, 1.13... )
 
-  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, 1.12, 1.13...
-  // branch.reverse().take(4).reverse() will get last 4 characters of the string.
-  switch( branch.reverse().take(4).reverse() ) {
-    case "ster": return "4"
-    case "1.13": return "2"
-    case "1.12": return "3"
-    default: return "4"
-  }
-}
-def printType(){
-  // print the test type and test machine that was initialized.
-
-  echo testType;
-  echo testMachine;
-}
-def getProperties(){
-  // get the properties of the test by reading the TestONOS.property
-
-  node( testMachine ){
-    return readProperties( file:'/var/jenkins/TestONOS.property' );
-  }
-}
-def getTestsToRun( testList ){
-  // get test to run by tokenizing the list.
-
-  testList.tokenize("\n;, ")
-}
-def getCurrentTime(){
-  // get time of the PST zone.
-
-  TimeZone.setDefault( TimeZone.getTimeZone('PST') )
-  return new Date();
-}
-def getTotalTime( start, end ){
-  // get total time of the test using start and end time.
-
-  return TimeCategory.minus( end, start );
-}
-def printTestToRun( testList ){
-  // printout the list of the test in the list.
-
-  for ( String test : testList ) {
-      println test;
-  }
-}
-def sendResultToSlack( start, isManualRun, branch ){
-  // send the result of the test to the slack when it is not manually running.
-  // start : start time of the test
-  // isManualRun : string that is whether "false" or "true"
-  // branch : branch of the onos.
-
-  try{
-    if( isManualRun == "false" ){
-        end = getCurrentTime();
-        TimeDuration duration = TimeCategory.minus( end , start );
-        slackSend( color:"#5816EE",
-                   message: testType + "-" + branch + " tests ended at: " + end.toString() + "\nTime took : " + duration )
+    testMachine = ( ( new StringBuilder( testMachine ) ).insert( testMachine.size() - 1, fabricOn( branch ) ) ).
+            toString()
+    if ( isTrend ){
+        machine += fabricOn( branch )
     }
-  }
-  catch( all ){}
+    else {
+        machineType[ testType ] += fabricOn( branch )
+    }
+    print testMachine
 }
-def initAndRunTest( testName, testCategory ){
-  // Bash script that will
-  // Initialize the environment to the machine and run the test.
-  // testName : name of the test
-  // testCategory : (SR,FUNC ... )
 
-  return '''#!/bin/bash -l
+def fabricOn( branch ){
+    // gets the fabric machines with the branch of onos.
+    // branch : master, 1.12, 1.13...
+    // branch.reverse().take(4).reverse() will get last 4 characters of the string.
+    switch ( branch.reverse().take( 4 ).reverse() ){
+        case "ster": return "4"
+        case "1.13": return "2"
+        case "1.12": return "3"
+        default: return "4"
+    }
+}
+
+def printType(){
+    // print the test type and test machine that was initialized.
+
+    echo testType
+    echo testMachine
+}
+
+def getProperties(){
+    // get the properties of the test by reading the TestONOS.property
+
+    node( testMachine ) {
+        return readProperties( file: '/var/jenkins/TestONOS.property' )
+    }
+}
+
+def getTestsToRun( testList ){
+    // get test to run by tokenizing the list.
+
+    testList.tokenize( "\n;, " )
+}
+
+def getCurrentTime(){
+    // get time of the PST zone.
+
+    TimeZone.setDefault( TimeZone.getTimeZone( 'PST' ) )
+    return new Date()
+}
+
+def getTotalTime( start, end ){
+    // get total time of the test using start and end time.
+
+    return TimeCategory.minus( end, start )
+}
+
+def printTestToRun( testList ){
+    // printout the list of the test in the list.
+
+    for ( String test : testList ){
+        println test
+    }
+}
+
+def sendResultToSlack( start, isManualRun, branch ){
+    // send the result of the test to the slack when it is not manually running.
+    // start : start time of the test
+    // isManualRun : string that is whether "false" or "true"
+    // branch : branch of the onos.
+
+    try {
+        if ( isManualRun == "false" ){
+            end = getCurrentTime()
+            TimeDuration duration = TimeCategory.minus( end, start )
+            slackSend( color: "#5816EE",
+                       message: testType + "-" + branch + " tests ended at: " + end.toString() +
+                                "\nTime took : " + duration )
+        }
+    }
+    catch ( all ){
+    }
+}
+
+def initAndRunTest( testName, testCategory ){
+    // Bash script that will
+    // Initialize the environment to the machine and run the test.
+    // testName : name of the test
+    // testCategory : (SR,FUNC ... )
+
+    return '''#!/bin/bash -l
         set -i # interactive
         set +e
         shopt -s expand_aliases # expand alias in non-interactive mode
@@ -170,19 +190,22 @@
         cd ~/OnosSystemTest/TestON/bin
         git log |head
         ./cleanup.sh -f
-        ''' + "./cli.py run " + ( !isSCPF ? testName : testCategory[ testName ][ 'test' ] )  + " --params GRAPH/nodeCluster=" + machineType[ testType ]  + '''
+        ''' + "./cli.py run " +
+           ( !isSCPF ? testName : testCategory[ testName ][ 'test' ] ) +
+           " --params GRAPH/nodeCluster=" + machineType[ testType ] + '''
         ./cleanup.sh -f
         # cleanup config changes
         cd ~/onos/tools/package/config
         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.
 
-  result = ""
-    if( testType == "SR" ){
-      result = '''
+def copyLogs( testName ){
+    // bash script part for copy the logs and other neccessary element for SR tests.
+    // testName : name of the test.
+
+    result = ""
+    if ( testType == "SR" ){
+        result = '''
       sudo rm /var/jenkins/workspace/SR-log-${WikiPrefix}/*
       sudo cp *karaf.log.* /var/jenkins/workspace/SR-log-${WikiPrefix}/
       sudo cp *Flows* /var/jenkins/workspace/SR-log-${WikiPrefix}/
@@ -190,14 +213,15 @@
       sudo cp *.tar.gz /var/jenkins/workspace/SR-log-${WikiPrefix}/
       sudo cp t3-* /var/jenkins/workspace/SR-log-${WikiPrefix}/
       '''
-  }
-  return result
+    }
+    return result
 }
-def cleanAndCopyFiles( testName ){
-  // clean up some files that were in the folder and copy the new files from the log
-  // testName : name of the test
 
-  return '''#!/bin/bash -i
+def cleanAndCopyFiles( testName ){
+    // clean up some files that were in the folder and copy the new files from the log
+    // testName : name of the test
+
+    return '''#!/bin/bash -i
         set +e
         echo "ONOS Branch is: ${ONOSBranch}"
         echo "TestON Branch is: ${TestONBranch}"
@@ -221,11 +245,12 @@
         ls -al
         cd '''
 }
-def fetchLogs( testName ){
-  // fetch the logs of onos from onos nodes to onos System Test logs
-  // testName: name of the test
 
-  return '''#!/bin/bash
+def fetchLogs( testName ){
+    // fetch the logs of onos from onos nodes to onos System Test logs
+    // testName: name of the test
+
+    return '''#!/bin/bash
   set +e
   cd ~/OnosSystemTest/TestON/logs
   echo "Job Name is: " + ''' + testName + '''
@@ -243,252 +268,291 @@
   fi
   cd'''
 }
+
 def isPostingResult( manual, postresult ){
-  // check if it is posting the result.
-  // posting when it is automatically running or has postResult condition from the manual run
+    // check if it is posting the result.
+    // posting when it is automatically running or has postResult condition from the manual run
 
-  return manual == "false" || postresult == "true"
+    return manual == "false" || postresult == "true"
 }
+
 def postResult( prop, graphOnly ){
-  // post the result by triggering postjob.
-  // prop : property dictionary that was read from the machine.
-  // graphOnly : if it is graph generating job
+    // post the result by triggering postjob.
+    // prop : property dictionary that was read from the machine.
+    // graphOnly : if it is graph generating job
 
-  if( graphOnly || isPostingResult( prop[ "manualRun" ], prop[ "postResult" ] ) ){
-    def post = build job: "postjob-" + ( graphOnly ? machine : machineType[ testType ] ), propagate: false
-  }
-}
-def postLogs( testName, prefix ){
-  // posting logs of the onos jobs specifically SR tests
-  // testName : name of the test
-  // prefix : branch prefix ( master, 1.12, 1.13 ... )
-
-  resultURL = ""
-  if( testType == "SR" ){
-    def post = build job: "SR-log-" + prefix, propagate: false
-    resultURL = post.getAbsoluteUrl()
-  }
-  return resultURL
-}
-def getSlackChannel(){
-  // get name of the slack channel.
-  // if the test is SR, it will return sr-failures
-
-  return "#" + ( testType == "SR" ? "sr-failures" : "jenkins-related" )
-}
-def analyzeResult( prop, workSpace, testName, otherTestName, 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 )
-  // 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 ){
-    resultContents = readFile workSpace + "/" + testName + "Result.txt"
-    resultContents = resultContents.split("\n")
-    if( resultContents[ 0 ] == "1" ){
-        print "All passed"
-    }else{
-        print "Failed"
-      if( prop[ "manualRun" ] == "false" ){
-        slackSend( channel:getSlackChannel(), color:"FF0000", message: "[" + prop[ "ONOSBranch" ] + "]"
-                                            + otherTestName + " : 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"
-                                            + ( isSCPF ? "" : ( "\n[Result on Wiki] : \n" + "https://wiki.onosproject.org/display/ONOS/" + wikiLink.replaceAll( "\\s","+" ) ) )
-                                            + ( resultURL != "" ? ( "\n[Karaf log] : \n" + resultURL + "artifact/" ) : "" ),
-                   teamDomain: 'onosproject' )
-      }
-        Failed
+    if ( graphOnly || isPostingResult( prop[ "manualRun" ], prop[ "postResult" ] ) ){
+        def post = build job: "postjob-" + ( graphOnly ? machine : machineType[ testType ] ), propagate: false
     }
-  }
 }
+
+def postLogs( testName, prefix ){
+    // posting logs of the onos jobs specifically SR tests
+    // testName : name of the test
+    // prefix : branch prefix ( master, 1.12, 1.13 ... )
+
+    resultURL = ""
+    if ( testType == "SR" ){
+        def post = build job: "SR-log-" + prefix, propagate: false
+        resultURL = post.getAbsoluteUrl()
+    }
+    return resultURL
+}
+
+def getSlackChannel(){
+    // get name of the slack channel.
+    // if the test is SR, it will return sr-failures
+
+    return "#" + ( testType == "SR" ? "sr-failures" : "jenkins-related" )
+}
+
+def analyzeResult( prop, workSpace, testName, otherTestName, 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 )
+    // 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" )
+        resultContents = resultContents.split( "\n" )
+        if ( resultContents[ 0 ] == "1" ){
+            print "All passed"
+        }
+        else {
+            print "Failed"
+            if ( prop[ "manualRun" ] == "false" ){
+                slackSend( channel: getSlackChannel(),
+                           color: "FF0000",
+                           message: "[" + prop[ "ONOSBranch" ] + "]" + otherTestName + " : 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" +
+                                    ( isSCPF ? "" : ( "\n[Result on Wiki] : \n" +
+                                                      "https://wiki.onosproject.org/display/ONOS/" +
+                                                      wikiLink.replaceAll( "\\s", "+" ) ) ) +
+                                    ( resultURL != "" ? ( "\n[Karaf log] : \n" +
+                                                          resultURL + "artifact/" ) : "" ),
+                           teamDomain: 'onosproject' )
+            }
+            Failed
+        }
+    }
+}
+
 def publishToConfluence( isManualRun, isPostResult, wikiLink, file ){
-  // publish HTML script to wiki confluence
-  // isManualRun : string "true" "false"
-  // isPostResult : string "true" "false"
-  // wikiLink : link of the wiki page to publish
-  // file : name of the file to be published
+    // publish HTML script to wiki confluence
+    // isManualRun : string "true" "false"
+    // isPostResult : string "true" "false"
+    // wikiLink : link of the wiki page to publish
+    // file : name of the file to be published
 
-  if( isPostingResult( isManualRun, isPostResult ) ){
-    publishConfluence siteName: 'wiki.onosproject.org', pageName: wikiLink, spaceName: 'ONOS',
-                  attachArchivedArtifacts: true, buildIfUnstable: true,
-                  editorList: [
-                      confluenceWritePage( confluenceFile( file ) )
-                  ]
-  }
+    if ( isPostingResult( isManualRun, isPostResult ) ){
+        publishConfluence siteName: 'wiki.onosproject.org', pageName: wikiLink, spaceName: 'ONOS',
+                          attachArchivedArtifacts: true, buildIfUnstable: true,
+                          editorList: [ confluenceWritePage( confluenceFile( file ) ) ]
+    }
 
 }
-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
-  // 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
-  // pureTestName : Pure name of the test. ( ex. pureTestName of SCPFflowTpFobj will be SCPFflowTp )
-  // graphOnly : check if it is generating graph job. If so, it will only generate the generating graph part
-  // testCategory : category of the test ( SCPF, SR, FUNC ... )
-  // graph_generator_file : Rscript file with the full path.
-  // graph_saved_directory : where the generated graph will be saved to.
 
-  return {
-      catchError{
-          stage( testName ) {
-              if ( toBeRun ){
-                  workSpace = "/var/jenkins/workspace/" + testName
-                  def fileContents = ""
-                  node( testMachine ){
-                      withEnv( [ 'ONOSBranch=' + prop[ "ONOSBranch" ],
-                                 'ONOSJVMHeap=' + prop[ "ONOSJVMHeap" ],
-                                 'TestONBranch=' + prop[ "TestONBranch" ],
-                                 'ONOSTag=' + prop[ "ONOSTag" ],
-                                 'WikiPrefix=' + prop[ "WikiPrefix" ],
-                                 'WORKSPACE=' + workSpace ] ){
-                        if( ! graphOnly ){
-                          sh initAndRunTest( testName, testCategory )
-                          // For the Wiki page
-                          sh cleanAndCopyFiles( pureTestName )
+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
+    // 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
+    // pureTestName : Pure name of the test. ( ex. pureTestName of SCPFflowTpFobj will be SCPFflowTp )
+    // graphOnly : check if it is generating graph job. If so, it will only generate the generating graph part
+    // testCategory : category of the test ( SCPF, SR, FUNC ... )
+    // graph_generator_file : Rscript file with the full path.
+    // graph_saved_directory : where the generated graph will be saved to.
+
+    return {
+        catchError {
+            stage( testName ) {
+                if ( toBeRun ){
+                    def workSpace = "/var/jenkins/workspace/" + testName
+                    def fileContents = ""
+                    node( testMachine ) {
+                        withEnv( [ 'ONOSBranch=' + prop[ "ONOSBranch" ],
+                                   'ONOSJVMHeap=' + prop[ "ONOSJVMHeap" ],
+                                   'TestONBranch=' + prop[ "TestONBranch" ],
+                                   'ONOSTag=' + prop[ "ONOSTag" ],
+                                   'WikiPrefix=' + prop[ "WikiPrefix" ],
+                                   'WORKSPACE=' + workSpace ] ) {
+                            if ( !graphOnly ){
+                                sh initAndRunTest( testName, testCategory )
+                                // For the Wiki page
+                                sh cleanAndCopyFiles( pureTestName )
+                            }
+                            databaseAndGraph( prop, testName, graphOnly, graph_generator_file, graph_saved_directory )
+                            if ( !graphOnly ){
+                                sh fetchLogs( pureTestName )
+                                if ( !isSCPF ){
+                                    publishToConfluence( prop[ "manualRun" ], prop[ "postResult" ],
+                                                         testCategory[ testName ][ 'wiki_link' ],
+                                                         workSpace + "/" + testCategory[ testName ][ 'wiki_file' ] )
+                                }
+                            }
                         }
-                          databaseAndGraph( prop, testName, graphOnly, graph_generator_file, graph_saved_directory )
-                        if( ! graphOnly ){
-                          sh fetchLogs( pureTestName )
-                          if( !isSCPF )
-                            publishToConfluence( prop[ "manualRun" ], prop[ "postResult" ],
-                                                 testCategory[ testName ][ 'wiki_link' ],
-                                                 workSpace + "/" + testCategory[ testName ][ 'wiki_file' ] )
-                        }
-                      }
-
-
-                  }
+                    }
                     postResult( prop, graphOnly )
-                  if( ! graphOnly ){
-                    resultURL = postLogs( testName, prop[ "WikiPrefix" ] )
-                    analyzeResult( prop, workSpace, pureTestName, testName, resultURL, isSCPF ? "" : testCategory[ testName ][ 'wiki_link' ], isSCPF )
-                  }
-              }
-          }
-      }
-  }
+                    if ( !graphOnly ){
+                        resultURL = postLogs( testName, prop[ "WikiPrefix" ] )
+                        analyzeResult( prop, workSpace, pureTestName, testName, resultURL,
+                                       isSCPF ? "" : testCategory[ testName ][ 'wiki_link' ],
+                                       isSCPF )
+                    }
+                }
+            }
+        }
+    }
 }
-def databaseAndGraph( prop, testName, 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
-  // 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( [
-          string( credentialsId: 'db_pass', variable: 'pass' ),
-          string( credentialsId: 'db_user', variable: 'user' ),
-          string( credentialsId: 'db_host', variable: 'host' ),
-          string( credentialsId: 'db_port', variable: 'port' ) ] ) {
-              def database_command =  generalFuncs.database_command_create( pass, host, port, user ) + ( !isSCPF ? sqlCommand( testName ) : SCPFfunc.sqlCommand( testName ) )
-              sh '''#!/bin/bash
+def databaseAndGraph( prop, testName, 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
+    // 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( [
+                string( credentialsId: 'db_pass', variable: 'pass' ),
+                string( credentialsId: 'db_user', variable: 'user' ),
+                string( credentialsId: 'db_host', variable: 'host' ),
+                string( credentialsId: 'db_port', variable: 'port' ) ] ) {
+            def database_command = generalFuncs.database_command_create( pass, host, port, user ) +
+                                   ( !isSCPF ? sqlCommand( testName ) : SCPFfunc.sqlCommand( testName ) )
+            sh '''#!/bin/bash
               export DATE=\$(date +%F_%T)
               cd ~
-              pwd ''' + ( graphOnly ? "" : ( !isSCPF ? databasePart( prop[ "WikiPrefix" ], testName, database_command )  :
-                         SCPFfunc.databasePart( testName, database_command ) ) ) + '''
-              ''' + ( !isSCPF ? graphGenerating( host, port, user, pass, testName, prop, graph_saved_directory, graph_generator_file ) : SCPFfunc.getGraphGeneratingCommand( host, port, user, pass, testName, prop ) )
-      }
-  }
-}
-def generateCategoryStatsGraph( testMachineOn, manualRun, postresult, stat_file, pie_file, type, branch, testListPart, save_path, pieTestListPart ){
-  // function that will generate the category stat graphs for the overall test.
-  // testMachineOn : the machine the graph will be generated. It will be TestStation-VMs for the most cases
-  // manualRun : string of "true" or "false"
-  // postresult : string of "true" or "false"
-  // stat_file : file name with full path for Rscript for the stat graph
-  // pie_file : file name with full path for Rscript for the pie graph
-  // type : type of the test ( USECASE, FUNC, HA )
-  // branch : branch of the test ( master, onos-1.12, onos-1.13 )
-  // testListPart : list of the test to be included
-  // save_path : path that will save the graphs to
-  // pieTestListPart : list of the test for pie graph
-
-  if( isPostingResult( manualRun, postresult ) ){
-    node( testMachineOn ){
-
-      withCredentials( [
-          string( credentialsId: 'db_pass', variable: 'pass' ),
-          string( credentialsId: 'db_user', variable: 'user' ),
-          string( credentialsId: 'db_host', variable: 'host' ),
-          string( credentialsId: 'db_port', variable: 'port' ) ] ) {
-              sh '''#!/bin/bash
-              ''' + generalFuncs.basicGraphPart( stat_file, host, port, user, pass, type, branch ) + " \"" + testListPart + "\" latest " + save_path + '''
-              ''' + getOverallPieGraph( pie_file, host, port, user, pass, branch, type, pieTestListPart, 'y', save_path ) + '''
-              ''' + getOverallPieGraph( pie_file, host, port, user, pass, branch, type, pieTestListPart, 'n', save_path )
-          }
+              pwd ''' + ( graphOnly ? "" :
+                          ( !isSCPF ? databasePart( prop[ "WikiPrefix" ], testName, database_command ) :
+                            SCPFfunc.databasePart( testName, database_command ) ) ) + '''
+              ''' + ( !isSCPF ? graphGenerating( host, port, user, pass, testName, prop, graph_saved_directory,
+                                                 graph_generator_file ) :
+                      SCPFfunc.getGraphGeneratingCommand( host, port, user, pass, testName, prop ) )
         }
-      postResult( [], true )
     }
 }
+
+def generateCategoryStatsGraph( testMachineOn, manualRun, postresult, stat_file, pie_file, type, branch, testListPart,
+                                save_path, pieTestListPart ){
+    // function that will generate the category stat graphs for the overall test.
+    // testMachineOn : the machine the graph will be generated. It will be TestStation-VMs for the most cases
+    // manualRun : string of "true" or "false"
+    // postresult : string of "true" or "false"
+    // stat_file : file name with full path for Rscript for the stat graph
+    // pie_file : file name with full path for Rscript for the pie graph
+    // type : type of the test ( USECASE, FUNC, HA )
+    // branch : branch of the test ( master, onos-1.12, onos-1.13 )
+    // testListPart : list of the test to be included
+    // save_path : path that will save the graphs to
+    // pieTestListPart : list of the test for pie graph
+
+    if ( isPostingResult( manualRun, postresult ) ){
+        node( testMachineOn ) {
+
+            withCredentials( [
+                    string( credentialsId: 'db_pass', variable: 'pass' ),
+                    string( credentialsId: 'db_user', variable: 'user' ),
+                    string( credentialsId: 'db_host', variable: 'host' ),
+                    string( credentialsId: 'db_port', variable: 'port' ) ] ) {
+                sh '''#!/bin/bash
+              ''' + generalFuncs.basicGraphPart( stat_file, host, port, user, pass, type,
+                                                 branch ) + " \"" + testListPart + "\" latest " + save_path + '''
+              ''' + getOverallPieGraph( pie_file, host, port, user, pass, branch, type, pieTestListPart, 'y',
+                                        save_path ) + '''
+              ''' +
+                   getOverallPieGraph( pie_file, host, port, user, pass, branch, type, pieTestListPart, 'n', save_path )
+            }
+        }
+        postResult( [ ], true )
+    }
+}
+
 def makeTestList( list, commaNeeded ){
-  // make the list of the test in to a string.
-  // list : list of the test
-  // commaNeeded : if comma is needed for the string
+    // make the list of the test in to a string.
+    // list : list of the test
+    // commaNeeded : if comma is needed for the string
 
-  return generalFuncs.getTestList( list ) + ( commaNeeded ? "," : "" )
+    return generalFuncs.getTestList( list ) + ( commaNeeded ? "," : "" )
 }
+
 def createStatsList( testCategory, list, semiNeeded ){
-  // make the list for stats
-  // testCategory : category of the test
-  // list : list of the test
-  // semiNeeded: if semi colon is needed
+    // make the list for stats
+    // testCategory : category of the test
+    // list : list of the test
+    // semiNeeded: if semi colon is needed
 
-  return testCategory + "-" + generalFuncs.getTestList( list ) + ( semiNeeded ? ";" : "" )
+    return testCategory + "-" + generalFuncs.getTestList( list ) + ( semiNeeded ? ";" : "" )
 }
+
 def generateOverallGraph( prop, testCategory, graph_saved_directory ){
-  // generate the overall graph for the test
+    // generate the overall graph for the test
 
-  if( isPostingResult( prop[ "manualRun" ], prop[ "postResult" ] ) ){
-    node( testMachine ){
+    if ( isPostingResult( prop[ "manualRun" ], prop[ "postResult" ] ) ){
+        node( testMachine ) {
 
-      withCredentials( [
-          string( credentialsId: 'db_pass', variable: 'pass' ),
-          string( credentialsId: 'db_user', variable: 'user' ),
-          string( credentialsId: 'db_host', variable: 'host' ),
-          string( credentialsId: 'db_port', variable: 'port' ) ] ) {
-              testList = generalFuncs.getTestList( testCategory )
-              sh '''#!/bin/bash
-              ''' + generalFuncs.basicGraphPart( trend_generator_file, host, port, user, pass, testType, prop[ "ONOSBranch" ] ) + " " + testList + " 20 " + graph_saved_directory
-          }
+            withCredentials( [
+                    string( credentialsId: 'db_pass', variable: 'pass' ),
+                    string( credentialsId: 'db_user', variable: 'user' ),
+                    string( credentialsId: 'db_host', variable: 'host' ),
+                    string( credentialsId: 'db_port', variable: 'port' ) ] ) {
+                testList = generalFuncs.getTestList( testCategory )
+                sh '''#!/bin/bash
+                   ''' +
+                   generalFuncs.basicGraphPart( trend_generator_file, host, port,
+                                                user, pass, testType,
+                                                prop[ "ONOSBranch" ] ) + " " + testList + " 20 " + graph_saved_directory
+            }
         }
-      postResult( prop, false )
+        postResult( prop, false )
     }
 }
+
 def getOverallPieGraph( file, host, port, user, pass, branch, type, testList, yOrN, path ){
-   // Rcommand for the pie graph
+    // Rcommand for the pie graph
 
-   return generalFuncs.basicGraphPart( file, host, port, user, pass, type, branch ) + " \"" + testList + "\" latest " + yOrN + " " + path
+    return generalFuncs.basicGraphPart( file, host, port, user, pass, type, branch ) +
+           " \"" + testList + "\" latest " + yOrN + " " + path
 }
+
 def sqlCommand( testName ){
-  // get the inserting sqlCommand for non-SCPF tests.
+    // get the inserting sqlCommand for non-SCPF tests.
 
-  return "\"INSERT INTO " + table_name + " VALUES('\$DATE','" + result_name + "','" + testName + "',\$BUILD_NUMBER, '\$ONOSBranch', \$line);\" "
+    return "\"INSERT INTO " + table_name + " VALUES('\$DATE','" + result_name + "','" +
+           testName + "',\$BUILD_NUMBER, '\$ONOSBranch', \$line);\" "
 }
+
 def graphGenerating( host, port, user, pass, testName, prop, graph_saved_directory, graph_generator_file ){
-  // get the graphGenerating R command for non-SCPF tests
+    // get the graphGenerating R command for non-SCPF tests
 
-  return generalFuncs.basicGraphPart( graph_generator_file, host, port, user, pass, testName, prop[ "ONOSBranch" ] ) + " 20 " + graph_saved_directory
+    return generalFuncs.basicGraphPart( graph_generator_file, host, port, user, pass, testName,
+                                        prop[ "ONOSBranch" ] ) + " 20 " + graph_saved_directory
 }
-def databasePart( wikiPrefix, testName, database_command ){
-  // to read and insert the data from .csv to the database
 
-  return '''
+def databasePart( wikiPrefix, testName, database_command ){
+    // to read and insert the data from .csv to the database
+
+    return '''
     sed 1d ''' + workSpace + "/" + wikiPrefix + "-" + testName + '''.csv | while read line
     do
     echo \$line
     echo ''' + database_command + '''
     done '''
 }
-def generateStatGraph( testMachineOn, onos_branch, AllTheTests, stat_graph_generator_file, pie_graph_generator_file, graph_saved_directory ){
+
+def generateStatGraph( testMachineOn, onos_branch, AllTheTests, stat_graph_generator_file, pie_graph_generator_file,
+                       graph_saved_directory ){
     // Will generate the stats graph.
 
     testListPart = createStatsList( "FUNC", AllTheTests[ "FUNC" ], true ) +
@@ -497,10 +561,13 @@
     pieTestList = makeTestList( AllTheTests[ "FUNC" ], true ) +
                   makeTestList( AllTheTests[ "HA" ], true ) +
                   makeTestList( AllTheTests[ "USECASE" ], false )
-    generateCategoryStatsGraph( testMachineOn, "false", "true", stat_graph_generator_file, pie_graph_generator_file, "ALL", onos_branch, testListPart, graph_saved_directory, pieTestList )
+    generateCategoryStatsGraph( testMachineOn, "false", "true", stat_graph_generator_file, pie_graph_generator_file,
+                                "ALL", onos_branch, testListPart, graph_saved_directory, pieTestList )
 }
+
 def branchWithPrefix( branch ){
     // get the branch with the prefix ( "onos-" )
     return ( ( branch != "master" ) ? "onos-" : "" ) + branch
 }
-return this;
+
+return this