Fix issue in netconf plugin dispatch for junos and iosxr (#57981)

*  If case xml reply is transformed or namespace is removed in ncclient
   device specific handler return modified xml response as string

*  If data xml node is present in xml response return the xml string
   with data node as root node

*  If none above is true return raw xml string received from host
   with rpc-reply as the root node
This commit is contained in:
Ganesh Nalawade 2019-06-18 20:06:04 +05:30 committed by Paul Belanger
parent 21a95c0a16
commit cc00f21a35

View file

@ -29,7 +29,7 @@ from ansible.module_utils.basic import missing_required_lib
try: try:
from ncclient.operations import RPCError from ncclient.operations import RPCError
from ncclient.xml_ import to_xml, to_ele from ncclient.xml_ import to_xml, to_ele, NCElement
HAS_NCCLIENT = True HAS_NCCLIENT = True
NCCLIENT_IMP_ERR = None NCCLIENT_IMP_ERR = None
except (ImportError, AttributeError) as err: # paramiko and gssapi are incompatible and raise AttributeError not ImportError except (ImportError, AttributeError) as err: # paramiko and gssapi are incompatible and raise AttributeError not ImportError
@ -225,7 +225,20 @@ class NetconfBase(AnsiblePlugin):
raise ValueError('rpc_command value must be provided') raise ValueError('rpc_command value must be provided')
resp = self.m.dispatch(fromstring(rpc_command), source=source, filter=filter) resp = self.m.dispatch(fromstring(rpc_command), source=source, filter=filter)
return resp.data_xml if hasattr(resp, 'data_xml') else resp.xml
if isinstance(resp, NCElement):
# In case xml reply is transformed or namespace is removed in
# ncclient device specific handler return modified xml response
result = resp.data_xml
elif hasattr(resp, 'data_ele') and resp.data_ele:
# if data node is present in xml response return the xml string
# with data node as root
result = resp.data_xml
else:
# return raw xml string received from host with rpc-reply as the root node
result = resp.xml
return result
@ensure_connected @ensure_connected
def lock(self, target="candidate"): def lock(self, target="candidate"):