Skip to content

Commit 72e7f88

Browse files
Praveen Chaudharyzhenggen-xu
authored andcommitted
[Sonic Yang Tree]: Updating Tree as per modification in YANG models. (#19)
* [Sonic Yang Tree]: Updating Tree as per modification in YANG models. * [sonic-port.yang]: Making lanes and speed mandatory and admin_status not mandatory. Including index of port. * [yangTest.json]: Fix tests for YANG models. * [_sonic_yang_ext.py]: Exception handling for delete_node and find_dependencies.
1 parent 2983dfe commit 72e7f88

5 files changed

Lines changed: 59 additions & 37 deletions

File tree

src/sonic-yang-mgmt/_sonic_yang_ext.py

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -606,22 +606,31 @@ def get_data(self):
606606
def delete_node(self, xpath):
607607

608608
# These MACROS used only here, can we get it from Libyang Header ?
609-
LYS_LEAF = 4
610-
node = self.find_data_node(xpath)
611-
if node is None:
612-
raise('Node {} not found'.format(xpath))
613-
614-
snode = node.schema()
615-
# check for a leaf if it is a key. If yes delete the parent
616-
if (snode.nodetype() == LYS_LEAF):
617-
leaf = ly.Schema_Node_Leaf(snode)
618-
if leaf.is_key():
619-
# try to delete parent
620-
nodeP = self.find_parent_node(xpath)
621-
xpathP = nodeP.path()
622-
return self._delete_node(xpath=xpathP, node=nodeP)
623-
else:
624-
return self._delete_node(xpath=xpath, node=node)
609+
try:
610+
LYS_LEAF = 4
611+
node = self.find_data_node(xpath)
612+
if node is None:
613+
raise('Node {} not found'.format(xpath))
614+
615+
snode = node.schema()
616+
# check for a leaf if it is a key. If yes delete the parent
617+
if (snode.nodetype() == LYS_LEAF):
618+
leaf = ly.Schema_Node_Leaf(snode)
619+
if leaf.is_key():
620+
# try to delete parent
621+
nodeP = self.find_parent_node(xpath)
622+
xpathP = nodeP.path()
623+
if self._delete_node(xpath=xpathP, node=nodeP) == False:
624+
raise('_delete_node failed')
625+
else:
626+
return True
627+
628+
# delete non key element
629+
if self._delete_node(xpath=xpath, node=node) == False:
630+
raise('_delete_node failed')
631+
except Exception as e:
632+
print(e)
633+
raise('Failed to delete node {}'.format(xpath))
625634

626635
return True
627636

src/sonic-yang-mgmt/sonic_yang.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -497,17 +497,21 @@ def find_data_dependencies (self, data_xpath):
497497
self.fail(e)
498498
return ref_list
499499

500-
value = str(self.find_node_value(data_xpath))
501-
502-
schema_node = ly.Schema_Node_Leaf(data_node.schema())
503-
backlinks = schema_node.backlinks()
504-
if backlinks.number() > 0:
505-
for link in backlinks.schema():
506-
node_set = node.find_path(link.path())
507-
for data_set in node_set.data():
508-
schema = data_set.schema()
509-
casted = data_set.subtype()
510-
if value == casted.value_str():
511-
ref_list.append(data_set.path())
500+
try:
501+
value = str(self.find_node_value(data_xpath))
502+
503+
schema_node = ly.Schema_Node_Leaf(data_node.schema())
504+
backlinks = schema_node.backlinks()
505+
if backlinks.number() > 0:
506+
for link in backlinks.schema():
507+
node_set = node.find_path(link.path())
508+
for data_set in node_set.data():
509+
schema = data_set.schema()
510+
casted = data_set.subtype()
511+
if value == casted.value_str():
512+
ref_list.append(data_set.path())
513+
except Exception as e:
514+
print('Failed to find node or dependencies for {}'.format(data_xpath))
515+
self.fail(e)
512516

513517
return ref_list

src/sonic-yang-mgmt/tests/yang-model-tests/yangTest.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@
254254
"DST_IP": "10.186.72.0/26",
255255
"SRC_IP": "10.176.0.0/15",
256256
"PRIORITY": 999980,
257-
"IP_TYPE": "IPV4ANY"
257+
"IP_TYPE": "IPv4ANY"
258258
}]
259259
},
260260
"sonic-acl:ACL_TABLE": {
@@ -299,7 +299,7 @@
299299
"PACKET_ACTION": "FORWARD",
300300
"SRC_IPV6": "2001::1/64",
301301
"PRIORITY": 999980,
302-
"IP_TYPE": "IPV4ANY"
302+
"IP_TYPE": "IPv4ANY"
303303
}]
304304
},
305305
"sonic-acl:ACL_TABLE": {

src/sonic-yang-mgmt/yang-models/Sonic Yang Tree

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ module: sonic-port
6868
+--rw speed? uint32
6969
+--rw mtu? uint16
7070
+--rw admin_status head:admin_status
71+
+--rw fec? string
7172
module: sonic-portchannel
7273
+--rw sonic-portchannel
7374
+--rw PORTCHANNEL
@@ -81,21 +82,22 @@ module: sonic-portchannel
8182
module: sonic-vlan
8283
+--rw sonic-vlan
8384
+--rw VLAN_INTERFACE
84-
| +--rw VLAN_INTERFACE_LIST* [vlanid ip-prefix]
85-
| +--rw vlanid -> ../../../VLAN/VLAN_LIST/vlanid
85+
| +--rw VLAN_INTERFACE_LIST* [vlan_name ip-prefix]
86+
| +--rw vlan_name -> /sonic-vlan/VLAN/VLAN_LIST/vlan_name
8687
| +--rw ip-prefix inet:ip-prefix
8788
| +--rw scope? enumeration
8889
| +--rw family? head:ip-family
8990
+--rw VLAN
90-
| +--rw VLAN_LIST* [vlanid]
91-
| +--rw vlanid uint16
91+
| +--rw VLAN_LIST* [vlan_name]
92+
| +--rw vlan_name string
93+
| +--rw vlanid? uint16
9294
| +--rw description? string
9395
| +--rw dhcp_servers* inet:ip-address
9496
| +--rw mtu? uint16
9597
| +--rw admin_status head:admin_status
9698
| +--rw members* -> /port:sonic-port/PORT/PORT_LIST/port_name
9799
+--rw VLAN_MEMBER
98-
+--rw VLAN_MEMBER_LIST* [vlanid port]
99-
+--rw vlanid -> ../../../VLAN/VLAN_LIST/vlanid
100+
+--rw VLAN_MEMBER_LIST* [vlan_name port]
101+
+--rw vlan_name -> /sonic-vlan/VLAN/VLAN_LIST/vlan_name
100102
+--rw port -> /port:sonic-port/PORT/PORT_LIST/port_name
101103
+--rw tagging_mode head:vlan_tagging_mode

src/sonic-yang-mgmt/yang-models/sonic-port.yang

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ module sonic-port{
4848
}
4949

5050
leaf lanes {
51+
mandatory true;
5152
type string {
5253
length 1..128;
5354
}
@@ -60,6 +61,7 @@ module sonic-port{
6061
}
6162

6263
leaf speed {
64+
mandatory true;
6365
type uint32 {
6466
range 1..100000;
6567
}
@@ -71,8 +73,13 @@ module sonic-port{
7173
}
7274
}
7375

76+
leaf index {
77+
type uint8 {
78+
range 1..128;
79+
}
80+
}
81+
7482
leaf admin_status {
75-
mandatory true;
7683
type head:admin_status;
7784
}
7885

0 commit comments

Comments
 (0)