From 5f450302301af5f19e4fee7cf37d2c724e098dea Mon Sep 17 00:00:00 2001
From: Cédric Ollivier <cedric.ollivier@orange.com>
Date: Mon, 22 Aug 2016 11:06:12 +0200
Subject: Catch exception if output.xml failed
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

It protects against a direct call to push_to_db without a previous run
even if it can not happen in the current implementation.

Change-Id: Ifa00aed60912fa8b96b80d581067548ac6727fb5
Signed-off-by: Cédric Ollivier <cedric.ollivier@orange.com>
---
 testcases/Controllers/ODL/OpenDaylightTesting.py | 34 +++++++++++++-----------
 1 file changed, 19 insertions(+), 15 deletions(-)

diff --git a/testcases/Controllers/ODL/OpenDaylightTesting.py b/testcases/Controllers/ODL/OpenDaylightTesting.py
index 0e38d04d8..74e3157dc 100755
--- a/testcases/Controllers/ODL/OpenDaylightTesting.py
+++ b/testcases/Controllers/ODL/OpenDaylightTesting.py
@@ -9,6 +9,7 @@ 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
@@ -118,21 +119,24 @@ class ODLTestCases:
 
     @classmethod
     def push_to_db(cls):
-        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
+        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__':
-- 
cgit