Add cli argument to use different .topo or .params files

- Add cli arguments
- Refactor xmlparser functions
- Cleaned up and fixed some logging
- main.testDir is now set to the directory where the test file is
  located
- main.testsRoot is now set to the full path of TestON/tests/
    - Fixed usages accordingly

Change-Id: I2a0f0c3728b5732b242a2e860e6538a6f3b65166
diff --git a/TestON/bin/cli.py b/TestON/bin/cli.py
index 8e48311..263d4b4 100755
--- a/TestON/bin/cli.py
+++ b/TestON/bin/cli.py
@@ -263,10 +263,16 @@
             while index < len( args ):
                 option = args[ index ]
                 if index > 0:
-                    if re.match( "--params", option, flags=0 ):
+                    if re.match( "--params-file", option, flags=0 ):
+                        # The more specific match must be before --params
+                        options[ 'paramsFile' ] = args[ index + 1 ]
+                    elif re.match( "--topo-file", option, flags=0 ):
+                        options[ 'topoFile' ] = args[ index + 1 ]
+                    elif re.match( "--params", option, flags=0 ):
                         # check if there is a params
                         options[ 'params' ].append( args[ index + 1 ] )
-                    elif re.match( "logdir|mail|example|testdir|testcases|onoscell", option, flags = 0 ):
+                    elif re.match( "logdir|mail|example|testdir|testcases|onoscell",
+                                   option, flags=0 ):
                         options[ option ] = args[ index + 1 ]
                         options = self.testcasesInRange( index + 1, option, args, options )
                     index += 2
@@ -292,6 +298,8 @@
         options[ 'onoscell' ] = None
         # init params as a empty list
         options[ 'params' ] = []
+        options[ 'paramsFile' ] = None
+        options[ 'topoFile' ] = None
         return options
 
     def testcasesInRange( self, index, option, args, options ):
diff --git a/TestON/core/logger.py b/TestON/core/logger.py
index dc2b2b2..551bacc 100644
--- a/TestON/core/logger.py
+++ b/TestON/core/logger.py
@@ -43,9 +43,9 @@
         for component in main.componentDictionary.keys():
             logmsg = logmsg + "\n\t" + component + " Session Log : " + main.logdir + "/" + component + ".session" + ""
 
-        logmsg = logmsg + "\n\tTest Script :" + path + "Tests/" + main.TEST + ".py" + ""
-        logmsg = logmsg + "\n\tTest Params : " + path + "Tests/" + main.TEST + ".params" + ""
-        logmsg = logmsg + "\n\tTopology : " + path + "Tests/" + main.TEST + ".topo" + ""
+        logmsg = logmsg + "\n\tTest Script : " + main.testFile + ""
+        logmsg = logmsg + "\n\tTest Params : " + main.testDir + "/" +  main.paramsFile + ""
+        logmsg = logmsg + "\n\tTopology : " + main.testDir + "/" + main.topoFile + ""
         logmsg = logmsg + "\n" + " " * 30 + "+" + "-" * 18 + "+" + "\n" + "-" * 27 + "  { Script Exec Params }  " + "-" * 27 + "\n" + " " * 30 + "+" + "-" * 18 + "+\n"
         values = "\n\t" + str( main.params )
         values = re.sub( ",", "\n\t", values )
diff --git a/TestON/core/teston.py b/TestON/core/teston.py
index 6794564..19449f4 100644
--- a/TestON/core/teston.py
+++ b/TestON/core/teston.py
@@ -90,6 +90,7 @@
         self.test_target = None
         self.lastcommand = None
         self.testDir = tests_path
+        self.testsRoot = tests_path
         self.configFile = config_path + "teston.cfg"
         self.parsingClass = "xmlparser"
         self.parserPath = core_path + "/xmlparser"
@@ -935,6 +936,7 @@
                         main.classPath = directory[ index: ].replace( '/', '.' ) + "." + main.TEST
                         break
     openspeakfile = directory + "/" + main.TEST + ".ospk"
+    main.testDir = directory
     main.testFile = directory + "/" + main.TEST + ".py"
     if os.path.exists( openspeakfile ):
         # Openspeak file found, compiling to python
@@ -962,8 +964,10 @@
     testClass = getattr( testModule, main.TEST )
     main.testObject = testClass()
     load_parser()
-    main.params = main.parser.parseParams( main.classPath )
-    main.topology = main.parser.parseTopology( main.classPath )
+    main.paramsFile = main.TEST + ".params" if options.paramsFile is None else options.paramsFile
+    main.topoFile = main.TEST + ".topo" if options.topoFile is None else options.topoFile
+    main.params = main.parser.parseFile( main.testDir + "/" + main.paramsFile )
+    main.topology = main.parser.parseFile( main.testDir + "/" + main.topoFile )
 
 def verifyParams( options ):
     try:
@@ -1039,8 +1043,7 @@
                                             -1 )
                 parsingClass = getattr( parsingModule, parsingClass )
                 main.parser = parsingClass()
-                if hasattr( main.parser, "parseParams" ) and\
-                   hasattr( main.parser, "parseTopology" ) and\
+                if hasattr( main.parser, "parseFile" ) and\
                    hasattr( main.parser, "parse" ):
                     pass
                 else:
@@ -1072,8 +1075,7 @@
                                     -1 )
         parsingClass = getattr( parsingModule, parsingClass )
         main.parser = parsingClass()
-        if hasattr( main.parser, "parseParams" ) and\
-           hasattr( main.parser, "parseTopology" ) and\
+        if hasattr( main.parser, "parseFile" ) and\
            hasattr( main.parser, "parse" ):
             pass
         else:
