From 540bf7ab73983f117902734711392086016ec44a Mon Sep 17 00:00:00 2001 From: Jeremie Leska Date: Fri, 13 Mar 2026 14:33:46 +0100 Subject: [PATCH] connection: add an option to compile obsolete nodes Since version 4 of sysrepo and libyang, obsolete nodes are no longer compiled by default. The sysrepo commit in the link makes sysrepo compile obsolete nodes. Add the compile_obsolete option, so that sysrepo can create a libyang context with the obsolete nodes. Link: https://github.com/sysrepo/sysrepo/commit/15b757ab02cee5d6ae041983c46e302edfdec237 Signed-off-by: Jeremie Leska --- cffi/cdefs.h | 1 + sysrepo/connection.py | 10 +++++++++- tests/test_connection.py | 6 ++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/cffi/cdefs.h b/cffi/cdefs.h index 6e61c62..869b156 100644 --- a/cffi/cdefs.h +++ b/cffi/cdefs.h @@ -52,6 +52,7 @@ typedef enum { SR_CTX_DEFAULT, SR_CTX_NO_PRINTED, SR_CTX_SET_PRIV_PARSED, + SR_CTX_COMPILE_OBSOLETE, ... } sr_context_flag_t; diff --git a/sysrepo/connection.py b/sysrepo/connection.py index 42d3253..78ced29 100644 --- a/sysrepo/connection.py +++ b/sysrepo/connection.py @@ -36,7 +36,12 @@ class SysrepoConnection: __slots__ = ("cdata",) - def __init__(self, cache_running: bool = False, not_printed: bool = True): + def __init__( + self, + cache_running: bool = False, + not_printed: bool = True, + compile_obsolete: bool = False, + ): """ :arg cache_running: Always cache running datastore data which makes mainly repeated retrieval of @@ -49,6 +54,9 @@ def __init__(self, cache_running: bool = False, not_printed: bool = True): if not_printed: ctx_flags |= lib.SR_CTX_NO_PRINTED + if compile_obsolete: + ctx_flags |= lib.SR_CTX_COMPILE_OBSOLETE + # mandatory flag to work with libyang-python ctx_flags |= lib.SR_CTX_SET_PRIV_PARSED diff --git a/tests/test_connection.py b/tests/test_connection.py index 1d4b528..f46c94f 100644 --- a/tests/test_connection.py +++ b/tests/test_connection.py @@ -93,3 +93,9 @@ def test_conn_start_session_with_printed_context(self): sess = conn.start_session() self.assertEqual(sess.get_datastore(), "running") sess.stop() + + def test_conn_start_session_compile_obsolete(self): + with sysrepo.SysrepoConnection(compile_obsolete=True) as conn: + sess = conn.start_session() + self.assertEqual(sess.get_datastore(), "running") + sess.stop()