Skip to content

Commit 207992e

Browse files
authored
[custom_junit] Add config options via ini file and env var (#160)
* [custom_junit] Add config options via ini file and env var The following options are added: * test_case_prefix * classname * [custom_junit] Add config option for output_dir
1 parent 5f7adac commit 207992e

File tree

1 file changed

+45
-4
lines changed

1 file changed

+45
-4
lines changed

callback_plugins/custom_junit.py

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,44 @@
66
import re
77
from ansible.utils._junit_xml import TestCase, TestError, TestFailure, TestSuite, TestSuites
88

9+
DOCUMENTATION = '''
10+
callback: custom_junit
11+
type: notification
12+
short_description: TODO
13+
description:
14+
custom_junit generates an XML files that Polarion can read.
15+
Only the tasks marked with $test_case_prefix are reported.
16+
The first line of the task name (excluding the prefix_ is converted
17+
to snake_case, and this becomes the testcase name in the results file.
18+
options:
19+
test_case_prefix:
20+
description: todo
21+
ini:
22+
- section: custom_junit
23+
key: test_case_prefix
24+
env:
25+
- name: JUNIT_TEST_CASE_PREFIX
26+
default: "TEST"
27+
type: string
28+
classname:
29+
description: The classname for the tests.
30+
ini:
31+
- section: custom_junit
32+
key: classname
33+
env:
34+
- name: CUSTOM_JUNIT_CLASSNAME
35+
default: "openstack-observability"
36+
type: string
37+
output_dir:
38+
description: the direcory which the output files are saved to
39+
ini:
40+
- section: custom_junit
41+
key: output_dir
42+
env:
43+
- name: JUNIT_OUTPUT_DIR
44+
default: "~/ci-framework-data/tests/feature-verification-tests/"
45+
type: path
46+
'''
947

1048
class CallbackModule(JunitCallbackModule):
1149
"""
@@ -14,12 +52,15 @@ class CallbackModule(JunitCallbackModule):
1452
CALLBACK_NAME = 'custom_junit'
1553

1654
def __init__(self):
55+
self._defs = None
1756
super(CallbackModule, self).__init__()
57+
self.set_options()
1858

19-
# Custom environment variable handling
2059
# Update this to parse these values from the config file, as well as the env.
21-
self._output_dir = os.path.expanduser("~/ci-framework-data/tests/feature-verification-tests/")
22-
self._test_case_prefix = os.getenv('JUNIT_TEST_CASE_PREFIX', 'TEST')
60+
self._output_dir = self.get_option("output_dir")
61+
self._test_case_prefix = self.get_option("test_case_prefix")
62+
self._classname = self.get_option("classname")
63+
2364
self._fail_on_ignore = 'true' # this is needed because we use "ignore_errors" on the playbooks so that all the tests are run
2465
self._include_setup_tasks_in_report = os.getenv('JUNIT_INCLUDE_SETUP_TASKS_IN_REPORT', 'False').lower()
2566
self._hide_task_arguments = os.getenv('JUNIT_HIDE_TASK_ARGUMENTS', 'True').lower()
@@ -104,5 +145,5 @@ def _build_test_case(self, task_data, host_data):
104145
# system_err elements that show STDOUT and STDERR
105146
tc.system_out = None
106147
tc.system_err = None
107-
tc.classname = "openstack-observability"
148+
tc.classname = self._classname
108149
return tc

0 commit comments

Comments
 (0)