Skip to content

Commit 551f44b

Browse files
stewegsamuel-gauthier
authored andcommitted
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 <[email protected]>
1 parent 5330a3f commit 551f44b

File tree

4 files changed

+24
-0
lines changed

4 files changed

+24
-0
lines changed

cffi/cdefs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ struct ly_ctx;
1616
#define LY_CTX_SET_PRIV_PARSED ...
1717
#define LY_CTX_LEAFREF_EXTENDED ...
1818
#define LY_CTX_LEAFREF_LINKING ...
19+
#define LY_CTX_BUILTIN_PLUGINS_ONLY ...
1920

2021

2122
typedef enum {

libyang/context.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ def __init__(
194194
explicit_compile: Optional[bool] = False,
195195
leafref_extended: bool = False,
196196
leafref_linking: bool = False,
197+
builtin_plugins_only: bool = False,
197198
yanglib_path: Optional[str] = None,
198199
yanglib_fmt: str = "json",
199200
cdata=None, # C type: "struct ly_ctx *"
@@ -214,6 +215,8 @@ def __init__(
214215
options |= lib.LY_CTX_LEAFREF_EXTENDED
215216
if leafref_linking:
216217
options |= lib.LY_CTX_LEAFREF_LINKING
218+
if builtin_plugins_only:
219+
options |= lib.LY_CTX_BUILTIN_PLUGINS_ONLY
217220
# force priv parsed
218221
options |= lib.LY_CTX_SET_PRIV_PARSED
219222

tests/test_data.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Copyright (c) 2020 6WIND S.A.
22
# SPDX-License-Identifier: MIT
33

4+
import gc
45
import json
56
import os
67
import unittest
@@ -1100,3 +1101,13 @@ def test_dnode_store_only(self):
11001101
self.assertIsInstance(dnode, DLeaf)
11011102
self.assertEqual(dnode.value(), 50)
11021103
dnode.free()
1104+
1105+
def test_dnode_builtin_plugins_only(self):
1106+
MAIN = {"yolo-nodetypes:ip-address": "test"}
1107+
self.tearDown()
1108+
gc.collect()
1109+
self.ctx = Context(YANG_DIR, builtin_plugins_only=True)
1110+
module = self.ctx.load_module("yolo-nodetypes")
1111+
dnode = dict_to_dnode(MAIN, module, None, validate=False, store_only=True)
1112+
self.assertIsInstance(dnode, DLeaf)
1113+
dnode.free()

tests/yang/yolo/yolo-nodetypes.yang

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ module yolo-nodetypes {
33
namespace "urn:yang:yolo:nodetypes";
44
prefix sys;
55

6+
import ietf-inet-types {
7+
prefix inet;
8+
revision-date 2013-07-15;
9+
}
10+
611
description
712
"YOLO Nodetypes.";
813

@@ -126,4 +131,8 @@ module yolo-nodetypes {
126131
anydata any1 {
127132
when "../cont2";
128133
}
134+
135+
leaf ip-address {
136+
type inet:ipv4-address;
137+
}
129138
}

0 commit comments

Comments
 (0)