Define ODL console_script
[functest-xtesting.git] / functest / opnfv_tests / sdn / odl / odl.py
old mode 100755 (executable)
new mode 100644 (file)
index 2f3dd74..67bf66e
@@ -34,6 +34,7 @@ from six import StringIO
 from six.moves import urllib
 
 from functest.core import testcase
+from functest.utils import constants
 import functest.utils.openstack_utils as op_utils
 
 __author__ = "Cedric Ollivier <cedric.ollivier@orange.com>"
@@ -65,14 +66,15 @@ class ODLResultVisitor(robot.api.ResultVisitor):
 class ODLTests(testcase.TestCase):
     """ODL test runner."""
 
-    repos = "/home/opnfv/repos/"
-    odl_test_repo = os.path.join(repos, "odl_test")
+    odl_test_repo = os.path.join(
+        constants.CONST.__getattribute__('dir_repos'), 'odl_test')
     neutron_suite_dir = os.path.join(odl_test_repo,
                                      "csit/suites/openstack/neutron")
     basic_suite_dir = os.path.join(odl_test_repo,
                                    "csit/suites/integration/basic")
     default_suites = [basic_suite_dir, neutron_suite_dir]
-    res_dir = '/home/opnfv/functest/results/odl/'
+    res_dir = os.path.join(
+        constants.CONST.__getattribute__('dir_results'), 'odl')
     __logger = logging.getLogger(__name__)
 
     @classmethod
@@ -108,14 +110,14 @@ class ODLTests(testcase.TestCase):
                 result.suite.statistics.critical.passed /
                 result.suite.statistics.critical.total)
         except ZeroDivisionError:
-            self.__logger.error("No test has been ran")
+            self.__logger.error("No test has been run")
         self.start_time = timestamp_to_secs(result.suite.starttime)
         self.stop_time = timestamp_to_secs(result.suite.endtime)
         self.details = {}
         self.details['description'] = result.suite.name
         self.details['tests'] = visitor.get_data()
 
-    def main(self, suites=None, **kwargs):
+    def run_suites(self, suites=None, **kwargs):
         """Run the test suites
 
         It has been designed to be called in any context.
@@ -244,7 +246,7 @@ class ODLTests(testcase.TestCase):
             self.__logger.exception("Cannot run ODL testcases.")
             return self.EX_RUN_ERROR
 
-        return self.main(suites, **kwargs)
+        return self.run_suites(suites, **kwargs)
 
 
 class ODLParser(object):  # pylint: disable=too-few-public-methods
@@ -299,16 +301,19 @@ class ODLParser(object):  # pylint: disable=too-few-public-methods
         return vars(self.parser.parse_args(argv))
 
 
-if __name__ == '__main__':
+def main():
+    """Entry point"""
     logging.basicConfig()
-    ODL = ODLTests()
-    PARSER = ODLParser()
-    ARGS = PARSER.parse_args(sys.argv[1:])
+    odl = ODLTests()
+    parser = ODLParser()
+    args = parser.parse_args(sys.argv[1:])
     try:
-        RESULT = ODL.main(ODLTests.default_suites, **ARGS)
-        if RESULT != testcase.TestCase.EX_OK:
-            sys.exit(RESULT)
-        if ARGS['pushtodb']:
-            sys.exit(ODL.push_to_db())
+        result = odl.run_suites(ODLTests.default_suites, **args)
+        if result != testcase.TestCase.EX_OK:
+            return result
+        if args['pushtodb']:
+            return odl.push_to_db()
+        else:
+            return result
     except Exception:  # pylint: disable=broad-except
-        sys.exit(testcase.TestCase.EX_RUN_ERROR)
+        return testcase.TestCase.EX_RUN_ERROR