Skip to content

Commit

Permalink
context: add builtin_plugins_only options
Browse files Browse the repository at this point in the history
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 <steweg@gmail.com>
  • Loading branch information
steweg committed Mar 3, 2024
1 parent ec6b19d commit 1de8c85
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions cffi/cdefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions libyang/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 *"
Expand All @@ -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

Expand Down
11 changes: 11 additions & 0 deletions tests/test_data.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Copyright (c) 2020 6WIND S.A.
# SPDX-License-Identifier: MIT

import gc
import json
import os
import unittest
Expand Down Expand Up @@ -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()
9 changes: 9 additions & 0 deletions tests/yang/yolo/yolo-nodetypes.yang
Original file line number Diff line number Diff line change
Expand Up @@ -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.";

Expand Down Expand Up @@ -81,4 +86,8 @@ module yolo-nodetypes {
leaf test1 {
type uint8;
}

leaf ip-address {
type inet:ipv4-address;
}
}

0 comments on commit 1de8c85

Please sign in to comment.