From 1df7af5ab2d870bf83dbc84189a4e312862cdd8d Mon Sep 17 00:00:00 2001 From: Ruchi Pakhle <72685035+Ruchip16@users.noreply.github.com> Date: Thu, 1 Aug 2024 23:44:14 +0530 Subject: [PATCH] fix the variable collision issue in downstream tests (#364) * fix the variable collision issue * make output format in such a way that it returns a dict * changes * changes * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * revert back changes * changes * changes * fix the error * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * add dict construct --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- plugins/plugin_utils/from_xml.py | 2 +- tests/integration/targets/utils_from_xml/tasks/simple.yaml | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/plugins/plugin_utils/from_xml.py b/plugins/plugin_utils/from_xml.py index eb1194e..c261629 100644 --- a/plugins/plugin_utils/from_xml.py +++ b/plugins/plugin_utils/from_xml.py @@ -44,7 +44,7 @@ def from_xml(data, engine): if not HAS_XMLTODICT: _raise_error("Missing required library xmltodict") try: - res = xmltodict.parse(data) + res = xmltodict.parse(data, dict_constructor=dict) except Exception: _raise_error("Input Xml is not valid") return res diff --git a/tests/integration/targets/utils_from_xml/tasks/simple.yaml b/tests/integration/targets/utils_from_xml/tasks/simple.yaml index edc529e..aae1074 100644 --- a/tests/integration/targets/utils_from_xml/tasks/simple.yaml +++ b/tests/integration/targets/utils_from_xml/tasks/simple.yaml @@ -19,10 +19,12 @@ - name: Integration tests with and without default engine as xmltodict and ansible.builtin.assert: - that: "{{ output == item.test }}" + that: "{{ output == test_item.test }}" loop: - test: "{{ data | ansible.utils.from_xml() }}" - test: "{{ data | ansible.utils.from_xml('xmltodict') }}" + loop_control: + loop_var: test_item - name: Setup invalid xml as input to ansible.utils.from_xml. ansible.builtin.set_fact: