Skip to content

session: fix rpc_send* methods #83

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
14 changes: 9 additions & 5 deletions sysrepo/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -1465,7 +1465,7 @@ def discard_changes(self) -> None:

def rpc_send_ly(
self, rpc_input: libyang.DNode, timeout_ms: int = 0
) -> libyang.DNode:
) -> Optional[libyang.DNode]:
"""
Send an RPC/action and wait for the result.

Expand All @@ -1480,7 +1480,7 @@ def rpc_send_ly(

:returns:
The RPC/action output tree. Allocated dynamically and must be freed by the
caller.
caller. If the RPC/action did not return any output, None is returned.
:raises SysrepoError:
If the RPC/action callback failed.
"""
Expand All @@ -1491,7 +1491,7 @@ def rpc_send_ly(
sr_data_p = ffi.new("sr_data_t **")
check_call(lib.sr_rpc_send_tree, self.cdata, in_dnode, timeout_ms, sr_data_p)
if not sr_data_p[0]:
raise SysrepoInternalError("sr_rpc_send_tree returned NULL")
return None

ctx = self.acquire_context()
dnode = libyang.DNode.new(ctx, sr_data_p[0].tree)
Expand All @@ -1515,7 +1515,7 @@ def rpc_send(
include_implicit_defaults: bool = False,
trim_default_values: bool = False,
keep_empty_containers: bool = False,
) -> Dict:
) -> Optional[Dict]:
"""
Same as rpc_send_ly() but takes a python dictionary and a YANG module name as
input arguments.
Expand All @@ -1539,7 +1539,8 @@ def rpc_send(
Include empty (non-presence) containers.

:returns:
A python dictionary with the RPC/action output tree.
A python dictionary with the RPC/action output tree or None if the RPC/action
did not return any output.
"""
rpc = {}
libyang.xpath_set(rpc, xpath, input_dict)
Expand All @@ -1553,6 +1554,9 @@ def rpc_send(
finally:
in_dnode.free()

if out_dnode is None:
return None

try:
out_dict = out_dnode.print_dict(
strip_prefixes=strip_prefixes,
Expand Down