CiscoDevNet / ydk-gen

Generate model-driven APIs from YANG models
http://ciscodevnet.github.io/ydk-gen/
Apache License 2.0
135 stars 74 forks source link

ydk.path.DataNode.find rejects absolute paths with a leading "/" #1022

Closed tdesh10 closed 2 years ago

tdesh10 commented 4 years ago

Expected Behavior

ydk.path.DataNode.find(path) should accept absolute paths with a leading / as defined in RFC 7950(section 6.5)

6.5.  Schema Node Identifier

   A schema node identifier is a string that identifies a node in the
   schema tree.  It has two forms, "absolute" and "descendant", defined
   by the rules "absolute-schema-nodeid" and "descendant-schema-nodeid"
   in Section 14, respectively.  A schema node identifier consists of a
   path of identifiers, separated by slashes ("/").  In an absolute
   schema node identifier, the first identifier after the leading slash
   is any top-level schema node in the local module or in an imported
   module.

   References to identifiers defined in external modules MUST be
   qualified with appropriate prefixes, and references to identifiers
   defined in the current module and its submodules MAY use a prefix.

   For example, to identify the child node "b" of top-level node "a",
   the string "/a/b" can be used.

Current Behavior

ydk.path.DataNode.find(path) rejects absolute paths with a leading /, with exception: YModelError: Unexpected character(s) '/' ("/Cisco-IOS-XR-cdp-cfg:cdp/timer"). Path:

Steps to Reproduce

Execute the script below in ydk-py docker container.

Your Script

from ydk.path import Repository, Capability
# import logging
# log = logging.getLogger('ydk')
# log.setLevel(logging.DEBUG)
# handler = logging.StreamHandler()
# log.addHandler(handler)

repo = Repository('/root/ydk-py/cisco-ios-xr/ydk/models/cisco_ios_xr/_yang')
root_schema = repo.create_root_schema([])

datanode_path = "/Cisco-IOS-XR-cdp-cfg:cdp/timer"
datanode_value = "10"

datanode = root_schema.create_datanode(datanode_path, datanode_value)

#Fails with YModelError: Unexpected character(s) '/' ("/Cisco-IOS-XR-cdp-cfg:cdp/timer"). Path 
datanode.get_root().find(datanode_path)

Logs

