From 73febf900b85dae4d953389696f3a78cf8267816 Mon Sep 17 00:00:00 2001 From: Panagiotis Karalis Date: Thu, 11 Apr 2019 13:28:21 +0300 Subject: Failed to upload results to ONAP portal The results.json file generated by running 'dovetail run --testsuite xxx' is different from the one generated by running 'dovetail run --testcase xxx'. The former can be uploaded to ONAP portal successfully but the latter one can't. The main reason is that the latter one lacking of 'vnf_type'. Keep the results.json with the same format for both running one test suite or several test cases. JIRA: DOVETAIL-769 Change-Id: I46af84f9f229f9e601439f68c9ed9df9477d002b Signed-off-by: Panagiotis Karalis --- dovetail/report.py | 7 ++ dovetail/testcase.py | 3 + dovetail/tests/unit/test_report.py | 118 ++++++++++++++++++++++++++++++++- dovetail/tests/unit/test_testcase.py | 7 ++ dovetail/tests/unit/test_testcase.yaml | 1 + 5 files changed, 135 insertions(+), 1 deletion(-) (limited to 'dovetail') diff --git a/dovetail/report.py b/dovetail/report.py index 36a33a49..06ef4159 100644 --- a/dovetail/report.py +++ b/dovetail/report.py @@ -122,6 +122,13 @@ class Report(object): testcase_inreport['result'] = testcase.passed() testcase_inreport['objective'] = testcase.objective() + try: + vnf_type = testcase.vnf_type() + except Exception: + vnf_type = None + if vnf_type: + report_obj['vnf_type'] = vnf_type + report_obj['vnf_checksum'] = self.get_checksum(vnf_type) testcase_inreport['mandatory'] = testcase.is_mandatory testcase_inreport['sub_testcase'] = [] if testcase.sub_testcase() is not None: diff --git a/dovetail/testcase.py b/dovetail/testcase.py index e40ec4db..b6f54fa7 100644 --- a/dovetail/testcase.py +++ b/dovetail/testcase.py @@ -85,6 +85,9 @@ class Testcase(object): def validate_type(self): return self.testcase['validate']['type'] + def vnf_type(self): + return self.testcase['vnf_type'] + def validate_testcase(self): return self.testcase['validate']['testcase'] diff --git a/dovetail/tests/unit/test_report.py b/dovetail/tests/unit/test_report.py index 53b06cb9..2dcb44e4 100644 --- a/dovetail/tests/unit/test_report.py +++ b/dovetail/tests/unit/test_report.py @@ -170,10 +170,125 @@ class ReportTesting(unittest.TestCase): mock_factory.create.assert_called_once_with('type') checker_obj.check.assert_called_once_with(testcase_obj, None) + @patch.object(dt_report.Report, 'get_checksum') + @patch('dovetail.report.Testcase') + @patch('dovetail.report.datetime.datetime') + @patch('dovetail.report.dt_cfg') + def test_generate_json(self, mock_config, mock_datetime, mock_testcase, + mock_checksum): + logger_obj = Mock() + report = dt_report.Report() + report.logger = logger_obj + testcase_list = ['ta.tb.tc', 'td.te.tf'] + duration = 42 + mock_config.dovetail_config = { + 'build_tag': 'build_tag', + 'version': '2018.09' + } + utc_obj = Mock() + utc_obj.strftime.return_value = '2018-01-13 13:13:13 UTC' + mock_datetime.utcnow.return_value = utc_obj + testcase_obj = Mock() + testcase_obj.passed.return_value = 'PASS' + testcase_obj.objective.return_value = 'objective' + mock_checksum.return_value = 'da39a3ee5e6b4b0d3255bfef95601890afd80709' + testcase_obj.is_mandatory = True + testcase_obj.vnf_type.return_value = 'tosca' + testcase_obj.sub_testcase.return_value = ['subt_a'] + testcase_obj.sub_testcase_passed.return_value = 'PASS' + mock_testcase.get.side_effect = [testcase_obj, None] + + result = report.generate_json(testcase_list, duration) + expected = { + 'version': '2018.09', + 'build_tag': 'build_tag', + 'vnf_type': 'tosca', + 'vnf_checksum': 'da39a3ee5e6b4b0d3255bfef95601890afd80709', + 'test_date': '2018-01-13 13:13:13 UTC', + 'duration': duration, + 'testcases_list': [ + { + 'name': 'ta.tb.tc', + 'result': 'PASS', + 'objective': 'objective', + 'mandatory': True, + 'sub_testcase': [{ + 'name': 'subt_a', + 'result': 'PASS' + }] + }, + { + 'name': 'td.te.tf', + 'result': 'Undefined', + 'objective': '', + 'mandatory': False, + 'sub_testcase': [] + } + ] + } + + self.assertEquals(expected, result) + + @patch('dovetail.report.Testcase') + @patch('dovetail.report.datetime.datetime') + @patch('dovetail.report.dt_cfg') + def test_generate_json_noVNF(self, mock_config, mock_datetime, + mock_testcase): + logger_obj = Mock() + report = dt_report.Report() + report.logger = logger_obj + testcase_list = ['ta.tb.tc', 'td.te.tf'] + duration = 42 + mock_config.dovetail_config = { + 'build_tag': 'build_tag', + 'version': '2018.09' + } + utc_obj = Mock() + utc_obj.strftime.return_value = '2018-01-13 13:13:13 UTC' + mock_datetime.utcnow.return_value = utc_obj + testcase_obj = Mock() + testcase_obj.passed.return_value = 'PASS' + testcase_obj.objective.return_value = 'objective' + testcase_obj.is_mandatory = True + testcase_obj.vnf_type.return_value = None + testcase_obj.sub_testcase.return_value = ['subt_a'] + testcase_obj.sub_testcase_passed.return_value = 'PASS' + mock_testcase.get.side_effect = [testcase_obj, None] + + result = report.generate_json(testcase_list, duration) + expected = { + 'version': '2018.09', + 'build_tag': 'build_tag', + 'test_date': '2018-01-13 13:13:13 UTC', + 'duration': duration, + 'testcases_list': [ + { + 'name': 'ta.tb.tc', + 'result': 'PASS', + 'objective': 'objective', + 'mandatory': True, + 'sub_testcase': [{ + 'name': 'subt_a', + 'result': 'PASS' + }] + }, + { + 'name': 'td.te.tf', + 'result': 'Undefined', + 'objective': '', + 'mandatory': False, + 'sub_testcase': [] + } + ] + } + + self.assertEquals(expected, result) + @patch('dovetail.report.Testcase') @patch('dovetail.report.datetime.datetime') @patch('dovetail.report.dt_cfg') - def test_generate_json(self, mock_config, mock_datetime, mock_testcase): + def test_generate_json_noVNF_inTestCase(self, mock_config, mock_datetime, + mock_testcase): logger_obj = Mock() report = dt_report.Report() report.logger = logger_obj @@ -190,6 +305,7 @@ class ReportTesting(unittest.TestCase): testcase_obj.passed.return_value = 'PASS' testcase_obj.objective.return_value = 'objective' testcase_obj.is_mandatory = True + testcase_obj.vnf_type.side_effect = Exception() testcase_obj.sub_testcase.return_value = ['subt_a'] testcase_obj.sub_testcase_passed.return_value = 'PASS' mock_testcase.get.side_effect = [testcase_obj, None] diff --git a/dovetail/tests/unit/test_testcase.py b/dovetail/tests/unit/test_testcase.py index e3f2a64c..b915556c 100644 --- a/dovetail/tests/unit/test_testcase.py +++ b/dovetail/tests/unit/test_testcase.py @@ -163,6 +163,13 @@ class TestcaseTesting(unittest.TestCase): self.assertEquals('tempest_smoke_serial', result) + def test_vnf_type(self): + testcase = tcase.OnapVtpTestcase(self.testcase_yaml) + + result = testcase.vnf_type() + + self.assertEquals('tosca', result) + def test_passed(self): testcase = tcase.Testcase(self.testcase_yaml) diff --git a/dovetail/tests/unit/test_testcase.yaml b/dovetail/tests/unit/test_testcase.yaml index cb947cd9..d1406127 100644 --- a/dovetail/tests/unit/test_testcase.yaml +++ b/dovetail/tests/unit/test_testcase.yaml @@ -2,6 +2,7 @@ dovetail.ipv6.tc001: name: dovetail.ipv6.tc001 objective: VIM ipv6 operations, to create/delete network, port and subnet in bulk operation + vnf_type: tosca validate: type: functest testcase: tempest_smoke_serial -- cgit 1.2.3-korg