[validations] fix: prevent cifmw_validations_xml_filter hang#4000
[validations] fix: prevent cifmw_validations_xml_filter hang#4000hgoelredhat wants to merge 1 commit into
Conversation
Issue: The validations playbook was hanging indefinitely when creating JUnit XML files for validation results. Root cause: ET.tostring() with encoding='utf-8' returned bytes, which Ansible's copy module couldn't serialize in a template context, causing an indefinite hang. Solution: Changed encoding parameter to 'unicode', which returns str directly, allowing Ansible to process it normally. Testing: - Created reproduction test proving filter returns bytes (problematic) - Applied the fix - Verified filter now returns str - Added 11 comprehensive unit tests covering: * Return type verification (critical for the fix) * Normal test cases (empty, single, multiple) * Malformed input handling (missing fields, long errors) * XML validity and proper escaping * Performance with 100+ tests - All 11 tests PASS - Ansible playbook completes successfully Signed-off-by: Harshita Goel <hgoel@redhat.com>
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
Build failed (check pipeline). Post ✔️ openstack-k8s-operators-content-provider SUCCESS in 18m 15s |
|
Summary of Work Done IssueThe validations playbook was hanging indefinitely when creating JUnit XML files for validation results. This prevented the playbook from completing successfully. Root Cause AnalysisThe Testing & ReproductionStep 1: Proved the Issue ExistsCreated a test script
Output: Return type is bytes?: True Return type is str?: False The filter returns BYTES instead of STR This causes Ansible to hang when trying to serialize! Step 2: Applied the FixChanged one line in # Before (problematic)
return ET.tostring(root_elm, encoding="utf-8", xml_declaration=True)
# After (fixed)
return ET.tostring(root_elm, encoding="unicode", xml_declaration=True)Step 3: Verified Fix WorksRan the same test script and confirmed:
Output: Return type is bytes?: False Return type is str?: True The filter returns STR Ansible can process it normally Step 4: Added Unit TestsCreated 11 comprehensive unit tests in Test Coverage:
Test Results: Step 5: Verified Playbook CompletesRan the actual Ansible playbook: ansible-playbook playbooks/validations.yml -vvvResult: localhost : ok=6 changed=0 unreachable=0 failed=0 skipped=4 rescued=0 ignored=0 ✅ Playbook completes successfully in 1.61 seconds (vs. hanging indefinitely before) Changes Made
Impact
Verification Checklist
|
evallesp
left a comment
There was a problem hiding this comment.
Thanks for the patch. Looks good to me in general, thanks for adding tests. Do you mind to reword a bit the docstrings?
| @@ -0,0 +1,149 @@ | |||
| #!/usr/bin/python3 | |||
There was a problem hiding this comment.
(blocking) suggestion: Could you add copyright header?
| @@ -0,0 +1,149 @@ | |||
| #!/usr/bin/python3 | |||
| """ | |||
| Unit tests for cifmw_validations_xml_filter. | |||
There was a problem hiding this comment.
(non-blocking) suggestion: Instead of having here a comment about the whole file, could you move this information in each tests? with the relevant information in each of the tests?
|
|
||
| def test_returns_string_not_bytes(self): | ||
| """ | ||
| ⚠️ CRITICAL TEST ⚠️ |
There was a problem hiding this comment.
(non-blocking) suggestion: I'd rather go by deleting these type of characters.
|
|
||
| Ensure filter returns str, not bytes. | ||
|
|
||
| Before fix: encoding='utf-8' → returns bytes → Ansible hangs |
There was a problem hiding this comment.
(blocking) suggestion: I don0t think tests should set what was the problem before and what's now.
Probably before fix and after fix is not necessary to have. If you wnat to check this tests you can check the git history.
Also the test name imo should be better like: test_returns_format
Issue: The validations playbook was hanging indefinitely when creating JUnit XML files for validation results.
Root cause: ET.tostring() with encoding='utf-8' returned bytes, which Ansible's copy module couldn't serialize in a template context, causing an indefinite hang.
Solution: Changed encoding parameter to 'unicode', which returns str directly, allowing Ansible to process it normally.
Testing: