Skip to content

Commit 17cfe55

Browse files
committed
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 3a4ee8e commit 17cfe55

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
@@ -31,6 +31,7 @@ def __init__(
3131
explicit_compile: Optional[bool] = False,
3232
leafref_extended: bool = False,
3333
leafref_linking: bool = False,
34+
builtin_plugins_only: bool = False,
3435
yanglib_path: Optional[str] = None,
3536
yanglib_fmt: str = "json",
3637
cdata=None, # C type: "struct ly_ctx *"
@@ -50,6 +51,8 @@ def __init__(
5051
options |= lib.LY_CTX_LEAFREF_EXTENDED
5152
if leafref_linking:
5253
options |= lib.LY_CTX_LEAFREF_LINKING
54+
if builtin_plugins_only:
55+
options |= lib.LY_CTX_BUILTIN_PLUGINS_ONLY
5356
# force priv parsed
5457
options |= lib.LY_CTX_SET_PRIV_PARSED
5558

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)