From 1de8c8544805fe80609d6cb1b92d8d79cbb55008 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 ebd264bb..6a7ba42f 100644 --- a/cffi/cdefs.h +++ b/cffi/cdefs.h @@ -15,6 +15,7 @@ struct ly_ctx; #define LY_CTX_REF_IMPLEMENTED ... #define LY_CTX_SET_PRIV_PARSED ... #define LY_CTX_LEAFREF_EXTENDED ... +#define LY_CTX_BUILTIN_PLUGINS_ONLY ... typedef enum { diff --git a/libyang/context.py b/libyang/context.py index 10b61f95..6d517eec 100644 --- a/libyang/context.py +++ b/libyang/context.py @@ -29,6 +29,7 @@ def __init__( disable_searchdir_cwd: bool = True, explicit_compile: Optional[bool] = False, leafref_extended: bool = False, + builtin_plugins_only: bool = False, yanglib_path: Optional[str] = None, yanglib_fmt: str = "json", cdata=None, # C type: "struct ly_ctx *" @@ -44,6 +45,8 @@ def __init__( options |= lib.LY_CTX_EXPLICIT_COMPILE if leafref_extended: options |= lib.LY_CTX_LEAFREF_EXTENDED + 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 a40056c0..6e6e6b2c 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 @@ -1036,3 +1037,13 @@ def test_dnode_attrs_set_and_remove_multiple(self): attrs.remove("ietf-netconf:operation") self.assertEqual(len(attrs), 0) + + def test_dnode_buildin_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 a456ae1d..f5698733 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."; @@ -81,4 +86,8 @@ module yolo-nodetypes { leaf test1 { type uint8; } + + leaf ip-address { + type inet:ipv4-address; + } }