Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions ansible_collections/juniper/device/plugins/connection/pyez.py
Original file line number Diff line number Diff line change
Expand Up @@ -503,11 +503,16 @@ def get_rpc_resp(self, rpc, ignore_warning, format):
rpc_val = rpc_val.encode("utf-8")
parser = etree.XMLParser(ns_clean=True, recover=True, encoding="utf-8")
rpc_etree = etree.fromstring(rpc_val, parser=parser)
resp = self.dev.rpc(
rpc_etree,
normalize=bool(format == "xml"),
ignore_warning=ignore_warning,
)
try:
resp = self.dev.rpc(
rpc_etree,
normalize=bool(format == "xml"),
ignore_warning=ignore_warning,
)
except pyez_exception.RpcTimeoutError as ex:
raise AnsibleError("RpcTimeoutError: %s" % str(ex))
except (pyez_exception.RpcError, pyez_exception.ConnectError) as ex:
raise AnsibleError("RpcError: %s" % str(ex))
if format == "json":
return resp
return etree.tostring(resp)
Expand Down
16 changes: 12 additions & 4 deletions ansible_collections/juniper/device/plugins/modules/rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -564,10 +564,17 @@ def main():
format=format,
)
except Exception as ex:
if "RpcError" in (str(ex)):
raise junos_module.pyez_exception.RpcError
if "ConnectError" in (str(ex)):
raise junos_module.pyez_exception.ConnectError
junos_module.logger.debug(
'Unable to execute RPC "%s". Error: %s',
junos_module.etree.tostring(rpc, pretty_print=True),
str(ex),
)
result["msg"] = "Unable to execute the RPC: %s. Error: %s" % (
junos_module.etree.tostring(rpc, pretty_print=True),
str(ex),
)
results.append(result)
continue
result["msg"] = "The RPC executed successfully."
junos_module.logger.debug(
'RPC "%s" executed successfully.',
Expand All @@ -576,6 +583,7 @@ def main():
except (
junos_module.pyez_exception.ConnectError,
junos_module.pyez_exception.RpcError,
junos_module.pyez_exception.RpcTimeoutError,
) as ex:
junos_module.logger.debug(
'Unable to execute RPC "%s". Error: %s',
Expand Down
Loading