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

Path API does not validate leafref properly #1001

Open 111pontes opened 4 years ago

111pontes commented 4 years ago

The schema path /oc-if:interfaces/interface/name is a leafref pointing to /oc-if:interfaces/interface/config/name. Validation should raise an exception if the values do not match in a payload. In the following example, the former has a value of Loopback0 and the latter has a value of Loopback1. Validation testing should cover this scenario.

Script

#!/usr/bin/env python3

from ydk.path import Repository, Capability, Codec
from ydk.types import EncodingFormat

payload = '''
<interfaces xmlns="http://openconfig.net/yang/interfaces">
  <interface>
    <name>Loopback0</name>
    <config>
      <name>Loopback1</name>
      <description>Lo0 interface description</description>
      <mtu>1500</mtu>
    </config>
  </interface>
</interfaces>
'''

repo = Repository('/home/host/.ydk/router')
caps = [Capability('openconfig-interfaces', '')]
root_schema = repo.create_root_schema(caps)

codec = Codec()

data_node = codec.decode(root_schema, payload, EncodingFormat.XML)

print(codec.encode(data_node, EncodingFormat.JSON, True))

Output:

user@host$ ./test.py 
{
  "openconfig-interfaces:interfaces": {
    "interface": [
      {
        "name": "Loopback0",
        "config": {
          "name": "Loopback1",
          "description": "Lo0 interface description",
          "mtu": 1500
        }
      }
    ]
  }
}

Segmentation fault
user@host$ 

System:

Ubuntu Bionic running:

user@host$ pip list | grep "ydk "
ydk                      0.8.4
user@host$