Open tarkatronic opened 6 years ago
The same error occurs when i serialise data into obj like bellow: KeyError: u'key value must be valid, {\'error-string\': \'vlan_name must be of a type compatible with leafref\', \'generated-type\': \'YANGDynClass(base=ReferenceType(referenced_path=\\'/VLAN/name__\\', caller=self._path() + [\\'vlan_name\\'], path_helper=self._path_helper, require_instance=True), is_leaf=True, yang_name="vlan_name", parent=self, path_helper=self._path_helper, extmethods=self._extmethods, register_paths=True, is_keyval=True, namespace=\\'http://north-api.aliababa.com/schema/vlan\\', defining_module=\\'vlan_schema\\', yang_type=\\'leafref\\', is_config=True)\', \'defined-type\': \'leafref\'}' do you have any suggestion about this ? here is my yang model and json data, thank you:
import ietf-inet-types {
prefix "inet";
}
import common-types {
prefix "common";
}
typedef mtu {
type uint16 {
range "64 .. 9216";
}
}
grouping vlan-config {
list VLAN {
key name__;
leaf name__ {
type string;
description
"VLAN name";
}
container ipAddress {
leaf-list ipv4Address {
type inet:ipv4-prefix;
}
leaf-list ipv6Address {
type inet:ipv6-prefix;
}
leaf ipv6Auto {
type common:enable-status;
}
}
leaf vrf {
type string;
}
leaf adminStatus {
type common:status;
}
leaf aclIn {
type string;
}
leaf aclOut {
type string;
}
leaf mtu {
type mtu;
}
leaf arpProxy {
type common:status;
}
leaf description {
type string;
}
leaf dhcpRelaySrcIP {
type inet:ip-address;
}
leaf-list dhcpSever {
type inet:ip-address;
}
leaf ndpProxy {
type common:enable-status;
}
}
}
grouping vlan_ip {
list VLAN_IP {
key vlan_name;
leaf vlan_name {
type leafref{
path "/VLAN/name__";
}
}
container ipAddress {
leaf-list ipv4Address {
type inet:ipv4-prefix;
}
leaf-list ipv6Address {
type inet:ipv6-prefix;
}
}
}
}
uses vlan_ip;
uses vlan-config;
}`
{ "VLAN_IP":{ "VLAN10":{ "ipAddress":{ "ipv6Address":[ "fe00::1/64", "fe00::2/64" ] }, "vlan_name":"VLAN10" } }, "VLAN":{ "VLAN10":{ "adminStatus":"down", "description":"default gateway", "ndpProxy":"enable", "aclIn":"AL01", "name__":"VLAN10", "aclOut":"AL02", "mtu":9100, "vrf":"golbal", "arpProxy":"up", "ipAddress":{ "ipv4Address":[ "11.210.88.1/30", "192.168.0.1/30" ], "ipv6Auto":"enable", "ipv6Address":[ "fe00::1/64", "fe00::2/64" ] }, "dhcpSever":[ "100.0.0.2" ], "dhcpRelaySrcIP":"12.162.231.2" } } }
This was discovered while converting xpath tests to use unittest. Specifically in
tests.xpath.01-list_leaflist.XPathListLeaflistTests.test_standalone_ref
.Given this section of the YANG model:
This test would fail:
With this error message:
This is due to the absence of a line calling
self.instance.standalone.l.add(1)
.While this is a valid error, the message could be a little more helpful. I don't have a solid suggestion on how to change it, but mentioning that the value assigned must be in the list of values added to the referred leaf would be much more helpful.