From c9af09f4f5bb09711acec96507558c0079f55e54 Mon Sep 17 00:00:00 2001 From: Olof hagsand Date: Mon, 19 Oct 2026 10:39:04 +0200 Subject: [PATCH] Filter transaction notification on controller-transaction The controller in post 1.9 send transaction progress information on the transaction stream. --- CHANGELOG.md | 10 ++++++++++ clixon/client.py | 4 +++- clixon/clixon.py | 3 ++- clixon/netconf.py | 10 ++++++++-- tests/test_netconf.py | 14 ++++++++++++++ 5 files changed, 37 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 32f0167..179ce9f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,15 @@ # Clixon Python API Changelog +## Unreleased + +### Features +* Transaction notification subscriptions now use an xpath filter + `select="controller-transaction"` so that progress notifications on the + unified `controller-transaction` stream are filtered out. + * This requires a clixon-controller where transaction progress and completion + share the `controller-transaction` stream. + * `rpc_subscription_create()` takes a new optional `select` argument. + ## 1.9.0 6 October 2026 diff --git a/clixon/client.py b/clixon/client.py index ffc7693..3b4cb48 100644 --- a/clixon/client.py +++ b/clixon/client.py @@ -261,7 +261,9 @@ def enable_transaction_notify(sock: socket, pp: bool) -> None: """ - rpc = rpc_subscription_create("controller-transaction") + rpc = rpc_subscription_create( + "controller-transaction", select="controller-transaction" + ) send(sock, rpc, pp) data = read(sock, pp) diff --git a/clixon/clixon.py b/clixon/clixon.py index ff26f7f..09ab261 100644 --- a/clixon/clixon.py +++ b/clixon/clixon.py @@ -339,7 +339,8 @@ def __enable_transaction_notify(self) -> None: """ enable_transaction_notify = rpc_subscription_create( - "controller-transaction", user=self.__user + "controller-transaction", user=self.__user, + select="controller-transaction" ) send(self.__socket, enable_transaction_notify, pp) diff --git a/clixon/netconf.py b/clixon/netconf.py index 097e473..dfec107 100644 --- a/clixon/netconf.py +++ b/clixon/netconf.py @@ -304,13 +304,19 @@ def rpc_header_get( def rpc_subscription_create( - stream: Optional[str] = "services-commit", user: Optional[str] = None + stream: Optional[str] = "services-commit", + user: Optional[str] = None, + select: Optional[str] = "", ) -> Element: """ Create a RPC subscription element. :param stream: Stream name :type stream: str + :param user: Username + :type user: str + :param select: XPath filter select, "" matches all notifications + :type select: str :return: RPC element :rtype: Element @@ -335,7 +341,7 @@ def rpc_subscription_create( root.rpc.create("create-subscription", attributes=attributes) root.rpc.create_subscription.create("stream") root.rpc.create_subscription.stream.cdata = stream - root.rpc.create_subscription.create("filter", {"type": "xpath", "select": ""}) + root.rpc.create_subscription.create("filter", {"type": "xpath", "select": select}) return root diff --git a/tests/test_netconf.py b/tests/test_netconf.py index 85a7994..6830557 100644 --- a/tests/test_netconf.py +++ b/tests/test_netconf.py @@ -109,6 +109,20 @@ def test_rpc_subscription_create_user(): assert root.dumps() == xmlstr +def test_rpc_subscription_create_select(): + """ + Test the rpc_subscription_create function with an xpath select filter. + """ + + xmlstr = f"""controller-transaction""" + + root = netconf.rpc_subscription_create( + "controller-transaction", select="controller-transaction" + ) + + assert root.dumps() == xmlstr + + def test_rpc_header_get(): """ Test the rpc_header_get function.