diff options
author | xudan <xudan16@huawei.com> | 2019-10-09 02:50:05 -0400 |
---|---|---|
committer | xudan <xudan16@huawei.com> | 2019-10-12 03:39:57 -0400 |
commit | 0d733e25f6531594cf27dbf3fe69e8f2229b5fa7 (patch) | |
tree | 84bf4ecc66736657c6f889379065d4df838657e7 | |
parent | 48d735cc1bec3b842d06a72992dc36c8799af381 (diff) |
Bugfix: got an error on ci when rally tests failed
see https://build.opnfv.org/ci/view/dovetail/job/dovetail-fuel-baremetal-proposed_tests-optional-hunter/10/console
Change-Id: I7c9b0426603c22a2ef5f4b15ca26fbc0768bd19f
Signed-off-by: xudan <xudan16@huawei.com>
-rw-r--r-- | dovetail/report.py | 51 | ||||
-rw-r--r-- | dovetail/tests/unit/test_report.py | 22 |
2 files changed, 51 insertions, 22 deletions
diff --git a/dovetail/report.py b/dovetail/report.py index d40303e4..9523d388 100644 --- a/dovetail/report.py +++ b/dovetail/report.py @@ -319,29 +319,36 @@ class FunctestCrawler(Crawler): testcase.set_results(json_results) return json_results - @staticmethod - def get_details(data): - t_details = data['details'] - details = { - 'tests': t_details['tests_number'], - 'failures': t_details['failures_number'], - 'success': t_details['success'], - 'errors': t_details['failures'], - 'skipped': t_details['skipped'] - } - return details + def get_details(self, data): + try: + t_details = data['details'] + details = { + 'tests': t_details['tests_number'], + 'failures': t_details['failures_number'], + 'success': t_details['success'], + 'errors': t_details['failures'], + 'skipped': t_details['skipped'] + } + return details + except Exception as e: + self.logger.exception("Failed to get details, {}.".format(e)) + return None - @staticmethod - def get_rally_details(data): - t_details = data['details'][0]['details'] - details = { - 'tests': len(t_details['success']) + len(t_details['failures']), - 'failures': len(t_details['failures']), - 'success': t_details['success'], - 'errors': t_details['failures'], - 'skipped': [] - } - return details + def get_rally_details(self, data): + try: + t_details = data['details'][0]['details'] + tests = len(t_details['success']) + len(t_details['failures']) + details = { + 'tests': tests, + 'failures': len(t_details['failures']), + 'success': t_details['success'], + 'errors': t_details['failures'], + 'skipped': [] + } + return details + except Exception as e: + self.logger.exception("Failed to get details, {}.".format(e)) + return None class FunctestK8sCrawler(FunctestCrawler): diff --git a/dovetail/tests/unit/test_report.py b/dovetail/tests/unit/test_report.py index fe6530c9..69cde0d5 100644 --- a/dovetail/tests/unit/test_report.py +++ b/dovetail/tests/unit/test_report.py @@ -640,6 +640,28 @@ class ReportTesting(unittest.TestCase): 'Result file not found: {}'.format(file_path)) self.assertEqual(None, result) + def test_functest_crawler_get_details_exception(self): + logger_obj = Mock() + dt_report.FunctestCrawler.logger = logger_obj + data = None + crawler = dt_report.FunctestCrawler() + + excepted = None + result = crawler.get_details(data) + logger_obj.exception.assert_called_once() + self.assertEqual(excepted, result) + + def test_functest_crawler_get_rally_details_exception(self): + logger_obj = Mock() + dt_report.FunctestCrawler.logger = logger_obj + data = None + crawler = dt_report.FunctestCrawler() + + excepted = None + result = crawler.get_rally_details(data) + logger_obj.exception.assert_called_once() + self.assertEqual(excepted, result) + @patch('builtins.open') @patch('dovetail.report.json') @patch('dovetail.report.dt_cfg') |