from robot.errors import RobotError
import robot.run
from robot.utils.robottime import timestamp_to_secs
+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>"
class ODLTests(testcase.TestCase):
"""ODL test runner."""
- repos = "/home/opnfv/repos/"
- odl_test_repo = os.path.join(repos, "odl_test")
+ odl_test_repo = constants.CONST.__getattribute__('dir_repo_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
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.
self.__logger.exception(
"Cannot create %s", self.res_dir)
return self.EX_RUN_ERROR
- stdout_file = os.path.join(self.res_dir, 'stdout.txt')
output_dir = os.path.join(self.res_dir, 'output.xml')
- with open(stdout_file, 'w+') as stdout:
- robot.run(*suites, variable=variables,
- output=output_dir,
- log='NONE',
- report='NONE',
- stdout=stdout)
- stdout.seek(0, 0)
- self.__logger.info("\n" + stdout.read())
+ stream = StringIO()
+ robot.run(*suites, variable=variables, output=output_dir,
+ log='NONE', report='NONE', stdout=stream)
+ self.__logger.info("\n" + stream.getvalue())
self.__logger.info("ODL results were successfully generated")
try:
self.parse_results()
self.__logger.error("Run tests before publishing: %s",
ex.message)
return self.EX_RUN_ERROR
- try:
- os.remove(stdout_file)
- except OSError:
- self.__logger.warning("Cannot remove %s", stdout_file)
return self.EX_OK
else:
return self.EX_RUN_ERROR
elif installer_type == 'joid':
kwargs['odlip'] = os.environ['SDN_CONTROLLER']
elif installer_type == 'compass':
+ kwargs['odlrestconfport'] = '8080'
+ elif installer_type == 'daisy':
+ kwargs['odlip'] = os.environ['SDN_CONTROLLER_IP']
kwargs['odlwebport'] = '8181'
+ kwargs['odlrestconfport'] = '8087'
else:
kwargs['odlip'] = os.environ['SDN_CONTROLLER_IP']
except KeyError as ex:
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
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