Allow non-inclusion of setup task in junit report

The JUnit callback pushes every tasks in the report. Even the setup
tasks that - sometime - might clutter the report rather than being
useful, based on one needs.

This PR allows one to specify whether or not the setup tasks should be
part of the final report, defaulting to True to be backward compatible
to what is already in place today.
This commit is contained in:
Yanis Guenane 2018-04-10 11:41:48 +02:00 committed by Matt Clay
parent c812396793
commit dc420fc5fa

View file

@ -45,6 +45,12 @@ DOCUMENTATION = '''
description: Consider failed tasks as a junit test failure even if ignore_on_error is set
env:
- name: JUNIT_FAIL_ON_IGNORE
include_setup_tasks_in_report:
name: JUnit include setup tasks in report
default: True
description: Should the setup tasks be included in the final report
env:
- name: JUNIT_INCLUDE_SETUP_TASKS_IN_REPORT
requirements:
- whitelist in configuration
- junit_xml (python lib)
@ -96,6 +102,8 @@ class CallbackModule(CallbackBase):
Default: False
JUNIT_FAIL_ON_IGNORE (optional): Consider failed tasks as a junit test failure even if ignore_on_error is set
Default: False
JUNIT_INCLUDE_SETUP_TASKS_IN_REPORT (optional): Should the setup tasks be included in the final report
Default: True
Requires:
junit_xml
@ -114,6 +122,7 @@ class CallbackModule(CallbackBase):
self._task_class = os.getenv('JUNIT_TASK_CLASS', 'False').lower()
self._fail_on_change = os.getenv('JUNIT_FAIL_ON_CHANGE', 'False').lower()
self._fail_on_ignore = os.getenv('JUNIT_FAIL_ON_IGNORE', 'False').lower()
self._include_setup_tasks_in_report = os.getenv('JUNIT_INCLUDE_SETUP_TASKS_IN_REPORT', 'True').lower()
self._playbook_path = None
self._playbook_name = None
self._play_name = None
@ -147,13 +156,14 @@ class CallbackModule(CallbackBase):
play = self._play_name
name = task.get_name().strip()
path = task.get_path()
action = task.action
if not task.no_log:
args = ', '.join(('%s=%s' % a for a in task.args.items()))
if args:
name += ' ' + args
self._task_data[uuid] = TaskData(uuid, name, path, play)
self._task_data[uuid] = TaskData(uuid, name, path, play, action)
def _finish_task(self, status, result):
""" record the results of a task for a single host """
@ -236,6 +246,9 @@ class CallbackModule(CallbackBase):
test_cases = []
for task_uuid, task_data in self._task_data.items():
if task_data.action == 'setup' and self._include_setup_tasks_in_report == 'false':
continue
for host_uuid, host_data in task_data.host_data.items():
test_cases.append(self._build_test_case(task_data, host_data))
@ -290,7 +303,7 @@ class TaskData:
Data about an individual task.
"""
def __init__(self, uuid, name, path, play):
def __init__(self, uuid, name, path, play, action):
self.uuid = uuid
self.name = name
self.path = path
@ -298,6 +311,7 @@ class TaskData:
self.start = None
self.host_data = OrderedDict()
self.start = time.time()
self.action = action
def add_host(self, host):
if host.uuid in self.host_data: