CiscoDevNet / ydk-gen

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

create_datanode in Path API returns incorrect object and sets incorrect value #1003

Closed tdesh10 closed 4 years ago

tdesh10 commented 4 years ago

Expected Behavior

ydk.path.DataNode.create_datanode(path, value=None) should return the datanode object at path and set the specified value.

Current Behavior

In some cases, ydk.path.DataNode.create_datanode(path, value=None) creates the expected datanode, but with value "" and returns a sibling datanode.

Steps to Reproduce

Execute the script below in ydk-py docker container.

Your Script

#!/usr/bin/python3
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-ifmgr-cfg:interface-configurations/interface-configuration[active='act'][interface-name='Loopback0']/description"
datanode_value = "PRIMARY ROUTER LOOPBACK"

datanode = root_schema.create_datanode(datanode_path, datanode_value)

print('In:  {}\n     "{}"\n'.format(datanode_path, datanode_value))
print('Out: {}\n     "{}"\n'.format(datanode.get_path(), datanode.get_value()))
print('     {}\n     "{}"\n'.format(datanode_path, datanode.get_root().find(datanode_path)[0].get_value()))
assert(datanode_path == datanode.get_path())

This script produces the following output:

In:  Cisco-IOS-XR-ifmgr-cfg:interface-configurations/interface-configuration[active='act'][interface-name='Loopback0']/description
     "PRIMARY ROUTER LOOPBACK"

Out: /Cisco-IOS-XR-ifmgr-cfg:interface-configurations/interface-configuration[active='act'][interface-name='Loopback0']/active
     "act"

     Cisco-IOS-XR-ifmgr-cfg:interface-configurations/interface-configuration[active='act'][interface-name='Loopback0']/description
     ""

Traceback (most recent call last):
  File "./bugtest.py", line 20, in <module>
    assert(datanode_path == datanode.get_path())
AssertionError

Logs

Output with DEBUG logging

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-ifmgr-cfg:interface-configurations/interface-configuration[active='act'][interface-name='Loopback0']/description'
Loading module 'Cisco-IOS-XR-ifmgr-cfg', revision ''
[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.
Added new libyang module 'Cisco-IOS-XR-ifmgr-cfg'
Populating new module schema 'Cisco-IOS-XR-ifmgr-cfg'
Looking to populate schemas for 'Cisco-IOS-XR-ifmgr-cfg:interface-configurations/interface-configuration[active='act'][interface-name='Loopback0']/description'
Getting new modules for path 'Cisco-IOS-XR-ifmgr-cfg:interface-configurations/interface-configuration[active='act'][interface-name='Loopback0']/description'
Loading module 'Cisco-IOS-XR-ifmgr-cfg', revision ''
The module 'Cisco-IOS-XR-ifmgr-cfg' schema has already been populated in YDK repository
Looking to populate schemas for 'PRIMARY ROUTER LOOPBACK'
Getting new modules for path 'PRIMARY ROUTER LOOPBACK'
Creating root data node with path '/Cisco-IOS-XR-ifmgr-cfg:interface-configurations'
Populating schema for 'interface-configuration[active='act'][interface-name='Loopback0']/description'
Looking to populate schemas for 'interface-configuration[active='act'][interface-name='Loopback0']/description'
Getting new modules for path 'interface-configuration[active='act'][interface-name='Loopback0']/description'
Creating node 'interface-configuration[active='act'][interface-name='Loopback0']/description' with value ''
Current path: /Cisco-IOS-XR-ifmgr-cfg:interface-configurations
Top container path: Cisco-IOS-XR-ifmgr-cfg:interface-configurations
Populating schema for 'interface-configuration[active='act'][interface-name='Loopback0']'
Looking to populate schemas for 'interface-configuration[active='act'][interface-name='Loopback0']'
Getting new modules for path 'interface-configuration[active='act'][interface-name='Loopback0']'
Getting child schema with path 'interface-configuration[active='act'][interface-name='Loopback0']' in /Cisco-IOS-XR-ifmgr-cfg:interface-configurations
Getting data nodes with path 'interface-configuration[active='act'][interface-name='Loopback0']'
Creating new data path 'interface-configuration[active='act'][interface-name='Loopback0']' in 'interface-configurations'
Creating new data path 'description' with value '' in 'interface-configuration'
In:  Cisco-IOS-XR-ifmgr-cfg:interface-configurations/interface-configuration[active='act'][interface-name='Loopback0']/description
     "PRIMARY ROUTER LOOPBACK"

Out: /Cisco-IOS-XR-ifmgr-cfg:interface-configurations/interface-configuration[active='act'][interface-name='Loopback0']/active
     "act"

Looking to populate schemas for 'Cisco-IOS-XR-ifmgr-cfg:interface-configurations/interface-configuration[active='act'][interface-name='Loopback0']/description'
Getting new modules for path 'Cisco-IOS-XR-ifmgr-cfg:interface-configurations/interface-configuration[active='act'][interface-name='Loopback0']/description'
Loading module 'Cisco-IOS-XR-ifmgr-cfg', revision ''
The module 'Cisco-IOS-XR-ifmgr-cfg' schema has already been populated in YDK repository
Looking for schema nodes path in root: '/Cisco-IOS-XR-ifmgr-cfg:interface-configurations/interface-configuration[active='act'][interface-name='Loopback0']/description'
     Cisco-IOS-XR-ifmgr-cfg:interface-configurations/interface-configuration[active='act'][interface-name='Loopback0']/description
     ""

Traceback (most recent call last):
  File "./bugtest.py", line 20, in <module>
    assert(datanode_path == datanode.get_path())
AssertionError

System Information

ydk (0.8.3) docker run -it ydkdev/ydk-py

ygorelik commented 4 years ago

Resolved in YDK-0.8.5.