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>
pull/363/head
Emanuele Bernardi 2024-07-25 18:50:32 +02:00 committed by GitHub
parent 8cba2c3b9e
commit 540e0d8963
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 10 additions and 5 deletions

View File

@ -0,0 +1,3 @@
---
minor_changes:
- The from_xml filter returns a python dictionary instead of a json string.

View File

@ -13,8 +13,6 @@ from __future__ import absolute_import, division, print_function
__metaclass__ = type
import json
from ansible.errors import AnsibleFilterError
@ -46,7 +44,7 @@ def from_xml(data, engine):
if not HAS_XMLTODICT:
_raise_error("Missing required library xmltodict")
try:
res = json.dumps(xmltodict.parse(data))
res = xmltodict.parse(data)
except Exception:
_raise_error("Input Xml is not valid")
return res

View File

@ -22,8 +22,12 @@ VALID_DATA = (
"<schemas><schema/></schemas></netconf-state>"
)
OUTPUT = """{"netconf-state": \
{"@xmlns": "urn:ietf:params:xml:ns:yang:ietf-netconf-monitoring", "schemas": {"schema": null}}}"""
OUTPUT = {
"netconf-state": {
"@xmlns": "urn:ietf:params:xml:ns:yang:ietf-netconf-monitoring",
"schemas": {"schema": None},
},
}
class TestFromXml(TestCase):