Skip to content

add update parameter to module change subscription #81

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

Merged
merged 2 commits into from
Feb 14, 2025
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
12 changes: 12 additions & 0 deletions sysrepo/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ def get_ly_ctx(self) -> libyang.Context:
to reject changes.
"""

# pylint: disable=too-many-arguments
def subscribe_module_change(
self,
module: str,
Expand All @@ -338,6 +339,7 @@ def subscribe_module_change(
passive: bool = False,
done_only: bool = False,
enabled: bool = False,
update: bool = False,
filter_origin: bool = False,
private_data: Any = None,
asyncio_register: bool = False,
Expand Down Expand Up @@ -372,6 +374,8 @@ def subscribe_module_change(
:arg enabled:
The subscriber wants to be notified about the current configuration
at the moment of subscribing.
:arg update:
The subscriber wants to be called before the configuration is applied.
:arg filter_origin:
Filter events on the originator side to unburden the subscriber, but
results in 0 value for filtered-out changes in the subscriber infos.
Expand Down Expand Up @@ -410,6 +414,7 @@ def subscribe_module_change(
passive=passive,
done_only=done_only,
enabled=enabled,
update=update,
filter_origin=filter_origin,
)

Expand Down Expand Up @@ -464,6 +469,7 @@ def subscribe_module_change_unsafe(
passive: bool = False,
done_only: bool = False,
enabled: bool = False,
update: bool = False,
filter_origin: bool = False,
private_data: Any = None,
asyncio_register: bool = False,
Expand Down Expand Up @@ -499,6 +505,8 @@ def subscribe_module_change_unsafe(
:arg enabled:
The subscriber wants to be notified about the current configuration
at the moment of subscribing.
:arg update:
The subscriber wants to be called before the configuration is applied.
:arg filter_origin:
Filter events on the originator side to unburden the subscriber, but
results in 0 value for filtered-out changes in the subscriber infos.
Expand Down Expand Up @@ -531,6 +539,7 @@ def subscribe_module_change_unsafe(
passive=passive,
done_only=done_only,
enabled=enabled,
update=update,
filter_origin=filter_origin,
)
check_call(
Expand Down Expand Up @@ -1659,6 +1668,7 @@ def _subscribe_flags(
enabled=False,
oper_merge=False,
filter_origin=False,
update=False,
):
flags = 0
if no_thread:
Expand All @@ -1669,6 +1679,8 @@ def _subscribe_flags(
flags |= lib.SR_SUBSCR_DONE_ONLY
if enabled:
flags |= lib.SR_SUBSCR_ENABLED
if update:
flags |= lib.SR_SUBSCR_UPDATE
if oper_merge:
flags |= lib.SR_SUBSCR_OPER_MERGE
if filter_origin:
Expand Down
6 changes: 4 additions & 2 deletions tests/test_subs_module_change.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def test_module_change_sub(self):
expected_changes = []

def module_change_cb(event, req_id, changes, private_data):
self.assertIn(event, ("change", "done", "abort"))
self.assertIn(event, ("change", "done", "abort", "update"))
self.assertIs(private_data, priv)
for c in changes:
if c.xpath == "/sysrepo-example:conf/system/hostname":
Expand All @@ -61,6 +61,7 @@ def module_change_cb(event, req_id, changes, private_data):
"/sysrepo-example:conf",
module_change_cb,
private_data=priv,
update=True,
)

with self.conn.start_session("running") as ch_sess:
Expand Down Expand Up @@ -316,7 +317,7 @@ def test_module_change_sub_unsafe(self):

def module_change_cb(session, event, req_id, private_data):
self.assertIsInstance(session, SysrepoSession)
self.assertIn(event, ("change", "done", "abort"))
self.assertIn(event, ("change", "done", "abort", "update"))
self.assertIsInstance(req_id, int)
self.assertIs(private_data, priv)
changes = list(session.get_changes("/sysrepo-example:conf//."))
Expand All @@ -334,6 +335,7 @@ def module_change_cb(session, event, req_id, private_data):
"/sysrepo-example:conf",
module_change_cb,
private_data=priv,
update=True,
)

with self.conn.start_session("running") as ch_sess:
Expand Down