Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 80c65f8

Browse files
committedFeb 12, 2025
IGNORE THIS COMMIT: merge libyang3 step 3 (PR #21716)
1 parent 905109d commit 80c65f8

File tree

11 files changed

+632
-240
lines changed

11 files changed

+632
-240
lines changed
 

‎rules/libyang3-py3.mk

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# libyang3 python3 deb package
22

33
LIBYANG3_PY3_VERSION = 3.0.3
4-
LIBYANG3_PY3_SUBVERSION = 1
4+
LIBYANG3_PY3_SUBVERSION = 1+b1sonic1
55
LIBYANG3_PY3_FULLVERSION = $(LIBYANG3_PY3_VERSION)-$(LIBYANG3_PY3_SUBVERSION)
66

77
export LIBYANG3_PY3_VERSION

‎rules/sonic-yang-mgmt-py3.mk

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
SONIC_YANG_MGMT_PY3 = sonic_yang_mgmt-1.0-py3-none-any.whl
44
$(SONIC_YANG_MGMT_PY3)_SRC_PATH = $(SRC_PATH)/sonic-yang-mgmt
55
$(SONIC_YANG_MGMT_PY3)_PYTHON_VERSION = 3
6-
$(SONIC_YANG_MGMT_PY3)_DEBS_DEPENDS = $(LIBYANG) $(LIBYANG_CPP) $(LIBYANG_PY3)
6+
$(SONIC_YANG_MGMT_PY3)_DEBS_DEPENDS = $(LIBYANG3) $(LIBYANG3_PY3)
77
$(SONIC_YANG_MGMT_PY3)_DEPENDS = $(SONIC_YANG_MODELS_PY3)
8-
$(SONIC_YANG_MGMT_PY3)_RDEPENDS = $(SONIC_YANG_MODELS_PY3) $(LIBYANG) \
9-
$(LIBYANG_CPP) $(LIBYANG_PY3)
8+
$(SONIC_YANG_MGMT_PY3)_RDEPENDS = $(SONIC_YANG_MODELS_PY3) $(LIBYANG3) \
9+
$(LIBYANG3_PY3)
1010

1111
SONIC_PYTHON_WHEELS += $(SONIC_YANG_MGMT_PY3)

‎src/libyang3-py3.patch/0001-debian.patch

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ diff -ruN libyang-python.orig/debian/changelog libyang-python.new/debian/changel
22
--- libyang-python.orig/debian/changelog 1970-01-01 00:00:00.000000000 +0000
33
+++ libyang-python.new/debian/changelog 2025-02-09 12:45:51.113010546 +0000
44
@@ -0,0 +1,5 @@
5-
+libyang-python (3.0.3-1) unstable; urgency=low
5+
+libyang-python (3.0.3-1+b1sonic1) unstable; urgency=low
66
+
77
+ * source package automatically created by stdeb 0.10.0
88
+

‎src/libyang3-py3.patch/0004-backlinks-pr132.patch

+475
Large diffs are not rendered by default.

‎src/libyang3-py3.patch/series

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
0001-debian.patch
22
0002-loose-json-datatypes.patch
33
0003-parse_module-memleak.patch
4+
0004-backlinks-pr132.patch

‎src/sonic-yang-mgmt/sonic_yang.py

+103-183
Large diffs are not rendered by default.

‎src/sonic-yang-mgmt/sonic_yang_ext.py

+8-9
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# class sonic_yang. A separate file is used to avoid a single large file.
33

44
from __future__ import print_function
5-
import yang as ly
5+
import libyang as ly
66
import syslog
77
from json import dump, dumps, loads
88
from xmltodict import parse
@@ -86,7 +86,7 @@ def _loadJsonYangModel(self):
8686
for f in self.yangFiles:
8787
m = self.ctx.get_module(f)
8888
if m is not None:
89-
xml = m.print_mem(ly.LYD_JSON, ly.LYP_FORMAT)
89+
xml = m.print_mem("yin")
9090
self.yJson.append(parse(xml))
9191
self.sysLog(msg="Parsed Json for {}".format(m.name()))
9292
except Exception as e:
@@ -328,7 +328,7 @@ def _fillLeafDictUses(self, uses_s, table, leafDict):
328328
Parameters:
329329
uses_s (str): uses statement in yang module.
330330
table (str): config DB table, this table is being translated.
331-
leafDict (dict): dict with leaf(s) information for List\Container
331+
leafDict (dict): dict with leaf(s) information for List Container
332332
corresponding to config DB table.
333333
334334
Returns:
@@ -369,7 +369,7 @@ def _createLeafDict(self, model, table):
369369
table (str): config DB table, this table is being translated.
370370
371371
Returns:
372-
leafDict (dict): dict with leaf(s) information for List\Container
372+
leafDict (dict): dict with leaf(s) information for List Container
373373
corresponding to config DB table.
374374
'''
375375
leafDict = dict()
@@ -1174,8 +1174,7 @@ def loadData(self, configdbJson, debug=False):
11741174
self._xlateConfigDB(xlateFile=xlateFile)
11751175
#print(self.xlateJson)
11761176
self.sysLog(msg="Try to load Data in the tree")
1177-
self.root = self.ctx.parse_data_mem(dumps(self.xlateJson), \
1178-
ly.LYD_JSON, ly.LYD_OPT_CONFIG|ly.LYD_OPT_STRICT)
1177+
self.root = self.ctx.parse_data_mem(dumps(self.xlateJson), "json", no_state=True, strict=True)
11791178

11801179
except Exception as e:
11811180
self.root = None
@@ -1195,7 +1194,7 @@ def getData(self, debug=False):
11951194
revXlateFile = None
11961195
if debug:
11971196
revXlateFile = "revXlateConfig.json"
1198-
self.xlateJson = loads(self._print_data_mem('JSON'))
1197+
self.xlateJson = loads(self._print_data_mem("JSON"))
11991198
# reset reverse xlate
12001199
self.revXlateJson = dict()
12011200
# result will be stored self.revXlateJson
@@ -1229,13 +1228,13 @@ def deleteNode(self, xpath):
12291228
# try to delete parent
12301229
nodeP = self._find_parent_data_node(xpath)
12311230
xpathP = nodeP.path()
1232-
if self._deleteNode(xpath=xpathP, node=nodeP) == False:
1231+
if self._deleteNode(xpath=xpathP) == False:
12331232
raise Exception('_deleteNode failed')
12341233
else:
12351234
return True
12361235

12371236
# delete non key element
1238-
if self._deleteNode(xpath=xpath, node=node) == False:
1237+
if self._deleteNode(xpath=xpath) == False:
12391238
raise Exception('_deleteNode failed')
12401239
except Exception as e:
12411240
self.sysLog(msg="deleteNode:{}".format(str(e)), \

‎src/sonic-yang-mgmt/tests/libyang-python-tests/config_data.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@
267267
"fc02:2000::2"
268268
],
269269
"container-in-list-test": {
270-
"leaf-1": true,
270+
"leaf-1": "up",
271271
"leaf-2": "test1",
272272
"mc-case-leaf-1": 55,
273273
"mc-case-leaf-3": 1234
@@ -281,7 +281,7 @@
281281
"2002:2001::2"
282282
],
283283
"container-in-list-test": {
284-
"leaf-1": false,
284+
"leaf-1": "down",
285285
"leaf-2": "test2",
286286
"mc-case-leaf-2": 77,
287287
"mc-case-leaf-3": 4321

‎src/sonic-yang-mgmt/tests/libyang-python-tests/sample-yang-models/test-yang-structure.yang

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ module test-yang-structure {
4545
leaf leaf-1 {
4646
description "test leaf in container";
4747
type string {
48-
pattern "false|true";
48+
pattern "down|up";
4949
}
5050
}
5151

‎src/sonic-yang-mgmt/tests/libyang-python-tests/test_SonicYang.json

+30-27
Original file line numberDiff line numberDiff line change
@@ -25,25 +25,25 @@
2525
],
2626
"data_type" : [
2727
{
28-
"data_type" : "LY_TYPE_STRING",
29-
"xpath" : "/test-port:port/test-port:PORT/test-port:PORT_LIST/test-port:port_name"
28+
"data_type" : "string",
29+
"xpath" : "/test-port:port/PORT/PORT_LIST/port_name"
3030
},
3131
{
32-
"data_type" : "LY_TYPE_LEAFREF",
33-
"xpath" : "/test-vlan:vlan/test-vlan:VLAN_INTERFACE/test-vlan:VLAN_INTERFACE_LIST/test-vlan:vlanid"
32+
"data_type" : "leafref",
33+
"xpath" : "/test-vlan:vlan/VLAN_INTERFACE/VLAN_INTERFACE_LIST/vlanid"
3434
}
3535
],
3636
"delete_nodes" : [
3737
{
38-
"valid" : "False",
38+
"valid" : false,
3939
"xpath" : "/test-port:port/PORT/PORT_LIST[port_name='Ethernet10']/speed"
4040
},
4141
{
42-
"valid" : "True",
42+
"valid" : true,
4343
"xpath" : "/test-port:port/PORT/PORT_LIST[port_name='Ethernet9']/mtu"
4444
},
4545
{
46-
"valid" : "False",
46+
"valid" : false,
4747
"xpath" : "/test-port:port/PORT/PORT_LIST[port_name='Ethernet20']/mtu"
4848
}
4949
],
@@ -67,11 +67,11 @@
6767
"xpath" : "/test-vlan:vlan/test-vlan:VLAN_INTERFACE/test-vlan:VLAN_INTERFACE_LIST/test-vlan:vlanid"
6868
},
6969
{
70-
"leafref_path" : "/test-port:port/test-port:PORT/test-port:PORT_LIST/test-port:port_name",
70+
"leafref_path" : "/port:port/port:PORT/port:PORT_LIST/port:port_name",
7171
"xpath" : "/test-interface:interface/test-interface:INTERFACE/test-interface:INTERFACE_LIST/test-interface:interface"
7272
},
7373
{
74-
"leafref_path" : "/test-port:port/test-port:PORT/test-port:PORT_LIST/test-port:port_name",
74+
"leafref_path" : "/port:port/port:PORT/port:PORT_LIST/port:port_name",
7575
"xpath" : "/test-vlan:vlan/test-vlan:VLAN_MEMBER/test-vlan:VLAN_MEMBER_LIST/test-vlan:port"
7676
},
7777
{
@@ -81,38 +81,38 @@
8181
],
8282
"leafref_type" : [
8383
{
84-
"data_type" : "LY_TYPE_UINT16",
84+
"data_type" : "uint16",
8585
"xpath" : "/test-vlan:vlan/VLAN_INTERFACE/VLAN_INTERFACE_LIST[vlanid='111'][ip-prefix='2000:f500:45:6709::/64']/vlanid"
8686
},
8787
{
88-
"data_type" : "LY_TYPE_STRING",
88+
"data_type" : "string",
8989
"xpath" : "/test-interface:interface/INTERFACE/INTERFACE_LIST[interface='Ethernet8'][ip-prefix='2000:f500:40:a749::/126']/interface"
9090
},
9191
{
92-
"data_type" : "LY_TYPE_STRING",
92+
"data_type" : "string",
9393
"xpath" : "/test-vlan:vlan/VLAN_MEMBER/VLAN_MEMBER_LIST[vlanid='111'][port='Ethernet0']/port"
9494
},
9595
{
96-
"data_type" : "LY_TYPE_UINT16",
96+
"data_type" : "uint16",
9797
"xpath" : "/test-vlan:vlan/VLAN_MEMBER/VLAN_MEMBER_LIST[vlanid='111'][port='Ethernet0']/vlanid"
9898
}
9999
],
100100
"leafref_type_schema" : [
101101
{
102-
"data_type" : "LY_TYPE_UINT16",
103-
"xpath" : "/test-vlan:vlan/test-vlan:VLAN_INTERFACE/test-vlan:VLAN_INTERFACE_LIST/test-vlan:vlanid"
102+
"data_type" : "uint16",
103+
"xpath" : "/test-vlan:vlan/VLAN_INTERFACE/VLAN_INTERFACE_LIST/vlanid"
104104
},
105105
{
106-
"data_type" : "LY_TYPE_STRING",
107-
"xpath" : "/test-interface:interface/test-interface:INTERFACE/test-interface:INTERFACE_LIST/test-interface:interface"
106+
"data_type" : "string",
107+
"xpath" : "/test-interface:interface/INTERFACE/INTERFACE_LIST/interface"
108108
},
109109
{
110-
"data_type" : "LY_TYPE_STRING",
111-
"xpath" : "/test-vlan:vlan/test-vlan:VLAN_MEMBER/test-vlan:VLAN_MEMBER_LIST/test-vlan:port"
110+
"data_type" : "string",
111+
"xpath" : "/test-vlan:vlan/VLAN_MEMBER/VLAN_MEMBER_LIST/port"
112112
},
113113
{
114-
"data_type" : "LY_TYPE_UINT16",
115-
"xpath" : "/test-vlan:vlan/test-vlan:VLAN_MEMBER/test-vlan:VLAN_MEMBER_LIST/test-vlan:vlanid"
114+
"data_type" : "uint16",
115+
"xpath" : "/test-vlan:vlan/VLAN_MEMBER/VLAN_MEMBER_LIST/vlanid"
116116
}
117117
],
118118
"members" : [
@@ -257,21 +257,24 @@
257257
"schema_dependencies" : [
258258
{
259259
"schema_dependencies" : [
260-
"/test-acl:acl/test-acl:ACL_TABLE/test-acl:ACL_TABLE_LIST/test-acl:ports",
261-
"/test-portchannel:portchannel/test-portchannel:PORTCHANNEL/test-portchannel:PORTCHANNEL_LIST/test-portchannel:members",
262-
"/test-interface:interface/test-interface:INTERFACE/test-interface:INTERFACE_LIST/test-interface:interface",
263-
"/test-vlan:vlan/test-vlan:VLAN_MEMBER/test-vlan:VLAN_MEMBER_LIST/test-vlan:port"
260+
"/test-acl:acl/ACL_RULE/ACL_RULE_LIST/ACL_TABLE_NAME",
261+
"/test-vlan:vlan/VLAN_MEMBER/VLAN_MEMBER_LIST/vlanid",
262+
"/test-vlan:vlan/VLAN_INTERFACE/VLAN_INTERFACE_LIST/vlanid",
263+
"/test-acl:acl/ACL_TABLE/ACL_TABLE_LIST/ports",
264+
"/test-portchannel:portchannel/PORTCHANNEL/PORTCHANNEL_LIST/members",
265+
"/test-interface:interface/INTERFACE/INTERFACE_LIST/interface",
266+
"/test-vlan:vlan/VLAN_MEMBER/VLAN_MEMBER_LIST/port"
264267
],
265268
"xpath" : "/test-port:port/test-port:PORT/test-port:PORT_LIST/test-port:port_name"
266269
}
267270
],
268271
"schema_nodes" : [
269272
{
270-
"value" : "/test-vlan:vlan/test-vlan:VLAN_INTERFACE/test-vlan:VLAN_INTERFACE_LIST/test-vlan:family",
273+
"value" : "/test-vlan:vlan/VLAN_INTERFACE/VLAN_INTERFACE_LIST/family",
271274
"xpath" : "/test-vlan:vlan/VLAN_INTERFACE/VLAN_INTERFACE_LIST[vlanid='111'][ip-prefix='10.1.1.64/26']/family"
272275
},
273276
{
274-
"value" : "/test-port:port/test-port:PORT/test-port:PORT_LIST/test-port:speed",
277+
"value" : "/test-port:port/PORT/PORT_LIST/speed",
275278
"xpath" : "/test-port:port/PORT/PORT_LIST[port_name='Ethernet9']/speed"
276279
}
277280
],

‎src/sonic-yang-mgmt/tests/libyang-python-tests/test_sonic_yang.py

+7-13
Original file line numberDiff line numberDiff line change
@@ -153,16 +153,15 @@ def test_find_data_node_value(self, data, yang_s):
153153
for node in data['node_values']:
154154
xpath = str(node['xpath'])
155155
value = str(node['value'])
156-
print(xpath)
157-
print(value)
158156
val = yang_s._find_data_node_value(xpath)
159157
assert str(val) == str(value)
160158

161159
#test delete data node
162160
def test_delete_node(self, data, yang_s):
163161
for node in data['delete_nodes']:
164162
xpath = str(node['xpath'])
165-
yang_s._deleteNode(xpath)
163+
rv = yang_s._deleteNode(xpath)
164+
assert rv == node['valid']
166165

167166
#test set node's value
168167
def test_set_datanode_value(self, data, yang_s):
@@ -218,8 +217,7 @@ def test_find_schema_dependencies(self, yang_s, data):
218217
def test_merge_data_tree(self, data, yang_s):
219218
data_merge_file = data['data_merge_file']
220219
yang_dir = str(data['yang_dir'])
221-
yang_s._merge_data(data_merge_file, yang_dir)
222-
#yang_s.root.print_mem(ly.LYD_JSON, ly.LYP_FORMAT)
220+
yang_s._merge_data(data_merge_file)
223221

224222
#test get module prefix
225223
def test_get_module_prefix(self, yang_s, data):
@@ -234,17 +232,15 @@ def test_get_data_type(self, yang_s, data):
234232
for node in data['data_type']:
235233
xpath = str(node['xpath'])
236234
expected = node['data_type']
237-
expected_type = yang_s._str_to_type(expected)
238235
data_type = yang_s._get_data_type(xpath)
239-
assert expected_type == data_type
236+
assert expected == data_type
240237

241238
def test_get_leafref_type(self, yang_s, data):
242239
for node in data['leafref_type']:
243240
xpath = str(node['xpath'])
244241
expected = node['data_type']
245-
expected_type = yang_s._str_to_type(expected)
246242
data_type = yang_s._get_leafref_type(xpath)
247-
assert expected_type == data_type
243+
assert expected == data_type
248244

249245
def test_get_leafref_path(self, yang_s, data):
250246
for node in data['leafref_path']:
@@ -257,9 +253,8 @@ def test_get_leafref_type_schema(self, yang_s, data):
257253
for node in data['leafref_type_schema']:
258254
xpath = str(node['xpath'])
259255
expected = node['data_type']
260-
expected_type = yang_s._str_to_type(expected)
261256
data_type = yang_s._get_leafref_type_schema(xpath)
262-
assert expected_type == data_type
257+
assert expected == data_type
263258

264259
"""
265260
This is helper function to load YANG models for tests cases, which works
@@ -345,8 +340,7 @@ def test_xlate_rev_xlate(self, sonic_yang_data):
345340
# print for better debugging, in case of failure.
346341
from jsondiff import diff
347342
print(diff(syc.jIn, syc.revXlateJson, syntax='symmetric'))
348-
# make it fail
349-
assert False == True
343+
raise Exception("Xlate and Rev Xlate failed")
350344

351345
return
352346

0 commit comments

Comments
 (0)
Please sign in to comment.