From 551f44b5db419cfb02a1e34acb0ecc35d85615a0 Mon Sep 17 00:00:00 2001 From: Stefan Gula Date: Sun, 3 Mar 2024 15:56:15 +0100 Subject: [PATCH] context: add builtin_plugins_only options This patch adds builtin_plugins_only option, which allows user to use only basic YANG type plugins, instead of using advanced plugins as ipv4-address etc. Signed-off-by: Stefan Gula --- cffi/cdefs.h | 1 + libyang/context.py | 3 +++ tests/test_data.py | 11 +++++++++++ tests/yang/yolo/yolo-nodetypes.yang | 9 +++++++++ 4 files changed, 24 insertions(+) diff --git a/cffi/cdefs.h b/cffi/cdefs.h index 6f20187..93f68c7 100644 --- a/cffi/cdefs.h +++ b/cffi/cdefs.h @@ -16,6 +16,7 @@ struct ly_ctx; #define LY_CTX_SET_PRIV_PARSED ... #define LY_CTX_LEAFREF_EXTENDED ... #define LY_CTX_LEAFREF_LINKING ... +#define LY_CTX_BUILTIN_PLUGINS_ONLY ... typedef enum { diff --git a/libyang/context.py b/libyang/context.py index b08df0c..1b1d4cd 100644 --- a/libyang/context.py +++ b/libyang/context.py @@ -194,6 +194,7 @@ def __init__( explicit_compile: Optional[bool] = False, leafref_extended: bool = False, leafref_linking: bool = False, + builtin_plugins_only: bool = False, yanglib_path: Optional[str] = None, yanglib_fmt: str = "json", cdata=None, # C type: "struct ly_ctx *" @@ -214,6 +215,8 @@ def __init__( options |= lib.LY_CTX_LEAFREF_EXTENDED if leafref_linking: options |= lib.LY_CTX_LEAFREF_LINKING + if builtin_plugins_only: + options |= lib.LY_CTX_BUILTIN_PLUGINS_ONLY # force priv parsed options |= lib.LY_CTX_SET_PRIV_PARSED diff --git a/tests/test_data.py b/tests/test_data.py index 9515a58..790b5cd 100644 --- a/tests/test_data.py +++ b/tests/test_data.py @@ -1,6 +1,7 @@ # Copyright (c) 2020 6WIND S.A. # SPDX-License-Identifier: MIT +import gc import json import os import unittest @@ -1100,3 +1101,13 @@ def test_dnode_store_only(self): self.assertIsInstance(dnode, DLeaf) self.assertEqual(dnode.value(), 50) dnode.free() + + def test_dnode_builtin_plugins_only(self): + MAIN = {"yolo-nodetypes:ip-address": "test"} + self.tearDown() + gc.collect() + self.ctx = Context(YANG_DIR, builtin_plugins_only=True) + module = self.ctx.load_module("yolo-nodetypes") + dnode = dict_to_dnode(MAIN, module, None, validate=False, store_only=True) + self.assertIsInstance(dnode, DLeaf) + dnode.free() diff --git a/tests/yang/yolo/yolo-nodetypes.yang b/tests/yang/yolo/yolo-nodetypes.yang index de4656b..0ec00a6 100644 --- a/tests/yang/yolo/yolo-nodetypes.yang +++ b/tests/yang/yolo/yolo-nodetypes.yang @@ -3,6 +3,11 @@ module yolo-nodetypes { namespace "urn:yang:yolo:nodetypes"; prefix sys; + import ietf-inet-types { + prefix inet; + revision-date 2013-07-15; + } + description "YOLO Nodetypes."; @@ -126,4 +131,8 @@ module yolo-nodetypes { anydata any1 { when "../cont2"; } + + leaf ip-address { + type inet:ipv4-address; + } }