Skip to content

Commit 0df4d2e

Browse files
committed
subscription: return parent node to oper_state callback via extra_info
The only way to differentiate two calls when there is a subscription on an internal element of a list is by using the parent node. Moreover, in these cases, it is on this parent node that the data structure to be returned must be built.
1 parent 956e214 commit 0df4d2e

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed

sysrepo/session.py

+4
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,10 @@ def subscribe_module_change_unsafe(
552552
* netconf_id: the NETCONF session ID set for the event originator
553553
sysrepo session
554554
* user: the effective username of the event originator sysrepo session
555+
* parent_xpath: XPath to an existing parent of the requested nodes. It is
556+
None for top-level nodes. Caller is supposed to append the requested
557+
nodes to this data subtree and return either the original parent or a
558+
top-level node.
555559
556560
The callback is expected to return a python dictionary containing the operational
557561
data. The dictionary should be in the libyang "dict" format. It will be parsed to a

sysrepo/subscription.py

+5
Original file line numberDiff line numberDiff line change
@@ -367,9 +367,14 @@ def oper_data_callback(session, sub_id, module, xpath, req_xpath, req_id, parent
367367
callback = subscription.callback
368368
private_data = subscription.private_data
369369
if subscription.extra_info:
370+
parent_xpath = None
371+
if parent[0]:
372+
with session.get_ly_ctx() as ly_ctx:
373+
parent_xpath = DNode.new(ly_ctx, parent[0]).path()
370374
extra_info = {
371375
"netconf_id": session.get_netconf_id(),
372376
"user": session.get_user(),
377+
"parent_xpath": parent_xpath,
373378
}
374379
else:
375380
extra_info = {}

tests/test_subs_oper.py

+2
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ def oper_data_cb(xpath, private_data, **kwargs):
8484
self.assertEqual(getpass.getuser(), kwargs["user"])
8585
self.assertIn("netconf_id", kwargs)
8686
self.assertEqual(kwargs["netconf_id"], 12)
87+
self.assertIn("parent_xpath", kwargs)
88+
self.assertIsNone(kwargs["parent_xpath"])
8789
calls.append((xpath, private_data, kwargs))
8890
return {"state": {}}
8991

0 commit comments

Comments
 (0)