Skip to content

Commit ee0df99

Browse files
committed
## Adding role junit2json under playbooks/infra/reporting/roles
### Functionality: #### 1. Filter plugin `junit2obj` Converts JUnit to JSON ##### Usage: ```yaml --- - name: convert junit 2 json ansible.builtin.set_fact: my_json: "{{ xml_data | junit2obj }}" ``` #### 2. Filter plugin `reportsmerger` Aggregates N JSON reports into to 1 ##### Usage: ```yaml --- - name: merge files ansible.builtin.set_fact: my_var: "{{['f1.json', 'f2.json'] | reportsmerger(strategy='normal', output_file='result.json') }}" ``` #### 3. Role `junit2json` Uses 1. & 2. to convert + merge list of reports ##### Usage: ```yaml --- - name: convert junit reports to json hosts: localhost connection: local vars: junit2_input_reports_list: - "/path/to/data/input1.xml" - "/path/to/data/input2.xml" - "/path/to/data/input2.xml" junit2_output_dir: "/path/to/output" tasks: - name: Apply role junit2json ansible.builtin.include_role: name: junit2json ``` ###### Several control options: | Variable | Value | Resul(t) | | ----------------- | ------- | ------------------------------------ | | `junit2_do_merge` | `false` | under `junit2_output_dir` | | `junit2_do_merge` | `true` | in `junit2_output_merged_report` | | `junit2_out_str` | `false` | saved as pretty json files | | `junit2_out_str` | `true` | saved as json strings (with escapes) | ### Tests: #### Locations - The tests are under `playbooks/infra/reporting/roles/junit2json/tests/unit` - The tests data is under `playbooks/infra/reporting/roles/junit2json/tests/unit/data` #### Running Running tests from playbooks' folder ```bash python3 -m pytest ./roles/junit2json/tests/unit ```` ### Documentation To generate role documentation with docsible: ```shell docsible -r playbooks/infra/reporting/roles/report_send -g -nob -nod ``` Signed-off-by: Maxim Kovgan <makovgan@redhat.com>
1 parent 37140f4 commit ee0df99

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+3456
-0
lines changed

playbooks/infra/reporting/roles/junit2json/README.md

Lines changed: 425 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
---
3+
# Default variables for junit2json role
4+
5+
# Custom dummy variables (will be merged with defaults from vars/dummy_variables.yml)
6+
# Use this to add project-specific template placeholders
7+
junit2_custom_dummy_variables: {}
8+
9+
# Enable verbose logging for dummy variable processing
10+
junit2_dummy_debug: false
11+
12+
# Original role defaults (preserved for compatibility)
13+
junit2_input_merged_report: "merged.junit.xml"
14+
junit2_output_merged_report: "merged.junit.json"
15+
junit2_do_merge: true
16+
junit2_out_str: true
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
# Template Handling in junit2json Role
2+
3+
## The Problem
4+
5+
Test data sometimes contains literal strings that look like Jinja2 templates:
6+
7+
```xml
8+
<testcase name="... expectations failed: {{ expectation_failed }}" />
9+
<testcase name="... log at: https://ci.example.com/jobs/{{ job_info.job.id }}/states" />
10+
```
11+
12+
When Ansible processes this data, it tries to evaluate these as templates, causing:
13+
14+
```
15+
ERROR! 'expectation_failed' is undefined
16+
ERROR! 'job_info' is undefined
17+
```
18+
19+
## The Solution
20+
21+
The role provides dummy variables for template patterns. Which method you use depends on **variable frequency** and **your maintenance access**:
22+
23+
## Adding Dummy Variables
24+
25+
### High Frequency Variables (appear across many teams/projects)
26+
27+
**If you maintain the role:**
28+
Edit `vars/dummy_variables.yml`:
29+
30+
```yaml
31+
junit2_dummy_variables:
32+
# Add variables that many teams encounter
33+
common_variable: "PLACEHOLDER_COMMON_VARIABLE"
34+
shared_info:
35+
build_id: "PLACEHOLDER_BUILD_ID"
36+
```
37+
38+
**If you don't maintain the role:**
39+
Request the role maintainer to add these variables to `vars/dummy_variables.yml`.
40+
41+
### Low Frequency Variables (specific to your team/project)
42+
43+
**If you maintain the playbook:**
44+
Add variables when calling the role:
45+
46+
```yaml
47+
- name: Convert test reports
48+
ansible.builtin.include_role:
49+
name: junit2json
50+
vars:
51+
junit2_custom_dummy_variables:
52+
# Add team-specific variables
53+
pipeline_id: "PLACEHOLDER_PIPELINE_ID"
54+
deployment:
55+
environment: "PLACEHOLDER_ENVIRONMENT"
56+
```
57+
58+
**If you don't maintain the playbook:**
59+
Create an external variables file `my_extras.yml`:
60+
61+
```yaml
62+
junit2_custom_dummy_variables:
63+
pipeline_id: "PLACEHOLDER_PIPELINE_ID"
64+
deployment:
65+
environment: "PLACEHOLDER_ENVIRONMENT"
66+
```
67+
68+
Run with:
69+
70+
```shell
71+
ansible-playbook my_playbook.yml -e @my_extras.yml
72+
```
73+
74+
### Debug Mode
75+
76+
Enable debug to see what variables are being set:
77+
78+
```yaml
79+
junit2_dummy_debug: true
80+
```
81+
82+
## Role Maintenance & Feedback
83+
84+
**This role is maintained by:** GitHub team `@redhatci/verification`
85+
86+
**Help us improve:** Please share your custom dummy variables with the maintenance team! When you add variables using `junit2_custom_dummy_variables` or external files, let `@redhatci/verification` know what variables you needed. This helps us identify high-frequency variables that should be moved into the role for everyone's benefit.
87+
88+
## Variables Already Handled
89+
90+
These patterns are already handled (may change based on test data encountered):
91+
92+
- `{{ expectation_failed }}`
93+
- `{{ job_info.job.id }}`
94+
- `{{ ci_job_id }}`
95+
- `{{ error_message }}`
96+
- `{{ timestamp }}`

0 commit comments

Comments
 (0)