From 4837e852b9be2c955e15f262650d97272a83ac66 Mon Sep 17 00:00:00 2001 From: Ping Mao Date: Sun, 22 Mar 2020 14:55:37 -0700 Subject: [PATCH 1/3] Address feedback from pull request Azure#3874 upstream github --- src/sonic-yang-mgmt/sonic_yang.py | 90 ++++----- .../sample-yang-models/sonic-module.yang | 144 -------------- .../{sonic-acl.yang => test-sonic-acl.yang} | 8 +- .../{sonic-head.yang => test-sonic-head.yang} | 4 +- ...terface.yang => test-sonic-interface.yang} | 6 +- .../{sonic-port.yang => test-sonic-port.yang} | 4 +- ...annel.yang => test-sonic-portchannel.yang} | 6 +- .../{sonic-vlan.yang => test-sonic-vlan.yang} | 6 +- .../sonic_config_data_merge.json | 12 +- .../libyang-python-tests/test_SonicYang.json | 178 +++++++++--------- .../libyang-python-tests/test_sonic_yang.py | 33 ++-- 11 files changed, 180 insertions(+), 311 deletions(-) delete mode 100644 src/sonic-yang-mgmt/tests/libyang-python-tests/sample-yang-models/sonic-module.yang rename src/sonic-yang-mgmt/tests/libyang-python-tests/sample-yang-models/{sonic-acl.yang => test-sonic-acl.yang} (97%) rename src/sonic-yang-mgmt/tests/libyang-python-tests/sample-yang-models/{sonic-head.yang => test-sonic-head.yang} (98%) rename src/sonic-yang-mgmt/tests/libyang-python-tests/sample-yang-models/{sonic-interface.yang => test-sonic-interface.yang} (94%) rename src/sonic-yang-mgmt/tests/libyang-python-tests/sample-yang-models/{sonic-port.yang => test-sonic-port.yang} (95%) rename src/sonic-yang-mgmt/tests/libyang-python-tests/sample-yang-models/{sonic-portchannel.yang => test-sonic-portchannel.yang} (94%) rename src/sonic-yang-mgmt/tests/libyang-python-tests/sample-yang-models/{sonic-vlan.yang => test-sonic-vlan.yang} (97%) diff --git a/src/sonic-yang-mgmt/sonic_yang.py b/src/sonic-yang-mgmt/sonic_yang.py index 1393594834ad..687decd917e7 100644 --- a/src/sonic-yang-mgmt/sonic_yang.py +++ b/src/sonic-yang-mgmt/sonic_yang.py @@ -128,12 +128,12 @@ def load_schema_modules_ctx(self, yang_dir=None): """ def load_data_file(self, data_file): try: - node = self.ctx.parse_data_path(data_file, ly.LYD_JSON, ly.LYD_OPT_CONFIG | ly.LYD_OPT_STRICT) + data_node = self.ctx.parse_data_path(data_file, ly.LYD_JSON, ly.LYD_OPT_CONFIG | ly.LYD_OPT_STRICT) except Exception as e: print("Failed to load data file: " + str(data_file)) self.fail(e) else: - self.root = node + self.root = data_node """ get module name from xpath @@ -169,7 +169,7 @@ def load_data_model (self, yang_dir, yang_files, data_files, output=None): self.load_data_file(data_files[0]) - for i in range(2, len(data_files)): + for i in range(1, len(data_files)): self.merge_data(data_files[i]) except Exception as e: print("Failed to load data files") @@ -256,59 +256,59 @@ def validate_data_tree (self): self.fail(e) """ - find_parent_node(): find the parent node object + find_parent_data_node(): find the parent node object input: data_xpath - xpath of the data node returns: parent node """ - def find_parent_node (self, data_xpath): + def find_parent_data_node (self, data_xpath): if (self.root is None): print("data not loaded") return None try: - node = self.find_data_node(data_xpath) + data_node = self.find_data_node(data_xpath) except Exception as e: print("Failed to find data node from xpath: " + str(data_xpath)) self.fail(e) else: - if node is not None: - return node.parent() + if data_node is not None: + return data_node.parent() return None """ - get_parent_xpath(): find the parent node xpath + get_parent_data_xpath(): find the parent data node's xpath input: data_xpath - xpathof the data node - returns: - xpath of parent node + returns: - xpath of parent data node - Exception if error """ - def get_parent_xpath (self, data_xpath): + def get_parent_data_xpath (self, data_xpath): path="" try: - node = self.find_parent_node(data_xpath) + data_node = self.find_parent_data_node(data_xpath) except Exception as e: print("Failed to find parent node from xpath: " + str(data_xpath)) self.fail(e) else: - if (node is not None): - path = node.path() + if (data_node is not None): + path = data_node.path() return path """ - new_node(): create a new data node in the data tree + new_data_node(): create a new data node in the data tree input: xpath: xpath of the new node value: value of the new node returns: new Data_Node object if success, Exception if falied """ - def new_node(self, xpath, value): + def new_data_node(self, xpath, value): val = str(value) try: - node = self.root.new_path(self.ctx, xpath, val, 0, 0) + data_node = self.root.new_path(self.ctx, xpath, val, 0, 0) except Exception as e: print("Failed to add data node for path: " + str(xpath)) self.fail(e) else: - return node + return data_node """ find_data_node(): find the data node from xpath @@ -325,9 +325,9 @@ def find_data_node(self, data_xpath): self.fail(e) else: if set is not None: - for node in set.data(): - if (data_xpath == node.path()): - return node + for data_node in set.data(): + if (data_xpath == data_node.path()): + return data_node return None """ find_schema_node(): find the schema node from schema xpath @@ -339,35 +339,35 @@ def find_data_node(self, data_xpath): def find_schema_node(self, schema_xpath): try: schema_set = self.ctx.find_path(schema_xpath) - for snode in schema_set.schema(): - if (schema_xpath == snode.path()): - return snode + for schema_node in schema_set.schema(): + if (schema_xpath == schema_node.path()): + return schema_node except Exception as e: self.fail(e) return None else: - for snode in schema_set.schema(): - if schema_xapth == snode.path(): - return snode + for schema_node in schema_set.schema(): + if schema_xapth == schema_node.path(): + return schema_node return None """ - find_node_schema_xpath(): find the xpath of the schema node from data xpath + find_data_node_schema_xpath(): find the xpath of the schema node from data xpath data xpath example: "/sonic-port:sonic-port/PORT/PORT_LIST[port_name='Ethernet0']/port_name" input: data_xpath - xpath of the data node returns: - xpath of the schema node if success - Exception if error """ - def find_node_schema_xpath(self, data_xpath): + def find_data_node_schema_xpath(self, data_xpath): path = "" try: set = self.root.find_path(data_xpath) except Exception as e: self.fail(e) else: - for node in set.data(): - if data_xpath == node.path(): - return node.schema().path() + for data_node in set.data(): + if data_xpath == data_node.path(): + return data_node.schema().path() return path """ @@ -375,11 +375,11 @@ def find_node_schema_xpath(self, data_xpath): input: xpath and value of the node to be added returns: Exception if failed """ - def add_node(self, xpath, value): + def add_data_node(self, data_xpath, value): try: - node = self.new_node(xpath, value) + data_node = self.new_data_node(data_xpath, value) #check if the node added to the data tree - self.find_data_node(xpath) + self.find_data_node(data_xpath) except Exception as e: print("add_node(): Failed to add data node for xpath: " + str(data_xpath)) self.fail(e) @@ -429,20 +429,20 @@ def _delete_node(self, xpath=None, node=None): return False """ - find_node_value(): find the value of a node from the schema/data tree + find_data_node_value(): find the value of a node from the data tree input: data_xpath of the data node returns: value string of the node """ - def find_node_value(self, data_xpath): + def find_data_node_value(self, data_xpath): output = "" try: - node = self.find_data_node(data_xpath) + data_node = self.find_data_node(data_xpath) except Exception as e: - print("find_node_value(): Failed to find data node from xpath: {}".format(data_xpath)) + print("find_data_node_value(): Failed to find data node from xpath: {}".format(data_xpath)) self.fail(e) else: - if (node is not None): - subtype = node.subtype() + if (data_node is not None): + subtype = data_node.subtype() if (subtype is not None): value = subtype.value_str() return value @@ -453,9 +453,9 @@ def find_node_value(self, data_xpath): input: xpath of the data node returns: Exception if failed """ - def set_dnode_value(self, data_xpath, value): + def set_data_node_value(self, data_xpath, value): try: - node = self.root.new_path(self.ctx, data_xpath, str(value), ly.LYD_ANYDATA_STRING, ly.LYD_PATH_OPT_UPDATE) + data_node = self.root.new_path(self.ctx, data_xpath, str(value), ly.LYD_ANYDATA_STRING, ly.LYD_PATH_OPT_UPDATE) except Exception as e: print("set data node value failed for xpath: " + str(data_xpath)) self.fail(e) @@ -497,8 +497,8 @@ def find_schema_dependencies (self, schema_xpath): self.fail(e) return ref_list - snode = ly.Schema_Node_Leaf(schema_node) - backlinks = snode.backlinks() + schema_node = ly.Schema_Node_Leaf(schema_node) + backlinks = schema_node.backlinks() if backlinks.number() > 0: for link in backlinks.schema(): print("backlink schema: {}".format(link.path())) diff --git a/src/sonic-yang-mgmt/tests/libyang-python-tests/sample-yang-models/sonic-module.yang b/src/sonic-yang-mgmt/tests/libyang-python-tests/sample-yang-models/sonic-module.yang deleted file mode 100644 index 687bb478aacb..000000000000 --- a/src/sonic-yang-mgmt/tests/libyang-python-tests/sample-yang-models/sonic-module.yang +++ /dev/null @@ -1,144 +0,0 @@ -module sonic-module { - yang-version 1.1; - namespace "urn:ietf:params:xml:ns:yang:sonic-module"; - - prefix tm; - - import ietf-inet-types { - prefix inet; - } - - organization "organization"; - description - "example yang module"; - contact - "example@example.org"; - - container ports { - list port { - config true; - key "name"; - - leaf name { - type string; - } - - leaf lanes { - //choice - type uint8; - } - -/* - leaf fec { - type string; - } - - leaf mtu { - type uint16; - description - "Set the max transmission unit size in octets - for the physical interface. If this is not set, the mtu is - set to the operational default -- e.g., 1514 bytes on an - Ethernet interface."; - } - leaf admin_status { - type enumeration { - enum UP { - description - "Ready to pass packets."; - } - enum DOWN { - description - "Not ready to pass packets and not in some test mode."; - } - enum TESTING { - //TODO: This is generally not supported as a configured - //admin state, though it's in the standard interfaces MIB. - //Consider removing it. - description - "In some test mode."; - } - } - } -*/ - leaf alias { - type string; - } - - leaf speed { - type string; - units "bits/second"; -/* - description - "An estimate of the interface's current bandwidth in bits - per second. For interfaces that do not vary in - bandwidth or for those where no accurate estimation can - be made, this node should contain the nominal bandwidth. - For interfaces that have no concept of bandwidth, this - node is not present."; - reference - "RFC 2863: The Interfaces Group MIB - - ifSpeed, ifHighSpeed"; -*/ - } - - } - } - - container vlans { - list vlan { - config true; - - key "name"; - - leaf name { - type string; - } - - leaf vlanid { - type string; - } - - leaf admin_status { - type string; -/* - type enumeration { - enum UP { - description - "Ready to pass packets."; - } - enum DOWN { - description - "Not ready to pass packets and not in some test mode."; - } - enum TESTING { - //TODO: This is generally not supported as a configured - //admin state, though it's in the standard interfaces MIB. - //Consider removing it. - description - "In some test mode."; - } - } -*/ - } - - leaf description { - type string; - } - - leaf mtu { - type uint16; - description - "Set the max transmission unit size in octets - for the physical interface. If this is not set, the mtu is - set to the operational default -- e.g., 1514 bytes on an - Ethernet interface."; - } - leaf-list members { - type leafref { - path "../../../ports/port/name"; - } - } - } - } -} diff --git a/src/sonic-yang-mgmt/tests/libyang-python-tests/sample-yang-models/sonic-acl.yang b/src/sonic-yang-mgmt/tests/libyang-python-tests/sample-yang-models/test-sonic-acl.yang similarity index 97% rename from src/sonic-yang-mgmt/tests/libyang-python-tests/sample-yang-models/sonic-acl.yang rename to src/sonic-yang-mgmt/tests/libyang-python-tests/sample-yang-models/test-sonic-acl.yang index 1aab4d7de0b1..79f2cdded177 100644 --- a/src/sonic-yang-mgmt/tests/libyang-python-tests/sample-yang-models/sonic-acl.yang +++ b/src/sonic-yang-mgmt/tests/libyang-python-tests/sample-yang-models/test-sonic-acl.yang @@ -1,4 +1,4 @@ -module sonic-acl { +module test-sonic-acl { yang-version 1.1; @@ -13,17 +13,17 @@ module sonic-acl { prefix inet; } - import sonic-head { + import test-sonic-head { prefix head; revision-date 2019-07-01; } - import sonic-port { + import test-sonic-port { prefix port; revision-date 2019-07-01; } - import sonic-portchannel { + import test-sonic-portchannel { prefix lag; revision-date 2019-07-01; } diff --git a/src/sonic-yang-mgmt/tests/libyang-python-tests/sample-yang-models/sonic-head.yang b/src/sonic-yang-mgmt/tests/libyang-python-tests/sample-yang-models/test-sonic-head.yang similarity index 98% rename from src/sonic-yang-mgmt/tests/libyang-python-tests/sample-yang-models/sonic-head.yang rename to src/sonic-yang-mgmt/tests/libyang-python-tests/sample-yang-models/test-sonic-head.yang index dd0da92c7152..547ac8ac1cb3 100644 --- a/src/sonic-yang-mgmt/tests/libyang-python-tests/sample-yang-models/sonic-head.yang +++ b/src/sonic-yang-mgmt/tests/libyang-python-tests/sample-yang-models/test-sonic-head.yang @@ -1,4 +1,4 @@ -module sonic-head { +module test-sonic-head { namespace "http://sonic-head"; prefix sonic-head; @@ -69,4 +69,4 @@ module sonic-head { enum priority_tagged; } } -} \ No newline at end of file +} diff --git a/src/sonic-yang-mgmt/tests/libyang-python-tests/sample-yang-models/sonic-interface.yang b/src/sonic-yang-mgmt/tests/libyang-python-tests/sample-yang-models/test-sonic-interface.yang similarity index 94% rename from src/sonic-yang-mgmt/tests/libyang-python-tests/sample-yang-models/sonic-interface.yang rename to src/sonic-yang-mgmt/tests/libyang-python-tests/sample-yang-models/test-sonic-interface.yang index dc8bc7389ea1..fd573b17707d 100644 --- a/src/sonic-yang-mgmt/tests/libyang-python-tests/sample-yang-models/sonic-interface.yang +++ b/src/sonic-yang-mgmt/tests/libyang-python-tests/sample-yang-models/test-sonic-interface.yang @@ -1,4 +1,4 @@ -module sonic-interface { +module test-sonic-interface { namespace "http://github.com/Azure/sonic-interface"; prefix intf; @@ -11,12 +11,12 @@ module sonic-interface { prefix inet; } - import sonic-head { + import test-sonic-head { prefix head; revision-date 2019-07-01; } - import sonic-port { + import test-sonic-port { prefix port; revision-date 2019-07-01; } diff --git a/src/sonic-yang-mgmt/tests/libyang-python-tests/sample-yang-models/sonic-port.yang b/src/sonic-yang-mgmt/tests/libyang-python-tests/sample-yang-models/test-sonic-port.yang similarity index 95% rename from src/sonic-yang-mgmt/tests/libyang-python-tests/sample-yang-models/sonic-port.yang rename to src/sonic-yang-mgmt/tests/libyang-python-tests/sample-yang-models/test-sonic-port.yang index be04a8aea4bd..494205ce4d92 100644 --- a/src/sonic-yang-mgmt/tests/libyang-python-tests/sample-yang-models/sonic-port.yang +++ b/src/sonic-yang-mgmt/tests/libyang-python-tests/sample-yang-models/test-sonic-port.yang @@ -1,4 +1,4 @@ -module sonic-port{ +module test-sonic-port{ namespace "http://github.com/Azure/sonic-port"; prefix port; @@ -11,7 +11,7 @@ module sonic-port{ prefix inet; } - import sonic-head { + import test-sonic-head { prefix head; revision-date 2019-07-01; } diff --git a/src/sonic-yang-mgmt/tests/libyang-python-tests/sample-yang-models/sonic-portchannel.yang b/src/sonic-yang-mgmt/tests/libyang-python-tests/sample-yang-models/test-sonic-portchannel.yang similarity index 94% rename from src/sonic-yang-mgmt/tests/libyang-python-tests/sample-yang-models/sonic-portchannel.yang rename to src/sonic-yang-mgmt/tests/libyang-python-tests/sample-yang-models/test-sonic-portchannel.yang index 656351f4e635..9b664c8289f0 100644 --- a/src/sonic-yang-mgmt/tests/libyang-python-tests/sample-yang-models/sonic-portchannel.yang +++ b/src/sonic-yang-mgmt/tests/libyang-python-tests/sample-yang-models/test-sonic-portchannel.yang @@ -1,4 +1,4 @@ -module sonic-portchannel { +module test-sonic-portchannel { namespace "http://github.com/Azure/sonic-portchannel"; prefix lag; @@ -11,12 +11,12 @@ module sonic-portchannel { prefix inet; } - import sonic-head { + import test-sonic-head { prefix head; revision-date 2019-07-01; } - import sonic-port { + import test-sonic-port { prefix port; revision-date 2019-07-01; } diff --git a/src/sonic-yang-mgmt/tests/libyang-python-tests/sample-yang-models/sonic-vlan.yang b/src/sonic-yang-mgmt/tests/libyang-python-tests/sample-yang-models/test-sonic-vlan.yang similarity index 97% rename from src/sonic-yang-mgmt/tests/libyang-python-tests/sample-yang-models/sonic-vlan.yang rename to src/sonic-yang-mgmt/tests/libyang-python-tests/sample-yang-models/test-sonic-vlan.yang index 6058ce3f1bfc..227c3c6dbe6b 100644 --- a/src/sonic-yang-mgmt/tests/libyang-python-tests/sample-yang-models/sonic-vlan.yang +++ b/src/sonic-yang-mgmt/tests/libyang-python-tests/sample-yang-models/test-sonic-vlan.yang @@ -1,4 +1,4 @@ -module sonic-vlan { +module test-sonic-vlan { namespace "http://github.com/Azure/sonic-vlan"; prefix vlan; @@ -11,12 +11,12 @@ module sonic-vlan { prefix inet; } - import sonic-head { + import test-sonic-head { prefix head; revision-date 2019-07-01; } - import sonic-port { + import test-sonic-port { prefix port; revision-date 2019-07-01; } diff --git a/src/sonic-yang-mgmt/tests/libyang-python-tests/sonic_config_data_merge.json b/src/sonic-yang-mgmt/tests/libyang-python-tests/sonic_config_data_merge.json index 3bb4f0f5954b..ae668566d9a3 100644 --- a/src/sonic-yang-mgmt/tests/libyang-python-tests/sonic_config_data_merge.json +++ b/src/sonic-yang-mgmt/tests/libyang-python-tests/sonic_config_data_merge.json @@ -1,6 +1,6 @@ { - "sonic-vlan:sonic-vlan": { - "sonic-vlan:VLAN_INTERFACE": { + "test-sonic-vlan:sonic-vlan": { + "test-sonic-vlan:VLAN_INTERFACE": { "VLAN_INTERFACE_LIST": [{ "vlanid": 111, "ip-prefix": "2000:f500:45:6709::1/64", @@ -28,7 +28,7 @@ ] }, - "sonic-vlan:VLAN": { + "test-sonic-vlan:VLAN": { "VLAN_LIST": [{ "vlanid": 200, "description": "server_vlan", @@ -72,7 +72,7 @@ ] }, - "sonic-vlan:VLAN_MEMBER": { + "test-sonic-vlan:VLAN_MEMBER": { "VLAN_MEMBER_LIST": [{ "vlanid": 200, "port": "Ethernet0", @@ -81,8 +81,8 @@ ] } }, - "sonic-port:sonic-port": { - "sonic-port:PORT": { + "test-sonic-port:sonic-port": { + "test-sonic-port:PORT": { "PORT_LIST": [{ "port_name": "Ethernet0", "alias": "eth0", diff --git a/src/sonic-yang-mgmt/tests/libyang-python-tests/test_SonicYang.json b/src/sonic-yang-mgmt/tests/libyang-python-tests/test_SonicYang.json index b023ba57860e..4ae66e8633a5 100644 --- a/src/sonic-yang-mgmt/tests/libyang-python-tests/test_SonicYang.json +++ b/src/sonic-yang-mgmt/tests/libyang-python-tests/test_SonicYang.json @@ -3,139 +3,145 @@ "data_file":"/sonic/src/sonic-yang-mgmt/tests/libyang-python-tests/sonic_config_data.json", "data_merge_file":"/sonic/src/sonic-yang-mgmt/tests/libyang-python-tests/sonic_config_data_merge.json", "modules":[ - {"file":"sonic-head.yang", "module":"sonic-head"}, - {"file":"sonic-port.yang", "module":"sonic-port"}, - {"file":"sonic-acl.yang", "module":"sonic-acl"}, - {"file":"sonic-interface.yang", "module":"sonic-interface"}, - {"file":"sonic-portchannel.yang", "module":"sonic-portchannel"}, - {"file":"sonic-vlan.yang", "module":"sonic-vlan"} + {"file":"test-sonic-head.yang", "module":"test-sonic-head"}, + {"file":"test-sonic-port.yang", "module":"test-sonic-port"}, + {"file":"test-sonic-acl.yang", "module":"test-sonic-acl"}, + {"file":"test-sonic-interface.yang", "module":"test-sonic-interface"}, + {"file":"test-sonic-portchannel.yang", "module":"test-sonic-portchannel"}, + {"file":"test-sonic-vlan.yang", "module":"test-sonic-vlan"} ], + "merged_nodes":[ + {"xpath":"/test-sonic-port:sonic-port/PORT/PORT_LIST[port_name='Ethernet10']/speed", "value":"25000"}, + {"xpath":"/test-sonic-vlan:sonic-vlan/VLAN_INTERFACE/VLAN_INTERFACE_LIST[vlanid='200'][ip-prefix='2000:f500:45:6708::/64']/family", + "value":"IPv6"} + ], + "new_nodes":[ - {"xpath":"/sonic-port:sonic-port/PORT/PORT_LIST[port_name='Ethernet12']/alias", "value":"Ethernet10_alias"}, - {"xpath":"/sonic-port:sonic-port/PORT/PORT_LIST[port_name='Ethernet12']/speed", "value":"5000"}, - {"xpath":"/sonic-acl:sonic-acl/ACL_RULE/ACL_RULE_LIST[ACL_TABLE_NAME='PACL-test'][RULE_NAME='rule_20']/RULE_NAME", + {"xpath":"/test-sonic-port:sonic-port/PORT/PORT_LIST[port_name='Ethernet12']/alias", "value":"Ethernet10_alias"}, + {"xpath":"/test-sonic-port:sonic-port/PORT/PORT_LIST[port_name='Ethernet12']/speed", "value":"5000"}, + {"xpath":"/test-sonic-acl:sonic-acl/ACL_RULE/ACL_RULE_LIST[ACL_TABLE_NAME='PACL-test'][RULE_NAME='rule_20']/RULE_NAME", "value":"rule_20"} ], "data_nodes":[ - {"xpath":"/sonic-port:sonic-port/PORT/PORT_LIST[port_name='Ethernet9']/alias", "valid":"True"}, - {"xpath":"/sonic-port:sonic-port/PORT/PORT_LIST[port_name='Ethernet20']/alias", "valid":"False"}, - {"xpath":"/sonic-vlan:sonic-vlan/VLAN_INTERFACE", "valid":"True"}, - {"xpath":"/sonic-vlan:sonic-vlan/VLAN_INTERFACE/VLAN_INTERFACE_LIST", "valid":"False"}, - {"xpath":"/sonic-vlan:sonic-vlan/VLAN_INTERFACE/VLAN_INTERFACE_LIST[vlanid='111'][ip-prefix='2000:f500:45:6709::/64']", "valid":"True"} + {"xpath":"/test-sonic-port:sonic-port/PORT/PORT_LIST[port_name='Ethernet9']/alias", "valid":"True"}, + {"xpath":"/test-sonic-port:sonic-port/PORT/PORT_LIST[port_name='Ethernet20']/alias", "valid":"False"}, + {"xpath":"/test-sonic-vlan:sonic-vlan/VLAN_INTERFACE", "valid":"True"}, + {"xpath":"/test-sonic-vlan:sonic-vlan/VLAN_INTERFACE/VLAN_INTERFACE_LIST", "valid":"False"}, + {"xpath":"/test-sonic-vlan:sonic-vlan/VLAN_INTERFACE/VLAN_INTERFACE_LIST[vlanid='111'][ip-prefix='2000:f500:45:6709::/64']", "valid":"True"} ], "set_nodes":[ - {"xpath":"/sonic-port:sonic-port/PORT/PORT_LIST[port_name='Ethernet10']/speed", "value":"10000"}, - {"xpath":"/sonic-port:sonic-port/PORT/PORT_LIST[port_name='Ethernet9']/mtu", "value":"1500"}, - {"xpath":"/sonic-vlan:sonic-vlan/VLAN/VLAN_LIST[vlanid='111']/description", "value":"server_vlan111"} + {"xpath":"/test-sonic-port:sonic-port/PORT/PORT_LIST[port_name='Ethernet10']/speed", "value":"10000"}, + {"xpath":"/test-sonic-port:sonic-port/PORT/PORT_LIST[port_name='Ethernet9']/mtu", "value":"1500"}, + {"xpath":"/test-sonic-vlan:sonic-vlan/VLAN/VLAN_LIST[vlanid='111']/description", "value":"server_vlan111"} ], "node_values":[ - {"xpath":"/sonic-port:sonic-port/PORT/PORT_LIST[port_name='Ethernet9']/speed", "value":"25000"}, - {"xpath":"/sonic-vlan:sonic-vlan/VLAN_INTERFACE/VLAN_INTERFACE_LIST[vlanid='111'][ip-prefix='2000:f500:45:6709::/64']/family", + {"xpath":"/test-sonic-port:sonic-port/PORT/PORT_LIST[port_name='Ethernet9']/speed", "value":"25000"}, + {"xpath":"/test-sonic-vlan:sonic-vlan/VLAN_INTERFACE/VLAN_INTERFACE_LIST[vlanid='111'][ip-prefix='2000:f500:45:6709::/64']/family", "value":"IPv6"} ], "schema_nodes":[ - {"xpath":"/sonic-vlan:sonic-vlan/VLAN_INTERFACE/VLAN_INTERFACE_LIST[vlanid='111'][ip-prefix='10.1.1.64/26']/family", - "value":"/sonic-vlan:sonic-vlan/sonic-vlan:VLAN_INTERFACE/sonic-vlan:VLAN_INTERFACE_LIST/sonic-vlan:family"}, - {"xpath":"/sonic-port:sonic-port/PORT/PORT_LIST[port_name='Ethernet9']/speed", - "value":"/sonic-port:sonic-port/sonic-port:PORT/sonic-port:PORT_LIST/sonic-port:speed"} + {"xpath":"/test-sonic-vlan:sonic-vlan/VLAN_INTERFACE/VLAN_INTERFACE_LIST[vlanid='111'][ip-prefix='10.1.1.64/26']/family", + "value":"/test-sonic-vlan:sonic-vlan/test-sonic-vlan:VLAN_INTERFACE/test-sonic-vlan:VLAN_INTERFACE_LIST/test-sonic-vlan:family"}, + {"xpath":"/test-sonic-port:sonic-port/PORT/PORT_LIST[port_name='Ethernet9']/speed", + "value":"/test-sonic-port:sonic-port/test-sonic-port:PORT/test-sonic-port:PORT_LIST/test-sonic-port:speed"} ], "delete_nodes":[ - {"xpath":"/sonic-port:sonic-port/PORT/PORT_LIST[port_name='Ethernet10']/speed", "valid":"False"}, - {"xpath":"/sonic-port:sonic-port/PORT/PORT_LIST[port_name='Ethernet9']/mtu", "valid":"True"}, - {"xpath":"/sonic-port:sonic-port/PORT/PORT_LIST[port_name='Ethernet20']/mtu", "valid":"False"} + {"xpath":"/test-sonic-port:sonic-port/PORT/PORT_LIST[port_name='Ethernet10']/speed", "valid":"False"}, + {"xpath":"/test-sonic-port:sonic-port/PORT/PORT_LIST[port_name='Ethernet9']/mtu", "valid":"True"}, + {"xpath":"/test-sonic-port:sonic-port/PORT/PORT_LIST[port_name='Ethernet20']/mtu", "valid":"False"} ], "dependencies":[ - {"xpath":"/sonic-port:sonic-port/PORT/PORT_LIST[port_name='Ethernet8']/port_name", + {"xpath":"/test-sonic-port:sonic-port/PORT/PORT_LIST[port_name='Ethernet8']/port_name", "dependencies": - ["/sonic-vlan:sonic-vlan/VLAN/VLAN_LIST[vlanid='111']/members[.='Ethernet8']", - "/sonic-vlan:sonic-vlan/VLAN/VLAN_LIST[vlanid='555']/members[.='Ethernet8']", - "/sonic-acl:sonic-acl/ACL_TABLE/ACL_TABLE_LIST[ACL_TABLE_NAME='PACL-V6']/ports[.='Ethernet8']", - "/sonic-interface:sonic-interface/INTERFACE/INTERFACE_LIST[interface='Ethernet8'][ip-prefix='10.1.1.64/26']/interface", - "/sonic-interface:sonic-interface/INTERFACE/INTERFACE_LIST[interface='Ethernet8'][ip-prefix='2000:f500:40:a749::/126']/interface"]} + ["/test-sonic-vlan:sonic-vlan/VLAN/VLAN_LIST[vlanid='111']/members[.='Ethernet8']", + "/test-sonic-vlan:sonic-vlan/VLAN/VLAN_LIST[vlanid='555']/members[.='Ethernet8']", + "/test-sonic-acl:sonic-acl/ACL_TABLE/ACL_TABLE_LIST[ACL_TABLE_NAME='PACL-V6']/ports[.='Ethernet8']", + "/test-sonic-interface:sonic-interface/INTERFACE/INTERFACE_LIST[interface='Ethernet8'][ip-prefix='10.1.1.64/26']/interface", + "/test-sonic-interface:sonic-interface/INTERFACE/INTERFACE_LIST[interface='Ethernet8'][ip-prefix='2000:f500:40:a749::/126']/interface"]} ], "schema_dependencies":[ - {"xpath":"/sonic-port:sonic-port/sonic-port:PORT/sonic-port:PORT_LIST/sonic-port:port_name", + {"xpath":"/test-sonic-port:sonic-port/test-sonic-port:PORT/test-sonic-port:PORT_LIST/test-sonic-port:port_name", "schema_dependencies": - ["/sonic-acl:sonic-acl/sonic-acl:ACL_TABLE/sonic-acl:ACL_TABLE_LIST/sonic-acl:ports", - "/sonic-portchannel:sonic-portchannel/sonic-portchannel:PORTCHANNEL/sonic-portchannel:PORTCHANNEL_LIST/sonic-portchannel:members", - "/sonic-interface:sonic-interface/sonic-interface:INTERFACE/sonic-interface:INTERFACE_LIST/sonic-interface:interface", - "/sonic-vlan:sonic-vlan/sonic-vlan:VLAN/sonic-vlan:VLAN_LIST/sonic-vlan:members", - "/sonic-vlan:sonic-vlan/sonic-vlan:VLAN_MEMBER/sonic-vlan:VLAN_MEMBER_LIST/sonic-vlan:port"]} + ["/test-sonic-acl:sonic-acl/test-sonic-acl:ACL_TABLE/test-sonic-acl:ACL_TABLE_LIST/test-sonic-acl:ports", + "/test-sonic-portchannel:sonic-portchannel/test-sonic-portchannel:PORTCHANNEL/test-sonic-portchannel:PORTCHANNEL_LIST/test-sonic-portchannel:members", + "/test-sonic-interface:sonic-interface/test-sonic-interface:INTERFACE/test-sonic-interface:INTERFACE_LIST/test-sonic-interface:interface", + "/test-sonic-vlan:sonic-vlan/test-sonic-vlan:VLAN/test-sonic-vlan:VLAN_LIST/test-sonic-vlan:members", + "/test-sonic-vlan:sonic-vlan/test-sonic-vlan:VLAN_MEMBER/test-sonic-vlan:VLAN_MEMBER_LIST/test-sonic-vlan:port"]} ], "members":[ - {"xpath":"/sonic-port:sonic-port/PORT/PORT_LIST", + {"xpath":"/test-sonic-port:sonic-port/PORT/PORT_LIST", "members": - ["/sonic-port:sonic-port/PORT/PORT_LIST[port_name='Ethernet0']", - "/sonic-port:sonic-port/PORT/PORT_LIST[port_name='Ethernet1']", - "/sonic-port:sonic-port/PORT/PORT_LIST[port_name='Ethernet2']", - "/sonic-port:sonic-port/PORT/PORT_LIST[port_name='Ethernet3']", - "/sonic-port:sonic-port/PORT/PORT_LIST[port_name='Ethernet4']", - "/sonic-port:sonic-port/PORT/PORT_LIST[port_name='Ethernet5']", - "/sonic-port:sonic-port/PORT/PORT_LIST[port_name='Ethernet6']", - "/sonic-port:sonic-port/PORT/PORT_LIST[port_name='Ethernet7']", - "/sonic-port:sonic-port/PORT/PORT_LIST[port_name='Ethernet8']", - "/sonic-port:sonic-port/PORT/PORT_LIST[port_name='Ethernet9']", - "/sonic-port:sonic-port/PORT/PORT_LIST[port_name='Ethernet10']", - "/sonic-port:sonic-port/PORT/PORT_LIST[port_name='Ethernet12']"]} + ["/test-sonic-port:sonic-port/PORT/PORT_LIST[port_name='Ethernet0']", + "/test-sonic-port:sonic-port/PORT/PORT_LIST[port_name='Ethernet1']", + "/test-sonic-port:sonic-port/PORT/PORT_LIST[port_name='Ethernet2']", + "/test-sonic-port:sonic-port/PORT/PORT_LIST[port_name='Ethernet3']", + "/test-sonic-port:sonic-port/PORT/PORT_LIST[port_name='Ethernet4']", + "/test-sonic-port:sonic-port/PORT/PORT_LIST[port_name='Ethernet5']", + "/test-sonic-port:sonic-port/PORT/PORT_LIST[port_name='Ethernet6']", + "/test-sonic-port:sonic-port/PORT/PORT_LIST[port_name='Ethernet7']", + "/test-sonic-port:sonic-port/PORT/PORT_LIST[port_name='Ethernet8']", + "/test-sonic-port:sonic-port/PORT/PORT_LIST[port_name='Ethernet9']", + "/test-sonic-port:sonic-port/PORT/PORT_LIST[port_name='Ethernet10']", + "/test-sonic-port:sonic-port/PORT/PORT_LIST[port_name='Ethernet12']"]} ], "parents":[ - {"xpath":"/sonic-vlan:sonic-vlan/VLAN_INTERFACE/VLAN_INTERFACE_LIST[vlanid='111'][ip-prefix='2000:f500:45:6709::/64']/family", - "parent":"/sonic-vlan:sonic-vlan/VLAN_INTERFACE/VLAN_INTERFACE_LIST[vlanid='111'][ip-prefix='2000:f500:45:6709::/64']"}, - {"xpath":"/sonic-vlan:sonic-vlan/VLAN_INTERFACE/VLAN_INTERFACE_LIST[vlanid='111'][ip-prefix='10.1.1.64/26']/scope", - "parent":"/sonic-vlan:sonic-vlan/VLAN_INTERFACE/VLAN_INTERFACE_LIST[vlanid='111'][ip-prefix='10.1.1.64/26']"}, - {"xpath":"/sonic-vlan:sonic-vlan/VLAN_INTERFACE/VLAN_INTERFACE_LIST[vlanid='111'][ip-prefix='10.1.1.64/26']/vlanid", - "parent":"/sonic-vlan:sonic-vlan/VLAN_INTERFACE/VLAN_INTERFACE_LIST[vlanid='111'][ip-prefix='10.1.1.64/26']"}, - {"xpath":"/sonic-vlan:sonic-vlan/VLAN_INTERFACE/VLAN_INTERFACE_LIST[vlanid='111'][ip-prefix='10.1.1.64/26']/ip-prefix", - "parent":"/sonic-vlan:sonic-vlan/VLAN_INTERFACE/VLAN_INTERFACE_LIST[vlanid='111'][ip-prefix='10.1.1.64/26']"}, - {"xpath":"/sonic-vlan:sonic-vlan/VLAN_INTERFACE/VLAN_INTERFACE_LIST[vlanid='111'][ip-prefix='10.1.1.64/26']/family", - "parent":"/sonic-vlan:sonic-vlan/VLAN_INTERFACE/VLAN_INTERFACE_LIST[vlanid='111'][ip-prefix='10.1.1.64/26']"}, - {"xpath":"/sonic-port:sonic-port/PORT/PORT_LIST[port_name='Ethernet9']/speed", - "parent":"/sonic-port:sonic-port/PORT/PORT_LIST[port_name='Ethernet9']"} - ], + {"xpath":"/test-sonic-vlan:sonic-vlan/VLAN_INTERFACE/VLAN_INTERFACE_LIST[vlanid='111'][ip-prefix='2000:f500:45:6709::/64']/family", + "parent":"/test-sonic-vlan:sonic-vlan/VLAN_INTERFACE/VLAN_INTERFACE_LIST[vlanid='111'][ip-prefix='2000:f500:45:6709::/64']"}, + {"xpath":"/test-sonic-vlan:sonic-vlan/VLAN_INTERFACE/VLAN_INTERFACE_LIST[vlanid='111'][ip-prefix='10.1.1.64/26']/scope", + "parent":"/test-sonic-vlan:sonic-vlan/VLAN_INTERFACE/VLAN_INTERFACE_LIST[vlanid='111'][ip-prefix='10.1.1.64/26']"}, + {"xpath":"/test-sonic-vlan:sonic-vlan/VLAN_INTERFACE/VLAN_INTERFACE_LIST[vlanid='111'][ip-prefix='10.1.1.64/26']/vlanid", + "parent":"/test-sonic-vlan:sonic-vlan/VLAN_INTERFACE/VLAN_INTERFACE_LIST[vlanid='111'][ip-prefix='10.1.1.64/26']"}, + {"xpath":"/test-sonic-vlan:sonic-vlan/VLAN_INTERFACE/VLAN_INTERFACE_LIST[vlanid='111'][ip-prefix='10.1.1.64/26']/ip-prefix", + "parent":"/test-sonic-vlan:sonic-vlan/VLAN_INTERFACE/VLAN_INTERFACE_LIST[vlanid='111'][ip-prefix='10.1.1.64/26']"}, + {"xpath":"/test-sonic-vlan:sonic-vlan/VLAN_INTERFACE/VLAN_INTERFACE_LIST[vlanid='111'][ip-prefix='10.1.1.64/26']/family", + "parent":"/test-sonic-vlan:sonic-vlan/VLAN_INTERFACE/VLAN_INTERFACE_LIST[vlanid='111'][ip-prefix='10.1.1.64/26']"}, + {"xpath":"/test-sonic-port:sonic-port/PORT/PORT_LIST[port_name='Ethernet9']/speed", + "parent":"/test-sonic-port:sonic-port/PORT/PORT_LIST[port_name='Ethernet9']"} + ], "prefix":[ - {"module_name":"sonic-head", "module_prefix":"sonic-head"}, - {"module_name":"sonic-port", "module_prefix":"port"}, - {"module_name":"sonic-acl", "module_prefix":"acl"}, - {"module_name":"sonic-interface", "module_prefix":"intf"}, - {"module_name":"sonic-portchannel", "module_prefix":"lag"}, - {"module_name":"sonic-vlan", "module_prefix":"vlan"} + {"module_name":"test-sonic-head", "module_prefix":"test-sonic-head"}, + {"module_name":"test-sonic-port", "module_prefix":"test-sonic-port"}, + {"module_name":"test-sonic-acl", "module_prefix":"test-sonic-acl"}, + {"module_name":"test-sonic-interface", "module_prefix":"test-sonic-intf"}, + {"module_name":"test-sonic-portchannel", "module_prefix":"test-sonic-lag"}, + {"module_name":"test-sonic-vlan", "module_prefix":"test-sonic-vlan"} ], "data_type":[ - {"xpath":"/sonic-port:sonic-port/sonic-port:PORT/sonic-port:PORT_LIST/sonic-port:port_name", "data_type":"LY_TYPE_STRING"}, - {"xpath":"/sonic-vlan:sonic-vlan/sonic-vlan:VLAN_INTERFACE/sonic-vlan:VLAN_INTERFACE_LIST/sonic-vlan:vlanid", "data_type":"LY_TYPE_LEAFREF"} + {"xpath":"/test-sonic-port:sonic-port/test-sonic-port:PORT/sonic-port:PORT_LIST/test-sonic-port:port_name", "data_type":"LY_TYPE_STRING"}, + {"xpath":"/test-sonic-vlan:sonic-vlan/test-sonic-vlan:VLAN_INTERFACE/test-sonic-vlan:VLAN_INTERFACE_LIST/test-sonic-vlan:vlanid", "data_type":"LY_TYPE_LEAFREF"} ], "leafref_type":[ - {"xpath":"/sonic-vlan:sonic-vlan/VLAN_INTERFACE/VLAN_INTERFACE_LIST[vlanid='111'][ip-prefix='2000:f500:45:6709::/64']/vlanid", "data_type":"LY_TYPE_UINT16"}, - {"xpath":"/sonic-interface:sonic-interface/INTERFACE/INTERFACE_LIST[interface='Ethernet8'][ip-prefix='2000:f500:40:a749::/126']/interface", "data_type":"LY_TYPE_STRING"}, - {"xpath":"/sonic-vlan:sonic-vlan/VLAN_MEMBER/VLAN_MEMBER_LIST[vlanid='111'][port='Ethernet0']/port", "data_type":"LY_TYPE_STRING"}, - {"xpath":"/sonic-vlan:sonic-vlan/VLAN_MEMBER/VLAN_MEMBER_LIST[vlanid='111'][port='Ethernet0']/vlanid", "data_type":"LY_TYPE_UINT16"} + {"xpath":"/test-sonic-vlan:sonic-vlan/VLAN_INTERFACE/VLAN_INTERFACE_LIST[vlanid='111'][ip-prefix='2000:f500:45:6709::/64']/vlanid", "data_type":"LY_TYPE_UINT16"}, + {"xpath":"/test-sonic-interface:sonic-interface/INTERFACE/INTERFACE_LIST[interface='Ethernet8'][ip-prefix='2000:f500:40:a749::/126']/interface", "data_type":"LY_TYPE_STRING"}, + {"xpath":"/test-sonic-vlan:sonic-vlan/VLAN_MEMBER/VLAN_MEMBER_LIST[vlanid='111'][port='Ethernet0']/port", "data_type":"LY_TYPE_STRING"}, + {"xpath":"/test-sonic-vlan:sonic-vlan/VLAN_MEMBER/VLAN_MEMBER_LIST[vlanid='111'][port='Ethernet0']/vlanid", "data_type":"LY_TYPE_UINT16"} ], "leafref_type_schema":[ - {"xpath":"/sonic-vlan:sonic-vlan/sonic-vlan:VLAN_INTERFACE/sonic-vlan:VLAN_INTERFACE_LIST/sonic-vlan:vlanid", + {"xpath":"/test-sonic-vlan:sonic-vlan/test-sonic-vlan:VLAN_INTERFACE/test-sonic-vlan:VLAN_INTERFACE_LIST/test-sonic-vlan:vlanid", "data_type":"LY_TYPE_UINT16"}, - {"xpath":"/sonic-interface:sonic-interface/sonic-interface:INTERFACE/sonic-interface:INTERFACE_LIST/sonic-interface:interface", + {"xpath":"/test-sonic-interface:sonic-interface/test-sonic-interface:INTERFACE/test-sonic-interface:INTERFACE_LIST/test-sonic-interface:interface", "data_type":"LY_TYPE_STRING"}, - {"xpath":"/sonic-vlan:sonic-vlan/sonic-vlan:VLAN_MEMBER/sonic-vlan:VLAN_MEMBER_LIST/sonic-vlan:port", + {"xpath":"/test-sonic-vlan:sonic-vlan/test-sonic-vlan:VLAN_MEMBER/test-sonic-vlan:VLAN_MEMBER_LIST/test-sonic-vlan:port", "data_type":"LY_TYPE_STRING"}, - {"xpath":"/sonic-vlan:sonic-vlan/sonic-vlan:VLAN_MEMBER/sonic-vlan:VLAN_MEMBER_LIST/sonic-vlan:vlanid", + {"xpath":"/test-sonic-vlan:sonic-vlan/test-sonic-vlan:VLAN_MEMBER/test-sonic-vlan:VLAN_MEMBER_LIST/test-sonic-vlan:vlanid", "data_type":"LY_TYPE_UINT16"} ], "leafref_path":[ - {"xpath":"/sonic-vlan:sonic-vlan/sonic-vlan:VLAN_INTERFACE/sonic-vlan:VLAN_INTERFACE_LIST/sonic-vlan:vlanid", + {"xpath":"/test-sonic-vlan:sonic-vlan/test-sonic-vlan:VLAN_INTERFACE/test-sonic-vlan:VLAN_INTERFACE_LIST/test-sonic-vlan:vlanid", "leafref_path":"../../../VLAN/VLAN_LIST/vlanid"}, - {"xpath":"/sonic-interface:sonic-interface/sonic-interface:INTERFACE/sonic-interface:INTERFACE_LIST/sonic-interface:interface", - "leafref_path":"/sonic-port:sonic-port/sonic-port:PORT/sonic-port:PORT_LIST/sonic-port:port_name"}, - {"xpath":"/sonic-vlan:sonic-vlan/sonic-vlan:VLAN_MEMBER/sonic-vlan:VLAN_MEMBER_LIST/sonic-vlan:port", - "leafref_path":"/sonic-port:sonic-port/sonic-port:PORT/sonic-port:PORT_LIST/sonic-port:port_name"}, - {"xpath":"/sonic-vlan:sonic-vlan/sonic-vlan:VLAN_MEMBER/sonic-vlan:VLAN_MEMBER_LIST/sonic-vlan:vlanid", + {"xpath":"/test-sonic-interface:sonic-interface/test-sonic-interface:INTERFACE/test-sonic-interface:INTERFACE_LIST/test-sonic-interface:interface", + "leafref_path":"/test-sonic-port:sonic-port/test-sonic-port:PORT/test-sonic-port:PORT_LIST/test-sonic-port:port_name"}, + {"xpath":"/test-sonic-vlan:sonic-vlan/test-sonic-vlan:VLAN_MEMBER/test-sonic-vlan:VLAN_MEMBER_LIST/test-sonic-vlan:port", + "leafref_path":"/test-sonic-port:sonic-port/test-sonic-port:PORT/test-sonic-port:PORT_LIST/test-sonic-port:port_name"}, + {"xpath":"/test-sonic-vlan:sonic-vlan/test-sonic-vlan:VLAN_MEMBER/test-sonic-vlan:VLAN_MEMBER_LIST/test-sonic-vlan:vlanid", "leafref_path":"../../../VLAN/VLAN_LIST/vlanid"} ] } diff --git a/src/sonic-yang-mgmt/tests/libyang-python-tests/test_sonic_yang.py b/src/sonic-yang-mgmt/tests/libyang-python-tests/test_sonic_yang.py index 46c92d521bd0..d782bb2d5437 100644 --- a/src/sonic-yang-mgmt/tests/libyang-python-tests/test_sonic_yang.py +++ b/src/sonic-yang-mgmt/tests/libyang-python-tests/test_sonic_yang.py @@ -114,6 +114,13 @@ def test_load_yang_model_data(self, data, yang_s): print(yang_files) yang_s.load_data_model(yang_dir, yang_files, data_files) + #validate the data tree from data_merge_file is loaded + for node in data['merged_nodes']: + xpath = str(node['xpath']) + value = str(node['value']) + val = yang_s.find_data_node_value(xpath) + assert str(val) == str(value) + #test load data file def test_load_data_file(self, data, yang_s): data_file = str(data['data_file']) @@ -141,19 +148,19 @@ def test_add_node(self, data, yang_s): for node in data['new_nodes']: xpath = str(node['xpath']) value = node['value'] - status = yang_s.add_node(xpath, str(value)) + status = yang_s.add_data_node(xpath, str(value)) - node = yang_s.find_data_node(xpath) - assert node is not None + data_node = yang_s.find_data_node(xpath) + assert data_node is not None #test find node value - def test_find_node_value(self, data, yang_s): + def test_find_data_node_value(self, data, yang_s): for node in data['node_values']: xpath = str(node['xpath']) value = str(node['value']) print(xpath) print(value) - val = yang_s.find_node_value(xpath) + val = yang_s.find_data_node_value(xpath) assert str(val) == str(value) #test delete data node @@ -161,16 +168,16 @@ def test_delete_node(self, data, yang_s): for node in data['delete_nodes']: expected = node['valid'] xpath = str(node['xpath']) - yang_s._delete_node(xpath) + yang_s.delete_data_node(xpath) #test set node's value def test_set_datanode_value(self, data, yang_s): for node in data['set_nodes']: xpath = str(node['xpath']) value = node['value'] - yang_s.set_dnode_value(xpath, value) + yang_s.set_data_node_value(xpath, value) - val = yang_s.find_node_value(xpath) + val = yang_s.find_data_node_value(xpath) assert str(val) == str(value) #test list of members @@ -182,19 +189,19 @@ def test_find_members(self, yang_s, data): assert list.sort() == members.sort() #get parent xpath - def test_get_parent_xpath(self, yang_s, data): + def test_get_parent_data_xpath(self, yang_s, data): for node in data['parents']: xpath = str(node['xpath']) expected_xpath = str(node['parent']) - path = yang_s.get_parent_xpath(xpath) + path = yang_s.get_parent_data_xpath(xpath) assert path == expected_xpath - #test find_node_schema_xpath - def test_find_node_schema_xpath(self, yang_s, data): + #test find_data_node_schema_xpath + def test_find_data_node_schema_xpath(self, yang_s, data): for node in data['schema_nodes']: xpath = str(node['xpath']) schema_xpath = str(node['value']) - path = yang_s.find_node_schema_xpath(xpath) + path = yang_s.find_data_node_schema_xpath(xpath) assert path == schema_xpath #test data dependencies From d2123f39b33812d77138ba80ceec5a28171f9e22 Mon Sep 17 00:00:00 2001 From: Ping Mao Date: Mon, 23 Mar 2020 12:30:25 -0700 Subject: [PATCH 2/3] Update function calls after libyang PLY APIs updates --- src/sonic-yang-mgmt/_sonic_yang_ext.py | 2 +- src/sonic-yang-mgmt/sonic_yang.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sonic-yang-mgmt/_sonic_yang_ext.py b/src/sonic-yang-mgmt/_sonic_yang_ext.py index e66997da6383..c0e04c217406 100644 --- a/src/sonic-yang-mgmt/_sonic_yang_ext.py +++ b/src/sonic-yang-mgmt/_sonic_yang_ext.py @@ -641,7 +641,7 @@ def delete_node(self, xpath): leaf = ly.Schema_Node_Leaf(snode) if leaf.is_key(): # try to delete parent - nodeP = self.find_parent_node(xpath) + nodeP = self.find_parent_data_node(xpath) xpathP = nodeP.path() if self._delete_node(xpath=xpathP, node=nodeP) == False: raise('_delete_node failed') diff --git a/src/sonic-yang-mgmt/sonic_yang.py b/src/sonic-yang-mgmt/sonic_yang.py index 687decd917e7..c1f2ddd1f573 100644 --- a/src/sonic-yang-mgmt/sonic_yang.py +++ b/src/sonic-yang-mgmt/sonic_yang.py @@ -522,7 +522,7 @@ def find_data_dependencies (self, data_xpath): return ref_list try: - value = str(self.find_node_value(data_xpath)) + value = str(self.find_data_node_value(data_xpath)) schema_node = ly.Schema_Node_Leaf(data_node.schema()) backlinks = schema_node.backlinks() From 45c52cf511c05ca1f6633163eb59cdbf75be968c Mon Sep 17 00:00:00 2001 From: Ping Mao Date: Thu, 23 Apr 2020 20:33:00 -0700 Subject: [PATCH 3/3] Fix test cases after sample yang files name changes --- .../sonic_config_data.json | 22 +++++++++---------- .../libyang-python-tests/test_SonicYang.json | 14 ++++++------ .../libyang-python-tests/test_sonic_yang.py | 2 +- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/sonic-yang-mgmt/tests/libyang-python-tests/sonic_config_data.json b/src/sonic-yang-mgmt/tests/libyang-python-tests/sonic_config_data.json index f7de6902c5d0..35857fd6609c 100644 --- a/src/sonic-yang-mgmt/tests/libyang-python-tests/sonic_config_data.json +++ b/src/sonic-yang-mgmt/tests/libyang-python-tests/sonic_config_data.json @@ -1,6 +1,6 @@ { - "sonic-vlan:sonic-vlan": { - "sonic-vlan:VLAN_INTERFACE": { + "test-sonic-vlan:sonic-vlan": { + "test-sonic-vlan:VLAN_INTERFACE": { "VLAN_INTERFACE_LIST": [{ "vlanid": 111, "ip-prefix": "2000:f500:45:6709::1/64", @@ -40,7 +40,7 @@ ] }, - "sonic-vlan:VLAN": { + "test-sonic-vlan:VLAN": { "VLAN_LIST": [{ "vlanid": 111, "description": "server_vlan", @@ -78,7 +78,7 @@ ] }, - "sonic-vlan:VLAN_MEMBER": { + "test-sonic-vlan:VLAN_MEMBER": { "VLAN_MEMBER_LIST": [{ "vlanid": 111, "port": "Ethernet0", @@ -117,8 +117,8 @@ ] } }, - "sonic-port:sonic-port": { - "sonic-port:PORT": { + "test-sonic-port:sonic-port": { + "test-sonic-port:PORT": { "PORT_LIST": [{ "port_name": "Ethernet0", "alias": "eth0", @@ -203,8 +203,8 @@ } }, - "sonic-acl:sonic-acl": { - "sonic-acl:ACL_RULE": { + "test-sonic-acl:sonic-acl": { + "test-sonic-acl:ACL_RULE": { "ACL_RULE_LIST": [{ "ACL_TABLE_NAME": "PACL-V4", "RULE_NAME": "Rule_20", @@ -237,7 +237,7 @@ ] }, - "sonic-acl:ACL_TABLE": { + "test-sonic-acl:ACL_TABLE": { "ACL_TABLE_LIST": [{ "ACL_TABLE_NAME": "PACL-V6", "policy_desc": "Filter IPv6", @@ -256,8 +256,8 @@ } }, - "sonic-interface:sonic-interface": { - "sonic-interface:INTERFACE": { + "test-sonic-interface:sonic-interface": { + "test-sonic-interface:INTERFACE": { "INTERFACE_LIST": [{ "interface": "Ethernet8", "ip-prefix": "10.1.1.65/26", diff --git a/src/sonic-yang-mgmt/tests/libyang-python-tests/test_SonicYang.json b/src/sonic-yang-mgmt/tests/libyang-python-tests/test_SonicYang.json index 4ae66e8633a5..5369cd3aaac4 100644 --- a/src/sonic-yang-mgmt/tests/libyang-python-tests/test_SonicYang.json +++ b/src/sonic-yang-mgmt/tests/libyang-python-tests/test_SonicYang.json @@ -107,15 +107,15 @@ "parent":"/test-sonic-port:sonic-port/PORT/PORT_LIST[port_name='Ethernet9']"} ], "prefix":[ - {"module_name":"test-sonic-head", "module_prefix":"test-sonic-head"}, - {"module_name":"test-sonic-port", "module_prefix":"test-sonic-port"}, - {"module_name":"test-sonic-acl", "module_prefix":"test-sonic-acl"}, - {"module_name":"test-sonic-interface", "module_prefix":"test-sonic-intf"}, - {"module_name":"test-sonic-portchannel", "module_prefix":"test-sonic-lag"}, - {"module_name":"test-sonic-vlan", "module_prefix":"test-sonic-vlan"} + {"module_name":"test-sonic-head", "module_prefix":"sonic-head"}, + {"module_name":"test-sonic-port", "module_prefix":"port"}, + {"module_name":"test-sonic-acl", "module_prefix":"acl"}, + {"module_name":"test-sonic-interface", "module_prefix":"intf"}, + {"module_name":"test-sonic-portchannel", "module_prefix":"lag"}, + {"module_name":"test-sonic-vlan", "module_prefix":"vlan"} ], "data_type":[ - {"xpath":"/test-sonic-port:sonic-port/test-sonic-port:PORT/sonic-port:PORT_LIST/test-sonic-port:port_name", "data_type":"LY_TYPE_STRING"}, + {"xpath":"/test-sonic-port:sonic-port/test-sonic-port:PORT/test-sonic-port:PORT_LIST/test-sonic-port:port_name", "data_type":"LY_TYPE_STRING"}, {"xpath":"/test-sonic-vlan:sonic-vlan/test-sonic-vlan:VLAN_INTERFACE/test-sonic-vlan:VLAN_INTERFACE_LIST/test-sonic-vlan:vlanid", "data_type":"LY_TYPE_LEAFREF"} ], "leafref_type":[ diff --git a/src/sonic-yang-mgmt/tests/libyang-python-tests/test_sonic_yang.py b/src/sonic-yang-mgmt/tests/libyang-python-tests/test_sonic_yang.py index d782bb2d5437..6f0c050f2301 100644 --- a/src/sonic-yang-mgmt/tests/libyang-python-tests/test_sonic_yang.py +++ b/src/sonic-yang-mgmt/tests/libyang-python-tests/test_sonic_yang.py @@ -168,7 +168,7 @@ def test_delete_node(self, data, yang_s): for node in data['delete_nodes']: expected = node['valid'] xpath = str(node['xpath']) - yang_s.delete_data_node(xpath) + yang_s._delete_node(xpath) #test set node's value def test_set_datanode_value(self, data, yang_s):