Skip to content

Commit

Permalink
[Sonic Yang Tree]: Updating Tree as per modification in YANG models. (s…
Browse files Browse the repository at this point in the history
…onic-net#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.
  • Loading branch information
Praveen Chaudhary authored and zhenggen-xu committed Dec 14, 2019
1 parent f071cf7 commit 167b354
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 37 deletions.
41 changes: 25 additions & 16 deletions src/sonic-yang-mgmt/_sonic_yang_ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -606,22 +606,31 @@ def get_data(self):
def delete_node(self, xpath):

# These MACROS used only here, can we get it from Libyang Header ?
LYS_LEAF = 4
node = self.find_data_node(xpath)
if node is None:
raise('Node {} not found'.format(xpath))

snode = node.schema()
# check for a leaf if it is a key. If yes delete the parent
if (snode.nodetype() == LYS_LEAF):
leaf = ly.Schema_Node_Leaf(snode)
if leaf.is_key():
# try to delete parent
nodeP = self.find_parent_node(xpath)
xpathP = nodeP.path()
return self._delete_node(xpath=xpathP, node=nodeP)
else:
return self._delete_node(xpath=xpath, node=node)
try:
LYS_LEAF = 4
node = self.find_data_node(xpath)
if node is None:
raise('Node {} not found'.format(xpath))

snode = node.schema()
# check for a leaf if it is a key. If yes delete the parent
if (snode.nodetype() == LYS_LEAF):
leaf = ly.Schema_Node_Leaf(snode)
if leaf.is_key():
# try to delete parent
nodeP = self.find_parent_node(xpath)
xpathP = nodeP.path()
if self._delete_node(xpath=xpathP, node=nodeP) == False:
raise('_delete_node failed')
else:
return True

# delete non key element
if self._delete_node(xpath=xpath, node=node) == False:
raise('_delete_node failed')
except Exception as e:
print(e)
raise('Failed to delete node {}'.format(xpath))

return True

Expand Down
28 changes: 16 additions & 12 deletions src/sonic-yang-mgmt/sonic_yang.py
Original file line number Diff line number Diff line change
Expand Up @@ -497,17 +497,21 @@ def find_data_dependencies (self, data_xpath):
self.fail(e)
return ref_list

value = str(self.find_node_value(data_xpath))

schema_node = ly.Schema_Node_Leaf(data_node.schema())
backlinks = schema_node.backlinks()
if backlinks.number() > 0:
for link in backlinks.schema():
node_set = node.find_path(link.path())
for data_set in node_set.data():
schema = data_set.schema()
casted = data_set.subtype()
if value == casted.value_str():
ref_list.append(data_set.path())
try:
value = str(self.find_node_value(data_xpath))

schema_node = ly.Schema_Node_Leaf(data_node.schema())
backlinks = schema_node.backlinks()
if backlinks.number() > 0:
for link in backlinks.schema():
node_set = node.find_path(link.path())
for data_set in node_set.data():
schema = data_set.schema()
casted = data_set.subtype()
if value == casted.value_str():
ref_list.append(data_set.path())
except Exception as e:
print('Failed to find node or dependencies for {}'.format(data_xpath))
self.fail(e)

return ref_list
4 changes: 2 additions & 2 deletions src/sonic-yang-mgmt/tests/yang-model-tests/yangTest.json
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@
"DST_IP": "10.186.72.0/26",
"SRC_IP": "10.176.0.0/15",
"PRIORITY": 999980,
"IP_TYPE": "IPV4ANY"
"IP_TYPE": "IPv4ANY"
}]
},
"sonic-acl:ACL_TABLE": {
Expand Down Expand Up @@ -299,7 +299,7 @@
"PACKET_ACTION": "FORWARD",
"SRC_IPV6": "2001::1/64",
"PRIORITY": 999980,
"IP_TYPE": "IPV4ANY"
"IP_TYPE": "IPv4ANY"
}]
},
"sonic-acl:ACL_TABLE": {
Expand Down
14 changes: 8 additions & 6 deletions src/sonic-yang-mgmt/yang-models/Sonic Yang Tree
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ module: sonic-port
+--rw speed? uint32
+--rw mtu? uint16
+--rw admin_status head:admin_status
+--rw fec? string
module: sonic-portchannel
+--rw sonic-portchannel
+--rw PORTCHANNEL
Expand All @@ -81,21 +82,22 @@ module: sonic-portchannel
module: sonic-vlan
+--rw sonic-vlan
+--rw VLAN_INTERFACE
| +--rw VLAN_INTERFACE_LIST* [vlanid ip-prefix]
| +--rw vlanid -> ../../../VLAN/VLAN_LIST/vlanid
| +--rw VLAN_INTERFACE_LIST* [vlan_name ip-prefix]
| +--rw vlan_name -> /sonic-vlan/VLAN/VLAN_LIST/vlan_name
| +--rw ip-prefix inet:ip-prefix
| +--rw scope? enumeration
| +--rw family? head:ip-family
+--rw VLAN
| +--rw VLAN_LIST* [vlanid]
| +--rw vlanid uint16
| +--rw VLAN_LIST* [vlan_name]
| +--rw vlan_name string
| +--rw vlanid? uint16
| +--rw description? string
| +--rw dhcp_servers* inet:ip-address
| +--rw mtu? uint16
| +--rw admin_status head:admin_status
| +--rw members* -> /port:sonic-port/PORT/PORT_LIST/port_name
+--rw VLAN_MEMBER
+--rw VLAN_MEMBER_LIST* [vlanid port]
+--rw vlanid -> ../../../VLAN/VLAN_LIST/vlanid
+--rw VLAN_MEMBER_LIST* [vlan_name port]
+--rw vlan_name -> /sonic-vlan/VLAN/VLAN_LIST/vlan_name
+--rw port -> /port:sonic-port/PORT/PORT_LIST/port_name
+--rw tagging_mode head:vlan_tagging_mode
9 changes: 8 additions & 1 deletion src/sonic-yang-mgmt/yang-models/sonic-port.yang
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ module sonic-port{
}

leaf lanes {
mandatory true;
type string {
length 1..128;
}
Expand All @@ -60,6 +61,7 @@ module sonic-port{
}

leaf speed {
mandatory true;
type uint32 {
range 1..100000;
}
Expand All @@ -71,8 +73,13 @@ module sonic-port{
}
}

leaf index {
type uint8 {
range 1..128;
}
}

leaf admin_status {
mandatory true;
type head:admin_status;
}

Expand Down

0 comments on commit 167b354

Please sign in to comment.