diff --git a/TestON/core/xmlparser.py b/TestON/core/xmlparser.py
index 12a3f61..d7af564 100644
--- a/TestON/core/xmlparser.py
+++ b/TestON/core/xmlparser.py
@@ -27,6 +27,7 @@
 
 import xmldict
 import re
+import os.path
 
 class xmlparser:
 
@@ -49,23 +50,10 @@
         else:
             print "File name is not correct"
 
-    def parseParams( self, paramsPath ):
+    def parseFile( self, fileName ):
         '''
-         It will take the params file path and will return the params dictionary
+         It will take a file path of an xml file and return the contents as a dictionary
         '''
-        paramsPath = re.sub( "\.", "/", paramsPath )
-        paramsPath = re.sub( "tests|examples", "", paramsPath )
-        params = self.parse( main.tests_path + paramsPath + ".params" )
-        paramsAsString = str( params )
-        return eval( paramsAsString )
-
-    def parseTopology( self, topologyPath ):
-        '''
-          It will take topology file path and will return topology dictionary
-        '''
-        topologyPath = re.sub( "\.", "/", topologyPath )
-        topologyPath = re.sub( "tests|examples", "", topologyPath )
-        topology = self.parse( main.tests_path + topologyPath + ".topo" )
-        topoAsString = str( topology )
-        return eval( topoAsString )
+        contents = self.parse( fileName )
+        return eval( str( contents ) )
 
diff --git a/TestON/tests/CHOTestMonkey/CHOTestMonkey.py b/TestON/tests/CHOTestMonkey/CHOTestMonkey.py
index 3efb3cc..3e02799 100644
--- a/TestON/tests/CHOTestMonkey/CHOTestMonkey.py
+++ b/TestON/tests/CHOTestMonkey/CHOTestMonkey.py
@@ -173,7 +173,7 @@
         main.step( "Start Mininet topology" )
         newTopo = main.params[ 'TOPO' ][ main.topoIndex ][ 'fileName' ]
         mininetDir = main.Mininet1.home + "/custom/"
-        topoPath = main.testDir + "/" + main.TEST + "/dependencies/topologies/" + newTopo
+        topoPath = main.testDir + "/dependencies/topologies/" + newTopo
         main.ONOSbench.secureCopy( main.Mininet1.user_name, main.Mininet1.ip_address, topoPath, mininetDir, direction="to" )
         topoPath = mininetDir + newTopo
         startStatus = main.Mininet1.startNet( topoFile=topoPath )
diff --git a/TestON/tests/PLAT/PLATdockertest/PLATdockertest.py b/TestON/tests/PLAT/PLATdockertest/PLATdockertest.py
index d871fae..bc4f3c3 100644
--- a/TestON/tests/PLAT/PLATdockertest/PLATdockertest.py
+++ b/TestON/tests/PLAT/PLATdockertest/PLATdockertest.py
@@ -91,7 +91,7 @@
         NODElist = main.params[ "SCALE" ][ "nodelist" ].split( ',' )
         main.log.info( "onos container names are: " + ",".join( NODElist ) )
         IPlist = list()
-        main.testOnDirectory = re.sub( "(/tests)$", "", main.testDir )
+        main.testOnDirectory = re.sub( "(/tests)$", "", main.testsRoot )
         CTIDlist = list()
 
         main.log.info( "Check docker status, it not running, try restart it" )
diff --git a/TestON/tests/USECASE/USECASE_SdnipFunction/USECASE_SdnipFunction.py b/TestON/tests/USECASE/USECASE_SdnipFunction/USECASE_SdnipFunction.py
index a45bdef..573f16d 100644
--- a/TestON/tests/USECASE/USECASE_SdnipFunction/USECASE_SdnipFunction.py
+++ b/TestON/tests/USECASE/USECASE_SdnipFunction/USECASE_SdnipFunction.py
@@ -33,7 +33,7 @@
         """
         import os
         main.case( "Setup the Mininet testbed" )
-        main.dependencyPath = main.testDir + \
+        main.dependencyPath = main.testsRoot + \
                               main.params[ 'DEPENDENCY' ][ 'path' ]
         main.topology = main.params[ 'DEPENDENCY' ][ 'topology' ]
 
diff --git a/TestON/tests/USECASE/USECASE_SdnipFunctionCluster/USECASE_SdnipFunctionCluster.py b/TestON/tests/USECASE/USECASE_SdnipFunctionCluster/USECASE_SdnipFunctionCluster.py
index 499df34..b984b1d 100644
--- a/TestON/tests/USECASE/USECASE_SdnipFunctionCluster/USECASE_SdnipFunctionCluster.py
+++ b/TestON/tests/USECASE/USECASE_SdnipFunctionCluster/USECASE_SdnipFunctionCluster.py
@@ -33,7 +33,7 @@
         """
         import imp
         main.case( "Setup the Mininet testbed" )
-        main.dependencyPath = main.testDir + \
+        main.dependencyPath = main.testsRoot + \
                               main.params[ 'DEPENDENCY' ][ 'path' ]
         main.topology = main.params[ 'DEPENDENCY' ][ 'topology' ]
 
diff --git a/TestON/tests/dependencies/ONOSSetup.py b/TestON/tests/dependencies/ONOSSetup.py
index ca10d3a..ee339be 100644
--- a/TestON/tests/dependencies/ONOSSetup.py
+++ b/TestON/tests/dependencies/ONOSSetup.py
@@ -46,7 +46,7 @@
         except ( NameError, AttributeError ):
             main.Cluster = Cluster( main.ONOScell.nodes )
         main.ONOSbench = main.Cluster.controllers[ 0 ].Bench
-        main.testOnDirectory = re.sub( "(/tests)$", "", main.testDir )
+        main.testOnDirectory = re.sub( "(/tests)$", "", main.testsRoot )
 
     def gitPulling( self, includeCaseDesc=True ):
         """