Skip to content

Commit 540bf7a

Browse files
committed
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: sysrepo/sysrepo@15b757a Signed-off-by: Jeremie Leska <jeremie.leska@6wind.com>
1 parent c5fbdaf commit 540bf7a

3 files changed

Lines changed: 16 additions & 1 deletion

File tree

cffi/cdefs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ typedef enum {
5252
SR_CTX_DEFAULT,
5353
SR_CTX_NO_PRINTED,
5454
SR_CTX_SET_PRIV_PARSED,
55+
SR_CTX_COMPILE_OBSOLETE,
5556
...
5657
} sr_context_flag_t;
5758

sysrepo/connection.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,12 @@ class SysrepoConnection:
3636

3737
__slots__ = ("cdata",)
3838

39-
def __init__(self, cache_running: bool = False, not_printed: bool = True):
39+
def __init__(
40+
self,
41+
cache_running: bool = False,
42+
not_printed: bool = True,
43+
compile_obsolete: bool = False,
44+
):
4045
"""
4146
:arg cache_running:
4247
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):
4954
if not_printed:
5055
ctx_flags |= lib.SR_CTX_NO_PRINTED
5156

57+
if compile_obsolete:
58+
ctx_flags |= lib.SR_CTX_COMPILE_OBSOLETE
59+
5260
# mandatory flag to work with libyang-python
5361
ctx_flags |= lib.SR_CTX_SET_PRIV_PARSED
5462

tests/test_connection.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,9 @@ def test_conn_start_session_with_printed_context(self):
9393
sess = conn.start_session()
9494
self.assertEqual(sess.get_datastore(), "running")
9595
sess.stop()
96+
97+
def test_conn_start_session_compile_obsolete(self):
98+
with sysrepo.SysrepoConnection(compile_obsolete=True) as conn:
99+
sess = conn.start_session()
100+
self.assertEqual(sess.get_datastore(), "running")
101+
sess.stop()

0 commit comments

Comments
 (0)