ansible-collections / community.yang

Ansible Community Collection to support Yang in network devices.
GNU General Public License v3.0
10 stars 14 forks source link

json_to_xml generates a root with namespace #29

Closed cidrblock closed 4 years ago

cidrblock commented 4 years ago

The XML resulting from json_to_xml has a namespace:

 0.4s json_to_xml: 
      etree.tostring(root)=b'<nc:config xmlns:arista-intf-augments="http://.../oc-if:interface></oc-if:interfaces></nc:config>' (file:///tmp/q53667086.txt)

This results in ansible.netcommon.netconf_config throwing an error:

fatal: [eos102]: FAILED! => changed=false 
  msg: content value should have xml string with <config> tag as root

because the namespace may be valid, this might be best fixed in ansible.netcommon.netconfig_config: (this has not been vetted)

def validate_config(module, config, format="xml"):
    if format == "xml":
        root = fromstring(config)
        parts = root.tag.split('}')
        if parts[-1] != "config":
            module.fail_json(
                msg="content value should have xml string with a <config> tag as root"
            )
cidrblock commented 4 years ago

BTW, the root tag ends up as:

 0.0s validate_config: '{urn:ietf:params:xml:ns:netconf:base:1.0}config'
rohitthakur2590 commented 4 years ago

@cidrblock I have PR opened to resolve this https://github.com/ansible-collections/ansible.netcommon/pull/137