From 13e644d0ba893ddc5e2944c2e827fde7cd58ae72 Mon Sep 17 00:00:00 2001 From: xudan Date: Tue, 11 Dec 2018 01:41:15 -0500 Subject: Enable ShellRunner 1. fix the bug 'ShellRunner' object has no attribute 'archive_logs' 2. remove the testarea_supported because it's not very necessary for the test cases themselves and can make it a little more simple to add a test case with new test area JIRA: DOVETAIL-750 Change-Id: I71ee74615200376adca2a0db040753e5fce329bc Signed-off-by: xudan --- dovetail/report.py | 19 ++++------- dovetail/test_runner.py | 64 +++++++++++++++++++----------------- dovetail/testcase.py | 2 -- dovetail/tests/unit/test_report.py | 60 ++++++--------------------------- dovetail/tests/unit/test_testcase.py | 8 ----- 5 files changed, 49 insertions(+), 104 deletions(-) (limited to 'dovetail') diff --git a/dovetail/report.py b/dovetail/report.py index 26cd6c52..f11bb242 100644 --- a/dovetail/report.py +++ b/dovetail/report.py @@ -121,22 +121,15 @@ class Report(object): sub_report = collections.OrderedDict() testcase_num = {} testcase_passnum = {} - for area in dt_cfg.dovetail_config['testarea_supported']: - sub_report[area] = '' - testcase_num[area] = 0 - testcase_passnum[area] = 0 testarea_scope = [] for testcase in report_data['testcases_list']: - supported_areas = dt_cfg.dovetail_config['testarea_supported'] - pattern = re.compile('|'.join(supported_areas)) - area = pattern.findall(testcase['name']) - if not supported_areas or not area: - self.logger.error('Test case {} not in supported testarea.' - .format(testcase['name'])) - return None - area = area[0] - testarea_scope.append(area) + area = testcase['name'].split('.')[1] + if area not in testarea_scope: + testarea_scope.append(area) + sub_report[area] = '' + testcase_num[area] = 0 + testcase_passnum[area] = 0 sub_report[area] += '-%-25s %s\n' %\ (testcase['name'], testcase['result']) if 'sub_testcase' in testcase: diff --git a/dovetail/test_runner.py b/dovetail/test_runner.py index d77c3c65..884ce1ad 100644 --- a/dovetail/test_runner.py +++ b/dovetail/test_runner.py @@ -21,7 +21,7 @@ import utils.dovetail_utils as dt_utils import utils.dovetail_logger as dt_logger -class DockerRunner(object): +class Runner(object): logger = None @@ -29,6 +29,36 @@ class DockerRunner(object): self.testcase = testcase self.logger.debug('Create runner: {}'.format(self.type)) + def archive_logs(self): + result_path = os.path.join(os.environ['DOVETAIL_HOME'], 'results') + src_files = dt_utils.get_value_from_dict( + 'report.source_archive_files', self.testcase.testcase) + dest_files = dt_utils.get_value_from_dict( + 'report.dest_archive_files', self.testcase.testcase) + if not src_files and not dest_files: + return True + if not (src_files and dest_files) or len(src_files) != len(dest_files): + self.logger.error("Can't find corresponding 'result_dest_files' " + "for 'result_source_files' with testcase {}" + .format(self.testcase.name())) + return False + res = True + for index in range(0, len(src_files)): + src_file_path = os.path.join(result_path, src_files[index]) + dest_file_path = os.path.join(result_path, dest_files[index]) + if os.path.isfile(src_file_path): + os.renames(src_file_path, dest_file_path) + else: + self.logger.error("Can't find file {}.".format(src_file_path)) + res = False + return res + + +class DockerRunner(Runner): + + def __init__(self, testcase): + super(DockerRunner, self).__init__(testcase) + @classmethod def create_log(cls): cls.logger = dt_logger.Logger(__name__ + '.DockerRunner').getLogger() @@ -110,30 +140,6 @@ class DockerRunner(object): if not dt_cfg.dovetail_config['noclean']: container.clean() - def archive_logs(self): - result_path = os.path.join(os.environ['DOVETAIL_HOME'], 'results') - src_files = dt_utils.get_value_from_dict( - 'report.source_archive_files', self.testcase.testcase) - dest_files = dt_utils.get_value_from_dict( - 'report.dest_archive_files', self.testcase.testcase) - if not src_files and not dest_files: - return True - if not (src_files and dest_files) or len(src_files) != len(dest_files): - self.logger.error("Can't find corresponding 'result_dest_files' " - "for 'result_source_files' with testcase {}" - .format(self.testcase.name())) - return False - res = True - for index in range(0, len(src_files)): - src_file_path = os.path.join(result_path, src_files[index]) - dest_file_path = os.path.join(result_path, dest_files[index]) - if os.path.isfile(src_file_path): - os.renames(src_file_path, dest_file_path) - else: - self.logger.error("Can't find file {}.".format(src_file_path)) - res = False - return res - @staticmethod def _render(task_template, **kwargs): return jinja2.Template(task_template).render(**kwargs) @@ -239,19 +245,15 @@ class BottlenecksRunner(DockerRunner): self._update_config(testcase) -class ShellRunner(object): - - logger = None +class ShellRunner(Runner): @classmethod def create_log(cls): cls.logger = dt_logger.Logger(__name__ + '.ShellRunner').getLogger() def __init__(self, testcase): - super(ShellRunner, self).__init__() - self.testcase = testcase self.type = 'shell' - self.logger.debug('Create runner: {}'.format(self.type)) + super(ShellRunner, self).__init__(testcase) def run(self): testcase_passed = 'PASS' diff --git a/dovetail/testcase.py b/dovetail/testcase.py index 3be1cb02..b79bcfa7 100644 --- a/dovetail/testcase.py +++ b/dovetail/testcase.py @@ -221,8 +221,6 @@ class Testcase(object): return True, area_full for area in testarea: - if area not in dt_cfg.dovetail_config['testarea_supported']: - return False, None if area == 'full': return True, area_full area_no_duplicate.append(area) diff --git a/dovetail/tests/unit/test_report.py b/dovetail/tests/unit/test_report.py index fa5a02e0..0f0d3eec 100644 --- a/dovetail/tests/unit/test_report.py +++ b/dovetail/tests/unit/test_report.py @@ -173,7 +173,7 @@ class ReportTesting(unittest.TestCase): logger_obj = Mock() report = dt_report.Report() report.logger = logger_obj - testcase_list = ['t_a', 't_b'] + testcase_list = ['ta.tb.tc', 'td.te.tf'] duration = 42 mock_config.dovetail_config = { 'build_tag': 'build_tag' @@ -197,7 +197,7 @@ class ReportTesting(unittest.TestCase): 'duration': duration, 'testcases_list': [ { - 'name': 't_a', + 'name': 'ta.tb.tc', 'result': 'PASS', 'objective': 'objective', 'mandatory': True, @@ -207,7 +207,7 @@ class ReportTesting(unittest.TestCase): }] }, { - 'name': 't_b', + 'name': 'td.te.tf', 'result': 'Undefined', 'objective': '', 'mandatory': False, @@ -250,10 +250,7 @@ class ReportTesting(unittest.TestCase): logger_obj = Mock() report = dt_report.Report() report.logger = logger_obj - testcase_list = ['t_a', 't_b'] - mock_config.dovetail_config = { - 'testarea_supported': testcase_list - } + testcase_list = ['ta.tb.tc', 'td.te.tf'] duration = 42 report_data = { 'version': 'v2', @@ -262,7 +259,7 @@ class ReportTesting(unittest.TestCase): 'duration': 42.42, 'testcases_list': [ { - 'name': 't_a', + 'name': 'ta.tb.tc', 'result': 'PASS', 'sub_testcase': [{ 'name': 'subt_a', @@ -270,7 +267,7 @@ class ReportTesting(unittest.TestCase): }] }, { - 'name': 't_b', + 'name': 'td.te.tf', 'result': 'SKIP' } ] @@ -280,51 +277,17 @@ class ReportTesting(unittest.TestCase): result = report.generate(testcase_list, duration) expected = self._produce_report_initial_text(report_data) expected += 'Pass Rate: 100.00% (1/1)\n' - expected += '%-25s pass rate %.2f%%\n' % ('t_a:', 100) - expected += '-%-25s %s\n' % ('t_a', 'PASS') + expected += '%-25s pass rate %.2f%%\n' % ('tb:', 100) + expected += '-%-25s %s\n' % ('ta.tb.tc', 'PASS') expected += '\t%-110s %s\n' % ('subt_a', 'PASS') - expected += '%-25s all skipped\n' % 't_b' - expected += '-%-25s %s\n' % ('t_b', 'SKIP') + expected += '%-25s all skipped\n' % 'te' + expected += '-%-25s %s\n' % ('td.te.tf', 'SKIP') mock_generate.assert_called_once_with(testcase_list, duration) mock_save.assert_called_once_with(report_data) report.logger.info.assert_called_once_with(expected) self.assertEquals(expected, result) - @patch('dovetail.report.dt_cfg') - @patch.object(dt_report.Report, 'generate_json') - @patch.object(dt_report.Report, 'save_json_results') - def test_generate_error(self, mock_save, mock_generate, mock_config): - logger_obj = Mock() - report = dt_report.Report() - report.logger = logger_obj - mock_config.dovetail_config = { - 'testarea_supported': [] - } - testcase_list = ['t_a'] - duration = 42 - report_data = { - 'version': 'v2', - 'build_tag': '2.0.0', - 'test_date': '2018-01-13 13:13:13 UTC', - 'duration': 42.42, - 'testcases_list': [{ - 'name': 't_a', - 'result': 'PASS' - }] - } - mock_generate.return_value = report_data - - result = report.generate(testcase_list, duration) - expected = None - - mock_generate.assert_called_once_with(testcase_list, duration) - mock_save.assert_called_once_with(report_data) - report.logger.error.assert_called_once_with( - 'Test case {} not in supported testarea.' - .format(report_data['testcases_list'][0]['name'])) - self.assertEquals(expected, result) - @patch('dovetail.report.dt_cfg') @patch.object(dt_report.Report, 'generate_json') @patch.object(dt_report.Report, 'save_json_results') @@ -332,9 +295,6 @@ class ReportTesting(unittest.TestCase): logger_obj = Mock() report = dt_report.Report() report.logger = logger_obj - mock_config.dovetail_config = { - 'testarea_supported': [] - } duration = 42 report_data = { 'version': 'v2', diff --git a/dovetail/tests/unit/test_testcase.py b/dovetail/tests/unit/test_testcase.py index 0d303206..e2b0b744 100644 --- a/dovetail/tests/unit/test_testcase.py +++ b/dovetail/tests/unit/test_testcase.py @@ -410,21 +410,13 @@ class TestcaseTesting(unittest.TestCase): self.assertEquals((True, ['full']), tcase.Testcase.check_testarea(None)) - @patch('dovetail.testcase.dt_cfg') - def test_check_testarea_not_in_config(self, mock_config): - mock_config.dovetail_config = {'testarea_supported': []} - self.assertEquals((False, None), - tcase.Testcase.check_testarea(['area'])) - @patch('dovetail.testcase.dt_cfg') def test_check_testarea_full(self, mock_config): - mock_config.dovetail_config = {'testarea_supported': ['full']} self.assertEquals((True, ['full']), tcase.Testcase.check_testarea(['full'])) @patch('dovetail.testcase.dt_cfg') def test_check_testarea(self, mock_config): - mock_config.dovetail_config = {'testarea_supported': ['area']} self.assertEquals((True, ['area']), tcase.Testcase.check_testarea(['area'])) -- cgit 1.2.3-korg