Creating libyang context in path: /root/ydk-py/cisco-ios-xr/ydk/models/cisco_ios_xr/_yang
[libyang] Extension plugin "/usr/local/lib/libyang/libyang_ext_test.so" successfully loaded.
[libyang] Extension plugin "/usr/local/lib/libyang/metadata.so" successfully loaded.
[libyang] Extension plugin "/usr/local/lib/libyang/nacm.so" successfully loaded.
[libyang] Reading module "ietf-yang-metadata".
[libyang] Module "ietf-yang-metadata@2016-08-05" successfully parsed as implemented.
[libyang] Reading module "yang".
[libyang] Resolving "yang" unresolved schema nodes and their constraints...
[libyang] All "yang" schema nodes and constraints resolved.
[libyang] Module "yang@2017-02-20" successfully parsed as implemented.
[libyang] Reading module "ietf-inet-types".
[libyang] Resolving derived type "union" failed, it will be attempted later.
[libyang] Resolving derived type "union" failed, it will be attempted later.
[libyang] Resolving derived type "union" failed, it will be attempted later.
[libyang] Resolving derived type "union" failed, it will be attempted later.
[libyang] Resolving "ietf-inet-types" unresolved schema nodes and their constraints...
[libyang] All "ietf-inet-types" schema nodes and constraints resolved.
[libyang] Module "ietf-inet-types@2013-07-15" successfully parsed as implemented.
[libyang] Reading module "ietf-yang-types".
[libyang] Module "ietf-yang-types@2013-07-15" successfully parsed as implemented.
[libyang] Reading module "ietf-datastores".
[libyang] Module "ietf-datastores@2017-08-17" successfully parsed as implemented.
[libyang] Reading module "ietf-yang-library".
[libyang] Module "ietf-yang-library@2017-08-17" successfully parsed as implemented.
Populating new module schema 'ietf-yang-metadata'
Populating new module schema 'yang'
Populating new module schema 'ietf-inet-types'
Populating new module schema 'ietf-yang-types'
Populating new module schema 'ietf-datastores'
Populating new module schema 'ietf-yang-library'
Getting new modules for path '/Cisco-IOS-XR-cdp-cfg:cdp/timer'
Loading module 'Cisco-IOS-XR-cdp-cfg', revision ''
[libyang] Searching for "Cisco-IOS-XR-cdp-cfg" in /root/ydk-py/cisco-ios-xr/ydk/models/cisco_ios_xr/_yang.
[libyang] Searching for "Cisco-IOS-XR-cdp-cfg" in /root/ydk-py/cisco-ios-xr/ydk/models/cisco_ios_xr/_yang/ietf@0.1.5-post2.
[libyang] Searching for "Cisco-IOS-XR-cdp-cfg" in /root/ydk-py/pathapi-taran.
[libyang] Loading schema from "/root/ydk-py/cisco-ios-xr/ydk/models/cisco_ios_xr/_yang/Cisco-IOS-XR-cdp-cfg.yang" file.
[libyang] Searching for "Cisco-IOS-XR-ifmgr-cfg" in /root/ydk-py/cisco-ios-xr/ydk/models/cisco_ios_xr/_yang.
[libyang] Searching for "Cisco-IOS-XR-ifmgr-cfg" in /root/ydk-py/cisco-ios-xr/ydk/models/cisco_ios_xr/_yang/ietf@0.1.5-post2.
[libyang] Searching for "Cisco-IOS-XR-ifmgr-cfg" in /root/ydk-py/pathapi-taran.
[libyang] Loading schema from "/root/ydk-py/cisco-ios-xr/ydk/models/cisco_ios_xr/_yang/Cisco-IOS-XR-ifmgr-cfg.yang" file.
[libyang] Searching for "Cisco-IOS-XR-types" in /root/ydk-py/cisco-ios-xr/ydk/models/cisco_ios_xr/_yang.
[libyang] Searching for "Cisco-IOS-XR-types" in /root/ydk-py/cisco-ios-xr/ydk/models/cisco_ios_xr/_yang/ietf@0.1.5-post2.
[libyang] Searching for "Cisco-IOS-XR-types" in /root/ydk-py/pathapi-taran.
[libyang] Loading schema from "/root/ydk-py/cisco-ios-xr/ydk/models/cisco_ios_xr/_yang/Cisco-IOS-XR-types.yang" file.
[libyang] Module "Cisco-IOS-XR-types@2018-06-29" successfully parsed as implemented.
[libyang] Resolving "Cisco-IOS-XR-ifmgr-cfg" unresolved schema nodes and their constraints...
[libyang] All "Cisco-IOS-XR-ifmgr-cfg" schema nodes and constraints resolved.
[libyang] Module "Cisco-IOS-XR-ifmgr-cfg@2017-09-07" successfully parsed as implemented.
[libyang] Module "Cisco-IOS-XR-cdp-cfg@2017-08-16" successfully parsed as implemented.
Added new libyang module 'Cisco-IOS-XR-cdp-cfg'
Populating new module schema 'Cisco-IOS-XR-cdp-cfg'
Populating augmented schema node 'cdp'
Populating new schema node 'cdp'
Looking to populate schemas for '/Cisco-IOS-XR-cdp-cfg:cdp/timer'
Getting new modules for path '/Cisco-IOS-XR-cdp-cfg:cdp/timer'
Loading module 'Cisco-IOS-XR-cdp-cfg', revision ''
The module 'Cisco-IOS-XR-cdp-cfg' schema has already been populated in YDK repository
Looking to populate schemas for '10'
Getting new modules for path '10'
Creating root data node with path '/Cisco-IOS-XR-cdp-cfg:cdp'
Populating schema for 'timer'
Looking to populate schemas for 'timer'
Getting new modules for path 'timer'
Populating schema for '10'
Looking to populate schemas for '10'
Getting new modules for path '10'
Creating node 'timer' with value '10'
Current path: /Cisco-IOS-XR-cdp-cfg:cdp
Top container path: Cisco-IOS-XR-cdp-cfg:cdp
Populating schema for 'timer'
Looking to populate schemas for 'timer'
Getting new modules for path 'timer'
Getting child schema with path 'timer' in /Cisco-IOS-XR-cdp-cfg:cdp
Getting data nodes with path 'timer'
Creating new data path 'timer' with value '10' in 'cdp'
Looking to populate schemas for '/Cisco-IOS-XR-cdp-cfg:cdp/timer'
Getting new modules for path '/Cisco-IOS-XR-cdp-cfg:cdp/timer'
Loading module 'Cisco-IOS-XR-cdp-cfg', revision ''
The module 'Cisco-IOS-XR-cdp-cfg' schema has already been populated in YDK repository
Looking for schema nodes path in root: '//Cisco-IOS-XR-cdp-cfg:cdp/timer'
Data is invalid according to the yang model. Libyang error: Unexpected character(s) '/' ("/Cisco-IOS-XR-cdp-cfg:cdp/timer").
Traceback (most recent call last):
  File "bugtest.py", line 18, in <module>
    datanode.get_root().find(datanode_path)
RuntimeError: YModelError: Unexpected character(s) '/' ("/Cisco-IOS-XR-cdp-cfg:cdp/timer"). Path:

System Information


ydk (0.8.3)
docker run -it ydkdev/ydk-py
111pontes commented 4 years ago

Related to #1005

ygorelik commented 4 years ago

Not a bug! The function ydk.path.DataNode.find() was designed to get a child node of a parent node. For this operation the path must be relative to the path of the parent node. The failure described in the script was resolved in YDK-0.8.5 while addressing issue #1005.