Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Path API decode fails on XML payload when root_schema_node uses empty Capabilities list #1004

Open
tdesh10 opened this issue Jul 2, 2020 · 3 comments
Labels

Comments

@tdesh10
Copy link

tdesh10 commented Jul 2, 2020

Expected Behavior

ydk.path.Codec.decode(root_schema_node, payload, encoding) should return the root datanode when root_schema_node uses empty Capabilities list.

Current Behavior

ydk.path.Codec.decode(root_schema_node, payload, encoding) fails with an XML payload and an empty Capabilities list. It does not fail with a JSON payload. Note that ydk.path.Codec.encode(data_node, encoding, pretty) works correctly when root_schema_node uses empty Capabilities list regardless of the encoding.

Steps to Reproduce

Execute the script below in ydk-py docker container.

Your Script

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

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

jsonfile = """{
    "Cisco-IOS-XR-cdp-cfg:cdp": {
      "timer": 10,
      "enable": true,
      "hold-time": 30,
      "log-adjacency": [null]
    }
  }
"""

xmlfile = """<cdp xmlns="http://cisco.com/ns/yang/Cisco-IOS-XR-cdp-cfg">
  <enable>true</enable>
  <hold-time>60</hold-time>
  <log-adjacency></log-adjacency>
  <timer>15</timer>
</cdp>
"""

# codec.decode(root_schema, jsonfile, EncodingFormat.JSON)
codec.decode(root_schema, xmlfile, EncodingFormat.XML)

This script produces the following output:

Traceback (most recent call last):
  File "bugtest.py", line 32, in <module>
    codec.decode(root_schema, xmlfile, EncodingFormat.XML)
RuntimeError: YCoreError: YCodecError:Data model "//cisco.com/ns/yang/Cisco-IOS-XR-cdp-cfg" not found.. Path: 

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'
ydk::path::Codec: Decoding from XML formatted payload:
<cdp xmlns="http://cisco.com/ns/yang/Cisco-IOS-XR-cdp-cfg">
  <enable>true</enable>
  <hold-time>60</hold-time>
  <log-adjacency></log-adjacency>
  <timer>15</timer>
</cdp>

Populating new schema from payload:
<cdp xmlns="http://cisco.com/ns/yang/Cisco-IOS-XR-cdp-cfg">
  <enable>true</enable>
  <hold-time>60</hold-time>
  <log-adjacency></log-adjacency>
  <timer>15</timer>
</cdp>

Extracting module namespaces from XML payload
Loading module '//cisco.com/ns/yang/Cisco-IOS-XR-cdp-cfg', revision ''
[libyang] Searching for "//cisco.com/ns/yang/Cisco-IOS-XR-cdp-cfg" in /root/ydk-py/cisco-ios-xr/ydk/models/cisco_ios_xr/_yang.
[libyang] Searching for "//cisco.com/ns/yang/Cisco-IOS-XR-cdp-cfg" in /root/ydk-py/cisco-ios-xr/ydk/models/cisco_ios_xr/_yang/[email protected].
[libyang] Searching for "//cisco.com/ns/yang/Cisco-IOS-XR-cdp-cfg" in /root/ydk-py/pathapi-taran.
Data is invalid according to the yang model. Libyang error: Data model "//cisco.com/ns/yang/Cisco-IOS-XR-cdp-cfg" not found.
Parsing failed with message Data model "//cisco.com/ns/yang/Cisco-IOS-XR-cdp-cfg" not found.
Traceback (most recent call last):
  File "bugtest.py", line 32, in <module>
    codec.decode(root_schema, xmlfile, EncodingFormat.XML)
RuntimeError: YCoreError: YCodecError:Data model "//cisco.com/ns/yang/Cisco-IOS-XR-cdp-cfg" not found.. Path: 

System Information

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

@111pontes 111pontes added the bug label Jul 2, 2020
@ygorelik
Copy link
Collaborator

ygorelik commented Jul 4, 2020

This is not a bug. This is the case where you have to supply to create_root_schema function not only capabilities, but a lookup table as well. These parameters are needed to give YDK mapping of namespaces to YANG module names.
In case of JSON encoding the module names are explicitly specified in payload, which allows user create root schema with empty capabilities.

@111pontes
Copy link
Collaborator

Repository already has all YANG files and can auto-generate such mapping if not specified by the user. There's no reason to ask the user to provide such info if the YANG files have been specified already.

@ygorelik
Copy link
Collaborator

ygorelik commented Aug 3, 2020 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants