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 <[email protected]>
  • Loading branch information
steweg authored and samuel-gauthier committed Sep 27, 2024
1 parent 5330a3f commit 551f44b
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 @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions libyang/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 *"
Expand All @@ -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

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 @@ -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()
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 @@ -126,4 +131,8 @@ module yolo-nodetypes {
anydata any1 {
when "../cont2";
}

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

0 comments on commit 551f44b

Please sign in to comment.