aboutsummaryrefslogtreecommitdiffstats
path: root/testcases/Controllers/ODL/OpenDaylightTesting.py
diff options
context:
space:
mode:
Diffstat (limited to 'testcases/Controllers/ODL/OpenDaylightTesting.py')
-rwxr-xr-xtestcases/Controllers/ODL/OpenDaylightTesting.py67
1 files changed, 60 insertions, 7 deletions
diff --git a/testcases/Controllers/ODL/OpenDaylightTesting.py b/testcases/Controllers/ODL/OpenDaylightTesting.py
index 79e385a2d..74e3157dc 100755
--- a/testcases/Controllers/ODL/OpenDaylightTesting.py
+++ b/testcases/Controllers/ODL/OpenDaylightTesting.py
@@ -8,8 +8,33 @@ import shutil
import sys
from robot import run
+from robot.api import ExecutionResult, ResultVisitor
+from robot.errors import RobotError
+from robot.utils.robottime import timestamp_to_secs
import functest.utils.functest_logger as ft_logger
+import functest.utils.functest_utils as ft_utils
+
+
+class ODLResultVisitor(ResultVisitor):
+
+ def __init__(self):
+ self._data = []
+
+ def visit_test(self, test):
+ output = {}
+ output['name'] = test.name
+ output['parent'] = test.parent.name
+ output['status'] = test.status
+ output['startime'] = test.starttime
+ output['endtime'] = test.endtime
+ output['critical'] = test.critical
+ output['text'] = test.message
+ output['elapsedtime'] = test.elapsedtime
+ self._data.append(output)
+
+ def get_data(self):
+ return self._data
class ODLTestCases:
@@ -18,6 +43,7 @@ class ODLTestCases:
odl_test_repo = repos + "odl_test/"
neutron_suite_dir = odl_test_repo + "csit/suites/openstack/neutron/"
basic_suite_dir = odl_test_repo + "csit/suites/integration/basic/"
+ res_dir = '/home/opnfv/functest/results/odl/'
logger = ft_logger.Logger("opendaylight").getLogger()
@classmethod
@@ -70,19 +96,18 @@ class ODLTestCases:
except KeyError as e:
cls.logger.error("Cannot run ODL testcases. Please check", e)
return False
- res_dir = '/home/opnfv/functest/results/odl/'
if (cls.copy_opnf_testcases() and
cls.set_robotframework_vars(odlusername, odlpassword)):
try:
- os.makedirs(res_dir)
+ os.makedirs(cls.res_dir)
except OSError:
pass
- stdout_file = res_dir + 'stdout.txt'
+ stdout_file = cls.res_dir + 'stdout.txt'
with open(stdout_file, 'w') as stdout:
result = run(*dirs, variable=variables,
- output=res_dir + 'output.xml',
- log=res_dir + 'log.html',
- report=res_dir + 'report.html',
+ output=cls.res_dir + 'output.xml',
+ log=cls.res_dir + 'log.html',
+ report=cls.res_dir + 'report.html',
stdout=stdout)
with open(stdout_file, 'r') as stdout:
@@ -92,6 +117,27 @@ class ODLTestCases:
else:
return False
+ @classmethod
+ def push_to_db(cls):
+ try:
+ result = ExecutionResult(cls.res_dir + 'output.xml')
+ visitor = ODLResultVisitor()
+ result.visit(visitor)
+ start_time = timestamp_to_secs(result.suite.starttime)
+ stop_time = timestamp_to_secs(result.suite.endtime)
+ details = {}
+ details['description'] = result.suite.name
+ details['tests'] = visitor.get_data()
+ if not ft_utils.push_results_to_db(
+ "functest", "odl", None, start_time, stop_time,
+ result.suite.status, details):
+ cls.logger.error("Cannot push ODL results to DB")
+ return False
+ else:
+ return True
+ except RobotError as e:
+ cls.logger.error("Run tests before publishing: %s" % e.message)
+
if __name__ == '__main__':
parser = argparse.ArgumentParser()
@@ -125,5 +171,12 @@ if __name__ == '__main__':
parser.add_argument('-e', '--odlpassword',
help='Password for ODL',
default='admin')
+ parser.add_argument('-p', '--pushtodb',
+ help='Push results to DB',
+ action='store_true')
+
args = vars(parser.parse_args())
- sys.exit(ODLTestCases.run(**args))
+ ODLTestCases.run(**args)
+ if args['pushtodb']:
+ sys.exit(not ODLTestCases.push_to_db())
+ sys.exit(os.EX_OK)