Skip to content

Commit 9d5d0b8

Browse files
committed
sonic-yang-mgmt: fix test cases
A few things of note here: * The paths generated by libyang3 no longer have the prefix before each node, so these changes are valid that strip those. See https://netopeer.liberouter.org/doc/libyang/master/html/howto_x_path.html: ``` As for the format of any prefixes, the standardized JSON (RFC 7951) was used. Summarized, xpath follows these conventions: ... * nodes always inherit their module (prefix) from their parent node so whenever a node is from a different module than its parent, it MUST have a prefix * nodes from the same module as their parent MUST NOT have a prefix ... ``` * The schema dependencies have been enhanced to support references within unions so more paths are returned now.
1 parent 98fcfcf commit 9d5d0b8

File tree

4 files changed

+84
-44
lines changed

4 files changed

+84
-44
lines changed

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

+74-28
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
],
@@ -56,6 +56,52 @@
5656
],
5757
"xpath" : "/test-port:port/PORT/PORT_LIST[port_name='Ethernet8']/port_name"
5858
},
59+
{
60+
"dependencies" : [
61+
"/test-acl:acl/ACL_RULE/ACL_RULE_LIST[ACL_TABLE_NAME='PACL-V6'][RULE_NAME='Rule_20']/ACL_TABLE_NAME",
62+
"/test-acl:acl/ACL_RULE/ACL_RULE_LIST[ACL_TABLE_NAME='PACL-test'][RULE_NAME='rule_20']/ACL_TABLE_NAME",
63+
"/test-acl:acl/ACL_RULE/ACL_RULE_LIST[ACL_TABLE_NAME='PACL-V4'][RULE_NAME='Rule_20']/ACL_TABLE_NAME",
64+
"/test-acl:acl/ACL_RULE/ACL_RULE_LIST[ACL_TABLE_NAME='PACL-V4'][RULE_NAME='Rule_40']/ACL_TABLE_NAME"
65+
],
66+
"xpath" : "/test-acl:acl/ACL_TABLE"
67+
},
68+
{
69+
"dependencies" : [
70+
"/test-acl:acl/ACL_TABLE/ACL_TABLE_LIST[ACL_TABLE_NAME='PACL-V6']/ports[.='Ethernet8']",
71+
"/test-vlan:vlan/VLAN_MEMBER/VLAN_MEMBER_LIST[vlanid='111'][port='Ethernet2']/port",
72+
"/test-vlan:vlan/VLAN_MEMBER/VLAN_MEMBER_LIST[vlanid='111'][port='Ethernet3']/vlanid",
73+
"/test-vlan:vlan/VLAN_INTERFACE/VLAN_INTERFACE_LIST[vlanid='555'][ip-prefix='fe80::/10']/vlanid",
74+
"/test-interface:interface/INTERFACE/INTERFACE_LIST[interface='Ethernet8'][ip-prefix='10.1.1.64/26']/interface",
75+
"/test-vlan:vlan/VLAN_INTERFACE/VLAN_INTERFACE_LIST[vlanid='111'][ip-prefix='2000:f500:45:6709::/64']/vlanid",
76+
"/test-vlan:vlan/VLAN_MEMBER/VLAN_MEMBER_LIST[vlanid='111'][port='Ethernet5']/vlanid",
77+
"/test-vlan:vlan/VLAN_MEMBER/VLAN_MEMBER_LIST[vlanid='111'][port='Ethernet1']/port",
78+
"/test-acl:acl/ACL_TABLE/ACL_TABLE_LIST[ACL_TABLE_NAME='PACL-V4']/ports[.='Ethernet0']",
79+
"/test-vlan:vlan/VLAN_MEMBER/VLAN_MEMBER_LIST[vlanid='111'][port='Ethernet6']/port",
80+
"/test-acl:acl/ACL_TABLE/ACL_TABLE_LIST[ACL_TABLE_NAME='PACL-V4']/ports[.='Ethernet2']",
81+
"/test-acl:acl/ACL_TABLE/ACL_TABLE_LIST[ACL_TABLE_NAME='PACL-V6']/ports[.='Ethernet7']",
82+
"/test-vlan:vlan/VLAN_MEMBER/VLAN_MEMBER_LIST[vlanid='111'][port='Ethernet3']/port",
83+
"/test-interface:interface/INTERFACE/INTERFACE_LIST[interface='Ethernet8'][ip-prefix='2000:f500:40:a749::/126']/interface",
84+
"/test-acl:acl/ACL_RULE/ACL_RULE_LIST[ACL_TABLE_NAME='PACL-test'][RULE_NAME='rule_20']/ACL_TABLE_NAME",
85+
"/test-vlan:vlan/VLAN_MEMBER/VLAN_MEMBER_LIST[vlanid='111'][port='Ethernet0']/port",
86+
"/test-vlan:vlan/VLAN_MEMBER/VLAN_MEMBER_LIST[vlanid='111'][port='Ethernet5']/port",
87+
"/test-vlan:vlan/VLAN_MEMBER/VLAN_MEMBER_LIST[vlanid='111'][port='Ethernet1']/vlanid",
88+
"/test-vlan:vlan/VLAN_INTERFACE/VLAN_INTERFACE_LIST[vlanid='111'][ip-prefix='fe80::/10']/vlanid",
89+
"/test-vlan:vlan/VLAN_MEMBER/VLAN_MEMBER_LIST[vlanid='111'][port='Ethernet4']/port",
90+
"/test-acl:acl/ACL_RULE/ACL_RULE_LIST[ACL_TABLE_NAME='PACL-V4'][RULE_NAME='Rule_20']/ACL_TABLE_NAME",
91+
"/test-vlan:vlan/VLAN_MEMBER/VLAN_MEMBER_LIST[vlanid='111'][port='Ethernet2']/vlanid",
92+
"/test-acl:acl/ACL_TABLE/ACL_TABLE_LIST[ACL_TABLE_NAME='PACL-V6']/ports[.='Ethernet9']",
93+
"/test-vlan:vlan/VLAN_MEMBER/VLAN_MEMBER_LIST[vlanid='111'][port='Ethernet6']/vlanid",
94+
"/test-acl:acl/ACL_RULE/ACL_RULE_LIST[ACL_TABLE_NAME='PACL-V4'][RULE_NAME='Rule_40']/ACL_TABLE_NAME",
95+
"/test-vlan:vlan/VLAN_MEMBER/VLAN_MEMBER_LIST[vlanid='111'][port='Ethernet0']/vlanid",
96+
"/test-acl:acl/ACL_RULE/ACL_RULE_LIST[ACL_TABLE_NAME='PACL-V6'][RULE_NAME='Rule_20']/ACL_TABLE_NAME",
97+
"/test-vlan:vlan/VLAN_INTERFACE/VLAN_INTERFACE_LIST[vlanid='111'][ip-prefix='10.1.1.64/26']/vlanid",
98+
"/test-vlan:vlan/VLAN_MEMBER/VLAN_MEMBER_LIST[vlanid='111'][port='Ethernet4']/vlanid",
99+
"/test-acl:acl/ACL_TABLE/ACL_TABLE_LIST[ACL_TABLE_NAME='PACL-V4']/ports[.='Ethernet1']",
100+
"/test-vlan:vlan/VLAN_INTERFACE/VLAN_INTERFACE_LIST[vlanid='555'][ip-prefix='2000:f500:41:4e9::/64']/vlanid",
101+
"/test-vlan:vlan/VLAN_INTERFACE/VLAN_INTERFACE_LIST[vlanid='555'][ip-prefix='10.1.5.64/26']/vlanid"
102+
],
103+
"xpath" : "/"
104+
},
59105
{
60106
"dependencies" : [],
61107
"xpath" : "/test-port:port/PORT/PORT_LIST[port_name='Ethernet8']/alias"
@@ -67,11 +113,11 @@
67113
"xpath" : "/test-vlan:vlan/test-vlan:VLAN_INTERFACE/test-vlan:VLAN_INTERFACE_LIST/test-vlan:vlanid"
68114
},
69115
{
70-
"leafref_path" : "/test-port:port/test-port:PORT/test-port:PORT_LIST/test-port:port_name",
116+
"leafref_path" : "/port:port/port:PORT/port:PORT_LIST/port:port_name",
71117
"xpath" : "/test-interface:interface/test-interface:INTERFACE/test-interface:INTERFACE_LIST/test-interface:interface"
72118
},
73119
{
74-
"leafref_path" : "/test-port:port/test-port:PORT/test-port:PORT_LIST/test-port:port_name",
120+
"leafref_path" : "/port:port/port:PORT/port:PORT_LIST/port:port_name",
75121
"xpath" : "/test-vlan:vlan/test-vlan:VLAN_MEMBER/test-vlan:VLAN_MEMBER_LIST/test-vlan:port"
76122
},
77123
{
@@ -81,38 +127,38 @@
81127
],
82128
"leafref_type" : [
83129
{
84-
"data_type" : "LY_TYPE_UINT16",
130+
"data_type" : "uint16",
85131
"xpath" : "/test-vlan:vlan/VLAN_INTERFACE/VLAN_INTERFACE_LIST[vlanid='111'][ip-prefix='2000:f500:45:6709::/64']/vlanid"
86132
},
87133
{
88-
"data_type" : "LY_TYPE_STRING",
134+
"data_type" : "string",
89135
"xpath" : "/test-interface:interface/INTERFACE/INTERFACE_LIST[interface='Ethernet8'][ip-prefix='2000:f500:40:a749::/126']/interface"
90136
},
91137
{
92-
"data_type" : "LY_TYPE_STRING",
138+
"data_type" : "string",
93139
"xpath" : "/test-vlan:vlan/VLAN_MEMBER/VLAN_MEMBER_LIST[vlanid='111'][port='Ethernet0']/port"
94140
},
95141
{
96-
"data_type" : "LY_TYPE_UINT16",
142+
"data_type" : "uint16",
97143
"xpath" : "/test-vlan:vlan/VLAN_MEMBER/VLAN_MEMBER_LIST[vlanid='111'][port='Ethernet0']/vlanid"
98144
}
99145
],
100146
"leafref_type_schema" : [
101147
{
102-
"data_type" : "LY_TYPE_UINT16",
103-
"xpath" : "/test-vlan:vlan/test-vlan:VLAN_INTERFACE/test-vlan:VLAN_INTERFACE_LIST/test-vlan:vlanid"
148+
"data_type" : "uint16",
149+
"xpath" : "/test-vlan:vlan/VLAN_INTERFACE/VLAN_INTERFACE_LIST/vlanid"
104150
},
105151
{
106-
"data_type" : "LY_TYPE_STRING",
107-
"xpath" : "/test-interface:interface/test-interface:INTERFACE/test-interface:INTERFACE_LIST/test-interface:interface"
152+
"data_type" : "string",
153+
"xpath" : "/test-interface:interface/INTERFACE/INTERFACE_LIST/interface"
108154
},
109155
{
110-
"data_type" : "LY_TYPE_STRING",
111-
"xpath" : "/test-vlan:vlan/test-vlan:VLAN_MEMBER/test-vlan:VLAN_MEMBER_LIST/test-vlan:port"
156+
"data_type" : "string",
157+
"xpath" : "/test-vlan:vlan/VLAN_MEMBER/VLAN_MEMBER_LIST/port"
112158
},
113159
{
114-
"data_type" : "LY_TYPE_UINT16",
115-
"xpath" : "/test-vlan:vlan/test-vlan:VLAN_MEMBER/test-vlan:VLAN_MEMBER_LIST/test-vlan:vlanid"
160+
"data_type" : "uint16",
161+
"xpath" : "/test-vlan:vlan/VLAN_MEMBER/VLAN_MEMBER_LIST/vlanid"
116162
}
117163
],
118164
"members" : [
@@ -257,21 +303,21 @@
257303
"schema_dependencies" : [
258304
{
259305
"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"
306+
"/test-acl:acl/ACL_TABLE/ACL_TABLE_LIST/ports",
307+
"/test-portchannel:portchannel/PORTCHANNEL/PORTCHANNEL_LIST/members",
308+
"/test-interface:interface/INTERFACE/INTERFACE_LIST/interface",
309+
"/test-vlan:vlan/VLAN_MEMBER/VLAN_MEMBER_LIST/port"
264310
],
265-
"xpath" : "/test-port:port/test-port:PORT/test-port:PORT_LIST/test-port:port_name"
311+
"xpath" : "/test-port:port/PORT/PORT_LIST/port_name"
266312
}
267313
],
268314
"schema_nodes" : [
269315
{
270-
"value" : "/test-vlan:vlan/test-vlan:VLAN_INTERFACE/test-vlan:VLAN_INTERFACE_LIST/test-vlan:family",
316+
"value" : "/test-vlan:vlan/VLAN_INTERFACE/VLAN_INTERFACE_LIST/family",
271317
"xpath" : "/test-vlan:vlan/VLAN_INTERFACE/VLAN_INTERFACE_LIST[vlanid='111'][ip-prefix='10.1.1.64/26']/family"
272318
},
273319
{
274-
"value" : "/test-port:port/test-port:PORT/test-port:PORT_LIST/test-port:speed",
320+
"value" : "/test-port:port/PORT/PORT_LIST/speed",
275321
"xpath" : "/test-port:port/PORT/PORT_LIST[port_name='Ethernet9']/speed"
276322
}
277323
],

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)