diff --git a/sysrepo/session.py b/sysrepo/session.py index a04db6a..f08cf10 100644 --- a/sysrepo/session.py +++ b/sysrepo/session.py @@ -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, @@ -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, @@ -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. @@ -410,6 +414,7 @@ def subscribe_module_change( passive=passive, done_only=done_only, enabled=enabled, + update=update, filter_origin=filter_origin, ) @@ -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, @@ -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. @@ -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( @@ -1659,6 +1668,7 @@ def _subscribe_flags( enabled=False, oper_merge=False, filter_origin=False, + update=False, ): flags = 0 if no_thread: @@ -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: diff --git a/tests/test_subs_module_change.py b/tests/test_subs_module_change.py index 79b64c1..19ddee3 100644 --- a/tests/test_subs_module_change.py +++ b/tests/test_subs_module_change.py @@ -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": @@ -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: @@ -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//.")) @@ -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: