Skip to content

Commit 540e0d8

Browse files
ebernapre-commit-ci[bot]Ruchip16NilashishC
authored
fix from_xml: return python dictionary (#361)
* removed the in between json conversion, now function returns python dict, changed unit tests to check against the dict. * remove the json import * changelog added * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * changed changelog to minor --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Ruchi Pakhle <72685035+Ruchip16@users.noreply.github.com> Co-authored-by: Nilashish Chakraborty <nilashishchakraborty8@gmail.com>
1 parent 8cba2c3 commit 540e0d8

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
---
2+
minor_changes:
3+
- The from_xml filter returns a python dictionary instead of a json string.

plugins/plugin_utils/from_xml.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313

1414
__metaclass__ = type
1515

16-
import json
17-
1816
from ansible.errors import AnsibleFilterError
1917

2018

@@ -46,7 +44,7 @@ def from_xml(data, engine):
4644
if not HAS_XMLTODICT:
4745
_raise_error("Missing required library xmltodict")
4846
try:
49-
res = json.dumps(xmltodict.parse(data))
47+
res = xmltodict.parse(data)
5048
except Exception:
5149
_raise_error("Input Xml is not valid")
5250
return res

tests/unit/plugins/filter/test_from_xml.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,12 @@
2222
"<schemas><schema/></schemas></netconf-state>"
2323
)
2424

25-
OUTPUT = """{"netconf-state": \
26-
{"@xmlns": "urn:ietf:params:xml:ns:yang:ietf-netconf-monitoring", "schemas": {"schema": null}}}"""
25+
OUTPUT = {
26+
"netconf-state": {
27+
"@xmlns": "urn:ietf:params:xml:ns:yang:ietf-netconf-monitoring",
28+
"schemas": {"schema": None},
29+
},
30+
}
2731

2832

2933
class TestFromXml(TestCase):

0 commit comments

Comments
 (0)