Skip to content

Commit fc83d27

Browse files
authored
Add configurable debug option to custom_junit callback plugin (#330)
Add a boolean 'debug' configuration option to the custom_junit callback plugin to control debug output. Debug statements are now only printed when explicitly enabled via CUSTOM_JUNIT_DEBUG environment variable or ansible.cfg setting. This reduces noise in normal operation while preserving debugging capability when troubleshooting test execution and JUnit XML generation.
1 parent 03384e3 commit fc83d27

File tree

1 file changed

+24
-9
lines changed

1 file changed

+24
-9
lines changed

callback_plugins/custom_junit.py

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,15 @@
4343
- name: JUNIT_OUTPUT_DIR
4444
default: "~/ci-framework-data/tests/feature-verification-tests/"
4545
type: path
46+
debug:
47+
description: Whether or not to print extra debugging information
48+
ini:
49+
- section: custom_junit
50+
key: debug
51+
env:
52+
- name: CUSTOM_JUNIT_DEBUG
53+
default: false
54+
type: boolean
4655
'''
4756

4857
class CallbackModule(JunitCallbackModule):
@@ -61,15 +70,18 @@ def __init__(self):
6170
self._test_case_prefix = self.get_option("test_case_prefix")
6271
self._classname = self.get_option("classname")
6372

73+
self._debug = self.get_option("debug")
6474
self._fail_on_ignore = 'true' # this is needed because we use "ignore_errors" on the playbooks so that all the tests are run
6575
self._include_setup_tasks_in_report = os.getenv('JUNIT_INCLUDE_SETUP_TASKS_IN_REPORT', 'False').lower()
6676
self._hide_task_arguments = os.getenv('JUNIT_HIDE_TASK_ARGUMENTS', 'True').lower()
6777
self._task_class = False
6878

69-
print("The output_dir is: %s" % self._output_dir)
79+
if self._debug:
80+
print("The output_dir is: %s" % self._output_dir)
7081
# Ensure the output directory exists
7182
if not os.path.exists(self._output_dir):
72-
print("Creating output dir: %s" % (self._output_dir))
83+
if self._debug:
84+
print("Creating output dir: %s" % (self._output_dir))
7385
os.makedirs(self._output_dir)
7486

7587
def _finish_task(self, status, result):
@@ -100,16 +112,16 @@ def _finish_task(self, status, result):
100112
task_data.add_host(HostData(host_uuid, host_name, status, result))
101113

102114
# Debugging
103-
if task_data.name.startswith(self._test_case_prefix):
115+
if self._debug and task_data.name.startswith(self._test_case_prefix):
104116
print(f"This task ({task_data.name}) starts with the test_prefix({self._test_case_prefix})")
105-
if self._test_case_prefix in task_data.name:
117+
if self._debug and self._test_case_prefix in task_data.name:
106118
print(f"This task ({task_data.name}) should be reported because it contains test_prefix({self._test_case_prefix})")
107-
if status == 'failed':
119+
if self._debug and status == 'failed':
108120
print(f"This task ({task_data.name}) failed, but may not be reported")
109121

110122
def mutate_task_name(self, task_name):
111123
# Debugging
112-
if not self._test_case_prefix in task_name:
124+
if self._debug and not self._test_case_prefix in task_name:
113125
print("task_name (%s) does not contain prefix (%s)" % (task_name, self._test_case_prefix))
114126
new_name = task_name
115127
new_name = new_name.split("\n")[0] # only use the first line, so we can include IDs and additional description
@@ -133,12 +145,15 @@ def _build_test_case(self, task_data, host_data):
133145
"""
134146
# Use the original task name to define the final name
135147

136-
print("%s\t(task_name, pre-_build_test_case)" % task_data.name)
148+
if self._debug:
149+
print("%s\t(task_name, pre-_build_test_case)" % task_data.name)
137150
tc = super()._build_test_case(task_data, host_data)
138-
print("%s\t(tc.name, post-_build_test_case)" % tc.name)
151+
if self._debug:
152+
print("%s\t(tc.name, post-_build_test_case)" % tc.name)
139153
tc.name = self.mutate_task_name(tc.name)
140154

141-
print("%s\t(tc.name, post-mutate_task_name)" % tc.name)
155+
if self._debug:
156+
print("%s\t(tc.name, post-mutate_task_name)" % tc.name)
142157

143158
# These can be able to omit with a config option
144159
# These two control whether testcases contain the system_out and

0 commit comments

Comments
 (0)